コード例 #1
0
        public CInterface BuildSqlScriptInterface(KDataStoreTestProject sqlTestKProject)
        {
            var @interface = new CInterface()
            {
                InterfaceName = "ISqlScript",
                Namespace     = new CNamespace()
                {
                    NamespaceName =
                        $"{sqlTestKProject.ProjectFullName}.DataAccess"
                },
            };

            AddNamespaceRefs(@interface);

            @interface.Method.Add(new CMethod()
            {
                SignatureOnly = true, ReturnType = "ICommand", MethodName = "ToCommand"
            });
            @interface.Method.Add(new CMethod()
            {
                SignatureOnly = true, ReturnType = "IQuery<IEnumerable<T>>", MethodName = "ToQuery<T>"
            });

            return(@interface);
        }
コード例 #2
0
        protected CInterface BuildDataHealthCheckInterface()
        {
            var dataHealthCheckInterface = new CInterface();



            dataHealthCheckInterface.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Threading.Tasks"
                }
            });

            dataHealthCheckInterface.Namespace = new CNamespace
            {
                NamespaceName =
                    $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.DataServices"
            };

            dataHealthCheckInterface.InterfaceName = $"IDataHealthCheckService";

            dataHealthCheckInterface.Method.Add(new CMethod
            {
                SignatureOnly = true,
                MethodName    = "Check",
                ReturnType    = "Task<bool>"
            });

            return(dataHealthCheckInterface);
        }
コード例 #3
0
        private void AddNamespaceRefs(CClass @class, CInterface dbProviderInterface)
        {
            var namespaces = new List <string>
            {
                "System.Collections.Generic",
                "System.Threading.Tasks",
                "Microsoft.Extensions.DependencyInjection",
                "Microsoft.VisualStudio.TestTools.UnitTesting",
                "Company.Datastore",
                "Company.Datastore.Query",
                "Company.Datastore.Command",
                $"{dbProviderInterface.Namespace.NamespaceName}",
                $"{@class.Namespace.NamespaceName}.DataAccess"
            };

            foreach (var ns in namespaces)
            {
                @class.NamespaceRef.Add(new CNamespaceRef
                {
                    ReferenceTo = new CNamespace {
                        NamespaceName = ns
                    }
                });
            }
        }
コード例 #4
0
        private void AddNamespaceRefs(CClass classTestInitialize, CInterface dbProviderInterface)
        {
            var namespaces = new List <string>
            {
                "System",
                "System.Data",
                "System.Data.Common",
                "Microsoft.Extensions.Configuration",
                "Microsoft.Extensions.DependencyInjection",
                "Microsoft.VisualStudio.TestTools.UnitTesting",
                "Moq",
                //"StructureMap",
                "Company.Configuration.ConfigCenter",

                $"{classTestInitialize.Namespace.NamespaceName}.Startup",
                $"{dbProviderInterface.Namespace.NamespaceName}"
            };

            foreach (var ns in namespaces)
            {
                classTestInitialize.NamespaceRef.Add(new CNamespaceRef
                {
                    ReferenceTo = new CNamespace {
                        NamespaceName = ns
                    }
                });
            }
        }
コード例 #5
0
        static BuiltIns()
        {
            /* These aren't fully resolved; we need to use Cecil to load the appropriate .NET type defitinions in.
             * See ClrImporter.LoadBuiltins. */
            Variant   = new CClass("__Variant", null);
            Byte      = new CClass("Byte", false);
            String    = new CClass("String", true);
            Int32     = new CClass("Int32", true);
            Int64     = new CClass("Int64", true);
            Character = new CClass("Character", false);
            Boolean   = new CClass("Boolean", true);
            Date      = new CClass("Date", true);
            Double    = new CClass("Double", true);
            Object    = Variant;
            DbNull    = new CClass("DbNull", false);
            Nothing   = new CClass("Nothing", false);
            Nothing.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            Void = new CClass("__Void", false);
            FunctionPlaceHolder = new CClass("__FunctionPlaceHolder", false);
            FunctionPlaceHolder.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            SubPlaceHolder = new CClass("__SubPlaceHolder", false);
            SubPlaceHolder.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            SetupGlobalTypes();

            CArgumentList arrArgs = new CArgumentList();

            arrArgs.Add(new CArgument(CToken.Keyword(null, "byval"),
                                      CToken.Identifer(null, "arglist"),
                                      new CTypeRef(null, Variant)));
            Array = new CFunction(CToken.Identifer(null, "Array"), "Array", "array", TokenTypes.visPublic, FunctionType.Function,
                                  arrArgs, new CTypeRef(null, new CArrayType(new CTypeRef(null, Variant), 1)));
            Array.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            CArgumentList dicArgs = new CArgumentList();

            dicArgs.Add(new CArgument(CToken.Keyword(null, "byval"),
                                      CToken.Identifer(null, "arglist"),
                                      new CTypeRef(null, Variant)));
            Dictionary = new CFunction(CToken.Identifer(null, "Dictionary"), "Dictionary", "dictionary", TokenTypes.visPublic, FunctionType.Function,
                                       dicArgs, new CTypeRef(null, new CDictionaryType(new CTypeRef(null, Variant))));
            Dictionary.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            CArgumentList refArgs = new CArgumentList();

            refArgs.Add(new CArgument(CToken.Keyword(null, "byval"),
                                      CToken.Identifer(null, "func"),
                                      new CTypeRef(null, BuiltIns.String)));
            GetRef = new CFunction(CToken.Identifer(null, "GetRef"), "GetRef", "getref", TokenTypes.visPublic, FunctionType.Function, refArgs,
                                   new CTypeRef(null, BuiltIns.FunctionPlaceHolder));
            GetRef.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            // add string ienumerator interface
            CToken     ifaceName = CToken.Identifer(null, "System.Collections.Generic.IEnumerable`1<char>");
            CInterface iface     = new CInterface(ifaceName, ifaceName);

            iface.GenericParameters.Add(Character);
            String.AddInterface(new CTypeRef(null, iface));
        }
コード例 #6
0
 public void VisitInterface(CInterface iface)
 {
     if (canGenerate(iface))
     {
         classname = iface.RawName;
         visitor.VisitInterface(iface);
         classname = "";
     }
 }
