コード例 #1
0
        //private static object FileLocker = new object();

        //private void WriteLog(string operation, string text)
        //{
        //    lock (FileLocker)
        //    {
        //        string str = string.Format("[{0}] {1} -> {2}\r\n", DateTime.Now.ToString(), operation, text);

        //        string logPath = @"Site.FTRobot_PATH\Log.txt";

        //        File.AppendAllText(logPath, str);
        //    }
        //}

        private void WriteLog(string filePath)
        {
            //lock (FileLocker)
            //{
            //    string logPath = @"d:\BH.BoobenRobot\Log.txt";

            //    File.AppendAllText(logPath, text + "\r\n");
            //}

            DBHelpers.SavePage(this.Code, filePath.Replace(Site.FTRobot_PATH, string.Empty));
        }
コード例 #2
0
ファイル: IndexService.cs プロジェクト: AndriiZ/BH
        private void IndexPrevMonth()
        {
            //index previous periods
            DateTime baseDate = new DateTime(2016, 11, 1); //DateTime.Now.AddMonths(-1); //baseDate.AddMonths(16);

            DateTime startDate = new DateTime(baseDate.Year, baseDate.Month, 1);
            DateTime endDate   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); //startDate.AddMonths(1);

            ThreadPool.QueueUserWorkItem(x =>
            {
                while (true)
                {
                    string zipPath;

                    for (int archiveIndex = 1; ; archiveIndex++)
                    {
                        if (archiveIndex == 1)
                        {
                            zipPath = Site.FTRobot_PATH + startDate.Year.ToString("0000") + startDate.Month.ToString("00") + ".zip";
                        }
                        else
                        {
                            zipPath = Site.FTRobot_PATH + startDate.Year.ToString("0000") + startDate.Month.ToString("00") + "_" + archiveIndex.ToString() + ".zip";
                        }

                        if (File.Exists(zipPath))
                        {
                            using (FileStream zipToOpen = new FileStream(zipPath, FileMode.Open))
                            {
                                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read))
                                {
                                    foreach (var ent in archive.Entries)
                                    {
                                        IndexEntry(ent, 0);
                                        DBHelpers.SavePage("", ent.FullName);
                                    }

                                    //DBHelpers.GetPages(IndexFile, archive, startDate, startDate.AddMonths(1));
                                }
                            }

                            break;
                        }
                        else
                        {
                            break;
                        }
                    }

                    startDate = startDate.AddMonths(1);

                    if (startDate >= endDate)
                    {
                        break;
                    }
                }
            });

            Thread.Sleep(100);

            IndexEqueue();

            ////index current period
            //startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            //DBHelpers.GetPages(IndexFile, null, startDate, startDate.AddMonths(1));

            //save index
            _service.SaveIndex();
        }