示例#1
0
        private static void RunProgram(DbDataSource dataSource)
        {
            while (true)
            {
                var authModule = new AuthModule(dataSource);

                var authResult = authModule.SignIn();

                switch (authResult.Role)
                {
                case RoleType.Client:
                {
                    var clientModule = new ClientModule(authResult.CurrentUserId, dataSource);
                    clientModule.WorkAsClient();

                    break;
                }

                case RoleType.Admin:
                {
                    var adminModule = new AdminModule(authResult.CurrentUserId, dataSource);
                    adminModule.WorkAsAdmin();

                    break;
                }

                default:
                {
                    throw new InvalidDataException();
                }
                }
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            DbDataSource  source    = new DbDataSource();
            DataProcessor processor = new DataProcessor(source);
            UserInterface UI        = new UserInterface(processor);

            UI.MainMenu();
        }
        private void AddLatestGameFile(string filename, List <IGameFile> gameFiles)
        {
            IGameFile gameFile = DbDataSource.GetGameFile(filename);

            if (gameFile != null)
            {
                gameFiles.Add(gameFile);
            }
        }
示例#4
0
 public static bool Compare(DbDataSource a, DbDataSource b)
 {
     if (a.Name != b.Name)
     {
         return(false);
     }
     if (a.Value != b.Value)
     {
         return(false);
     }
     return(true);
 }
        public AADapperRepositoryTest()
        {
            DbEntityMap.InitMapCfgs();
            //init datasourse
            IDbDatasource dbDatasource = new DbDataSource();

            dbDatasource.Init(new NameValueCollection()
            {
                ["aa.dataSource.master_AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenter;User ID = sa; Password = db123;",
                ["aa.dataSource.master_AaCenter.provider"]         = "SqlServer"
            });

            //dbDatasource.Init(new NameValueCollection()
            //{
            //    ["aa.dataSource.slave_AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenterS1;User ID = sa; Password = db123;",
            //    ["aa.dataSource.slave_AaCenter.provider"] = "SqlServer"
            //});
        }
示例#6
0
        public AADapperRepositoryMysqlTest()
        {
            DbEntityMap.InitMapCfgs();
            //init datasourse
            IDbDatasource dbDatasource = new DbDataSource();

            dbDatasource.Init(new NameValueCollection()
            {
                ["aa.dataSource.master_demo.connectionString"] = "Data Source =localhost; Initial Catalog = demo;User ID = root; Password = cheng@123;",
                ["aa.dataSource.master_demo.provider"]         = "MySql"
            });

            //dbDatasource.Init(new NameValueCollection()
            //{
            //    ["aa.dataSource.slave_AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenterS1;User ID = sa; Password = lee2018;",
            //    ["aa.dataSource.slave_AaCenter.provider"] = "SqlServer"
            //});
        }
示例#7
0
        public void TextDapperContextMul()
        {
            //TODO 主从 数据库使用下划线_作为分隔符
            DbEntityMap.InitMapCfgs();
            //init datasourse
            IDbDatasource dbDatasource = new DbDataSource();

            dbDatasource.Init(new NameValueCollection()
            {
                ["aa.dataSource.master_AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenter;User ID = sa; Password = db123;",
                ["aa.dataSource.master_AaCenter.provider"]         = "SqlServer"
            });

            dbDatasource.Init(new NameValueCollection()
            {
                ["aa.dataSource.slave_AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenterS1;User ID = sa; Password = db123;",
                ["aa.dataSource.slave_AaCenter.provider"]         = "SqlServer"
            });



            IDapperContext dapperContext = new DapperContext();


            IVillageRepository villageRepository = new VillageRepository(dapperContext);

            IUserInfoRepository userInfoRepository = new UserInfoRepository(dapperContext);

            DbContextHolder.SetDbSourceMode("slave");

            try
            {
                var user  = userInfoRepository.Count();
                var model = villageRepository.Get(new Guid("6D880321-DB17-4B32-9F0A-CE9F3F25AA01"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#8
0
        private static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(typeof(Program).Assembly.Location));

            try
            {
                using (var context = new DatabaseContext())
                {
                    using (var dataSource = new DbDataSource(context))
                    {
                        RunProgram(dataSource);
                    }
                }
            }
            catch (Exception ex)
            {
                #if DEBUG
                Console.WriteLine(ex.Message);
                #endif
                LogToFile(ex.Message);
                LogToFile(ex.StackTrace);
            }
        }
示例#9
0
 private List<DomainStatsEntityModel> GetDomainsStats(DbDataSource<DomainEntity, int> domainEntityDs)
 {
     return InvokeSafe(() => {
         var domainsStats = domainEntityDs
             .Sort(DomainEntity.Fields.Domain, SortDirection.Asc)
             .AsList(
                 DomainEntity.Fields.ID,
                 DomainEntity.Fields.Domain,
                 DomainEntity.Fields.Visitsmonth,
                 DomainEntity.Fields.Advertsgoogle,
                 DomainEntity.Fields.Advertsyandex,
                 DomainEntity.Fields.Budgetgoogle,
                 DomainEntity.Fields.Budgetyandex,
                 DomainEntity.Fields.Datecollected,
                 DomainEntity.Fields.Phrasesgoogle,
                 DomainEntity.Fields.Phrasesyandex,
                 DomainEntity.Fields.Status,
                 Domainphrase.Fields.SE
             )
             .GroupBy(de => de.ID)
             .Select(gde => gde.First())
             .Select(d => new DomainStatsEntityModel {
                 DomainID = d.ID,
                 Domain = d.Domain,
                 VisitsMonth = d.Visitsmonth.Value,
                 Advertsgoogle = d.Advertsgoogle.Value,
                 Advertsyandex = d.Advertsyandex.Value,
                 Budgetgoogle = d.Budgetgoogle.Value,
                 Budgetyandex = d.Budgetyandex.Value,
                 Datecollected = d.Datecollected,
                 Phrasesgoogle = d.Phrasesgoogle.Value,
                 Phrasesyandex = d.Phrasesyandex.Value,
                 Status = d.Status,
                 SearchEngine = d.GetJoinedEntity<Domainphrase>().SE
             })
             .ToList();
         var domainIDs = domainsStats.Select(ds => ds.DomainID).ToArray();
         var emailsMap = Domainemail.DataSource
             .WhereIn(Domainemail.Fields.DomainID, domainIDs)
             .AsMapByField<int>(Domainemail.Fields.DomainID, Domainemail.Fields.Email);
         var phonesMap = Domainphone.DataSource
             .WhereIn(Domainphone.Fields.DomainID, domainIDs)
             .AsMapByField<int>(Domainphone.Fields.DomainID, Domainphone.Fields.Phone);
         foreach (var domainStat in domainsStats) {
             List<Domainphone> phonesForDomain;
             if (phonesMap.TryGetValue(domainStat.DomainID, out phonesForDomain)) {
                 domainStat.Phones = phonesForDomain.Select(phD => phD.Phone).ToArray();
             }
             List<Domainemail> emailsForDomain;
             if (emailsMap.TryGetValue(domainStat.DomainID, out emailsForDomain)) {
                 domainStat.Emails = emailsForDomain.Select(phD => phD.Email).ToArray();
             }
         }
         return domainsStats;
     }, new List<DomainStatsEntityModel>());
 }
示例#10
0
        public static void AddAa(this IServiceCollection services, NameValueCollection dbInfo)
        {
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            EngineContext.Create();

            var assemblys = AppDomain.CurrentDomain.GetAssemblies();
            var binPath   = AppContext.BaseDirectory;

            string[] dllPaths = Directory.GetFiles(binPath, "*.dll", SearchOption.TopDirectoryOnly);

            var loadedAssemblyNames = new List <string>();

            foreach (var a in assemblys)
            {
                loadedAssemblyNames.Add(a.FullName);
            }
            foreach (var dllPath in dllPaths)
            {
                try
                {
                    var an = AssemblyName.GetAssemblyName(dllPath);
                    if (!loadedAssemblyNames.Contains(an.FullName))
                    {
                        AppDomain.CurrentDomain.Load(an);
                    }
                }
                catch (BadImageFormatException ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
            assemblys = AppDomain.CurrentDomain.GetAssemblies();
            //automapper
            var configurationActions = new List <Action <IMapperConfigurationExpression> >();

            foreach (var assembly in assemblys)
            {
                var instancesMapper = assembly.GetTypes().Where(x => x.GetInterface("IMapperConfiguration") != null)
                                      .Select(mapper => (IMapperConfiguration)Activator.CreateInstance(mapper));

                foreach (var instance in instancesMapper)
                {
                    configurationActions.Add(instance.GetConfiguration());
                }
            }
            AutoMapperConfiguration.Init(configurationActions);
            ObjectMapManager.ObjectMapper = new AutoMapperObjectMapper();
            //AA.Dapper
            Action <FluentMapConfiguration> action = null;

            foreach (var assembly in assemblys)
            {
                var instancesMapper = assembly.GetTypes().Where(x => x.GetInterface("IMapConfiguration") != null)
                                      .Select(mapper => (IMapConfiguration)Activator.CreateInstance(mapper));

                foreach (var instance in instancesMapper)
                {
                    action = instance.GetConfiguration();
                }
            }
            IDbDatasource dbDatasource = new DbDataSource();

            dbDatasource.Init(dbInfo);
            services.AddScoped <IDapperContext, DapperContext>();

            if (action == null)
            {
                throw new Exception("FluentMapConfiguration is null");
            }
            else
            {
                MapConfiguration.Init(action);
            }
        }
示例#11
0
        public void Execute(string[] zipFiles)
        {
            m_invalidFiles.Clear();

            SyncFileCount   = zipFiles.Length;
            SyncFileCurrent = 0;

            foreach (string fileName in zipFiles)
            {
                if (SyncFileChange != null)
                {
                    CurrentSyncFileName = fileName;
                    SyncFileChange(this, new EventArgs());
                }

                IGameFile file     = SyncDataSource.GetGameFile(fileName);
                IGameFile existing = DbDataSource.GetGameFile(file.FileName);

                if (existing != null)
                {
                    file = existing;
                }

                if (m_fileManagement == FileManagement.Unmanaged)
                {
                    file.FileName = fileName;
                }

                if (file != null)
                {
                    CurrentGameFile = file;
                    GameFileDataNeeded?.Invoke(this, new EventArgs());
                    file.Downloaded = DateTime.Now;

                    try
                    {
                        using (IArchiveReader reader = ArchiveReader.Create(Path.Combine(GameFileDirectory.GetFullPath(), file.FileName)))
                        {
                            FillTextFileInfo(file, reader);
                            FillMapInfo(file, reader);
                        }
                    }
                    catch (IOException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "File is in use/Not found"));
                    }
                    catch (InvalidDataException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "Zip archive invalid or contained an improper pk3"));
                    }
                    catch (Exception ex)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, CreateExceptionMsg(ex)));
                    }

                    if (existing == null)
                    {
                        DbDataSource.InsertGameFile(file);
                    }
                    else
                    {
                        DbDataSource.UpdateGameFile(file, Util.GetSyncGameFileUpdateFields());
                    }
                }
                else
                {
                    m_invalidFiles.Add(new InvalidFile(fileName, "Not a valid zip archive"));

                    try
                    {
                        FileInfo fileDelete = new FileInfo(Path.Combine(GameFileDirectory.GetFullPath(), fileName));
                        if (fileDelete.Exists)
                        {
                            fileDelete.Delete();
                        }
                    }
                    catch
                    {
                        //delete failed, just keep going
                    }
                }

                SyncFileCurrent++;
            }
        }
示例#12
0
 protected ServiceBase(DbDataSource context)
 {
     this.Context = context;
 }
示例#13
0
        public int OnExecute(CommandLineApplication app)
        {
            if (!string.IsNullOrEmpty(this.Connect))
            {
                var uri = new Uri(this.Connect);
                switch (uri.Scheme)
                {
                case "postgresql":
                    string userName = "";
                    string password = "";
                    if (!string.IsNullOrEmpty(uri.UserInfo))
                    {
                        var ss = uri.UserInfo.Split(":");
                        userName = ss[0];
                        password = ss.Length > 1 ? ss[1] : "";
                    }

                    if (!string.IsNullOrEmpty(this.UserName))
                    {
                        userName = this.UserName;
                    }
                    if (!string.IsNullOrEmpty(this.Password))
                    {
                        password = this.Password;
                    }

                    var port          = uri.Port > 0 ? uri.Port : 5432;
                    var database      = uri.AbsolutePath.Trim('/');
                    var connectString = $"Host={uri.Host};Port={port};Username={userName};Password={password};Database={database}";


                    var sql   = "";
                    int index = 0;
                    if (this.TableName.StartsWith("select", StringComparison.InvariantCultureIgnoreCase))
                    {
                        sql = this.TableName;
                    }
                    else
                    {
                        if (this.Index == null || int.TryParse(this.Index, out index))
                        {
                            sql = $"select * from {this.TableName}";
                        }
                        else
                        {
                            sql = $"select {this.Index} from {this.TableName}";
                        }
                    }


                    var dataSource = new DbDataSource(Npgsql.NpgsqlFactory.Instance, connectString);
                    var data       = dataSource.GetData(sql, index);

                    var stats = new  RunningStatistics(data);
                    Console.WriteLine($"总数:{stats.Count}");
                    Console.WriteLine($"最大值:{stats.Maximum}");
                    Console.WriteLine($"最小值:{stats.Minimum}");
                    Console.WriteLine($"平均值Mean::{stats.Mean}");
                    Console.WriteLine($"均方差StandardDeviation: {stats.StandardDeviation}");
                    Console.WriteLine($"{stats.ToString()}");
                    Console.WriteLine($"中位数: {data.Median()}");
                    Console.WriteLine(@"{0} - 有偏方差", data.PopulationVariance().ToString(" #0.00000;-#0.00000"));
                    Console.WriteLine(@"{0} - 无偏方差", data.Variance().ToString(" #0.00000;-#0.00000"));
                    Console.WriteLine(@"{0} - 标准偏差", data.StandardDeviation().ToString(" #0.00000;-#0.00000"));
                    Console.WriteLine(@"{0} - 标准有偏偏差", data.PopulationStandardDeviation().ToString(" #0.00000;-#0.00000"));
                    Console.WriteLine($"25% 中位数:{data.LowerQuartile()}");
                    Console.WriteLine($"75% 中位数:{data.UpperQuartile()}");


                    return(1);

                case "file":
                    this.FilePath = uri.LocalPath;
                    if (Directory.Exists(this.FilePath) && !string.IsNullOrEmpty(this.TableName))
                    {
                        this.FilePath = Path.Combine(this.FilePath, this.TableName);
                    }

                    break;

                default:
                    return(0);
                }
            }

            if (!string.IsNullOrEmpty(this.FilePath))
            {
                IEnumerable <double> data;
                var ext   = Path.GetExtension(this.FilePath);
                var index = 0;


                if (ext.Equals(".shp", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (!int.TryParse(this.Index, out index))
                    {
                        index = ShapeFileHelper.FindIndex(this.FilePath, this.Index);
                    }
                    var shpDataSource = new ShapeDataSource(this.FilePath, index);
                    data = shpDataSource.GetData();
                }
                else
                {
                    if (!int.TryParse(this.Index, out index))
                    {
                        Console.WriteLine("索引参数不对!");
                        return(1);
                    }
                    var dataSource = new CsvDataSource(this.FilePath, index);
                    data = dataSource.GetData();
                }
                var stats = new  RunningStatistics(data);
                Console.WriteLine($"总数:{stats.Count}");
                Console.WriteLine($"最大值:{stats.Maximum}");
                Console.WriteLine($"最小值:{stats.Minimum}");
                Console.WriteLine($"平均值Mean::{stats.Mean}");
                Console.WriteLine($"均方差StandardDeviation: {stats.StandardDeviation}");
                Console.WriteLine($"{stats.ToString()}");
                Console.WriteLine($"中位数: {data.Median()}");
                Console.WriteLine(@"{0} - 有偏方差", data.PopulationVariance().ToString(" #0.00000;-#0.00000"));
                Console.WriteLine(@"{0} - 无偏方差", data.Variance().ToString(" #0.00000;-#0.00000"));
                Console.WriteLine(@"{0} - 标准偏差", data.StandardDeviation().ToString(" #0.00000;-#0.00000"));
                Console.WriteLine(@"{0} - 标准有偏偏差", data.PopulationStandardDeviation().ToString(" #0.00000;-#0.00000"));
                Console.WriteLine($"25% 中位数:{data.LowerQuartile()}");
                Console.WriteLine($"75% 中位数:{data.UpperQuartile()}");
                //new DescriptiveStatistics()

                var histogram = new Histogram(data, 100, stats.Minimum, stats.Maximum);
                //Console.WriteLine($"{histogram.ToString()}");
                for (var i = 0; i < 100; i++)
                {
                    var bucket = histogram[i];
                    Console.WriteLine($"({bucket.LowerBound}, {bucket.UpperBound}] {bucket.Count}");
                }

                return(1);
            }
            app.ShowHelp();
            return(1);
        }
示例#14
0
 public AuthModule(DbDataSource dataSource)
 {
     AuthService = new AuthService(dataSource);
 }
示例#15
0
 public ClientModule(int currentUserId, DbDataSource dataSource) : base(currentUserId)
 {
     BusinessService = new ClientService(dataSource);
 }
        public void Execute(string[] syncFiles)
        {
            m_invalidFiles.Clear();
            IEnumerable <string> diff = null;

            if (syncFiles == null)
            {
                IEnumerable <string> dsFiles = SyncDataSource.GetGameFileNames();
                IEnumerable <string> dbFiles = DbDataSource.GetGameFileNames();
                diff = dsFiles.Except(dbFiles);
            }
            else
            {
                diff = syncFiles;
            }

            SyncFileCount   = diff.Count();
            SyncFileCurrent = 0;

            foreach (string fileName in diff)
            {
                if (SyncFileChange != null)
                {
                    CurrentSyncFileName = fileName;
                    SyncFileChange(this, new EventArgs());
                }

                IGameFile file     = SyncDataSource.GetGameFile(fileName);
                IGameFile existing = DbDataSource.GetGameFile(file.FileName);

                if (existing != null)
                {
                    file = existing;
                }

                if (file != null)
                {
                    CurrentGameFile = file;
                    GameFileDataNeeded?.Invoke(this, new EventArgs());
                    file.Downloaded = DateTime.Now;

                    try
                    {
                        file.Map = GetMaps(Path.Combine(GameFileDirectory.GetFullPath(), file.FileName));
                        if (!string.IsNullOrEmpty(file.Map))
                        {
                            file.MapCount = file.Map.Count(x => x == ',') + 1;
                        }
                    }
                    catch (IOException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "File is in use"));
                    }
                    catch (InvalidDataException)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, "Zip archive contained an improper pk3"));
                    }
                    catch (Exception ex)
                    {
                        file.Map = string.Empty;
                        m_invalidFiles.Add(new InvalidFile(fileName, CreateExceptionMsg(ex)));
                    }

                    if (existing == null)
                    {
                        DbDataSource.InsertGameFile(file);
                    }
                    else
                    {
                        DbDataSource.UpdateGameFile(file, Util.GetSyncGameFileUpdateFields());
                    }
                }
                else
                {
                    m_invalidFiles.Add(new InvalidFile(fileName, "Not a valid zip archive"));

                    try
                    {
                        FileInfo fileDelete = new FileInfo(Path.Combine(GameFileDirectory.GetFullPath(), fileName));
                        if (fileDelete.Exists)
                        {
                            fileDelete.Delete();
                        }
                    }
                    catch
                    {
                        //delete failed, just keep going
                    }
                }

                SyncFileCurrent++;
            }
        }