コード例 #7
0
        private CClass BuildBaseDataServiceClass(CInterface dbProviderInterface)
        {
            var dataService = new CClass($"BaseDataService")
            {
                IsAbstract = true
            };

            dataService.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System"
                }
            });

            dataService.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = dbProviderInterface.Namespace
            });

            dataService.Namespace = new CNamespace
            {
                NamespaceName =
                    $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.DataServices.Base"
            };
            dataService.Field.Add(new CField
            {
                AccessModifier = CAccessModifier.Protected,
                FieldName      = "DbProvider",
                FieldType      = $"I{_dataLayerKProject.ProjectName}DbProvider",
                IsReadonly     = true
            });

            var staticConstructor = new CConstructor
            {
                IsStatic        = true,
                AccessModifier  = CAccessModifier.Private,
                ConstructorName = "BaseDataService"
            };

            dataService.Constructor.Add(staticConstructor);

            var constructor = new CConstructor
            {
                ConstructorName = dataService.ClassName,
                AccessModifier  = CAccessModifier.Protected
            };

            constructor.Parameter.Add(new CParameter
            {
                ParameterName = "dbProvider",
                Type          = $"I{_dataLayerKProject.ProjectName}DbProvider"
            });
            constructor.CodeSnippet = "DbProvider = dbProvider ?? throw new ArgumentException(nameof(dbProvider));";
            dataService.Constructor.Add(constructor);


            return(dataService);
        }
コード例 #8
0
        private CClass BuildDbProviderClass(CInterface dbProviderInterface)
        {
            var dbProvider = new CClass($"{_dataLayerKProject.ProjectName}DbProvider");

            dbProvider.Implements.Add(dbProviderInterface);
            dbProvider.Namespace = new CNamespace
            {
                NamespaceName =
                    $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.Providers"
            };
            return(dbProvider);
        }
コード例 #9
0
        private CInterface BuildDbProviderInterface()
        {
            var dbProviderInterface = new CInterface();

            dbProviderInterface.InterfaceName = $"I{_dataLayerKProject.ProjectName}DbProvider";

            dbProviderInterface.Namespace = new CNamespace
            {
                NamespaceName =
                    $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.Providers"
            };
            return(dbProviderInterface);
        }
コード例 #10
0
        private void AddNamespaceRefs(CInterface @interface)
        {
            var namespaces = new List <string>
            {
                "Company.Datastore.Provider"
            };

            foreach (var ns in namespaces)
            {
                @interface.NamespaceRef.Add(new CNamespaceRef
                {
                    ReferenceTo = new CNamespace {
                        NamespaceName = ns
                    }
                });
            }
        }
コード例 #11
0
        public void InitiateInterface()
        {
            //MTTS-HARI - v1.3.6A - 2/8/2017 - #5875 - Equip IND890 API with a 4th channel for 'high speed' serial communication.
            //Change the Interface communications from Terminal client to Serial client
            m_Interface1             = m_APISerialClient.Interface[1];
            m_Interface1.DataMode    = CInterface.enumDataMode.MODE_STRING;
            m_Interface1.OnRxString += m_Interface1_OnRxString;
            //Handled OnRxByte event in binary mode for #4289, V1.3.2a Iteration II
            m_Interface1.OnRxByte += new CInterface.RxByte(m_Interface1_OnRxByte);
            //
            m_Interface2             = m_APISerialClient.Interface[2];
            m_Interface2.DataMode    = CInterface.enumDataMode.MODE_STRING;
            m_Interface2.OnRxString += new CInterface.RxString(m_Interface2_OnRxString);
            m_Interface2.OnRxByte   += new CInterface.RxByte(m_Interface2_OnRxByte);
            //
            m_Interface3             = m_APISerialClient.Interface[3];
            m_Interface3.DataMode    = CInterface.enumDataMode.MODE_STRING;
            m_Interface3.OnRxString += new CInterface.RxString(m_Interface3_OnRxString);
            m_Interface3.OnRxByte   += new CInterface.RxByte(m_Interface3_OnRxByte);
            //
            m_Interface4             = m_APISerialClient.Interface[4];
            m_Interface4.DataMode    = CInterface.enumDataMode.MODE_STRING;
            m_Interface4.OnRxString += new CInterface.RxString(m_Interface4_OnRxString);
            m_Interface4.OnRxByte   += new CInterface.RxByte(m_Interface4_OnRxByte);
            //
            m_Interface5             = m_APISerialClient.Interface[5];
            m_Interface5.DataMode    = CInterface.enumDataMode.MODE_STRING;
            m_Interface5.OnRxString += new CInterface.RxString(m_Interface5_OnRxString);
            m_Interface5.OnRxByte   += new CInterface.RxByte(m_Interface5_OnRxByte);
            //
            m_Interface6             = m_APISerialClient.Interface[6];
            m_Interface6.DataMode    = CInterface.enumDataMode.MODE_STRING;
            m_Interface6.OnRxString += new CInterface.RxString(m_Interface6_OnRxString);
            m_Interface6.OnRxByte   += new CInterface.RxByte(m_Interface6_OnRxByte);

            m_Ethernet             = m_APISerialClient.Interface[7];
            m_Ethernet.DataMode    = CInterface.enumDataMode.MODE_STRING;
            m_Ethernet.OnRxString += new CInterface.RxString(m_Ethernet_OnRxString);
            m_Ethernet.OnRxByte   += new CInterface.RxByte(m_Ethernet_OnRxByte);

            EnableInterfaceContols();
        }
コード例 #12
0
        public static bool STARTE_SCALE()
        {
            bool bRet = false;

            try
            {
                objSCALE = new cScale();
                bRet     = objSCALE.Start();

                objRS232_X5          = objCIND890APIClient.Interface[5];
                objRS232_X5.DataMode = MTTS.IND890.CE.CInterface.enumDataMode.MODE_STRING;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "GlobalScale (a)");
                throw;
            }

            return(bRet);
        }
コード例 #13
0
        private void AddNamespaceRefs(CInterface @interface)
        {
            var namespaces = new List <string>
            {
                "System.Collections.Generic",
                "Company.Datastore",
                "Company.Datastore.Query",
                "Company.Datastore.Command"
            };

            foreach (var ns in namespaces)
            {
                @interface.NamespaceRef.Add(new CNamespaceRef
                {
                    ReferenceTo = new CNamespace {
                        NamespaceName = ns
                    }
                });
            }
        }
