Exemplo n.º 1
0
    public static async Task <IServiceCollection> ConfigureBankService(this IServiceCollection service, ApplicationOption option)
    {
        service.VerifyNotNull(nameof(service));

        ApplicationOption applicationOption = await DirectoryClient.Run <ApplicationOption>(option.DirectoryUrl, option.DirectoryApiKey, async client =>
        {
            ServiceRecord serviceRecord  = await client.GetServiceRecord(option.RunEnvironment, "Bank");
            ServiceRecord artifactRecord = await client.GetServiceRecord(option.RunEnvironment, "Artifact");

            option = option with
            {
                HostUrl        = serviceRecord.HostUrl,
                ApiKey         = serviceRecord.ApiKey,
                ArtifactUrl    = artifactRecord.HostUrl,
                ArtifactApiKey = artifactRecord.ApiKey,
            };

            return(option.Verify());
        });

        service.AddSingleton(applicationOption);
        service.AddSingleton <BankAccountService>();
        service.AddSingleton <BankTransactionService>();

        service.AddHttpClient <ArtifactClient>((service, httpClient) =>
        {
            ApplicationOption option = service.GetRequiredService <ApplicationOption>();
            httpClient.BaseAddress   = new Uri(option.ArtifactUrl);
            httpClient.DefaultRequestHeaders.Add(Constants.ApiKeyName, option.ArtifactApiKey);
        });

        return(service);
    }
Exemplo n.º 2
0
 public UserController(IAllUser userRep, ApplicationOption appOptions, ServiceUser serviceUser, EmailService emailService)
 {
     this.userRep      = userRep;
     this.appOptions   = appOptions;
     this.serviceUser  = serviceUser;
     this.emailService = emailService;
 }
Exemplo n.º 3
0
    public static HttpClient GetClient()
    {
        lock (_lock)
        {
            if (_client != null)
            {
                return(_client);
            }

            ILogger logger = LoggerFactory.Create(builder =>
            {
                builder.AddDebug();
            }).CreateLogger <Program>();

            _host = new WebApplicationFactory <Program>()
                    .WithWebHostBuilder(builder =>
            {
                builder.UseEnvironment("Test");
                builder.ConfigureServices(service => ConfigureModelBindingExceptionHandling(service, logger));
            });

            ApplicationOption option = _host.Services.GetRequiredService <ApplicationOption>();

            _client = _host.CreateClient();
            _client.DefaultRequestHeaders.Add(Constants.ApiKeyName, option.ApiKey);
            _client.DefaultRequestHeaders.Add(Constants.BypassCacheName, "true");

            return(_client);
        }
    }
Exemplo n.º 4
0
        private void LoadConfig()
        {
            ApplicationOption app = new ApplicationOption();
            var opt = app.CreateOption(defaultFile);

            app.WriteOption(defaultFile, opt);
            option = app.ReadOption(option.FileName);
        }
        public ApplicationOption GetApplicationOption()
        {
            UnitOfWork.BeginTransaction();
            ApplicationOption result = ApplicationSettingSystem.GetApplicationOption();

            UnitOfWork.CommitTransaction();
            return(result);
        }
        public void TestAll()
        {
            ApplicationSettingFacade facade = new ApplicationSettingFacade(UnitOfWork);
            ApplicationOption        list   = facade.GetApplicationOption();

            if (list != null)
            {
            }
        }
Exemplo n.º 7
0
    public static ApplicationOption VerifyBootstrap(this ApplicationOption option)
    {
        option.VerifyNotNull(nameof(option));

        option.DirectoryUrl.VerifyNotEmpty($"{nameof(option.DirectoryUrl)} is required");
        option.DirectoryApiKey.VerifyNotEmpty($"{nameof(option.DirectoryApiKey)} is required");

        return(option);
    }
Exemplo n.º 8
0
 public ApplicationOption GetApplicationOption()
 {
     using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CMSDataStoreKey))
     {
         ApplicationSettingFacade settingFacade = new ApplicationSettingFacade(uow);
         ApplicationOption        result        = settingFacade.GetApplicationOption();
         return(result);
     }
 }
