Beispiel #1
0
        public void Process(string tempDirectory, IEnumerable <TableData> sourceTables, IJobSpecification job)
        {
            var tables = sourceTables.Select(t => t.Schema).ToArray();

            using (var server = new Server())
            {
                server.Connect(ConnectionString);

                var db = server.Databases.Find(DbName);

                if (!Update)
                {
                    if (db != null)
                    {
                        db.Drop();
                    }

                    CreateSchema(db, server, tables);
                    db = server.Databases.Find(DbName);
                }

                //server.CaptureXml = true; <- Doesn't work with QueryBinding and errors from empty partitions marked as never processed.

                foreach (var table in sourceTables)
                {
                    var processingType = !Update && IncrementalUpdate.HasFlag(
                        table.Schema.IsDimension() ? SqlClearOptions.Dimensions : SqlClearOptions.Facts)
                        ? ProcessType.ProcessAdd
                        : ProcessType.ProcessFull;

                    if (table.Schema.IsDimension())
                    {
                        ProcessPartition(db, table.Name, table.Name, processingType);
                    }
                    else
                    {
                        var partition = SqlUpdateUtil.GetPartitionField(table.Schema);
                        if (partition != null)
                        {
                            ProcessPartition(db, table.Name, GetTransientPartitionName(table.Schema), ProcessType.ProcessFull,
                                             string.Format("SELECT [{0}].* FROM [{0}] {1}", table.Name, SqlUpdateUtil.GetUpdateCriteria(table.Schema, partition, true, date: ReferenceDate)));

                            ProcessPartition(db, table.Name, table.Name, processingType,
                                             string.Format("SELECT [{0}].* FROM [{0}] {1}", table.Name, SqlUpdateUtil.GetUpdateCriteria(table.Schema, partition, false, date: ReferenceDate, cutoff: CutOff)));
                        }
                        else
                        {
                            ProcessPartition(db, table.Name, table.Name, processingType);
                        }
                    }
                }

                //server.ExecuteCaptureLog(true, true);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Log.EventLogInfo    += (msg) => { Console.WriteLine(msg); };
            Log.EventLogWarning += (msg) => { Console.WriteLine(msg); };
            Log.EventLogError   += (msg) => { Console.WriteLine(msg); };
            Log.EventLogDebug   += (msg) => { Console.WriteLine(msg); };



            DirectoryInfo root = new DirectoryInfo(rootDir);

            DirectoryInfo[] dis = root.GetDirectories("*", SearchOption.AllDirectories);
            foreach (var di in dis)
            {
                if (di.Parent.Parent.FullName == root.FullName &&
                    Regex.IsMatch(di.Name, @"^v\d+\.\d+\.\d+.\d+$"))
                {
                    Console.WriteLine($"找到了一个文件夹:{di.FullName}");
                    FileInfo fiVerJson = new FileInfo(di.FullName + ".json");
                    if (!fiVerJson.Exists)
                    {
                        Console.WriteLine($"这个版本没有计算过SHA256,开始计算...");

                        List <uint> ver = new List <uint>();
                        foreach (Match m in Regex.Matches(di.Name, @"\d+"))
                        {
                            ver.Add(Convert.ToUInt32(m.Value));
                        }

                        IncrementalUpdate.CreateSoftVersionFile(softVerson_rootPath, ver.ToArray(), softVerson_rootURL + root.RelativePath(di) + "/", di.FullName, fiVerJson.FullName);
                        Console.WriteLine($"计算结束,保存到{fiVerJson.FullName}");
                    }
                    else
                    {
                        Console.WriteLine($"这个版本已经计算过SHA256,跳过...");
                    }
                }
            }

            Console.WriteLine($"执行完毕,按键退出...");
            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Download dl = new Download();

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-s":
                    if (i + 1 >= args.Length)
                    {
                        break;
                    }
                    Setup setup = new Setup(args[i + 1]);
                    setup.calcSHA1();
                    setup.removePath();
                    dl.bms.setup = setup;
                    break;

                case "-u":
                    if (i + 1 >= args.Length)
                    {
                        break;
                    }
                    IncrementalUpdate iun = new IncrementalUpdate(args[i + 1]);
                    iun.calcSHA1();
                    iun.removePath();
                    dl.bms.addUpdate(iun);
                    break;

                default:
                    break;
                }
            }

            XmlSerializer serializer = new XmlSerializer(typeof(Download));
            StreamWriter  sw         = new StreamWriter("Setup.xml", false, new UTF8Encoding(false));

            serializer.Serialize(sw, dl);

            sw.Close();
        }
