예제 #1
0
    /// <summary>
    /// 返回数据库连接字符串
    /// </summary>
    static public string GetConnectionString()
    {
        string LinkString = "";

        LinkString = WebConfigReader.GetDatabaseString();
        return(LinkString);
    }
예제 #2
0
        public static void Configuration(IAppBuilder appBuilder)
        {
            var cfgReader = new WebConfigReader();
            var cookieAuthenticationOptions = new CookieAuthenticationOptions
            {
                AuthenticationType = ConstantStrings.AuthorizationCookieName,
                LoginPath          = new PathString("/Login")
            };

            appBuilder.UseCookieAuthentication(cookieAuthenticationOptions);

            appBuilder.UseFacebookAuthentication(new FacebookAuthenticationOptions
            {
                AppId     = cfgReader.FacebookAppId,
                AppSecret = cfgReader.FacebookAppSecret,
                SignInAsAuthenticationType = ConstantStrings.AuthorizationCookieName
            });

            appBuilder.UseTwitterAuthentication(new TwitterAuthenticationOptions
            {
                ConsumerKey                     = cfgReader.TwitterConsumerKey,
                ConsumerSecret                  = cfgReader.TwitterConsumerSecret,
                SignInAsAuthenticationType      = ConstantStrings.AuthorizationCookieName,
                BackchannelCertificateValidator = null   // can be for demo purposes
            });


            appBuilder.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
            {
                ClientId     = cfgReader.GoogleClientId,
                ClientSecret = cfgReader.GoogleClientSecret,
                SignInAsAuthenticationType = ConstantStrings.AuthorizationCookieName
            });
        }
예제 #3
0
 public static void StartProcess()
 {
     lock (lockObj)
     {
         if (SignalConnectionManager.ConnectedClient == 1)
         {
             RedisCacheServerProcess = new Process();
             RedisCacheServerProcess.StartInfo.FileName = WebConfigReader.Read("RedisServerExePath");
             RedisCacheServerProcess.Start();
         }
     }
 }
예제 #4
0
        public static List <StockModel.Symbol> GetSymbolForMarket(Exchange exchange)
        {
            // Method to get all the company names & their symbols and set their default value & Id
            int i = 1;

            Random random = new Random();
            List <StockModel.Symbol> symbols = new List <StockModel.Symbol>();
            string jsonString;
            string symbolFilePath = string.Empty;

            //exchange specific symbol file paths are configured
            symbolFilePath = WebConfigurationManager.AppSettings[exchange.ToString() + "_SymbolFilePath"];

            //exchange specific symbol file paths are not configured. Pick Defaults.
            if (string.IsNullOrEmpty(symbolFilePath))
            {
                symbolFilePath = WebConfigReader.Read("SymbolFilePath");
            }

            jsonString = System.IO.File.ReadAllText(symbolFilePath);

            JArray jsonArray = JsonConvert.DeserializeObject <JArray>(jsonString);

            foreach (JObject jsonObject in jsonArray)
            {
                StockModel.Symbol symbol = new StockModel.Symbol();
                foreach (var property in jsonObject)
                {
                    if (property.Key == "Name")
                    {
                        symbol.SymbolName = property.Value.ToString();
                    }
                    if (property.Key == "Symbol")
                    {
                        symbol.SymbolCode = property.Value.ToString();
                    }

                    symbol.DefaultVal = random.NextDouble() * 1000;
                    symbol.Id         = i;
                }
                i = i + 1;
                symbols.Add(symbol);
            }

            return(symbols);
        }
예제 #5
0
        public static void StartProcess(string exchange)
        {
            lock (lockObj)
            {
                if (SignalConnectionManager.ConnectedClient == 1)
                {
                    StockDataGeneratorProcess = new Process();
                    StockDataGeneratorProcess.StartInfo.FileName  = WebConfigReader.Read("DataGeneratorProcessPath");
                    StockDataGeneratorProcess.StartInfo.Arguments = string.Format("\"{0}\" \"{1}\"", exchange, WebConfigReader.Read("DataGenerator"));
                    StockDataGeneratorProcess.Start();

                    MVAGeneratorProcess = new Process();
                    MVAGeneratorProcess.StartInfo.FileName  = WebConfigReader.Read("MVAGeneratorProcessPath");
                    MVAGeneratorProcess.StartInfo.Arguments = string.Format("\"{0}\" \"{1}\"", Constants.REDIS_MVA_ROOM_PREFIX, exchange);
                    MVAGeneratorProcess.Start();
                }
            }
        }
