private void Initialize(string revitBasicFileInfoString) { if (string.IsNullOrEmpty(revitBasicFileInfoString)) { return; } //Clear disturbs var basicFileInfoString = revitBasicFileInfoString.Replace("\0", string.Empty); //Read lines var detailInfoLines = basicFileInfoString.Split(new[] { "\r\n" }, new StringSplitOptions()); foreach (var detailInfoLine in detailInfoLines) { //Divide by ":" var index = detailInfoLine.IndexOf(":", StringComparison.Ordinal); if (index < 0) { continue; } var infoKey = detailInfoLine.Substring(0, index).Trim(); var fileInfoKey = RevitFileUtils.ResolveFileInfoKey(infoKey); if (fileInfoKey == FileInfoKey.Invalid) { continue; } var infoValue = detailInfoLine.Substring(index + 1).Trim(); FileInfoPair.Add(fileInfoKey, infoValue); } }
/// <summary> /// 线程执行体:上传本地目录的所有文件到ftp目录(不对本地目录进行递归运算,无法上传子目录文件) /// </summary> private void UploadPathThread() { while (m_runThread) { if (m_queueUploadFile.Count == 0) { Thread.Sleep(0); continue; } DateTime dt = DateTime.Now; lock (m_queueUploadFile) { FileInfoPair fileInfo = m_queueUploadFile.Peek(); Upload(fileInfo.SourceFileName, fileInfo.FtpPath); File.Delete(fileInfo.SourceFileName); m_queueUploadFile.Dequeue(); Thread.Sleep(0); } TimeSpan sp = DateTime.Now - dt; int a = 0; a++; } }
/// <summary></summary> /// <param name=""></param> private void ExecuteCompare(BackgroundMessage UserInterfaceMessage) { List <PairOfFiles> ltKnownPairs = new List <PairOfFiles>(); Drive SourceDrive = UserInterfaceMessage.PairProperty.SourceDrive; _quReturn.Enqueue(new BackgroundMessage(BackgroundMessage.nType.UserMessage, BackgroundMessage.nReturnCode.StartCompare)); // first, find out as quickly as possible how many directories and files there are switch (SourceDrive.eEncryptionType) { case Drive.nEncryptionType.DirectoryUnencrypted: ReadSourceDirectories(UserInterfaceMessage.PairProperty, ltKnownPairs); break; } switch (UserInterfaceMessage.PairProperty.DestinationDrive.eEncryptionType) { case Drive.nEncryptionType.DirectoryUnencrypted: ReadDestinationDirectories(UserInterfaceMessage.PairProperty, ltKnownPairs); break; } if (_eState == nState.Working) { // now we know how many directories and files there are and can set up the progress bar _quReturn.Enqueue(new BackgroundMessage(BackgroundMessage.nType.SetupProgress, 0, ltKnownPairs.Count())); foreach (PairOfFiles FileInfoPair in ltKnownPairs) { if (_eState == nState.Working) { // we can report progess to the user, now do the time-consuming reading of the file size, attributes and dates: FileInfoPair.ReadProperties(); _quReturn.Enqueue(new BackgroundMessage(BackgroundMessage.nType.NewPair, FileInfoPair)); // send the PairOfFiles to the MainViewModel } } } _quReturn.Enqueue(new BackgroundMessage(BackgroundMessage.nType.UserMessage, BackgroundMessage.nReturnCode.FinishCompare)); }
/// <summary> /// 上传本地目录的所有文件到ftp目录(不对本地目录进行递归运算,无法上传子目录文件) /// </summary> /// <param name="localFilePath">本地目录</param> /// <param name="ftpPath">上传到的目标目录</param> public void UploadPath(string localFilePath, string ftpPath) { if (!Directory.Exists(localFilePath)) { return; } string[] localFileList = GetLocalFileName(localFilePath); if (localFileList == null || localFileList.Length == 0) { return; } IsExistsOfFTPDirectory(ftpPath); foreach (string fileName in localFileList) { FileInfoPair fileInfo = new FileInfoPair(); fileInfo.SourceFileName = fileName; fileInfo.FtpPath = ftpPath; m_queueUploadFile.Enqueue(fileInfo); } if (m_uploadThread == null) { //ParameterizedThreadStart ParStart = new ParameterizedThreadStart(UploadPathThread); //m_uploadThread = new Thread(ParStart); m_uploadThread = new Thread(new ThreadStart(this.UploadPathThread)); m_uploadThread.IsBackground = true; m_runThread = true; m_uploadThread.Start(); //string[] path = new string[] { localFilePath, ftpPath }; //thread.Start(path); } }