Exemplo n.º 9
0
    public static ApplicationOption VerifyPartial(this ApplicationOption option)
    {
        option.VerifyNotNull(nameof(option));

        option.ConfigStore.VerifyNotEmpty($"{nameof(option.ConfigStore)} is required");
        option.DirectoryUrl.VerifyNotEmpty($"{nameof(option.DirectoryUrl)} is required");
        option.DirectoryApiKey.VerifyNotEmpty($"{nameof(option.DirectoryApiKey)} is required");

        return(option);
    }
Exemplo n.º 10
0
    public static IServiceCollection ConfigureDirectoryService(this IServiceCollection service)
    {
        service.VerifyNotNull(nameof(service));

        service.AddSingleton <IMemoryCache, MemoryCache>();

        service.AddSingleton <DirectoryService>(service =>
        {
            ApplicationOption option     = service.GetRequiredService <ApplicationOption>();
            ILoggerFactory loggerFactory = service.GetRequiredService <ILoggerFactory>();
            IMemoryCache memoryCache     = service.GetRequiredService <IMemoryCache>();

            var datalakeOption = new DatalakeStoreOption
            {
                AccountName   = option.Storage.AccountName,
                ContainerName = option.Storage.ContainerName,
                AccountKey    = option.Storage.AccountKey,
                BasePath      = option.Storage.BasePath
            };

            var store    = new DatalakeStore(datalakeOption, loggerFactory.CreateLogger <DatalakeStore>());
            var document = new DocumentStorage(store, memoryCache);
            return(new DirectoryService(document));
        });

        service.AddSingleton <IdentityService>(service =>
        {
            ApplicationOption option     = service.GetRequiredService <ApplicationOption>();
            ILoggerFactory loggerFactory = service.GetRequiredService <ILoggerFactory>();
            IMemoryCache memoryCache     = service.GetRequiredService <IMemoryCache>();

            var datalakeOption = new DatalakeStoreOption
            {
                AccountName   = option.IdentityStorage.AccountName,
                ContainerName = option.IdentityStorage.ContainerName,
                AccountKey    = option.IdentityStorage.AccountKey,
                BasePath      = option.IdentityStorage.BasePath
            };

            var store    = new DatalakeStore(datalakeOption, loggerFactory.CreateLogger <DatalakeStore>());
            var document = new DocumentStorage(store, memoryCache);
            return(new IdentityService(document, loggerFactory.CreateLogger <IdentityService>()));
        });

        service.AddSingleton <SigningService>(service =>
        {
            DirectoryService directoryService = service.GetRequiredService <DirectoryService>();
            IdentityService identityService   = service.GetRequiredService <IdentityService>();
            ILoggerFactory loggerFactory      = service.GetRequiredService <ILoggerFactory>();

            return(new SigningService(directoryService, identityService, loggerFactory.CreateLogger <SigningService>()));
        });

        return(service);
    }
Exemplo n.º 11
0
    public static ApplicationOption Verify(this ApplicationOption option)
    {
        option.VerifyBootstrap();

        option.HostUrl.VerifyNotEmpty($"{nameof(option.HostUrl)} is required");
        option.ApiKey.VerifyNotEmpty($"{nameof(option.ApiKey)} is required");
        option.ArtifactUrl.VerifyNotNull(nameof(option.ArtifactUrl));
        option.ArtifactApiKey.VerifyNotNull(nameof(option.ArtifactApiKey));

        return(option);
    }
Exemplo n.º 12
0
        internal ApplicationOption GetApplicationOption()
        {
            ApplicationOption          option  = new ApplicationOption();
            IApplicationSettingService service = UnitOfWork.GetService <IApplicationSettingService>();
            var query = service.GetAll();

            if (query.HasResult)
            {
                ParseSettings(option, query.DataList);
            }

            return(option);
        }
Exemplo n.º 13
0
    public static IApplicationBuilder ConfigureDirectoryService(this IApplicationBuilder app)
    {
        app.VerifyNotNull(nameof(app));

        ApplicationOption option = app.ApplicationServices.GetRequiredService <ApplicationOption>();

        app.UseMiddleware <ApiKeyMiddleware>(Constants.ApiKeyName, option.ApiKey, "/api/ping".ToEnumerable());

        app.ApplicationServices
        .GetRequiredService <IServiceStatus>()
        .SetStatus(ServiceStatusLevel.Ready, "Ready and running");

        return(app);
    }
