/// <summary> /// Adds a folder to the zip file /// </summary> /// <param name="Folder">Folder to add</param> public virtual void AddFolder(string Folder) { Folder.ThrowIfNullOrEmpty("Folder"); Folder = new DirectoryInfo(Folder).FullName; if (Folder.EndsWith(@"\")) Folder = Folder.Remove(Folder.Length - 1); using (Package Package = ZipPackage.Open(ZipFileStream, FileMode.OpenOrCreate)) { new DirectoryInfo(Folder) .GetFiles() .ForEach(x => AddFile(x.FullName.Replace(Folder, ""), x, Package)); } }
public virtual void AddFolder(string Folder) { Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(Folder), "Folder"); Folder = new DirectoryInfo(Folder).FullName; if (Folder.EndsWith(@"\", StringComparison.InvariantCulture)) Folder = Folder.Remove(Folder.Length - 1); using (Package Package = ZipPackage.Open(ZipFileStream, FileMode.OpenOrCreate)) { new DirectoryInfo(Folder) .GetFiles() .ForEach(x => AddFile(x.FullName.Replace(Folder, ""), x, Package)); } }
private static bool IsIgnoredDirectory(string sourcePath) { var sourcePathLowerAbsolute = new DirectoryInfo(sourcePath).FullName.ToLower(); var apiPath = new DirectoryInfo( Path.Combine( Directory.GetCurrentDirectory(), Settings.Default.SourceDirectory, Settings.Default.APIFolderLocation)).FullName.ToLower(); return !sourcePathLowerAbsolute.StartsWith(apiPath) && IgnoredFolders.Any(e => sourcePathLowerAbsolute.EndsWith(Path.DirectorySeparatorChar + e)); }
/// <summary> /// Writes the REST file for a given type /// </summary> /// <param name="rootFolder"></param> /// <param name="type"></param> private void WriteRESTFile( string rootFolder, Type type ) { string pluralizedName = pls.Pluralize( type.Name ); string baseName = new DirectoryInfo( rootFolder ).Name; if ( baseName.EndsWith( ".Rest", StringComparison.OrdinalIgnoreCase ) ) { baseName = baseName.Substring( 0, baseName.Length - 5 ); } string restNamespace = type.Namespace; if ( restNamespace.StartsWith( baseName + ".", true, null ) ) { restNamespace = baseName + ".Rest" + restNamespace.Substring( baseName.Length ); } else { restNamespace = ".Rest." + restNamespace; } restNamespace = restNamespace.Replace( ".Model", ".Controllers" ); var sb = new StringBuilder(); sb.AppendLine( "//------------------------------------------------------------------------------" ); sb.AppendLine( "// <auto-generated>" ); sb.AppendLine( "// This code was generated by the Rock.CodeGeneration project" ); sb.AppendLine( "// Changes to this file will be lost when the code is regenerated." ); sb.AppendLine( "// </auto-generated>" ); sb.AppendLine( "//------------------------------------------------------------------------------" ); sb.AppendLine( "// <copyright>" ); sb.AppendLine( "// Copyright 2013 by the Spark Development Network" ); sb.AppendLine( "//" ); sb.AppendLine( "// Licensed under the Apache License, Version 2.0 (the \"License\");" ); sb.AppendLine( "// you may not use this file except in compliance with the License." ); sb.AppendLine( "// You may obtain a copy of the License at" ); sb.AppendLine( "//" ); sb.AppendLine( "// http://www.apache.org/licenses/LICENSE-2.0" ); sb.AppendLine( "//" ); sb.AppendLine( "// Unless required by applicable law or agreed to in writing, software" ); sb.AppendLine( "// distributed under the License is distributed on an \"AS IS\" BASIS," ); sb.AppendLine( "// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied." ); sb.AppendLine( "// See the License for the specific language governing permissions and" ); sb.AppendLine( "// limitations under the License." ); sb.AppendLine( "// </copyright>" ); sb.AppendLine( "//" ); sb.AppendLine( "" ); sb.AppendFormat( "using {0};" + Environment.NewLine, type.Namespace ); sb.AppendLine( "" ); sb.AppendFormat( "namespace {0}" + Environment.NewLine, restNamespace ); sb.AppendLine( "{" ); sb.AppendLine( " /// <summary>" ); sb.AppendFormat( " /// {0} REST API" + Environment.NewLine, pluralizedName ); sb.AppendLine( " /// </summary>" ); sb.AppendFormat( " public partial class {0}Controller : Rock.Rest.ApiController<{1}.{2}>" + Environment.NewLine, pluralizedName, type.Namespace, type.Name ); sb.AppendLine( " {" ); sb.AppendFormat( " public {0}Controller() : base( new {1}.{2}Service( new Rock.Data.RockContext() ) ) {{ }} " + Environment.NewLine, pluralizedName, type.Namespace, type.Name ); sb.AppendLine( " }" ); sb.AppendLine( "}" ); var file = new FileInfo( Path.Combine( NamespaceFolder( rootFolder, restNamespace ).FullName, "CodeGenerated", pluralizedName + "Controller.cs" ) ); WriteFile( file, sb ); }
/// <summary> /// Writes the REST file for a given type /// </summary> /// <param name="rootFolder"></param> /// <param name="type"></param> private void WriteRESTFile( string rootFolder, Type type ) { string pluralizedName = pls.Pluralize( type.Name ); string baseName = new DirectoryInfo( rootFolder ).Name; if ( baseName.EndsWith( ".Rest", StringComparison.OrdinalIgnoreCase ) ) { baseName = baseName.Substring( 0, baseName.Length - 5 ); } string restNamespace = type.Namespace; if ( restNamespace.StartsWith( baseName + ".", true, null ) ) { restNamespace = baseName + ".Rest" + restNamespace.Substring( baseName.Length ); } else { restNamespace = ".Rest." + restNamespace; } restNamespace = restNamespace.Replace( ".Model", ".Controllers" ); var properties = GetEntityProperties( type ); var sb = new StringBuilder(); sb.AppendLine( "//------------------------------------------------------------------------------" ); sb.AppendLine( "// <auto-generated>" ); sb.AppendLine( "// This code was generated by the Rock.CodeGeneration project" ); sb.AppendLine( "// Changes to this file will be lost when the code is regenerated." ); sb.AppendLine( "// </auto-generated>" ); sb.AppendLine( "//------------------------------------------------------------------------------" ); sb.AppendLine( "//" ); sb.AppendLine( "// THIS WORK IS LICENSED UNDER A CREATIVE COMMONS ATTRIBUTION-NONCOMMERCIAL-" ); sb.AppendLine( "// SHAREALIKE 3.0 UNPORTED LICENSE:" ); sb.AppendLine( "// http://creativecommons.org/licenses/by-nc-sa/3.0/" ); sb.AppendLine( "//" ); sb.AppendLine( "" ); sb.AppendFormat( "using {0};" + Environment.NewLine, type.Namespace ); sb.AppendLine( "" ); sb.AppendFormat( "namespace {0}" + Environment.NewLine, restNamespace ); sb.AppendLine( "{" ); sb.AppendLine( " /// <summary>" ); sb.AppendFormat( " /// {0} REST API" + Environment.NewLine, pluralizedName ); sb.AppendLine( " /// </summary>" ); sb.AppendFormat( " public partial class {0}Controller : Rock.Rest.ApiController<{1}.{2}, {1}.{2}Dto>" + Environment.NewLine, pluralizedName, type.Namespace, type.Name ); sb.AppendLine( " {" ); sb.AppendFormat( " public {0}Controller() : base( new {1}.{2}Service() ) {{ }} " + Environment.NewLine, pluralizedName, type.Namespace, type.Name ); sb.AppendLine( " }" ); sb.AppendLine( "}" ); var file = new FileInfo( Path.Combine( NamespaceFolder( rootFolder, restNamespace ).FullName, "CodeGenerated", pluralizedName + "Controller.cs" ) ); WriteFile( file, sb ); }