Beispiel #1
0
        static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json")
                         .Build();

            if (config != null)
            {
                var folderPath = config.GetSection("folderPath").Value;
                var xmlConfig  = config.GetSection("xml");

                if (!string.IsNullOrEmpty(folderPath))
                {
                    if (xmlConfig.Exists())
                    {
                        var directory      = new DirectoryInfo(folderPath);
                        var xmlFileService = new XmlFileService();

                        xmlFileService.ParseFile(xmlConfig, directory);

                        return;
                    }
                }

                Console.WriteLine("Configuration file is not valid");
                return;
            }

            Console.WriteLine("No configuration file present");
            return;
        }
        public XmlFileServiceTest()
        {
            var xmlFileService = new XmlFileService();

            xmlFileEntity01 = xmlFileService.LoadXmlFile(@"Data\Services\01\data01.xml");
            xmlFileEntity02 = xmlFileService.LoadXmlFile(@"Data\Services\01\data02.xml");
        }
Beispiel #3
0
        XmlFileService GetXmlFileServiceInstance()
        {
            if (xmlFileService == null)
            {
                xmlFileService = new XmlFileService();
            }

            return(xmlFileService);
        }
Beispiel #4
0
        protected override void SetUp()
        {
            base.SetUp();

            pathUtility = NewMock <IPathUtility>();
            file        = NewMock <IFileWrapper>();
            directory   = NewMock <IDirectoryWrapper>();

            xmlFileService = new XmlFileService(pathUtility, file, directory);
        }
Beispiel #5
0
        private void CreateServices()
        {
            var textFileService = new TextFileService();
            var xmlFileService  = new XmlFileService();

            //var sqlDataService = new SqlDataService();
            //var webAppPoolService = new WebAppPoolService();

            this.LogService           = new LogService(this.AppName, textFileService);
            this.ConfigurationService = new ConfigurationService(this.AppName, xmlFileService);
            //this.MonitorService = new MonitorService(sqlDataService, this.WebAppPoolService, this.LogService);
        }
Beispiel #6
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            XmlFileService service = new XmlFileService();

            //зчитую час який звлишився до зміни картинки
            TimeSpan remains = DateTime.Now.Subtract(service.ReadClosingTime("settings.xml"));

            //перевірка чи пройшов час до зміни картинки
            if (remains.TotalSeconds - service.ReadRemainsIntervalTime("settings.xml").TotalSeconds >= 0)
            {
                //змінюю картинку
                WallpaperCraftParser parser = new WallpaperCraftParser();
                Wallpaper.Set(new Uri(parser.ParseImage(service.ReadCategories("wallpaperscraftInfo.xml")[0], service.ReadSelectedResolution("settings.xml"))), Wallpaper.Style.Centered);

                //поновлюю час який залишвся на початковий
                service.WriteRemainsIntervalTime("settings.xml", ConverterTime.ToTimeSpan(service.ReadInterval("settings.xml")));
            }
            else
            {
                //поновлюю час який залишвся
                service.WriteRemainsIntervalTime("settings.xml", new TimeSpan(0, 0, Math.Abs((int)(remains.TotalSeconds - service.ReadRemainsIntervalTime("settings.xml").TotalSeconds))));
            }
        }