コード例 #14
0
        public CProject BuildProject(KSolution kSolution, KDataStoreProject dataStoreKProject, KDataStoreTestProject sqlTestKProject,
                                     KDataLayerProject dataLayerKProject,
                                     CProject dataStoreProject, CInterface dbProviderInterface, CClass dbProviderClass)
        {
            _dataStoreKProject   = dataStoreKProject;
            _sqlTestKProject     = sqlTestKProject;
            _dataLayerKProject   = dataLayerKProject;
            _dataStoreProject    = dataStoreProject;
            _dbProviderInterface = dbProviderInterface;
            _dbProviderClass     = dbProviderClass;

            var dbTestProject = new CProject
            {
                ProjectName      = sqlTestKProject.ProjectFullName,
                ProjectShortName = sqlTestKProject.ProjectName,
                ProjectFolder    = sqlTestKProject.ProjectFolder,
                ProjectType      = CProjectType.CsProj
            };

            dbTestProject.ProjectReference.Add(dataStoreProject);

            dbTestProject.TemplateProjectPath = @"templates\NetCore31ConsoleApp.csproj";

            AddTestInitializationClass(dbTestProject);
            AddStartupContainerClass(dbTestProject);
            AddTestDataServiceClass(dbTestProject);
            AddTestDataServiceBuilderInterface(dbTestProject);
            AddTestDataServiceBuilderClass(dbTestProject);
            AddReadSqlScriptClass(dbTestProject);
            AddSqlScriptInterface(dbTestProject);
            AddSqlScriptClass(dbTestProject);
            AddEmbeddedSqlCommandClass(dbTestProject);
            AddEmbeddedSqlQueryClass(dbTestProject);
            AddAssemblyExtensionClass(dbTestProject);
            AddAppSettingsJson(dbTestProject);
            AddDataServiceTestClass(dbTestProject);
            AddNuGetRefs(dbTestProject);

            return(dbTestProject);
        }
コード例 #15
0
        private void AddNamespaceRefs(CClass @class, CInterface dbProviderInterface)
        {
            var namespaces = new List <string>
            {
                "System",
                "Microsoft.Extensions.DependencyInjection",
                //"StructureMap",
                "Company.Datastore",
                "Company.Datastore.Connection",
                "Company.Datastore.Dapper",
                $"{dbProviderInterface.Namespace.NamespaceName}"
            };

            foreach (var ns in namespaces)
            {
                @class.NamespaceRef.Add(new CNamespaceRef
                {
                    ReferenceTo = new CNamespace {
                        NamespaceName = ns
                    }
                });
            }
        }
コード例 #16
0
        private CMethod BuildAddAppServicesMethod(KGrpcProject grpcKProject, DataStoreTypes connectsToDatabaseType, CInterface dbProviderInterface, CClass dbProviderClass)
        {
            var method = new CMethod
            {
                AccessModifier    = CAccessModifier.Private,
                IsStatic          = true,
                IsExtensionMethod = true,
                ReturnType        = "void",
                MethodName        = "AddAppServices",
                Parameter         = new List <CParameter>
                {
                    new CParameter {
                        Type = "IServiceCollection", ParameterName = "services"
                    },
                    new CParameter {
                        Type = "IConfiguration", ParameterName = "configuration"
                    }
                }
            };
            var methodSnippet = new CodeWriter();

            methodSnippet.WriteLine($@"services.AddSingleton(");
            methodSnippet.WriteLine($@"p => p.GetRequiredService<IOptions<ServiceSettings>>().Value);");
            methodSnippet.WriteLine();
            methodSnippet.Unindent();


            methodSnippet.WriteLine($@"services.AddSingleton(");
            methodSnippet.Indent();
            methodSnippet.WriteLine($@"p => p.GetRequiredService<IOptions<CloudformationOutputs>>().Value);");
            methodSnippet.Unindent();

            methodSnippet.WriteLine();

            methodSnippet.WriteLine($@"services.AddSingleton(");
            methodSnippet.Indent();
            methodSnippet.WriteLine($@"p => p.GetRequiredService<IOptions<AuthenticationSettings>>().Value);");

            methodSnippet.WriteLine();
            methodSnippet.Unindent();

            if (dbProviderInterface != null)
            {
                methodSnippet.WriteLine($@"services.AddTransient<{dbProviderInterface.InterfaceName}>(");
                methodSnippet.Indent();
                methodSnippet.WriteLine(
                    $@"p => 
                    {{
                        var outputs = p.GetRequiredService<CloudformationOutputs>();");

                methodSnippet.Indent();
                if (connectsToDatabaseType == DataStoreTypes.SqlServer ||
                    connectsToDatabaseType == DataStoreTypes.Postgres ||
                    connectsToDatabaseType == DataStoreTypes.MySql)
                {
                    methodSnippet.WriteLine(
                        $@"if (!string.IsNullOrWhiteSpace(outputs.DBEndpoint))
                        {{
                            return new {grpcKProject.ProjectNameAsClassNameFriendly}DbProvider(
                                outputs.DBEndpoint,
                                outputs.Database,
                                outputs.DBUsername,
                                outputs.DBPassword,
                                outputs.Port);  
                        }}

                        return new {dbProviderClass.ClassName}(configuration.GetConnectionString(""{
                                grpcKProject.ProjectName
                            }""));");
                }
                else
                {
                    methodSnippet.WriteLine($@"return new {dbProviderClass.ClassName}();");
                    methodSnippet.Unindent();
                }

                methodSnippet.WriteLine("});");
                methodSnippet.WriteLine();
                methodSnippet.Unindent();
                methodSnippet.Unindent();
            }

            method.CodeSnippet = methodSnippet.ToString();

            return(method);
        }
コード例 #17
0
        public CClass BuildTestInitializationClass(CProject dbTestProject, KDataStoreTestProject sqlTestKProject, CInterface dbProviderInterface)
        {
            var @class = new CClass("TestInitialization")
            {
                Namespace = new CNamespace()
                {
                    NamespaceName =
                        $"{sqlTestKProject.ProjectFullName}"
                }
            };

            AddNamespaceRefs(@class, dbProviderInterface);
            @class.ClassAttribute.Add(new CClassAttribute()
            {
                AttributeName = "TestClass"
            });

            @class.Field.Add(new CField()
            {
                AccessModifier = CAccessModifier.Public,
                FieldType      = "IServiceProvider",
                IsStatic       = true,
                FieldName      = "ServiceProvider"
            });

            @class.Field.Add(new CField()
            {
                AccessModifier = CAccessModifier.Private,
                IsConst        = true,
                FieldType      = "string",
                FieldName      = "EnvPrefix",
                DefaultValue   = @"""SAMPLE_SVC_TESTS_"""
            });

            @class.Property.Add(new CProperty()
            {
                AccessModifier = CAccessModifier.Private,
                IsStatic       = true,
                Type           = "string",
                PropertyName   = "EnvironmentName",
                DefaultValue   = @"Environment.GetEnvironmentVariable(""ASPNETCORE_ENVIRONMENT"")"
            });
            @class.Property.Add(new CProperty()
            {
                AccessModifier = CAccessModifier.Private, IsStatic = true, Type = "string", PropertyName = "ApplicationName", DefaultValue = "Environment.GetEnvironmentVariable(EnvPrefix + \"ApplicationName\") ?? \"daypart-integration-test\""
            });

            @class.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public,
                IsStatic       = true,
                ReturnType     = "void",
                MethodName     = "AssemblySetup",
                Attribute      = new List <CMethodAttribute>()
                {
                    new CMethodAttribute()
                    {
                        AttributeName = "AssemblyInitialize"
                    }
                },
                Parameter = new List <CParameter>()
                {
                    new CParameter()
                    {
                        Type = "TestContext", ParameterName = "testContext"
                    }
                },
                CodeSnippet = "ServiceProvider = InitializeServiceProvider();"
            });

            @class.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public,
                IsStatic       = true,
                ReturnType     = "void",
                MethodName     = "AssemblyCleanup",
                Attribute      = new List <CMethodAttribute>()
                {
                    new CMethodAttribute()
                    {
                        AttributeName = "AssemblyCleanup"
                    }
                },
                CodeSnippet = "ServiceProvider.Dispose();"
            });

            @class.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public,
                ReturnType     = "void",
                MethodName     = "TestServiceProvider",
                Attribute      = new List <CMethodAttribute>()
                {
                    new CMethodAttribute()
                    {
                        AttributeName = "TestMethod"
                    }
                },
                CodeSnippet = @"var container = ((StructureMapServiceProvider)ServiceProvider).Container;
                                /*
                                 * Some of these could be intentional
                                 */
                                var dbConnectionMock = new Mock<DbConnection>();
                                var dbTransactionMock = new Mock<DbTransaction>();
                                container.Configure(c =>
                                {
                                    c.For<IDbConnection>().Use(dbConnectionMock.Object);
                                    c.For<IDbTransaction>().Use(dbTransactionMock.Object);
                                });

                                container.AssertConfigurationIsValid();"
            });

            @class.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Private,
                IsStatic       = true,
                ReturnType     = "IServiceProvider",
                MethodName     = "InitializeServiceProvider",
                CodeSnippet    = $@"var configuration = InitializeConfiguration();
                                var serviceCollection = InitializeServiceCollection(configuration);
                               serviceCollection.AddTransient<{dbProviderInterface.InterfaceName}>(
                                            p =>
                                            {{

                                                return new EventCaptureDbProvider(configuration.GetConnectionString(""EventCapture""));
                                            }});
                                return serviceCollection.ConfigureContainer();//configuration);"
            });

            @class.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Private,
                IsStatic       = true,
                ReturnType     = "IServiceCollection",
                MethodName     = "InitializeServiceCollection",
                Parameter      = new List <CParameter>()
                {
                    new CParameter()
                    {
                        Type = "IConfigurationRoot", ParameterName = "config"
                    }
                },
                CodeSnippet = @"var serviceCollection = new ServiceCollection();

                                /*ServiceCollectionExtensions.ConfigureServiceCollection(serviceCollection, config)
                                    .Configure<AppSettings>(config)
                                    .Configure<DaypartConfig>(config.GetSection(""zzzzz""));*/

                                    return serviceCollection; "
            });

            @class.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Private,
                IsStatic       = true,
                ReturnType     = "IConfigurationRoot",
                MethodName     = "InitializeConfiguration",
                CodeSnippet    = @"return new ConfigurationBuilder()
                                        .AddJsonFile(""appsettings.json"", false)
                                        .AddJsonFile($""appsettings.{EnvironmentName}.json"", true)
                                            .AddEnvironmentVariables(EnvPrefix)
                                        .AddConfigCenter(ApplicationName, EnvPrefix)
                                            .Build(); "
            });

            return(@class);
        }