Beispiel #4
0
        public static void Run()
        {
            Security sec = new Security()
            {
                Id = 1, Type = SecurityType.Future, Group = "GC", Product = "GC", Contract = "GCZ6"
            };

            var mds = new FixUdpServer(new MarketDataChannelConnection()
            {
                IPAddress = IPAddress.Loopback, Port = 8453
            });
            var mdc = new FixUdpClient(IPAddress.Loopback, 8453);

            mdc.Listen();
            mds.Send(new SecurityDefinition(sec));
            mds.Send(new StatusUpdate(StatusUpdateType.Group, sec, SecurityTradingStatus.Halt, StatusChangeReason.MarketEvent, SecurityTradingEvent.ImpliedMatchingOff));

            var volumeUpdate = new IncrementalUpdate(MatchEventIndicator.LastVolume, DateTime.UtcNow);

            volumeUpdate.MDEntries.Add(MarketDataUpdateDataBlock.VolumeNew(sec, 99, 12733));
            mds.Send(volumeUpdate);

            Thread.Sleep(1000);
        }
 public void CreateConfigFile()
 {
     IncrementalUpdate.CreateSoftVersionFile(".", new uint[] { 0, 0, 1, 0 }, null, ".", "./config.json");
 }
Beispiel #6
0
        /// <summary>
        /// 执行一次升级的流程
        /// </summary>
        public async Task Start(string configPath, Action <string> setMessage, Action <int> setProgress)
        {
            DLog.Init("log", "Update", DLog.INIT_RELATIVE.MODULE, false);

            string movedoneFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "movedone");

            if (File.Exists(movedoneFile))
            {
                File.Delete(movedoneFile);
            }

            //载入配置
            setMessage("载入配置...");
            config = JsonMapper.ToObject <UpdateConfig>(File.ReadAllText(configPath));
            if (config != null)
            {
                DLog.LogI($"DoUpdate.Start():载入配置文件{configPath}成功,SoftName:{config.SoftName}");
            }
            else
            {
                DLog.LogE($"DoUpdate.Start():载入配置文件{configPath}失败!");
                return;
            }

            //联网得到最新json内容
            setMessage("联网得到最新版本内容...");
            bool isGetNewVersionInfo = false;

            for (int i = 0; i < config.newVersionUrl.Length; i++)
            {
                if (!isGetNewVersionInfo)//有一个地址能成功就不再试后面的地址了
                {
                    try
                    {
                        string rtext = await config.newVersionUrl[i].GetStringAsync();
                        newVersionSoft      = JsonMapper.ToObject <SoftFile>(rtext);
                        isGetNewVersionInfo = true;
                        DLog.LogI($"DoUpdate.Start():联网获取最新软件版本成功,url={config.newVersionUrl[i]},最新版本为v{newVersionSoft.version[0]}.{newVersionSoft.version[1]}.{newVersionSoft.version[2]}.{newVersionSoft.version[3]}");
                    }
                    catch (Exception e)
                    {
                        newVersionSoft = null;
                        DLog.LogW($"DoUpdate.Start():联网获取最新软件版本失败,url={config.newVersionUrl[i]},err={e.Message}");
                    }
                }
            }
            if (newVersionSoft == null)
            {
                DLog.LogE($"DoUpdate.Start():联网获取最新软件地址失败...");
                setMessage("联网获取最新软件地址失败...");
                return;
            }
            setMessage("联网得到最新版本内容成功!");

            //载入本地当前软件版本信息
            setMessage("载入本地当前软件版本信息...");
            if (File.Exists(config.curVersionFile))
            {
                var sr = File.OpenText(config.curVersionFile);
                curVersionSoft = JsonMapper.ToObject <SoftFile>(sr);
                sr.Close();
                DLog.LogI($"DoUpdate.Start():当前软件版本为v{curVersionSoft.version[0]}.{curVersionSoft.version[1]}.{curVersionSoft.version[2]}.{curVersionSoft.version[3]}");
            }
            else
            {
                setMessage("没有找到本地当前软件版本信息...");
            }

            DownloadList downloadList = IncrementalUpdate.CompareToDownloadList(curVersionSoft, newVersionSoft);

            DLog.LogI($"DoUpdate.Start():有{downloadList.files.Count}个需要下载项.");
            if (downloadList.files.Count == 0)
            {
                DLog.LogI($"DoUpdate.Start():文件都是最新的,不需要下载!");
                setMessage("文件都是最新的,不需要更新!");
                return;
            }

            DirectoryInfo downlodeDir = new DirectoryInfo(Path.Combine(config.CacheDir, "download"));//下载到临时文件夹的download文件夹

            if (!downlodeDir.Exists)
            {
                Directory.CreateDirectory(downlodeDir.FullName);
            }

            DLog.LogI($"DoUpdate.Start():downlodeDir={downlodeDir.FullName}");
            //删除download文件夹里面所有不在下载列表里的文件,好方便等会无脑拷贝
            FileInfo[] fiIndw = downlodeDir.GetFiles("*", SearchOption.AllDirectories);
            for (int i = 0; i < fiIndw.Length; i++)
            {
                string rp = downlodeDir.RelativePath(fiIndw[i]);
                if (!downloadList.IsRelativePathInFiles(rp))
                {
                    fiIndw[i].Delete();
                }
            }

            bool isError = true;

            while (isError)
            {
                isError = false;//开始启动刷一遍下载的时候是error置为0的
                //下载每一项
                int doneCount = 0;
                foreach (var item in downloadList.files)
                {
                    try
                    {
                        FileInfo dwfilePath    = new FileInfo(Path.Combine(downlodeDir.FullName, item.relativePath));
                        FileInfo targefilePath = new FileInfo(Path.Combine(config.SoftDir, item.relativePath));
                        //判断文件是否已经存在了,就跳过到下一个文件
                        if (targefilePath.Exists && targefilePath.SHA256() == item.SHA256)
                        {
                            DLog.LogI($"{item.relativePath} 目标位置文件是最新,不需要下载!");
                            setMessage($"{item.relativePath} 目标位置文件是最新,不需要下载!");
                            if (dwfilePath.Exists)
                            {
                                dwfilePath.Delete();
                            }
                        }
                        else if (dwfilePath.Exists && dwfilePath.SHA256() == item.SHA256)
                        {
                            DLog.LogI($"{item.relativePath} 有缓存文件了!");
                            setMessage($"{item.relativePath} 有缓存文件了!");
                        }
                        else
                        {
                            DLog.LogI($"下载:{item.relativePath}...");
                            setMessage($"下载:{item.relativePath}...");
                            //如果文件不存在才下载
                            try
                            {
                                await item.url.DownloadFileAsync(dwfilePath.Directory.FullName);

                                dwfilePath.Refresh();//需要刷新一下
                                //下载完成之后校验sha256
                                if (dwfilePath.Exists && (dwfilePath.SHA256() == item.SHA256))
                                {
                                    DLog.LogI($"下载:{item.relativePath}成功,校验SHA256通过!");
                                }
                                else
                                {
                                    DLog.LogE($"DoUpdate.Start():校验文件SHA256失败{item.relativePath}");
                                    isError = true;
                                }
                            }
                            catch (Exception e)
                            {
                                DLog.LogE($"DoUpdate.Start():下载文件失败...  {item.url},err={e.Message}");
                                isError = true;
                            }
                        }
                        doneCount++;
                        setProgress(doneCount * 100 / downloadList.files.Count);
                    }
                    catch (Exception e)
                    {
                        DLog.LogE($"下载文件发生错误!" + e.Message);
                        setMessage($"下载文件发生错误!" + e.Message);
                        isError = true;
                    }
                }
            }

            FileInfo[] needCopyFis = downlodeDir.GetFiles("*", SearchOption.AllDirectories);
            if (needCopyFis.Length == 0)
            {
                DLog.LogI($"没有需要更新的文件!");
                setMessage($"没有需要更新的文件!");
                return;
            }
            DLog.LogI($"所有文件下载完成!");
            setMessage($"所有文件下载完成!");

            //TODO:这里需要向追踪服务查询是否空闲
            try
            {
                DLog.LogI($"查询是否可以移动文件...");
                while (true)
                {
                    string canMoveFile = await config.CanMoveFileUrl.GetStringAsync();

                    DLog.LogI($"查询结果:{canMoveFile}");
                    if (canMoveFile == "true")
                    {
                        DLog.LogI($"查询成功,可以开始移动文件!");
                        break;
                    }
                    else
                    {
                        DLog.LogI($"当前有人正在使用程序,不能移动文件,等待30秒后再试!");
                        Thread.Sleep(60 * 1000);//60秒后再问一次
                    }
                }
            }
            catch (Exception e)
            {
                //如果异常那么也直接启动拷贝程序
                DLog.LogI($"查询是否可以移动文件异常{e.Message}");
            }

            foreach (var item in config.NeedCloseExeName)
            {
                while (KillProcess(item))//一直关闭到找不到这个进程
                {
                    await Task.Delay(500);
                }
            }
            setMessage($"启动拷贝文件程序...");
            //到了此处应该所有文件都下载完成了
            FileInfo movefileEXE = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "movefile.exe"));

            if (movefileEXE.Exists)
            {
                DLog.LogI($"启动拷贝文件程序" + movefileEXE.FullName);
                Process.Start(movefileEXE.FullName);
            }
            else
            {
                DLog.LogI($"启动拷贝文件程序 不存在" + movefileEXE.FullName);
            }
        }