Beispiel #7
0
 public FindMissingsInFileServiceTest()
 {
     xmlPathsFileService = new XmlPathsFileService();
     xmlFileService      = new XmlFileService();
     findMissingsService = new FindMissingsInFileService(xmlPathsFileService, xmlFileService);
 }
        /// <summary>
        /// Import data from .xml file to SQL
        /// </summary>
        /// <param fullFileName=".xml">fullFileName</param>
        public List <ExamClass> ImportFromXmlFileToSQL(string xmlFileName)
        {
            try
            {
                XmlFileService   xmlFileService = new XmlFileService();
                List <ExamClass> modelList      = xmlFileService.ImportData(xmlFileName);
                using (var connect = new NpgsqlConnection(connectSql))
                {
                    connect.Open();
                    // 创建DataTable
                    DataSet   dataSet   = new DataSet();
                    DataTable dataTable = new DataTable(tableName);

                    // 设置table各列的字段
                    DataColumn dc = dataTable.Columns.Add("Id", Type.GetType("System.Int32"));
                    dc.AutoIncrement     = true; //自动增加
                    dc.AutoIncrementSeed = 1;    //起始为1
                    dc.AutoIncrementStep = 1;    //步长为1
                    dc.AllowDBNull       = false;
                    dataTable.Columns.Add("ClassNo", Type.GetType("System.String"));
                    dataTable.Columns.Add("InstituteStudents", Type.GetType("System.String"));
                    dataTable.Columns.Add("NumberStudents", Type.GetType("System.Int32"));
                    dataTable.Columns.Add("InstituteProctors", Type.GetType("System.String"));
                    dataTable.Columns.Add("NumberProctors", Type.GetType("System.Int32"));

                    // 将列表数据添加到 dataTable 中
                    foreach (var model in modelList)
                    {
                        DataRow row = dataTable.NewRow();
                        row["Id"]                = model.Id;
                        row["ClassNo"]           = model.ClassNo;
                        row["InstituteStudents"] = model.InstituteStudents;
                        row["NumberStudents"]    = model.NumberStudents;
                        row["InstituteProctors"] = model.InstituteProctors;
                        row["NumberProctors"]    = model.NumberProctors;

                        dataTable.Rows.Add(row);
                    }

                    dataSet.Tables.Add(dataTable);

                    /* 查看dataset中的数据 */
                    //for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                    //{
                    //    string one1 = dataSet.Tables[0].Rows[i].ItemArray[0].ToString();
                    //    string one2 = dataSet.Tables[0].Rows[i].ItemArray[1].ToString();
                    //    string one3 = dataSet.Tables[0].Rows[i].ItemArray[2].ToString();
                    //    string one4 = dataSet.Tables[0].Rows[i].ItemArray[3].ToString();
                    //    string one5 = dataSet.Tables[0].Rows[i].ItemArray[4].ToString();
                    //    string one6 = dataSet.Tables[0].Rows[i].ItemArray[5].ToString();
                    //    Console.WriteLine("w:{0},x:{1},y:{2},z:{3},z:{4},z:{5}", one1, one2, one3, one4, one5, one6);
                    //}

                    /* 清空table, 否则update操作会出错 */
                    string deleteSql = string.Format("DELETE FROM  {0};", tableName);
                    using (NpgsqlCommand cmd = new NpgsqlCommand(deleteSql, connect))
                    {
                        cmd.ExecuteNonQuery();//执行查询命令
                    }


                    /* 上传数据到数据库 */
                    string selectSql = string.Format("SELECT * FROM  {0};", tableName);
                    using (NpgsqlDataAdapter nadapter = new NpgsqlDataAdapter(selectSql, connect))
                    {
                        NpgsqlCommandBuilder commendBuilder = new NpgsqlCommandBuilder(nadapter);
                        int count = nadapter.Update(dataSet, tableName);
                        Console.WriteLine("Succeed tot import {0} items from {1} to SQL:{2}.{3}", count, xmlFileName, sqlName, tableName);
                        return(modelList);
                    }
                }
            }
            catch
            {
                Console.WriteLine("Error of importing data from {0} to SQL {1}", xmlFileName, sqlName);
                return(null);
            }
        }
Beispiel #9
0
 /// <summary>
 /// 初始化,理论上需要在游戏服务端配置文件加载完成后才能调用
 /// </summary>
 public static void Init()
 {
     GameDB = new XmlFileService();
 }
Beispiel #10
0
        /// <summary>
        /// 初始化,理论上需要在游戏服务端配置文件加载完成后才能调用
        /// </summary>

        public static void Init()
        {
            GameDB = new XmlFileService();
        }
Beispiel #11
0
 public FindMissingsInFileService(XmlPathsFileService xmlPathsFileService, XmlFileService xmlFileService)
 {
     _errMsg = string.Empty;
     this.xmlPathsFileService = xmlPathsFileService;
     this.xmlFileService      = xmlFileService;
 }
Beispiel #12
0
        private void App_OnExit(object sender, ExitEventArgs e)
        {
            XmlFileService service = new XmlFileService();

            service.WriteClosingTime("settings.xml", DateTime.Now);
        }