コード例 #18
0
        public CClass BuildDataServiceTestClass(KDataStoreProject sqlKProject, KDataLayerProject dataLayerKProject, KDataStoreTestProject sqlTestKProject, CInterface dbProviderInterface)
        {
            var @class = new CClass("EventCaptureDataServiceTest")
            {
                Namespace = new CNamespace()
                {
                    NamespaceName =
                        $"{sqlTestKProject.ProjectFullName}"
                },
                ClassAttribute = new List <CClassAttribute>()
                {
                    new CClassAttribute()
                    {
                        AttributeName = "TestClass"
                    }
                }
            };

            AddNamespaceRefs(@class, dbProviderInterface);

            @class.Field.Add(new CField()
            {
                AccessModifier = CAccessModifier.Private,
                IsStatic       = true,
                FieldType      = $"TestDataService<{dbProviderInterface.InterfaceName}>",
                FieldName      = "_testDataService"
            });

            @class.Method.Add(new CMethod()
            {
                Attribute = new List <CMethodAttribute>()
                {
                    new CMethodAttribute()
                    {
                        AttributeName = "ClassInitialize"
                    }
                },
                AccessModifier = CAccessModifier.Public,
                IsStatic       = true,
                ReturnType     = "void",
                MethodName     = "ClassInitialize",
                Parameter      = new List <CParameter>()
                {
                    new CParameter()
                    {
                        Type = "TestContext", ParameterName = "context"
                    }
                },
                CodeSnippet = $@"var testDataServiceBuilder = 
                                     TestInitialization.ServiceProvider.GetService<ITestDataServiceBuilder<{dbProviderInterface.InterfaceName}>>();

                                _testDataService = testDataServiceBuilder.Create();

                                _testDataService.SeedAsync()
                                    .GetAwaiter()
                                    .GetResult();"
            });

            var service = new DataLayerServiceProjectServiceBase();

            foreach (var kStoredProcedure in sqlKProject.StoredProcedure)
            {
                if (!string.IsNullOrEmpty(kStoredProcedure.ParameterSetName))
                {
                    var @entityClass = service.BuildParameterEntityClass(kStoredProcedure.GeneratedStoredProcedure, kStoredProcedure.ParameterSetName);
                    int x            = 1;
                }

                if (!string.IsNullOrWhiteSpace(kStoredProcedure.ResultSetName))
                {
                    var @entityClass = service.BuildResultEntityClass(kStoredProcedure.GeneratedStoredProcedure, kStoredProcedure.ResultSetName, dataLayerKProject);
                    @class.Method.Add(new CMethod()
                    {
                        Attribute = new List <CMethodAttribute>()
                        {
                            new CMethodAttribute()
                            {
                                AttributeName = "TestMethod"
                            }
                        },

                        AccessModifier = CAccessModifier.Public,
                        IsAsync        = true,
                        ReturnType     = "Task",
                        MethodName     = $"Test{kStoredProcedure.StoredProcedureName}",
                        CodeSnippet    = $@"var result = await _testDataService.Query(new EmbeddedSqlQuery<{@entityClass.ClassName}>(""{kStoredProcedure.StoredProcedureName}""));"
                    });
                }
            }



            return(@class);
        }