Exemplo n.º 14
0
        private void SetupEmailSender(ApplicationOption appOption)
        {
            string smtpServer = appOption.SMTPServer.Trim();

            if (smtpServer.Length > 0)
            {
                EmailSender sender = new EmailSender(smtpServer);
                sender.Port = appOption.SMTPPort;
                if (appOption.SMTPUsername.TrimHasValue() && appOption.SMTPPassword.TrimHasValue())
                {
                    sender.Credentials = new NetworkCredential(appOption.SMTPUsername.Trim(), appOption.SMTPPassword.Trim(), smtpServer);
                }

                EmailSender = sender;
            }
        }
Exemplo n.º 15
0
        public static HttpClient GetClient()
        {
            lock (_lock)
            {
                if (_client != null)
                {
                    return(_client);
                }

                _host = new WebApplicationFactory <Program>()
                        .WithWebHostBuilder(builder => builder.UseEnvironment("Test"));

                ApplicationOption option = _host.Services.GetRequiredService <ApplicationOption>();

                _client = _host.CreateClient();
                _client.DefaultRequestHeaders.Add(Constants.ApiKeyName, option.ApiKey);
                _client.DefaultRequestHeaders.Add(Constants.BypassCacheName, "true");

                return(_client);
            }
        }
Exemplo n.º 16
0
    public static ApplicationOption Verify(this ApplicationOption option)
    {
        option.VerifyNotNull(nameof(option));

        option.ApiKey.VerifyNotEmpty($"{nameof(option.ApiKey)} is required");
        option.ConfigStore.VerifyNotEmpty($"{nameof(option.ConfigStore)} is required");

        option.Storage.VerifyNotNull($"{nameof(option.ConfigStore)} is required");
        option.Storage.AccountName.VerifyNotEmpty($"Storage.{nameof(option.Storage.AccountName)} is required");
        option.Storage.ContainerName.VerifyNotEmpty($"Storage.{nameof(option.Storage.ContainerName)} is required");
        option.Storage.AccountKey.VerifyNotEmpty($"Storage.{nameof(option.Storage.AccountKey)} is required");
        option.Storage.BasePath.VerifyNotEmpty($"Storage.{nameof(option.Storage.BasePath)} is required");

        option.IdentityStorage.VerifyNotNull($"{nameof(option.IdentityStorage)} is required");
        option.IdentityStorage.AccountName.VerifyNotEmpty($"IdentityStorage.{nameof(option.IdentityStorage.AccountName)} is required");
        option.IdentityStorage.ContainerName.VerifyNotEmpty($"IdentityStorage.{nameof(option.IdentityStorage.ContainerName)} is required");
        option.IdentityStorage.AccountKey.VerifyNotEmpty($"IdentityStorage.{nameof(option.IdentityStorage.AccountKey)} is required");
        option.IdentityStorage.BasePath.VerifyNotEmpty($"IdentityStorage.{nameof(option.IdentityStorage.BasePath)} is required");

        return(option);
    }
Exemplo n.º 17
0
    public static ApplicationOption Verify(this ApplicationOption option)
    {
        option.VerifyPartial();

        option.HostUrl.VerifyNotEmpty($"{nameof(option.HostUrl)} is required");
        option.ApiKey.VerifyNotEmpty($"{nameof(option.ApiKey)} is required");

        option.Storage.VerifyNotNull($"{nameof(option.ConfigStore)} is required");
        option.Storage.VerifyAssert(x => x.Count > 0, $"{nameof(option.ConfigStore)} is required");

        option.Storage
        .ForEach(x =>
        {
            x.AccountName.VerifyNotEmpty($"{nameof(x.AccountName)} is required");
            x.AccountName.VerifyNotEmpty($"{nameof(x.AccountName)} is required");
            x.ContainerName.VerifyNotEmpty($"{nameof(x.ContainerName)} is required");
            x.AccountKey.VerifyNotEmpty($"{nameof(x.AccountKey)} is required");
            x.BasePath.VerifyNotEmpty($"{nameof(x.BasePath)} is required");
        });

        return(option);
    }
