Exemplo n.º 1
0
        private void RenderDataContextFactory()
        {
            _hdrUtil.WriteClassHeader(_output);

            _output.autoTabLn("using System.Configuration;");
            _output.autoTabLn("using System.Data.Linq;");
            _output.autoTabLn("using System.Data.Linq.Mapping;");
            _output.autoTabLn("");
            _output.autoTabLn("namespace " + StringFormatter.ConvertPathToNamespace(_script.Settings.Namespace + ".DataObjects") + "." + _script.Settings.DataOptions.ORMFramework.Selected);
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("public static class DataContextFactory");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("private static readonly string _connectionString;");
            _output.autoTabLn("private static readonly MappingSource _mappingSource;");
            _output.autoTabLn("");
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Static constructor.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <remarks>");
            _output.autoTabLn("/// Static initialization of connectionstring and mappingSource.");
            _output.autoTabLn("/// This significantly increases performance, primarily due to mappingSource cache.");
            _output.autoTabLn("/// </remarks>		");
            _output.autoTabLn("static DataContextFactory()");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("string connectionStringName = ConfigurationManager.AppSettings.Get(\"ConnectionStringName\");");
            _output.autoTabLn("_connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;");
            _output.tabLevel--;
            _output.autoTabLn("");
            _output.tabLevel++;
            _output.autoTabLn("DataContext context = new " + _script.Settings.DataOptions.DataContext.Name + "(_connectionString);");
            _output.autoTabLn("_mappingSource = context.Mapping.MappingSource;");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Rapidly creates a new DataContext using cached connectionstring and mapping source.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <returns></returns>");
            _output.autoTabLn("public static " + _script.Settings.DataOptions.DataContext.Name + " CreateContext()");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("return new " + _script.Settings.DataOptions.DataContext.Name + "(_connectionString, _mappingSource);");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");

            _context.FileList.Add("    DataContextFactory.cs");
            SaveOutput(CreateFullPath(_script.Settings.DataOptions.DataObjectsNamespace + "\\" + _script.Settings.DataOptions.ORMFramework.Selected, "DataContextFactory.cs"), SaveActions.Overwrite);
        }
Exemplo n.º 2
0
        private void RenderVersionConverter()
        {
            _hdrUtil.WriteClassHeader(_output);

            _output.autoTabLn("using System;");
            _output.autoTabLn("using System.Data.Linq;");
            _output.autoTabLn("");
            _output.autoTabLn("namespace " + StringFormatter.ConvertPathToNamespace(_script.Settings.Namespace + ".DataObjects") + "." + _script.Settings.DataOptions.ORMFramework.Selected);
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("public static class VersionConverter");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Converts binary value to string.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <param name=\"version\">Binary version number.</param>");
            _output.autoTabLn("/// <returns>Base64 version number.</returns>");
            _output.autoTabLn("public static string ToString(Binary version)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("if (version == null)");
            _output.tabLevel++;
            _output.autoTabLn("return null;");
            _output.tabLevel--;
            _output.autoTabLn("");
            _output.autoTabLn("return Convert.ToBase64String(version.ToArray());");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Converts string to binary value.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <param name=\"version\">Base64 version number.</param>");
            _output.autoTabLn("/// <returns>Binary version number.</returns>");
            _output.autoTabLn("public static Binary ToBinary(string version)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("if (string.IsNullOrEmpty(version))");
            _output.tabLevel++;
            _output.autoTabLn("return null;");
            _output.tabLevel--;
            _output.autoTabLn("");
            _output.autoTabLn("return new Binary(Convert.FromBase64String(version));");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");

            _context.FileList.Add("    VersionConverter.cs");
            SaveOutput(CreateFullPath(_script.Settings.DataOptions.DataObjectsNamespace + "\\" + _script.Settings.DataOptions.ORMFramework.Selected, "VersionConverter.cs"), SaveActions.Overwrite);
        }