コード例 #19
0
        protected CInterface BuildDataServiceInterface(List <CClass> dtoClasses)
        {
            var dbProviderInterface = new CInterface();

            dbProviderInterface.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System"
                }
            });

            /*
             * dbProviderInterface.NamespaceRef.Add(new CNamespaceRef
             * {
             *  ReferenceTo = new CNamespace {NamespaceName = "System.Data"}
             * });
             */
            /*
             * dbProviderInterface.NamespaceRef.Add(new CNamespaceRef
             * {
             *  ReferenceTo = new CNamespace {NamespaceName = "System.Data.SqlClient"}
             * });*/
            dbProviderInterface.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Collections.Generic"
                }
            });
            dbProviderInterface.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Threading.Tasks"
                }
            });

            /*dbProviderInterface.NamespaceRef.Add(new CNamespaceRef
             * {
             *  ReferenceTo = new CNamespace { NamespaceName = "System.Reflection" }
             * });
             */

            dbProviderInterface.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace
                {
                    NamespaceName =
                        $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.Entities"
                }
            });

            /*
             * //todo: clean this up
             * if (dtoClasses.Count > 0)
             *  dbProviderInterface.NamespaceRef.Add(
             *      _dataProject.BuildNamespaceRefForType(dtoClasses.First().ClassName));
             */

            dbProviderInterface.Namespace = new CNamespace
            {
                NamespaceName =
                    $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.DataServices"
            };


            dbProviderInterface.InterfaceName =
                $"I{_dataLayerKProject.ProjectNameAsClassNameFriendly}{_dataLayerKProject.ProjectSuffix}Service";
            var methods = GetDataServiceMethods();

            foreach (var m in methods)
            {
                m.IsAsync       = false;
                m.SignatureOnly = true;
            }

            dbProviderInterface.Method.AddRange(methods);


            return(dbProviderInterface);
        }
コード例 #20
0
        public CInterface BuildTestDataServiceBuilderInterface(KDataStoreTestProject sqlTestKProject)
        {
            var @interface = new CInterface()
            {
                InterfaceName = "ITestDataServiceBuilder<T>",
                Namespace     = new CNamespace()
                {
                    NamespaceName =
                        $"{sqlTestKProject.ProjectFullName}.DataAccess"
                },

                Where = new List <CWhere> {
                    new CWhere()
                    {
                        WhereName = "T : IDbProvider"
                    }
                }
            };

            AddNamespaceRefs(@interface);



            @interface.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public,
                ReturnType     = "ITestDataServiceBuilder<T>",
                MethodName     = "NewSetup",
                SignatureOnly  = true
            });

            @interface.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public,
                ReturnType     = "ITestDataServiceBuilder<T>",
                MethodName     = "WithSeedScript",
                Parameter      = new List <CParameter>()
                {
                    new CParameter {
                        Type = "string", ParameterName = "scriptName"
                    },
                    new CParameter {
                        Type = "object", ParameterName = "parameters", DefaultValue = "null"
                    }
                },
                SignatureOnly = true
            });

            @interface.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public,
                ReturnType     = "ITestDataServiceBuilder<T>",
                MethodName     = "WithSeedQuery",
                Parameter      = new List <CParameter>()
                {
                    new CParameter {
                        Type = "string", ParameterName = "scriptName"
                    },
                    new CParameter {
                        Type = "object", ParameterName = "parameters", DefaultValue = "null"
                    }
                },
                SignatureOnly = true
            });

            @interface.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public,
                ReturnType     = "ITestDataServiceBuilder<T>",
                MethodName     = "WithCleanScript",
                Parameter      = new List <CParameter>()
                {
                    new CParameter {
                        Type = "string", ParameterName = "scriptName"
                    },
                    new CParameter {
                        Type = "object", ParameterName = "parameters", DefaultValue = "null"
                    }
                },
                SignatureOnly = true
            });

            @interface.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public,
                ReturnType     = "TestDataService<T>",
                MethodName     = "Create",
                SignatureOnly  = true
            });

            return(@interface);
        }
コード例 #21
0
        private CClass BuildDataServiceClass(CInterface dataServiceInterface, CInterface dataProviderInterface, List <CClass> dtoClasses)
        {
            var dataService = new CClass($"{_dataLayerKProject.ProjectName}{_dataLayerKProject.ProjectSuffix}Service")
            {
                Namespace = new CNamespace
                {
                    NamespaceName =
                        $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.{_dataLayerKProject.ProjectSuffix}.DataServices"
                },
                IsAbstract   = false,
                InheritsFrom = new CClass("BaseDataService"),
                Implements   = new List <CInterface> {
                    new CInterface {
                        InterfaceName = dataServiceInterface.InterfaceName
                    }
                }
            };

            dataService.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System"
                }
            });
            dataService.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Collections.Generic"
                }
            });
            dataService.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Data"
                }
            });
            dataService.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Linq"
                }
            });

            dataService.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Reflection"
                }
            });

            dataService.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Threading.Tasks"
                }
            });

            //dataService.NamespaceRef.Add(new CNamespaceRef { ReferenceTo = new CNamespace { NamespaceName = "Dapper" } });

            dataService.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.DataServices.Base"
                }
            });

            //dataService.NamespaceRef.Add(new CNamespaceRef { ReferenceTo = new CNamespace { NamespaceName = $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.Extensions" } });

            dataService.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.Entities"
                }
            });

            dataService.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = dataProviderInterface.Namespace
            });


            /*
             * if (ConnectsToDatabaseType == DatabaseTypes.Postgres)
             * {
             *  dataService.NamespaceRef.Add(new CNamespaceRef
             *  {
             *      ReferenceTo = new CNamespace { NamespaceName = "Npgsql" }
             *  });
             * }*/

            //dataService.Field.Add(new SField() { FieldName = "DefaultPageNumber", FieldType = "int", IsReadonly = false });
            //dataService.Field.Add(new SField() { FieldName = "DefaultPageSize", FieldType = "int", IsReadonly = false });

            var constructor = new CConstructor
            {
                IsStatic        = false,
                ConstructorName = dataService.ClassName,
                CodeSnippet     = "//empty constructor"
            };

            constructor.Parameter.Add(new CParameter
            {
                PassToBaseClass = true,
                ParameterName   = "dbProvider",
                Type            = $"I{_dataLayerKProject.ProjectName}DbProvider"
            });

            dataService.Constructor.Add(constructor);

            var methods = GetDataServiceMethods();

            foreach (var m in methods)
            {
                m.CodeSnippet = "throw new NotImplementedException();";
            }

            dataService.Method.AddRange(methods);


            //todo: clean this up
            // if (dtoClasses.Count > 0)
            //     dataService.NamespaceRef.Add(_dataProject.BuildNamespaceRefForType(dtoClasses.First().ClassName));
            return(dataService);
        }