示例#17
0
 public AuthService(DbDataSource context) : base(context)
 {
 }
 public ClientService(DbDataSource context) : base(context)
 {
 }
示例#19
0
 public AdminService(DbDataSource context) : base(context)
 {
 }
示例#20
0
        public void TextDapperContext()
        {
            //TODO 主从 数据库使用下划线_作为分隔符
            DbEntityMap.InitMapCfgs();
            //init datasourse
            IDbDatasource dbDatasource = new DbDataSource();

            dbDatasource.Init(new NameValueCollection()
            {
                ["aa.dataSource.master_AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenter;User ID = sa; Password = db123;",
                ["aa.dataSource.master_AaCenter.provider"]         = "SqlServer"
            });

            dbDatasource.Init(new NameValueCollection()
            {
                ["aa.dataSource.slave_AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenterS1;User ID = sa; Password = db123;",
                ["aa.dataSource.slave_AaCenter.provider"]         = "SqlServer"
            });



            IDapperContext dapperContext      = new DapperContext();
            IDapperContext dapperContextSlave = new DapperContext();

            DbContextHolder.SetDbSourceMode("master");
            IUserInfoRepository _userInforepository = new UserInfoRepository(dapperContext);
            IVillageRepository  villageRepository   = new VillageRepository(dapperContext);

            villageRepository.Insert(new Village
            {
                Id          = Guid.NewGuid(),
                VillageName = "aa",
                GmtCreate   = DateTime.Now,
                GmtModified = DateTime.Now
            });

            DbContextHolder.SetDbSourceMode("slave");
            var model = villageRepository.Get(new Guid("6D880321-DB17-4B32-9F0A-CE9F3F25AA01"));

            model.VillageName = "bbb";
            villageRepository.Update(model);

            //var obj = _userInforepository.Insert(new UserInfo()
            //{
            //    RealName = "111",
            //    UserName = "******",
            //    GmtCreate=DateTime.Now,
            //    LastLoginDate=DateTime.Now,
            //    GmtModified=DateTime.Now
            //});
            var users    = _userInforepository.QueryAll();
            var userList = _userInforepository.From(sql =>
                                                    sql.Select()
                                                    .Where(p => p.RealName.Contains("成"))
                                                    .OrderBy(x => x.SysNo)
                                                    .Page(1, 20)
                                                    );

            var count = userList.ToList().Count();

            //动态where
            Expression <Func <UserInfo, bool> > expression = p => p.RealName == "成天";

            var where = DynamicWhereExpression.Init <UserInfo>();

            where = where.And(x => x.RealName == "成天");
            var dynamicUsers = _userInforepository.From(sql =>
                                                        sql.Select()
                                                        .Where(where)
                                                        .OrderBy(x => x.SysNo)
                                                        .Page(1, 20)
                                                        );
            var count2 = dynamicUsers.ToList().Count();
        }
示例#21
0
 protected BusinessLogicServiceBase(DbDataSource context) : base(context)
 {
     Mapper = new Mapper();
 }
示例#22
0
 public FileService(DbDataSource context) : base(context)
 {
 }
示例#23
0
 public AdminModule(int currentUserId, DbDataSource dataSource) : base(currentUserId)
 {
     BusinessService = new AdminService(dataSource);
     FileService     = new FileService(dataSource);
 }