public void GenerateConfigurationClass(VSNetCSharpProject utProj) { TraceInfoEvent.Raise("Adding configuration class."); utProj.AddFile(GenerationHelper.GetConfigClassFileName()); CSharpFile file = CSharpFilePool.Obtain(Path.Combine(m_Arch.UtilityLayer.FullPath, GenerationHelper.GetConfigClassFileName())); file.NameSpace = m_Arch.UtilityLayer.NameSpace; file.Description = "Class handling configuration"; file.Usings.Add("System.Data"); file.Usings.Add("Grepton.Runtime"); file.Usings.Add("Grepton.Runtime.BusinessHosting"); CSharpTypeDef typeDef = new CSharpTypeDef(); file.InnerTypes.Add(typeDef); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = "public class Configuration: ConfigurationBase"; foreach (DataAccessModel model in m_Arch.DataLayers) { if ((model.UsingClause != string.Empty) && !file.Usings.Contains(model.UsingClause)) { file.Usings.Add(model.UsingClause); } CSharpPropertyDef def2 = new CSharpPropertyDef(); typeDef.Properties.Add(def2); def2.HeaderLine = string.Format("public static string {0}ConnStr", model.ConfigKeyName); def2.Comment.Summary = string.Format("Get connection string for '{0}'", model.LayerName); TextWriter getWriter = def2.GetWriter; getWriter.WriteLine("try"); getWriter.WriteLine("{"); getWriter.WriteLine(" return GetConfigString(CONFIG_SECTION, \"{0}\");", model.ConfigKeyName); getWriter.WriteLine("}"); getWriter.WriteLine("catch"); getWriter.WriteLine("{"); getWriter.WriteLine(" return String.Empty;"); getWriter.WriteLine("}"); CSharpPropertyDef def3 = new CSharpPropertyDef(); typeDef.Properties.Add(def3); def3.HeaderLine = string.Format("public static {0} {1}Connection", model.ConnectionClass, model.ConfigKeyName); def3.Comment.Summary = string.Format("Get connection instance for '{0}'", model.LayerName); getWriter = def3.GetWriter; getWriter.WriteLine("if ({0}ConnStr == String.Empty)", model.ConfigKeyName); getWriter.WriteLine(" return new {0}(@\"{1}\");", model.ConnectionClass, model.ConnectionString); getWriter.WriteLine("else"); getWriter.WriteLine(" return new {0}({1}ConnStr);", model.ConnectionClass, model.ConfigKeyName); } }
public void GenerateLocalServiceFactory(VSNetCSharpProject bsProj, ServiceLayerModel svLayer) { string localSFClassFileName = GenerationHelper.GetLocalSFClassFileName(); string str2 = svLayer.FullPath + localSFClassFileName; bsProj.AddFile(localSFClassFileName); CSharpFile file = CSharpFilePool.Obtain(str2); TraceInfoEvent.Raise("Adding local service factory class."); file.Description = "Local service factory class."; file.NameSpace = bsProj.ProjectName; file.Usings.Add("Grepton.Runtime"); file.Usings.Add("Grepton.Runtime.DBTypes"); file.Usings.Add("Grepton.Runtime.BusinessHosting"); file.Usings.Add(m_Arch.BusinessDocsLayer.NameSpace); CSharpTypeDef typeDef = new CSharpTypeDef(); file.InnerTypes.Add(typeDef); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = "public class LocalServiceFactory: IServiceFactory"; foreach (ServiceModel model in svLayer.Services) { CSharpMethodDef def2 = new CSharpMethodDef(); def2.Comment.Summary = string.Format("Gets the service interface for '{0}'.", model.MappingName); def2.HeaderLine = string.Format("public I{0} Get{0}", model.MappingName); def2.Writer.WriteLine("return new {0}();", model.MappingName); typeDef.Methods.Add(def2); } }
public void GenerateServiceSnippets(VSNetCSharpProject bsProj, ServiceLayerModel svLayer) { foreach (ServiceModel model in svLayer.Services) { string serviceFileName = GenerationHelper.GetServiceFileName(model); string str2 = svLayer.FullPath + serviceFileName; bsProj.AddFile(serviceFileName); CSharpFile docFile = CSharpFilePool.Obtain(str2); docFile.NameSpace = bsProj.ProjectName; TraceInfoEvent.Raise(string.Format("Adding service snippet for '{0}'.", model.MappingName)); GenerateSnippetService(docFile, model); } }
public void GenerateSnippetInterfaces(VSNetCSharpProject bdProj) { string projectName = bdProj.ProjectName; foreach (ServiceLayerModel model in m_Arch.ServiceLayers) { foreach (ServiceModel model2 in model.Services) { string interfaceFileName = GenerationHelper.GetInterfaceFileName(model2); string str3 = m_Arch.BusinessDocsLayer.FullPath + interfaceFileName; bdProj.AddFile(interfaceFileName); CSharpFile docFile = CSharpFilePool.Obtain(str3); docFile.NameSpace = projectName; TraceInfoEvent.Raise(string.Format("Adding snippet interface for '{0}'.", model2.MappingName)); GenerateSnippetInterface(docFile, model2); } } }
public void GenerateSnippetDocs(VSNetCSharpProject bdProj) { string projectName = bdProj.ProjectName; foreach (BusinessDocModel model in m_Arch.BusinessDocsLayer.Documents) { DataEntityModel rootEntity = model.RootEntity; if (model.IsSimple) { string snippetDocumentFileName = GenerationHelper.GetSnippetDocumentFileName(rootEntity); string str3 = m_Arch.BusinessDocsLayer.FullPath + snippetDocumentFileName; bdProj.AddFile(snippetDocumentFileName); CSharpFile docFile = CSharpFilePool.Obtain(str3); docFile.NameSpace = projectName; TraceInfoEvent.Raise(string.Format("Adding document snippet for '{0}'.", rootEntity.MappingName)); GenerateSnippetDocument(docFile, rootEntity, rootEntity.MappingName); TraceInfoEvent.Raise(string.Format("Adding document container snippet for '{0}'.", rootEntity.MappingName)); GenerateContainerClass(docFile, rootEntity, rootEntity.MappingName, string.Format("{0}Container", rootEntity.MappingName), string.Format("{0}ContainerBase", rootEntity.MappingName)); } else { string file = GenerationHelper.GetSnippetDocumentFileName(model); string str5 = m_Arch.BusinessDocsLayer.FullPath + file; bdProj.AddFile(file); CSharpFile file2 = CSharpFilePool.Obtain(str5); file2.NameSpace = projectName; TraceInfoEvent.Raise(string.Format("Adding document snippet for '{0}'.", model.Name)); GenerateSnippetDocument(file2, model.RootEntity, model.Name, model.RootEntity.MappingName); TraceInfoEvent.Raise(string.Format("Adding document container snippet for '{0}'.", model.Name)); GenerateContainerClass(file2, model.RootEntity, model.Name, string.Format("{0}Container", model.Name), string.Format("{0}ContainerBase", model.Name)); } } }
public void GenerateServiceFactoryInterface(VSNetCSharpProject bdProj) { string projectName = bdProj.ProjectName; string sFIntFileName = GenerationHelper.GetSFIntFileName(); string str3 = m_Arch.BusinessDocsLayer.FullPath + sFIntFileName; bdProj.AddFile(sFIntFileName); CSharpFile file = CSharpFilePool.Obtain(str3); file.NameSpace = bdProj.ProjectName; TraceInfoEvent.Raise("Adding service factory interface."); file.Description = "Service factory interface."; CSharpInterfaceDef typeDef = new CSharpInterfaceDef(); file.InnerTypes.Add(typeDef); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = "public interface IServiceFactory"; foreach (ServiceLayerModel model in m_Arch.ServiceLayers) { foreach (ServiceModel model2 in model.Services) { CSharpMethodDef def2 = new CSharpMethodDef(); def2.Comment.Summary = string.Format("Gets the service interface for '{0}'.", model2.MappingName); def2.HeaderLine = string.Format("I{0} Get{0}", model2.MappingName); typeDef.Methods.Add(def2); } } }
public void GenerateServiceFactoryClass(VSNetCSharpProject bdProj) { string projectName = bdProj.ProjectName; string sFClassFileName = GenerationHelper.GetSFClassFileName(); string str3 = m_Arch.BusinessDocsLayer.FullPath + sFClassFileName; bdProj.AddFile(sFClassFileName); CSharpFile file = CSharpFilePool.Obtain(str3); file.NameSpace = bdProj.ProjectName; TraceInfoEvent.Raise("Adding service factory class."); file.Description = "Service factory class."; file.Usings.Add("System.Collections.Specialized"); file.Usings.Add("System.Configuration"); file.Usings.Add("Grepton.Helpers"); file.Usings.Add("Grepton.Runtime"); file.Usings.Add("Grepton.Runtime.BusinessHosting"); file.Usings.Add("Grepton.Diagnostics.Exceptions"); CSharpTypeDef typeDef = new CSharpTypeDef(); file.InnerTypes.Add(typeDef); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = "public class ServiceFactory"; CSharpFieldDef def2 = new CSharpFieldDef(); def2.DefLine = "static IServiceFactory m_ServiceFactory;"; typeDef.Fields.Add(def2); CSharpMethodDef def3 = new CSharpMethodDef(); typeDef.Ctors.Add(def3); def3.Comment.Summary = "Initializes the service factory"; def3.HeaderLine = "static ServiceFactory"; TextWriter writer = def3.Writer; writer.WriteLine("try"); writer.WriteLine("{"); writer.WriteLine(" SetFactory(null);"); writer.WriteLine("}"); writer.WriteLine("catch (Exception ex)"); writer.WriteLine("{"); writer.WriteLine(" ExceptionManager.Publish(ex);"); writer.WriteLine("}"); CSharpMethodDef def4 = new CSharpMethodDef(); typeDef.Methods.Add(def4); def4.Comment.Summary = "Initializes the service factory dispatcher"; def4.HeaderLine = "public static void SetFactory"; def4.AddParam("className", "string", "Service factory class name."); writer = def4.Writer; writer.WriteLine("try"); writer.WriteLine("{"); writer.WriteLine(" if (className == null || className == String.Empty)"); writer.WriteLine(" {"); writer.WriteLine(" className = ((NameValueCollection)ConfigurationSettings."); writer.WriteLine(" GetConfig(\"ServiceFactory\"))[\"class\"];"); writer.WriteLine(" }"); writer.WriteLine(" DynamicType plugIn = new DynamicType(className);"); writer.WriteLine(" m_ServiceFactory = (IServiceFactory)plugIn.CreateInstance();"); writer.WriteLine("}"); writer.WriteLine("catch (Exception ex)"); writer.WriteLine("{"); writer.WriteLine(" ExceptionManager.Publish(ex);"); writer.WriteLine(" throw ex;"); writer.WriteLine("}"); foreach (ServiceLayerModel model in m_Arch.ServiceLayers) { foreach (ServiceModel model2 in model.Services) { CSharpMethodDef def5 = new CSharpMethodDef(); def5.Comment.Summary = string.Format("Gets the service interface for '{0}'.", model2.MappingName); def5.HeaderLine = string.Format("public static I{0} Get{0}", model2.MappingName); def5.Writer.WriteLine("return m_ServiceFactory.Get{0}();", model2.MappingName); typeDef.Methods.Add(def5); } } }
public void GenerateRemoteServiceFactory(VSNetCSharpProject bdProj) { string projectName = bdProj.ProjectName; string remoteSFClassFileName = GenerationHelper.GetRemoteSFClassFileName(); string str3 = m_Arch.BusinessDocsLayer.FullPath + remoteSFClassFileName; bdProj.AddFile(remoteSFClassFileName); CSharpFile file = CSharpFilePool.Obtain(str3); file.NameSpace = bdProj.ProjectName; TraceInfoEvent.Raise("Adding remotes service factory class."); file.Description = "Remote service factory class."; file.Usings.Add("System.Collections.Specialized"); file.Usings.Add("System.Configuration"); file.Usings.Add("Grepton.Helpers"); file.Usings.Add("Grepton.Runtime"); file.Usings.Add("Grepton.Runtime.BusinessHosting"); file.Usings.Add("Grepton.Diagnostics.Exceptions"); file.Usings.Add(m_Arch.BusinessDocsLayer.NameSpace); CSharpTypeDef typeDef = new CSharpTypeDef(); file.InnerTypes.Add(typeDef); typeDef.Comment.Summary = file.Description; typeDef.HeaderLine = "public class RemoteServiceFactory: IServiceFactory"; CSharpMethodDef def2 = new CSharpMethodDef(); typeDef.Ctors.Add(def2); def2.Comment.Summary = "Initializes the service factory with URIs."; def2.HeaderLine = "static RemoteServiceFactory"; foreach (ServiceLayerModel model in m_Arch.ServiceLayers) { foreach (ServiceModel model2 in model.Services) { CSharpFieldDef def3 = new CSharpFieldDef(); def3.CommentLine = string.Format("URI for '{0}'", model2.MappingName); def3.DefLine = string.Format("private static string m_{0}Uri;", model2.MappingName); typeDef.Fields.Add(def3); CSharpMethodDef def4 = new CSharpMethodDef(); def4.Comment.Summary = string.Format("Gets the service interface for '{0}'.", model2.MappingName); def4.HeaderLine = string.Format("public I{0} Get{0}", model2.MappingName); def4.Writer.WriteLine("return (I{0})Activator.GetObject(typeof(I{0}), m_{0}Uri);", model2.MappingName); typeDef.Methods.Add(def4); def2.Writer.WriteLine("m_{0}Uri = RemoteFactory.GetUri(\"{1}/{0}\");", model2.MappingName, model2.Parent.NameSpace); } } }