コード例 #22
0
        private CClass BuildDataHealthCheckClass(CInterface dataHealthCheckInterface, CClass baseDataService, CInterface dbProviderInterface)
        {
            var @class = new CClass("DataHealthCheckService")
            {
                AccessModifier = CAccessModifier.Public,
                Implements     = new List <CInterface>()
                {
                    dataHealthCheckInterface
                },
                InheritsFrom = baseDataService
            };

            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System"
                }
            });



            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Threading.Tasks"
                }
            });

            /*
             * @class.NamespaceRef.Add(new CNamespaceRef
             * {
             *  ReferenceTo = new CNamespace { NamespaceName = "Dapper" }
             * });
             */

            @class.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = baseDataService.Namespace
            });
            @class.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = dbProviderInterface.Namespace
            });


            @class.Namespace = new CNamespace {
                NamespaceName = dataHealthCheckInterface.Namespace.NamespaceName
            };

            var constructor = new CConstructor
            {
                AccessModifier  = CAccessModifier.Public,
                ConstructorName = "DataHealthCheckService",
                Parameter       = new List <CParameter>
                {
                    new CParameter {
                        Type = dbProviderInterface.InterfaceName, ParameterName = "dbProvider", PassToBaseClass = true
                    },
                },
                CodeSnippet = "//Empty Constructor"
            };

            @class.Constructor.Add(constructor);

            var methodCheck = new CMethod {
                ReturnType = "Task<bool>", MethodName = "Check", IsAsync = true, AccessModifier = CAccessModifier.Public
            };

            /*
             * methodCheck.CodeSnippet =
             *  @"using var connection = DbProvider.GetConnection();
             *
             *  return await connection.QueryFirstAsync<bool>(""select 1"").ConfigureAwait(false);
             * ";
             */
            methodCheck.CodeSnippet = "throw new NotImplementedException();";
            @class.Method.Add(methodCheck);

            return(@class);
        }
コード例 #23
0
        public CClass AddContainerClass(KGrpcProject grpcKProject, DataStoreTypes connectsToDatabaseType,
                                        CProject project,
                                        CInterface dbProviderInterface,
                                        CClass dbProviderClass,
                                        CInterface dbDiagnosticsFactoryInterface,
                                        CClass dbDiagnosticsFactoryClass)
        {
            var @class = new CClass($"ContainerExtensions")
            {
                Namespace = new CNamespace
                {
                    NamespaceName =
                        $"{grpcKProject.CompanyName}.{grpcKProject.ProjectName}{grpcKProject.NamespaceSuffix}.{grpcKProject.ProjectSuffix}.Infrastructure"
                },
                AccessModifier = CAccessModifier.Public,
                IsStatic       = true
            };

            @class.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System"
                }
            });
            @class.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Grpc.Core"
                }
            });
            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Microsoft.Extensions.DependencyInjection"
                }
            });
            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Microsoft.Extensions.Configuration"
                }
            });

            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Microsoft.Extensions.Options"
                }
            });

            //@class.NamespaceRef.Add(new CNamespaceRef { ReferenceTo = new CNamespace { NamespaceName = "StructureMap" } });
            @class.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "MediatR"
                }
            });
            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Company.GrpcCommon.Infrastructure"
                }
            });

            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Company.GrpcCommon.Tracing"
                }
            });

            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = $"{grpcKProject.CompanyName}.{grpcKProject.ProjectName}{grpcKProject.NamespaceSuffix}.{grpcKProject.ProjectSuffix}.Config"
                }
            });

            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = dbProviderInterface.Namespace
            });

            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = dbDiagnosticsFactoryInterface.Namespace
            });

            @class.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = dbDiagnosticsFactoryClass.Namespace
            });

            @class.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Lamar"
                }
            });



            @class.Method.Add(new CMethod
            {
                AccessModifier    = CAccessModifier.Public,
                ReturnType        = "void",
                IsStatic          = true,
                IsExtensionMethod = true,
                MethodName        = "Configure",
                Parameter         = new List <CParameter>
                {
                    new CParameter {
                        Type = "ServiceRegistry", ParameterName = "r"
                    },
                    new CParameter {
                        Type = "IConfiguration", ParameterName = "configuration"
                    }
                },
                CodeSnippet = GetConfigureCodeSnippet(grpcKProject.ProjectNameAsClassNameFriendly)
            });

            /*
             * @class.Method.Add(new CMethod()
             * {
             *   AccessModifier = CAccessModifier.Public,
             *   ReturnType = "IServiceProvider",
             *   MethodName = "GetServiceProvider",
             *   CodeSnippet = "return _container.GetInstance<IServiceProvider>();"
             * });
             *
             * @class.Method.Add(new CMethod
             * {
             *   AccessModifier = CAccessModifier.Public,
             *   ReturnType = "void",
             *   MethodName = "ConfigureContainer",
             *
             *   CodeSnippet =
             *       $@"_container.Configure(config =>
             * {{
             *   // Register stuff in container, using the StructureMap APIs
             *   // also register MediatR specifics
             *   config.Scan(scanner =>
             *   {{
             *       scanner.AssembliesAndExecutablesFromApplicationBaseDirectory(a => a.FullName.StartsWith(""{
             *               grpcKProject.CompanyName
             *           }""));
             *       scanner.AssemblyContainingType<IMediator>();
             *       scanner.WithDefaultConventions();
             *       scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<,>));
             *       scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<,>));
             *       scanner.ConnectImplementationsToTypesClosing(typeof(INotificationHandler<>));
             *       scanner.ConnectImplementationsToTypesClosing(typeof(INotificationHandler<>));
             *   }});
             *
             *   config.For<ServiceFactory>().Use<ServiceFactory>(ctx => ctx.GetInstance);
             *
             *   config.For<IMediatorExecutor>().Use<MediatorExecutor>();
             *   // Populate the container using the service collection
             *   config.Populate(_services);
             * }});"
             * });
             */

            @class.Method.Add(BuildAddAppServicesMethod(grpcKProject, connectsToDatabaseType, dbProviderInterface, dbProviderClass));

            project.ProjectContent.Add(new CProjectContent
            {
                Content     = @class,
                BuildAction = grpcKProject.DotNetType == DotNetType.Framework ? CBuildAction.Compile : CBuildAction.DoNotInclude,
                File        = new CFile {
                    Folder = $@"Infrastructure", FileName = $"{@class.ClassName}.cs"
                }
            });

            return(@class);
        }
