Esempio n. 1
0
        internal static bool IsTimeMatch(string timeExp, DateTime tTime)
        {
            bool   blnRet = false;
            string cmpSet = timeExp.Trim(new char[] { ' ', '[', ']', '(', ')' });

            // > >= == < <=
            int nIndex = GlobalUtil.FindFirstNumber(cmpSet);

            if (nIndex == -1)
            {
                throw new InvalidOperationException("时间值规则定义错误,必须包含数字(以及比较符号> >= == < <=) !");
            }

            string cmpStr   = cmpSet.Substring(0, nIndex).Trim();
            string cmpValue = cmpSet.Substring(nIndex).Trim();

            if (cmpStr == ">")
            {
                blnRet = Convert.ToDateTime(cmpValue) > tTime;
            }
            else if (cmpStr == ">=")
            {
                blnRet = Convert.ToDateTime(cmpValue) >= tTime;
            }
            else if (cmpStr == "==")
            {
                blnRet = Convert.ToDateTime(cmpValue) == tTime;
            }
            else if (cmpStr == "<")
            {
                blnRet = Convert.ToDateTime(cmpValue) < tTime;
            }
            else if (cmpStr == "<=")
            {
                blnRet = Convert.ToDateTime(cmpValue) <= tTime;
            }
            return(blnRet);
        }
Esempio n. 2
0
        static void BuildSynFile(string baseDir, string targetFileName)
        {
            SynchronizationFile synOld  = null;
            SynchronizationFile synFile = new SynchronizationFile();

            string             sKey = "Guz(%&hj7x89H$yuBI0456FtmaT5&fvHUFCy76*h%(HilJ$lhj!y6&(*jkP87jH7";
            SymmetricAlgorithm mobjCryptoService = new RijndaelManaged();

            byte[] key = GetLegalKey(mobjCryptoService, sKey);
            byte[] iv  = GetLegalIV(mobjCryptoService);

            SymmetricCryptography <RijndaelManaged> CryProvider = new SymmetricCryptography <RijndaelManaged>(key, iv);

            if (File.Exists(targetFileName))
            {
                byte[] eBytes = File.ReadAllBytes(targetFileName);
                eBytes = CryProvider.Decrypt(eBytes);
                synOld = eBytes.GetObject <SynchronizationFile>();
            }

            using (FileSystemWorker fSysWorker = new FileSystemWorker(baseDir,
                                                                      new BuildSynFileWorker(baseDir, synFile, synOld)))
            {
                string siteRoot = AppDomain.CurrentDomain.BaseDirectory;
                //设置忽视隐藏文件夹或文件
                fSysWorker.FileExclude = f =>
                {
                    //return (f.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
                    return(f.FullName.EndsWith(".syn", StringComparison.InvariantCultureIgnoreCase));
                };
                //fSysWorker.IgnoreHiddenFolder = true;

                fSysWorker.MsgReport = str => Console.WriteLine(string.Format("{0}",
                                                                              str.Replace(siteRoot, "").Replace(baseDir, "").Replace("\\", "/")));

                fSysWorker.ProgressReport = p => Progress(string.Format("已完成{0}",
                                                                        Regex.Replace((p * 100).ToString("0.00") + "%...", "\\.0{1,}(%...)$", "%")));

                fSysWorker.Execute();
            }

            synFile.SynTimeUTC = DateTime.Now.ToUniversalTime();

            if (synOld == null)
            {
                File.WriteAllBytes(targetFileName, CryProvider.Encrypt(synFile.GetBytes()));
            }
            else
            {
                //比较旧结构不同,找出删除文件
                GlobalUtil.SetNotExistFileIn(synFile, synOld, f => {
                    synFile.RemoveFiles.Add(f.FileID, f);
                });

                //修复只是重命名的文件,而不是删除了重新添加的一个文件。
                synFile.RenameList = GlobalUtil.FixedRename(synFile.RemoveFiles, synFile.AddFiles);

                //Create Patch
                //File.WriteAllBytes(targetFileName, CryProvider.Encrypt(synFile.GetBytes()));
            }

            Progress(".目录{0}\r\n已创建同步文件为{1}", baseDir, targetFileName);

            Progress("同步文件信息:共{0}文件,大小{1}字节!\r\n + {2}, * {3}, - {4}, R {5}",
                     synFile.TotalFileCount,
                     synFile.TotalFileSize,
                     synFile.AddFiles.Count,
                     synFile.UpdateFiles.Count,
                     synFile.RemoveFiles.Count,
                     synFile.RenameList.Length
                     );

            #region 详细变化情况
            if (synFile.AddFiles.Count > 0)
            {
                foreach (SynFile aFile in synFile.AddFiles.Values)
                {
                    Progress("添加了文件:{0}, 文件大小:{1}bytes", aFile.FileID, aFile.FileSize);
                }
            }

            if (synFile.UpdateFiles.Count > 0)
            {
                foreach (SynFile uFile in synFile.UpdateFiles.Values)
                {
                    Progress("修改了文件:{0}, 文件大小:{1}bytes", uFile.FileID, uFile.FileSize);
                }
            }

            if (synFile.RemoveFiles.Count > 0)
            {
                foreach (SynFile dFile in synFile.RemoveFiles.Values)
                {
                    Progress("删除了文件:{0}, 文件大小:{1}bytes", dFile.FileID, dFile.FileSize);
                }
            }

            if (synFile.RenameList.Length > 0)
            {
                for (int i = 0, j = synFile.RenameList.Length; i < j; i++)
                {
                    Progress("重命名{0}为{1}", synFile.RenameList[i].OldSynFile.FileID, synFile.RenameList[i].NewSynFile.FileID);
                }
            }
            #endregion
        }