Exemplo n.º 18
0
    public static async Task <IServiceCollection> ConfigureArtifactService(this IServiceCollection service, ApplicationOption option)
    {
        service.VerifyNotNull(nameof(service));

        ApplicationOption applicationOption = await DirectoryClient.Run <ApplicationOption>(option.DirectoryUrl, option.DirectoryApiKey, async client =>
        {
            ServiceRecord serviceRecord = await client.GetServiceRecord(option.RunEnvironment, "Artifact");
            IReadOnlyList <StorageRecord> storageRecords = await client.GetStorageRecord(option.RunEnvironment, "Artifact");

            return(option with
            {
                HostUrl = serviceRecord.HostUrl,
                ApiKey = serviceRecord.ApiKey,
                Storage = storageRecords,
            });
        });

        service.AddSingleton <IDocumentPackage, DocumentPackage>();
        service.AddSingleton(applicationOption);

        service.AddSingleton <DocumentPackageFactory>(service =>
        {
            ApplicationOption option     = service.GetRequiredService <ApplicationOption>();
            ILoggerFactory loggerFactory = service.GetRequiredService <ILoggerFactory>();

            var list = option.Storage
                       .Select(x => (Container: x.Container, Option: new DatalakeStoreOption
            {
                AccountName = x.AccountName,
                ContainerName = x.ContainerName,
                AccountKey = x.AccountKey,
                BasePath = x.BasePath
            }));

            return(new DocumentPackageFactory(list, loggerFactory));
        });

        return(service);
    }
Exemplo n.º 19
0
 public CustomerController(ICustomerService customerService, IOptions <ApplicationOption> options, ILogger <CustomerController> logger)
 {
     _customerService = customerService;
     _options         = options.Value;
     _logger          = logger;
 }
Exemplo n.º 20
0
        private void ParseSettings(ApplicationOption option, IEnumerable <ApplicationSettingData> settings)
        {
            ApplicationSettingData setting;

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.Name.ToString()));
            if (setting != null)
            {
                option.Name = setting.SettingValue;
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.Version.ToString()));
            if (setting != null)
            {
                option.Version = setting.SettingValue;
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsTestMode.ToString()));
            if (setting != null)
            {
                try { option.IsTestMode = Convert.ToBoolean(setting.SettingValue); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableSSL.ToString()));
            if (setting != null)
            {
                try { option.EnableSSL = Convert.ToBoolean(setting.SettingValue); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableMultiUser.ToString()));
            if (setting != null)
            {
                try
                {
                    option.EnableMultiUser = Convert.ToBoolean(setting.SettingValue);
                }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableGridColumnFilter.ToString()));
            if (setting != null)
            {
                try { option.EnableGridColumnFilter = Convert.ToBoolean(setting.SettingValue); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableNotification.ToString()));
            if (setting != null)
            {
                try { option.EnableNotification = Convert.ToBoolean(setting.SettingValue); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.SchedulerDefaultView.ToString()));
            if (setting != null)
            {
                try { option.SchedulerDefaultView = (SchedulerViewTypes)Enum.Parse(typeof(SchedulerViewTypes), setting.SettingValue.Trim()); }
                catch { }
            }
            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DayStartTime.ToString()));
            if (setting != null)
            {
                try { option.DayStartTime = TimeSpan.Parse(setting.SettingValue.Trim()); }
                catch { }
            }
            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DayEndTime.ToString()));
            if (setting != null)
            {
                try { option.DayEndTime = TimeSpan.Parse(setting.SettingValue.Trim()); }
                catch { }
            }
            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DropDownHeight.ToString()));
            if (setting != null)
            {
                try { option.DropDownHeight = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }
            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.GridPageSize.ToString()));
            if (setting != null)
            {
                try { option.GridPageSize = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }
            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EditFormColumnMax.ToString()));
            if (setting != null)
            {
                try { option.EditFormColumnMax = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.NewsContentBriefLength.ToString()));
            if (setting != null)
            {
                try { option.NewsContentBriefLength = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DateFormat.ToString()));
            if (setting != null)
            {
                try { option.DateFormat = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DateTimeFormat.ToString()));
            if (setting != null)
            {
                try { option.DateTimeFormat = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.TimeFormat.ToString()));
            if (setting != null)
            {
                try { option.TimeFormat = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DateFormatString.ToString()));
            if (setting != null)
            {
                try { option.DateFormatString = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DateTimeFormatString.ToString()));
            if (setting != null)
            {
                try { option.DateTimeFormatString = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.TimeFormatString.ToString()));
            if (setting != null)
            {
                try { option.TimeFormatString = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.SMTPServer.ToString()));
            if (setting != null)
            {
                try { option.SMTPServer = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.SMTPPort.ToString()));
            if (setting != null)
            {
                try { option.SMTPPort = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.SMTPUsername.ToString()));
            if (setting != null)
            {
                try { option.SMTPUsername = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.SMTPPassword.ToString()));
            if (setting != null)
            {
                try { option.SMTPPassword = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.OrderCoordinatorEmail.ToString()));
            if (setting != null)
            {
                try { option.OrderCoordinatorEmail = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DefaultEmailFrom.ToString()));
            if (setting != null)
            {
                try { option.DefaultEmailFrom = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.OrderTrackingUrlFormat.ToString()));
            if (setting != null)
            {
                try { option.OrderTrackingUrlFormat = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsEmailToCustomer.ToString()));
            if (setting != null)
            {
                try { option.IsEmailToCustomer = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsSetSOHold.ToString()));
            if (setting != null)
            {
                try { option.IsSetSOHold = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsEmailToSupplier.ToString()));
            if (setting != null)
            {
                try { option.IsEmailToSupplier = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsAccountActivateRequired.ToString()));
            if (setting != null)
            {
                try { option.IsAccountActivateRequired = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsShoppingSupported.ToString()));
            if (setting != null)
            {
                try { option.IsShoppingSupported = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsMultiLanguageSupported.ToString()));
            if (setting != null)
            {
                try { option.IsMultiLanguageSupported = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DefaultLanguageId.ToString()));
            if (setting != null)
            {
                try { option.DefaultLanguageId = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.GlobalProductCatalogId.ToString()));
            if (setting != null)
            {
                try { option.GlobalProductCatalogId = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }
            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.SupplierCatalogId.ToString()));
            if (setting != null)
            {
                try { option.SupplierCatalogId = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.SiteCoordinatorEmail.ToString()));
            if (setting != null)
            {
                try { option.SiteCoordinatorEmail = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.QuoteCoordinatorEmail.ToString()));
            if (setting != null)
            {
                try { option.QuoteCoordinatorEmail = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsQuoteSupported.ToString()));
            if (setting != null)
            {
                try { option.IsQuoteSupported = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableRegister.ToString()));
            if (setting != null)
            {
                try { option.EnableRegister = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }
        }