コード例 #24
0
        public CClass BuildStartupContainerClass(KDataStoreTestProject sqlTestKProject, CInterface dbProviderInterface, CClass dbProviderClass)
        {
            var @class = new CClass("ServiceCollectionExtensions")
            {
                Namespace = new CNamespace
                {
                    NamespaceName =
                        $"{sqlTestKProject.CompanyName}.{sqlTestKProject.ProjectName}{sqlTestKProject.NamespaceSuffix}.{sqlTestKProject.ProjectSuffix}.Startup"
                },

                AccessModifier = CAccessModifier.Public,
                IsStatic       = true
            };


            AddNamespaceRefs(@class, dbProviderInterface);

            @class.Field.Add(new CField
            {
                AccessModifier = CAccessModifier.Private,
                IsStatic       = true,
                FieldType      = "IContainer",
                FieldName      = "_container"
            });

            @class.Method.Add(new CMethod
            {
                IsStatic          = true,
                IsExtensionMethod = true,
                ReturnType        = "IServiceProvider",
                MethodName        = "ConfigureContainer",
                Parameter         = new List <CParameter>
                {
                    new CParameter {
                        Type = "IServiceCollection", ParameterName = "services"
                    }
                },
                CodeSnippet =
                    $@"
            r.Scan(scanner =>
            {{
                scanner.AssembliesAndExecutablesFromApplicationBaseDirectory(a => a.FullName.StartsWith(""Company""));
                scanner.WithDefaultConventions();
                scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler<,>));
                scanner.ConnectImplementationsToTypesClosing(typeof(INotificationHandler<>));
            }});

            r.For<IMediator>().Use<Mediator>().Transient();
            r.For<ServiceFactory>().Use(ctx => ctx.GetInstance);
            r.For<IMediatorExecutor>().Use(ctx => new MediatorExecutor(ctx.GetInstance<IServiceScopeFactory>()));

            r.AddAppServices(configuration);

            r.AddSingleton(configuration)
                .AddLogging()
                .AddOptions()
                .Configure<CloudformationOutputs>(configuration.GetSection(""CloudformationOutputs""))
                .Configure<AuthenticationSettings>(configuration.GetSection(""Authentication""));

            var tracingOptions = new TracingOptions(configuration);
            if (tracingOptions.Enabled)
            {{
                r.AddDatadogOpenTracing(new TracingSettings
                {{
                    TracingAddress = tracingOptions.TracingAddress,
                    ServiceName = tracingOptions.ServiceName
                }});

                r.AddTransient<IDbDiagnosticsFactory, ServiceDbDiagnosticsFactory>();
            }}
        "
            });

            @class.Method.Add(
                new CMethod
            {
                AccessModifier    = CAccessModifier.Public,
                IsStatic          = true,
                IsExtensionMethod = true,
                ReturnType        = "void",
                MethodName        = "Dispose",
                Parameter         = new List <CParameter>
                {
                    new CParameter {
                        Type = "IServiceProvider", ParameterName = "services"
                    }
                },
                CodeSnippet = "_container.Dispose();"
            });


            return(@class);
        }
コード例 #25
0
 public void VisitCInterface(CInterface sInterface)
 {
     _interfaceVisitor.Visit(this, sInterface);
 }