예제 #6
0
        protected void Application_Start()
        {
            // Create the container as usual.
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            container.Register <IWebConfigReader, WebConfigReader>(Lifestyle.Scoped);
            container.Register <IBase64Codec, Base64Codec>(Lifestyle.Scoped);
            container.Register <IHttpClientAuthorizeConfigurator, HttpClientAuthorizeConfigurator>(Lifestyle.Scoped);

            var webConfigReader = new WebConfigReader();
            var clientProvider  = new HttpClientProvider(webConfigReader);

            container.Register <IHttpClientProvider>(() => clientProvider, Lifestyle.Scoped);

            container.Register <IGitHubAPICredentialsReader, GitHubAPICredentialsReader>(Lifestyle.Scoped);
            container.Register <IGitHubApiRepoHelpers, GitHubApiRepoHelpers>(Lifestyle.Scoped);
            container.Register <IGitHubRepos, GitHubRepos>(Lifestyle.Scoped);
            container.Register <IGitHubPullReqs, GitHubPullReqs>(Lifestyle.Scoped);

            container.Register <IGitHubApiCallServices, GitHubApiCallServices>(Lifestyle.Scoped);
            container.Register <IGhUserReposServices, GhUserReposServices>(Lifestyle.Scoped);

            // This is an extension method from the [Simple Injector] integration package.
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));

            // the rest of the 'normal' registration stuff.
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
예제 #7
0
        public static void Main(string[] args)
        {
            //FhirSearchParamters test = new FhirSearchParamters();
            //string SQL = test.GetMSSQLQuerySearchParameterTargetResources();

            Dictionary <string, string> Arguments = ProcessArguments(args);
            bool UnattendedMode = false;

            if (Arguments.ContainsKey("-unattendedmode"))
            {
                if (Arguments["-unattendedmode"] == "true")
                {
                    UnattendedMode = true;
                }
            }


            WebConfigReader  WebConfigReader = new WebConfigReader();
            DbConnectionInfo ConnectionInfo  = WebConfigReader.Read("PyroConnectionString");

            //string connectionString = string.Empty;
            if (ConnectionInfo != null)
            {
                string            TargetScriptFolder = string.Empty;
                Tools.SynchToDbUp SynchToDbUp        = new Tools.SynchToDbUp();

                UpgradeEngineBuilder UpgradeEngineBuilder = null;
                if (ConnectionInfo.ProviderName == ResourceStore.MsSQLProviderName)
                {
                    SynchToDbUp.RunMsSQL(ConnectionInfo.ConnectionString);

                    EnsureDatabase.For.SqlDatabase(ConnectionInfo.ConnectionString);

                    TargetScriptFolder   = $"{ResourceStore.BaseSqlScriptFolder}.{ResourceStore.MsSQLScriptFolder}";
                    UpgradeEngineBuilder = DeployChanges.To
                                           .SqlDatabase(ConnectionInfo.ConnectionString, null) //null or "" for default schema for user
                                           .JournalToSqlTable("dbo", ResourceStore.DbUpSchemaVersionsTableName)
                                           .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly(), (string s) => s.StartsWith(TargetScriptFolder));
                }
                else if (ConnectionInfo.ProviderName == ResourceStore.PostgreSQLProviderName)
                {
                    SynchToDbUp.RunPostgreSQL(ConnectionInfo.ConnectionString);
                    EnsureDatabase.For.PostgresqlDatabase(ConnectionInfo.ConnectionString);

                    TargetScriptFolder   = $"{ResourceStore.BaseSqlScriptFolder}.{ResourceStore.PostgreSqlScriptFolder}";
                    UpgradeEngineBuilder = DeployChanges.To
                                           .PostgresqlDatabase(ConnectionInfo.ConnectionString, null) //null or "" for default schema for user
                                           .JournalToPostgresqlTable("public", ResourceStore.DbUpSchemaVersionsTableName)
                                           .WithScriptsAndCodeEmbeddedInAssembly(Assembly.GetExecutingAssembly(), (string s) => s.StartsWith(TargetScriptFolder));
                }
                else
                {
                    throw new ApplicationException($"The ProviderName from the Connection information in the Web.Config file is not supported. Name was {ConnectionInfo.ProviderName}, supported are '{ResourceStore.MsSQLProviderName}' and '{ResourceStore.PostgreSQLProviderName}'.");
                }

                //Common to both SQL Server and PostgreSQL
                UpgradeEngineBuilder.WithTransactionPerScript()
                .WithVariablesDisabled()
                .LogToConsole()
                .WithExecutionTimeout(TimeSpan.FromSeconds(180));

                var upgrader = UpgradeEngineBuilder.Build();

                Console.WriteLine("Building upgrade knowledge, please wait...");
                System.Threading.Thread.Sleep(1000 * 10);
                bool UpgradeRequired = upgrader.IsUpgradeRequired();
                Console.WriteLine("Database upgrade required: " + UpgradeRequired.ToString());
                if (UpgradeRequired)
                {
                    var ScriptsToExecute = upgrader.GetScriptsToExecute();
                    Console.WriteLine("Scripts to execute:");
                    foreach (var Script in ScriptsToExecute)
                    {
                        Console.ForegroundColor = ConsoleColor.Cyan;

                        Console.WriteLine($"  {Script.Name.Substring(TargetScriptFolder.Count() + 1, Script.Name.Count() - (TargetScriptFolder.Count() + 1))}");
                    }



                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("");
                    bool OutputComplted = false;
                    while (!OutputComplted)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Would you like the SQL scripts output to a folder");
                        Console.WriteLine("before they are applied to the database?");
                        Console.Write("Answer (Y/N)?: ");
                        bool OutputSqlScripts = false;
                        if (UnattendedMode)
                        {
                            OutputSqlScripts = false;
                            OutputComplted   = true;
                        }
                        else
                        {
                            ConsoleKeyInfo Input = Console.ReadKey();
                            if (Input.Key == ConsoleKey.Y)
                            {
                                OutputSqlScripts = true;
                            }
                            else
                            {
                                OutputComplted = true;
                            }
                        }

                        if (OutputSqlScripts)
                        {
                            Console.Clear();
                            Console.WriteLine();
                            Console.WriteLine("Please type the directory name where you would like the SQL scripts writen to?");
                            Console.WriteLine("e.g 'C:\\Temp\\PyroSqlScripts' and hit [Enter]");
                            Console.Write("Directory: ");
                            string UserPath = Console.ReadLine();
                            UserPath = UserPath.TrimEnd('\\');
                            Tools.ScriptFileDrop ScriptFileDrop = new Tools.ScriptFileDrop(UserPath, ScriptsToExecute);
                            string ScriptFileDropResult         = ScriptFileDrop.Output(TargetScriptFolder);
                            if (string.IsNullOrWhiteSpace(ScriptFileDropResult))
                            {
                                OutputComplted = true;
                                foreach (var Script in ScriptsToExecute)
                                {
                                    Console.ForegroundColor = ConsoleColor.Cyan;
                                    Console.WriteLine($"  {Script.Name.Substring(TargetScriptFolder.Count() + 1, Script.Name.Count() - (TargetScriptFolder.Count() + 1))}");
                                }

                                Console.WriteLine();
                                Console.ForegroundColor = ConsoleColor.Magenta;
                                Console.WriteLine($"All Sql Scripts where output to : '{UserPath}'");
                            }
                            else
                            {
                                Console.WriteLine();
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine(ScriptFileDropResult);
                                Console.ForegroundColor = ConsoleColor.Magenta;
                                OutputComplted          = false;
                            }
                        }
                    }


                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("");
                    Console.WriteLine("");
                    Console.WriteLine("###############################################################################");
                    Console.WriteLine("################### Have you backed up your database? #########################");
                    Console.WriteLine("###############################################################################");
                    Console.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("Do you wish to perform the upgrade against the database ?");
                    Console.Write("Answer (Y/N)?: ");
                    bool Run = false;
                    if (UnattendedMode)
                    {
                        Run = true;
                    }
                    else
                    {
                        ConsoleKeyInfo Input = Console.ReadKey();
                        if (Input.Key == ConsoleKey.Y)
                        {
                            Run = true;
                        }
                    }

                    if (Run)
                    {
                        DateTime StartTime = DateTime.Now;
                        Console.ResetColor();
                        Console.WriteLine();
                        Console.WriteLine($"Start Time: {StartTime.ToShortDateString()} {StartTime.ToShortTimeString()}");
                        var result = upgrader.PerformUpgrade();

                        // Display the result
                        if (result.Successful)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("Success!");
                            DateTime EndTime = DateTime.Now;
                            var      Timer   = EndTime.Subtract(StartTime);
                            Console.ResetColor();
                            Console.WriteLine($"TimeTaken: {Timer.Hours}:Hrs, {Timer.Minutes}:Mins, {Timer.Seconds}: Secs");
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine(result.Error);
                            Console.WriteLine("Failed!");
                            DateTime EndTime = DateTime.Now;
                            var      Timer   = EndTime.Subtract(StartTime);
                            Console.ResetColor();
                            Console.WriteLine($"TimeTaken: {Timer.Hours}:Hrs, {Timer.Minutes}:Mins, {Timer.Seconds}: Secs");
                        }
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("Upgrade aborted, press any key to end.");
                    }
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("");
                    Console.WriteLine("No upgrades are required!");
                }

                Console.ResetColor();
                Console.WriteLine("");
                Console.Write("Hit any key to end.");
                Console.ReadKey();
            }
        }