Exemplo n.º 21
0
 public CryptoService(ApplicationOption options)
 {
     this.options = options;
 }
Exemplo n.º 22
0
        public async Task InitializeMockUsers(IServiceProvider serviceProvider, MockDataInitializeContract mdata = null)
        {
            _userManager            = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
            _context                = serviceProvider.GetRequiredService <ApplicationDbContext>();
            _hexagonal              = serviceProvider.GetRequiredService <IHexagonal>();
            _locationHistoryService = serviceProvider.GetRequiredService <ILocationHistoryService>();
            _zoneBoundaryService    = serviceProvider.GetRequiredService <IZoneBoundaryService>();

            int i = 0;

            if (mdata == null)
            {
                //mdata = new MockDataInitializeContract() //kenzie
                //{
                //    Email = "*****@*****.**",
                //    Latitude = 30.3986877,
                //    Longitude = -97.72359399999999
                //};
                mdata = new MockDataInitializeContract() // dogwood
                {
                    Email     = "*****@*****.**",
                    Latitude  = 30.401916,
                    Longitude = -97.722651
                };
            }

            var option = await _context.ApplicationOptions
                         .OrderByDescending(a => a.OptionsDate)
                         .FirstOrDefaultAsync();

            if (option == null)
            {
                var appOption = new ApplicationOption()
                {
                    OptionsDate    = DateTime.Now.ToUniversalTime(),
                    DataTimeWindow = TimeSpan.FromHours(12),
                    EndUserLicenseAgreementSource = "http://www.google.com/",
                    TermsConditionsSource         = "http://www.google.com/",
                    PrivacyPolicySource           = "http://www.google.com/",
                    Version      = 1,
                    VersionMajor = 0,
                    VersionMinor = 0
                };
                await _context.ApplicationOptions
                .AddAsync(appOption);

                await _context.SaveChangesAsync();
            }

            //create the mock users if they don't exist
            for (i = 1; i <= NUMBEROFMOCKUSERS + NUMBEROFMOCKZONEUSERS; ++i)
            {
                string mockFirst  = String.Format("Mock{0}", i.ToString("D2"));
                string mockLast   = String.Format("Data{0}", i.ToString("D2"));
                string mockMail   = String.Format("{0}@RyanRauch.com", mockFirst);
                string mockNumber = String.Format("55512300{0}", i.ToString("D2"));
                string mockPass   = String.Format("Password{0}!", i.ToString("D2"));
                var    mock       = await _userManager.FindByEmailAsync(mockMail);

                if (mock == null)
                {
                    var user = new ApplicationUser
                    {
                        UserName    = mockFirst + mockLast,
                        Email       = mockMail,
                        DateOfBirth = DateTime.Now.Date.AddYears(-30).Subtract(TimeSpan.FromDays(30 * i)),
                        FirstName   = mockFirst,
                        LastName    = mockLast,
                        PhoneNumber = mockNumber.RemoveNonNumeric(),
                        AccountType = AccountType.MockedData,
                        Gender      = i % 2 == 0 ? AccountGender.Male : AccountGender.Female
                    };
                    var result = await _userManager.CreateAsync(user, mockPass);
                }
            }

            ///////////////////////////////////////////////////
            // Zone and ZoneShape Data
            ///////////////////////////////////////////////////
            // West 6th
            string zoneName    = "West 6th";
            var    currentZone = await _context.Zones.FirstOrDefaultAsync(z => z.Description.Equals(zoneName, StringComparison.OrdinalIgnoreCase));

            if (currentZone == null)
            {
                currentZone = new Zone()
                {
                    Description = zoneName, ARGBFill = "8095C6E4", Type = ZoneType.BarDistrict
                };
                await _context.Zones.AddAsync(currentZone);

                await _context.SaveChangesAsync();
            }
            currentZone = await _context.Zones.FirstOrDefaultAsync(z => z.Description.Equals(zoneName, StringComparison.OrdinalIgnoreCase));

            var currentZoneShapes = await _context.ZoneShapes.Where(z => z.ParentZoneId.Equals(currentZone.ZoneID)).ToArrayAsync();

            _context.ZoneShapes.RemoveRange(currentZoneShapes);
            await _context.SaveChangesAsync();

            i = 0;
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.273021, Longitude = -97.749524
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.271798, Longitude = -97.745204
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.268091, Longitude = -97.746655
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.269296, Longitude = -97.750918
            });
            await _context.SaveChangesAsync();

            // Rockrose-domain
            zoneName    = "Rockrose";
            currentZone = await _context.Zones.FirstOrDefaultAsync(z => z.Description.Equals(zoneName, StringComparison.OrdinalIgnoreCase));

            if (currentZone == null)
            {
                currentZone = new Zone()
                {
                    Description = zoneName, ARGBFill = "80FF0000", Type = ZoneType.BarDistrict
                };
                await _context.Zones.AddAsync(currentZone);

                await _context.SaveChangesAsync();
            }
            currentZone = await _context.Zones.FirstOrDefaultAsync(z => z.Description.Equals(zoneName, StringComparison.OrdinalIgnoreCase));

            currentZoneShapes = await _context.ZoneShapes.Where(z => z.ParentZoneId.Equals(currentZone.ZoneID)).ToArrayAsync();

            _context.ZoneShapes.RemoveRange(currentZoneShapes);
            await _context.SaveChangesAsync();

            i = 0;
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.39983, Longitude = -97.723719
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.40182, Longitude = -97.722989
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.402172, Longitude = -97.724245
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.403236, Longitude = -97.72374
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.402606, Longitude = -97.721659
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.399562, Longitude = -97.723011
            });
            await _context.SaveChangesAsync();

            // Warehouse District
            zoneName    = "Warehouse District";
            currentZone = await _context.Zones.FirstOrDefaultAsync(z => z.Description.Equals(zoneName, StringComparison.OrdinalIgnoreCase));

            if (currentZone == null)
            {
                currentZone = new Zone()
                {
                    Description = zoneName, ARGBFill = "80D2B7D8", Type = ZoneType.BarDistrict
                };
                await _context.Zones.AddAsync(currentZone);

                await _context.SaveChangesAsync();
            }
            currentZone = await _context.Zones.FirstOrDefaultAsync(z => z.Description.Equals(zoneName, StringComparison.OrdinalIgnoreCase));

            currentZoneShapes = await _context.ZoneShapes.Where(z => z.ParentZoneId.Equals(currentZone.ZoneID)).ToArrayAsync();

            _context.ZoneShapes.RemoveRange(currentZoneShapes);
            await _context.SaveChangesAsync();

            i = 0;
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.269036, Longitude = -97.74634
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.268019, Longitude = -97.742779
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.26522, Longitude = -97.743823
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.266814, Longitude = -97.749481
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.269279, Longitude = -97.750911
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.268091, Longitude = -97.746655
            });
            await _context.SaveChangesAsync();

            // 2nd Street
            zoneName    = "2nd Street";
            currentZone = await _context.Zones.FirstOrDefaultAsync(z => z.Description.Equals(zoneName, StringComparison.OrdinalIgnoreCase));

            if (currentZone == null)
            {
                currentZone = new Zone()
                {
                    Description = zoneName, ARGBFill = "806F7FBD", Type = ZoneType.BarDistrict
                };
                await _context.Zones.AddAsync(currentZone);

                await _context.SaveChangesAsync();
            }
            currentZone = await _context.Zones.FirstOrDefaultAsync(z => z.Description.Equals(zoneName, StringComparison.OrdinalIgnoreCase));

            currentZoneShapes = await _context.ZoneShapes.Where(z => z.ParentZoneId.Equals(currentZone.ZoneID)).ToArrayAsync();

            _context.ZoneShapes.RemoveRange(currentZoneShapes);
            await _context.SaveChangesAsync();

            i = 0;
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.266517, Longitude = -97.748421
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.26522, Longitude = -97.743823
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.263367, Longitude = -97.744544
            });
            _context.ZoneShapes.Add(new ZoneShape()
            {
                ParentZone = currentZone, ParentZoneId = currentZone.ZoneID, Order = ++i, Latitude = 30.264683, Longitude = -97.749128
            });
            await _context.SaveChangesAsync();


            //update current location data for mock users
            /////////////////////////////////////////////
            double latmin = mdata.Latitude - 0.0025d;
            double latmax = mdata.Latitude + 0.0025d;
            double lonmin = mdata.Longitude - 0.0012d;
            double lonmax = mdata.Longitude + 0.0012d;

            Random randomLat   = new Random((int)DateTime.Now.Ticks);
            Random randomLon   = new Random((int)DateTime.Now.Ticks);
            Random randomMin   = new Random((int)DateTime.Now.Ticks);
            var    mockedUsers = await _context.ApplicationUsers
                                 .Where(a => a.AccountType.Equals(AccountType.MockedData))
                                 .ToListAsync();

            int mockLocationCount = 0;

            foreach (var user in mockedUsers)
            {
                ++mockLocationCount;
                DateTime timeStamp = DateTime.Now.Subtract(TimeSpan.FromMinutes(randomMin.NextDouble() * 60));
                double   lat       = randomLat.NextDouble() * (latmax - latmin) + latmin;
                double   lon       = randomLon.NextDouble() * (lonmax - lonmin) + lonmin;
                if (mockLocationCount > NUMBEROFMOCKUSERS)
                {
                    GetRandomZoneCoordinates(out lat, out lon);
                }
                await _locationHistoryService.DeleteAllLocationHistoryAsync(user.Id);

                await _locationHistoryService.CreateLocationHistoryAsync(user.Id, lat, lon, timeStamp);

                _hexagonal.Initialize(lat, lon, _hexagonal.Layers[0]);
                String layers          = _hexagonal.AllLayersDelimited();
                Guid   currentZoneGuid = await _zoneBoundaryService.IsCoordinateInsideZone(ZoneType.BarDistrict,
                                                                                           lat,
                                                                                           lon);

                string cZone = _zoneBoundaryService.IsEmptyZone(currentZoneGuid) ? null : currentZoneGuid.ToString();

                var currentLayer = await _context.CurrentLayers
                                   .FirstOrDefaultAsync(c => c.UserId.Equals(user.Id));

                if (currentLayer == null)
                {
                    await _context.CurrentLayers.AddAsync(new CurrentLayer()
                    {
                        UserId          = user.Id,
                        LayersDelimited = layers,
                        TimeStamp       = timeStamp,
                        CurrentZoneId   = cZone
                    });
                }
                else
                {
                    currentLayer.LayersDelimited = layers;
                    currentLayer.TimeStamp       = timeStamp;
                    currentLayer.CurrentZoneId   = cZone;
                }
            }
            await _context.SaveChangesAsync();

            //establish friend-requests for all of the mock users
            //////////////////////////////////////////
            var ryan = await _context.ApplicationUsers
                       .FirstOrDefaultAsync(a => a.Email.Equals(mdata.Email, StringComparison.OrdinalIgnoreCase));

            if (ryan == null)
            {
                ryan = await _context.ApplicationUsers
                       .FirstOrDefaultAsync(a => a.Email.Equals("*****@*****.**", StringComparison.OrdinalIgnoreCase));
            }
            mockedUsers = await _context.ApplicationUsers
                          .Where(a => a.AccountType.Equals(AccountType.MockedData))
                          .ToListAsync();

            foreach (var initiator in mockedUsers)
            {
                DateTime timeStamp     = DateTime.Now.Subtract(TimeSpan.FromMinutes(randomMin.NextDouble() * 60));
                var      friendRequest = await _context.FriendRequests
                                         .FirstOrDefaultAsync(f => f.InitiatorId.Equals(initiator.Id) &&
                                                              f.TargetId.Equals(ryan.Id));

                if (friendRequest == null)
                {
                    await _context.FriendRequests
                    .AddAsync(new FriendRequest()
                    {
                        InitiatorId = initiator.Id,
                        TargetId    = ryan.Id,
                        TimeStamp   = DateTime.Now,
                        Type        = FriendRequestType.Normal
                    });
                }
                else
                {
                    friendRequest.TimeStamp = timeStamp;
                }
            }
            await _context.SaveChangesAsync();

            ///////////////////////////////////////////////////
            // FriendGroup data
            ///////////////////////////////////////////////////
        }
 public IApplication CreateApplication(ApplicationOption option)
 {
     return(Applications[option]);
 }
        private void ParseSettings(ApplicationOption option, IEnumerable <ApplicationSettingData> settings)
        {
            ApplicationSettingData setting;

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.Name.ToString()));
            if (setting != null)
            {
                option.Name = setting.SettingValue;
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsTestMode.ToString()));
            if (setting != null)
            {
                try { option.IsTestMode = Convert.ToBoolean(setting.SettingValue); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableSSL.ToString()));
            if (setting != null)
            {
                try { option.EnableSSL = Convert.ToBoolean(setting.SettingValue); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableAds.ToString()));
            if (setting != null)
            {
                try
                {
                    option.EnableAds = Convert.ToBoolean(setting.SettingValue);
                }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableNotification.ToString()));
            if (setting != null)
            {
                try { option.EnableNotification = Convert.ToBoolean(setting.SettingValue); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.NoticeContentBriefLength.ToString()));
            if (setting != null)
            {
                try { option.NoticeContentBriefLength = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DateFormatString.ToString()));
            if (setting != null)
            {
                try { option.DateFormatString = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DateTimeFormatString.ToString()));
            if (setting != null)
            {
                try { option.DateTimeFormatString = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.ImageServeRoot.ToString()));
            if (setting != null)
            {
                try { option.ImageServeRoot = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.BaseDirectory.ToString()));
            if (setting != null)
            {
                try { option.BaseDirectory = setting.SettingValue.Trim(); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsMultiLanguageSupported.ToString()));
            if (setting != null)
            {
                try { option.IsMultiLanguageSupported = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DefaultLanguageId.ToString()));
            if (setting != null)
            {
                try { option.DefaultLanguageId = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableReview.ToString()));
            if (setting != null)
            {
                try { option.EnableReview = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.EnableTracking.ToString()));
            if (setting != null)
            {
                try { option.EnableTracking = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }
            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.IsMultiLocationSupported.ToString()));
            if (setting != null)
            {
                try { option.IsMultiLocationSupported = Convert.ToBoolean(setting.SettingValue.Trim()); }
                catch { }
            }

            setting = settings.SingleOrDefault(o => o.SettingKey.Equals(ApplicationSettingKeys.DefaultLocationId.ToString()));
            if (setting != null)
            {
                try { option.DefaultLocationId = Convert.ToInt32(setting.SettingValue.Trim()); }
                catch { }
            }
        }
Exemplo n.º 25
0
 public LoginController(IAllUser userRep, ServiceUser servicesUser, ApplicationOption applicationOption)
 {
     this.userRep           = userRep;
     this.servicesUser      = servicesUser;
     this.applicationOption = applicationOption;
 }