コード例 #26
0
ファイル: MainWindow.xaml.cs プロジェクト: Frimia/SynapseX-1
        private void LaunchWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            SetStatusText("Loading Synapse...", 25);

            var BaseDirectory = Directory.GetParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
                                .FullName;

            try
            {
                Directory.SetCurrentDirectory(BaseDirectory);
                CInterface.Init();
            }
            catch (Exception)
            {
                Dispatcher.Invoke(() =>
                {
                    Topmost = false;
                    MessageBox.Show(
                        "Failed to load Synapse libraries. Please check you have the Visual Studio 2017 Redistrutable installed.",
                        "Synapse X", MessageBoxButton.OK, MessageBoxImage.Error);
                    Environment.Exit(0);
                });
            }

            SetStatusText("Getting version...", 50);

            var RawArgs     = Environment.GetCommandLineArgs();
            var DecodedArgs = DecodeUrlString(RawArgs[1]).Split(' ');
            var Args        = DecodedArgs.Select(Arg => Arg.Split(':')).ToDictionary(Split => Split[0], CombineArgs);

            int SecureSeed;

            using (var RNG = new RNGCryptoServiceProvider())
            {
                var Data = new byte[4];
                RNG.GetBytes(Data);

                SecureSeed = BitConverter.ToInt32(Data, 0);
            }

            var SpoofBrowserTracker = new Random(SecureSeed).Next();
            var UnixEpoch           =
                new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var UnixTime = (long)(DateTime.UtcNow - UnixEpoch).TotalMilliseconds;

            string CurrentVersion;

            using (var WC = new WebClient())
            {
                CurrentVersion =
                    WC.DownloadString(
                        "https://versioncompatibility.api.roblox.com/GetCurrentClientVersionUpload/?apiKey=76e5a40c-3ae1-4028-9f10-7c62520bd94f&binaryType=WindowsPlayer")
                    .Replace("\"", "");
            }

            SetStatusText("Launching...", 75);

            var VersionFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), $"Roblox\\Versions\\{CurrentVersion}\\");

            if (!Directory.Exists(VersionFolder))
            {
                VersionFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), $"Roblox\\Versions\\{CurrentVersion}\\");
                if (!Directory.Exists(VersionFolder))
                {
                    VersionFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), $"Roblox\\Versions\\{CurrentVersion}\\");
                    if (!Directory.Exists(VersionFolder))
                    {
                        if (!DataInterface.Exists("launcherbackup") || !File.Exists(DataInterface.Read <string>("launcherbackup")))
                        {
                            Dispatcher.Invoke(() =>
                            {
                                MessageBox.Show(
                                    "Synapse X has detected a Roblox update and could not find its backup executable. Please reinstall Roblox.",
                                    "Synapse X", MessageBoxButton.OK, MessageBoxImage.Warning);
                            });

                            Environment.Exit(0);
                            return;
                        }

                        Process.Start(DataInterface.Read <string>("launcherbackup"), RawArgs[1]);
                        Environment.Exit(0);
                        return;
                    }
                }
            }

            var SI  = new STARTUPINFO();
            var Suc = CreateProcess(Path.Combine(VersionFolder, "RobloxPlayerBeta.exe"),
                                    $"--play -a https://www.roblox.com/Login/Negotiate.ashx -t {Args["gameinfo"]} -j {Args["placelauncherurl"].Replace(Args["browsertrackerid"], SpoofBrowserTracker.ToString())} -b {SpoofBrowserTracker} --launchtime={UnixTime} --rloc {Args["robloxLocale"]} --gloc {Args["gameLocale"]}",
                                    IntPtr.Zero, IntPtr.Zero, false,
                                    ProcessCreationFlags.CREATE_SUSPENDED,
                                    IntPtr.Zero, null, ref SI, out var PI);

            if (Suc)
            {
                if (!SendData("SynapseLaunch", "SYN_LAUNCH_NOTIIFCATION|" + PI.dwProcessId))
                {
                    DataInterface.Save("savedpid", new Data.SavedPid
                    {
                        Pid       = Convert.ToInt32(PI.dwProcessId),
                        StartTime = Process.GetProcessById(Convert.ToInt32(PI.dwProcessId)).StartTime
                    });

                    StreamReader InteractReader;

                    new Thread(() =>
                    {
                        try
                        {
                            var PS   = new PipeSecurity();
                            var Rule = new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null),
                                                          PipeAccessRights.ReadWrite, AccessControlType.Allow);
                            PS.AddAccessRule(Rule);
                            var Server = new NamedPipeServerStream("SynapseInteract", PipeDirection.InOut, 1,
                                                                   PipeTransmissionMode.Byte, PipeOptions.None, 0, 0, PS);
                            Server.WaitForConnection();
                            InteractReader = new StreamReader(Server);

                            while (true)
                            {
                                string Line;
                                try
                                {
                                    Line = InteractReader.ReadLine();
                                }
                                catch (Exception)
                                {
                                    Line = "SYN_INTERRUPT";
                                }

                                InteractMessageRecieved?.Invoke(this, Line);
                                if (Line != "SYN_READY" && Line != "SYN_REATTACH_READY" && Line != "SYN_INTERRUPT")
                                {
                                    continue;
                                }

                                Thread.Sleep(1500);
                                Environment.Exit(0);
                            }
                        }
                        catch (Exception)
                        {
                            Environment.Exit(0);
                        }
                    }).Start();

                    InteractMessageRecieved += delegate(object Sender, string Input)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            switch (Input)
                            {
                            case "SYN_CHECK_WL":
                                SetStatusText("Checking whitelist...", 80);
                                break;

                            case "SYN_SCANNING":
                                SetStatusText("Scanning...", 95);
                                break;

                            case "SYN_INTERRUPT":
                                Environment.Exit(0);
                                break;

                            case "SYN_READY":
                                {
                                    SetStatusText("Ready!", 100);
                                    break;
                                }
                            }
                        });

                        if (Input == "SYN_READY")
                        {
                            var Read    = DataInterface.Read <Data.OptionsHolder>("options");
                            var Options = JsonConvert.DeserializeObject <Data.Options>(Read.Data);

                            var EnableUnlock     = Options.UnlockFPS ? "TRUE" : "FALSE";
                            var EnableInternalUI = Options.InternalUI ? "TRUE" : "FALSE";
                            var EnableIngameChat = Options.IngameChat ? "TRUE" : "FALSE";
                            Execute(Convert.ToInt32(PI.dwProcessId), "SYN_FILE_PATH|" + Path.Combine(BaseDirectory, "workspace") + "|" + EnableUnlock + "|FALSE|" + EnableInternalUI + "|" + EnableIngameChat);

                            Thread.Sleep(1500);
                            Environment.Exit(0);
                        }
                    };

                    CInterface.Inject(BaseDirectory + "\\bin\\" + Utils.CreateFileName("Synapse.dll"),
                                      BaseDirectory + "\\bin\\redis\\D3DCompiler_43.dll",
                                      BaseDirectory + "\\bin\\redis\\xinput1_3.dll", Convert.ToInt32(PI.dwProcessId), true);
                    ResumeThread(PI.hThread);

                    return;
                }

                CInterface.Inject(BaseDirectory + "\\bin\\" + Utils.CreateFileName("Synapse.dll"),
                                  BaseDirectory + "\\bin\\redis\\D3DCompiler_43.dll", BaseDirectory + "\\bin\\redis\\xinput1_3.dll",
                                  Convert.ToInt32(PI.dwProcessId), true);
                ResumeThread(PI.hThread);
            }

            SetStatusText("Ready!", 100);

            Thread.Sleep(1500);
            Environment.Exit(0);
        }
コード例 #27
0
        public void Visit(IVisitor visitor, CInterface @interface)
        {
            CodeWriter.Clear();
            //CodeWriter.WriteLine("using System;"); //todo: use metadata
            foreach (var r in @interface.NamespaceRef)
            {
                CodeWriter.WriteLine($"using {r.ReferenceTo.NamespaceName};");
            }

            CodeWriter.WriteLine();

            CodeWriter.WriteLine($"namespace {@interface.Namespace}");
            CodeWriter.WriteLine("{");
            CodeWriter.Indent();


            CodeWriter.Write($"public interface {@interface.InterfaceName}");
            if (@interface.IsGeneric)
            {
                CodeWriter.Write("<T>");
            }

            if (@interface.InheritsFrom != null)
            {
                CodeWriter.Write($" : {@interface.InheritsFrom.InterfaceName}");
                if (@interface.InheritsFrom.IsGeneric)
                {
                    CodeWriter.Write("<T>");
                }
            }
            if (@interface.Where.Any())
            {
                CodeWriter.Write(" where ");
                foreach (var w in @interface.Where)
                {
                    CodeWriter.Write(w.WhereName);
                }
            }

            CodeWriter.WriteLine("");
            CodeWriter.WriteLine("{");
            CodeWriter.Indent();
            //CodeWriter.WriteLine("//methods go here");
            int methodIndex = 0;

            foreach (var method in @interface.Method)
            {
                method.Accept(visitor);
                methodIndex++;

                /*
                 * if (methodIndex < @interface.Method.Count)
                 * {
                 *  CodeWriter.WriteLine();
                 * }*/
            }
            CodeWriter.Unindent();
            CodeWriter.WriteLine("}");
            CodeWriter.Unindent();
            CodeWriter.Write("}");
        }