Click here to Skip to main content
15,885,216 members
Articles / Web Development / HTML

Gallery Server Pro - An ASP.NET Gallery for Sharing Photos, Video, Audio and Other Media

Rate me:
Please Sign up or sign in to vote.
4.86/5 (131 votes)
18 Oct 2013GPL331 min read 825.2K   539  
Gallery Server Pro is a complete, stable ASP.NET gallery for sharing photos, video, audio and other media. This article presents the overall architecture and major features.
// Brandon Haynes - http://brandonhaynes.org
// Copyright (c) 2008
// by Brandon Haynes

// Please refer to the project license, located at http://www.codeplex.com/DNNLocalization/license

// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.

//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
//USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

using System;
using System.CodeDom;
using System.Globalization;
using System.Linq;

namespace BrandonHaynes.DotNetNukeResXBuildProvider
{
	internal static class Extensions
	{
		public static CodeCompileUnit Adapt(this CodeCompileUnit code, ResourcePathMetadata resourceMetaData)
		{
			// Single namespace, single class in this unit
			var codeClass = code.Namespaces.Cast<CodeNamespace>().Single().Types.Cast<CodeTypeDeclaration>().Single();

			// Locate property "ResourceManager"
			var resourceManager = codeClass.Members.OfType<CodeMemberProperty>().Single(member => member.Name == "ResourceManager");

			// Clear existing ResourceManager_get statements
			resourceManager.GetStatements.Clear();

			// Add adapted statements to property getter:

			// if(resourceMan == null) 
			//		resourceMan = new BrandonHaynes.DotNetNukeResXBuildProvider.DecoratedHybridResourceManager(typeName, virtualPath); 
			resourceManager.GetStatements.Add(
				new CodeConditionStatement(
					new CodeBinaryOperatorExpression(
						new CodeVariableReferenceExpression("resourceMan"),
						CodeBinaryOperatorType.IdentityEquality,
						new CodePrimitiveExpression(null)),
					new CodeAssignStatement(
					new CodeVariableReferenceExpression("resourceMan"),
					new CodeObjectCreateExpression("BrandonHaynes.DotNetNukeResXBuildProvider.DecoratedHybridResourceManager",
						new CodeTypeOfExpression(resourceMetaData.QualifiedTypeName),
						new CodePrimitiveExpression(resourceMetaData.VirtualPath)))));

			// return resourceMan;
			resourceManager.GetStatements.Add(
				new CodeMethodReturnStatement(
					new CodeVariableReferenceExpression("resourceMan")));

			return code;
		}

		public static bool TryGetCulture(string name, out CultureInfo culture)
		{
			try
			{
				culture = CultureInfo.GetCultureInfo(name);
			}
			catch (ArgumentException)
			{
				culture = CultureInfo.InvariantCulture;
			}

			return culture != CultureInfo.InvariantCulture;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) Tech Info Systems
United States United States
I have nearly 20 years of industry experience in software development, architecture, and Microsoft Office products. My company Tech Info Systems provides custom software development services for corporations, governments, and other organizations. Tech Info Systems is a registered member of the Microsoft Partner Program and I am a Microsoft Certified Professional Developer (MCPD).

I am the creator and lead developer of Gallery Server Pro, a free, open source ASP.NET gallery for sharing photos, video, audio, documents, and other files over the web. It has been developed over several years and has involved thousands of hours. The end result is a robust, configurable, and professional grade gallery that can be integrated into your web site, whether you are a large corporation, small business, professional photographer, or a local church.

Comments and Discussions