Commit 3d77de43 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+359 −0

File added.

Preview size limit exceeded, changes collapsed.

+687 KiB

File added.

No diff preview for this file type.

+73 −0
Changes for AspNetGallery/Lib/AspNetGallery.Extensions/AspNetGallery.Extensions.csproj: 73 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{35219575-A9B0-42CD-B7AD-40A70E04DD61}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>AspNetGallery.Extensions</RootNamespace>
    <AssemblyName>AspNetGallery.Extensions</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Web" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Controls\FixedTextBox.cs" />
    <Compile Include="Handlers\DynImageHandler.cs" />
    <None Include="Handlers\WpfDynImageHandler.cs" />
    <Compile Include="Handlers\NorthwindPhotoImageHandler.cs" />
    <Compile Include="Handlers\PictureViewerHandler.cs" />
    <Compile Include="Handlers\PictureViewerInfo.cs" />
    <Compile Include="Handlers\SimpleHandler.cs" />
    <Compile Include="Modules\LoggingModule.cs" />
    <Compile Include="Modules\QueryString\QueryStringDescriptor.cs" />
    <Compile Include="Modules\QueryString\QueryStringErrorCodes.cs" />
    <Compile Include="Modules\QueryString\QueryStringHelper.cs" />
    <Compile Include="Modules\QueryString\QueryStringModule.cs" />
    <Compile Include="Modules\MarkerModule.cs" />
    <Compile Include="Modules\QueryString\QueryStringParamCollection.cs" />
    <Compile Include="Modules\QueryString\QueryStringParamInfo.cs" />
    <Compile Include="Modules\QueryString\QueryStringParamTypes.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Utilities\ControlExtensions.cs" />
    <Compile Include="Utilities\StringExtensions.cs" />
  </ItemGroup>
  <ItemGroup />
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>
 No newline at end of file
+30 −0
Changes for AspNetGallery/Lib/AspNetGallery.Extensions/Controls/FixedTextBox.cs: 30 added lines, 0 removed lines.
Original line number Diff line number Diff line
using System;
using System.Collections.Specialized;
using System.Web.UI.WebControls;


namespace AspNetGallery.Extensions.Controls
{
    public class FixedTextBox : TextBox
    {
        protected override Boolean LoadPostData(String postDataKey, NameValueCollection postCollection)
        {
            var updated = base.LoadPostData(postDataKey, postCollection);
            if (updated)
            {
                Text = Text.Substring(0, MaxLength);
            }

            return updated;
        }


        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            var ctl = new HiddenField();
            ctl.ID = ID + "_ReadOnly";
            Controls.Add(ctl);
        }
    }
}
 No newline at end of file
+108 −0
Changes for AspNetGallery/Lib/AspNetGallery.Extensions/Handlers/DynImageHandler.cs: 108 added lines, 0 removed lines.
Original line number Diff line number Diff line
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.IO;
using System.Configuration;

namespace AspNetGallery.Extensions.Handlers
{
    public class DynImageHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            // Process the URL param
            var o1 = context.Request["url"];
            if (o1 == null)
            {
                context.Response.Write("No image found.");
                context.Response.End();
                return;
            }
            var file = context.Server.MapPath(o1);

            // Process the thumbnail param
            var useThumbnail = false;
            var o2 = context.Request["small"];
            if (o2 != null)
            {
                Boolean.TryParse(o2, out useThumbnail);
            }

            // Read copyright string from AppSettings
            var msg = ConfigurationManager.AppSettings["CopyrightNoteForImages"];
            if (File.Exists(file))
            {
                Bitmap bmp;
                if (useThumbnail)
                    bmp = GetThumbnail(file);
                else
                    bmp = AddCopyright(file, msg);

                context.Response.ContentType = "image/jpeg";
                bmp.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                bmp.Dispose();
            }
            else
            {
                context.Response.Write("No image found.");
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        #region Helpers
        private static Bitmap GetThumbnail(string file)
        {
            var bmp = new Bitmap(file);
            var newImg = (Bitmap) bmp.GetThumbnailImage(
                bmp.Width / 2, bmp.Height / 2, null, IntPtr.Zero);
            return newImg;
        }

        private static Bitmap AddCopyright(string file, string msg)
        {
            // Load the file and create the graphics
            var bmp = new Bitmap(file);
            var g = Graphics.FromImage(bmp);

            // Define text alignment
            var strFmt = new StringFormat {Alignment = StringAlignment.Center};

            // Create brushes for the bottom writing
            // (green text on black background)
            var btmForeColor = new SolidBrush(Color.PaleGreen);
            var btmBackColor = new SolidBrush(Color.Black);

            // To calculate writing coordinates, obtain the size of the text
            // given font typeface and size
            var btmFont = new Font("Verdana", 7);
            var textSize = g.MeasureString(msg, btmFont);

            // Calculate the output rectangle and fill
            float x = (bmp.Width - textSize.Width - 3);
            float y = (bmp.Height - textSize.Height - 3);
            float w = (x + textSize.Width);
            float h = (y + textSize.Height);
            var textArea = new RectangleF(x, y, w, h);
            g.FillRectangle(btmBackColor, textArea);

            // Draw the text and free resources
            g.DrawString(msg, btmFont, btmForeColor, textArea);
            btmForeColor.Dispose();
            btmBackColor.Dispose();
            btmFont.Dispose();
            g.Dispose();

            return bmp;
        }
        #endregion
    }
}
 No newline at end of file
Loading