Exemplo n.º 1
0
 public static BitmapImage GetImage(FileStates state)
 {
     if ((state & FileStates.Conflicted) != 0)
     {
         return(conflictedImage);
     }
     else if ((state & FileStates.NewInIndex) != 0 || (state & FileStates.NewInWorkdir) != 0)
     {
         return(newImage);
     }
     else if ((state & FileStates.DeletedFromIndex) != 0 || (state & FileStates.DeletedFromWorkdir) != 0)
     {
         return(deletedImage);
     }
     else if ((state & FileStates.ModifiedInIndex) != 0 || (state & FileStates.ModifiedInWorkdir) != 0)
     {
         return(modifiedImage);
     }
     else if ((state & FileStates.RenamedInIndex) != 0 || (state & FileStates.RenamedInWorkdir) != 0)
     {
         return(renamedImage);
     }
     else if ((state & FileStates.TypeChangeInIndex) != 0 || (state & FileStates.TypeChangeInWorkdir) != 0)
     {
         return(typeChangedImage);
     }
     else
     {
         return(unknownImage);
     }
 }
        public static string GetFileName(DateTime timeStamp, FileStates fileState)
        {
            var fileName = "{0:yyyyMMdd-HHmmss-fff}.{1}"
                .FormatWith(timeStamp, fileState);

            return fileName;
        }
Exemplo n.º 3
0
 public File(string fullPath)
 {
     this.fullPath = fullPath;
     string[] parts = fullPath.Split('\\');
     this.path  = parts[parts.Length - 1];
     this.state = FileStates.NONE;
 }
        public IEnumerable<File> GetFiles(FileStates state)
        {
            var searchPattern = "*.{0}"
                .FormatWith(state);

            var files = _dropShipperLocation.GetFiles(searchPattern);

            return files;
        }
        public IEnumerable<File> GetFiles(FileTypes type, FileStates state)
        {
            var searchPattern = "*.{0}.{1}"
                .FormatWith(type, state);

            var files = _vendorLocation.GetFiles(searchPattern);

            return files;
        }
Exemplo n.º 6
0
        public static bool IsAnyStates(FileStates stateFlag, FileStates[] states)
        {
            foreach (var state in states)
            {
                if ((stateFlag & state) != 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 开始接收
        /// </summary>
        private void Receive()
        {
            if (ChatViewModel != null && AppData.CanInternetAction())
            {
                _targetModel.MessageState = MessageStates.None;
                this.FileState            = FileStates.Receiving;
                _operateTask = new System.Threading.CancellationTokenSource();
                AcioningItems.Add(this);

                CSClient.Helper.MessageHelper.LoadFileContent(_targetModel, _operateTask, ChatViewModel, (result) =>
                {
                    AcioningItems.Remove(this);
                    if (_operateTask != null)
                    {
                        _operateTask.Cancel();
                        _operateTask = null;
                    }
                });
            }
        }
Exemplo n.º 8
0
        private void CalFileState()
        {
            if (this.FileState == FileStates.Receiving)
            {
                return;
            }
            try
            {
                this.tbName.ToolTip = System.IO.Path.GetFileName(this.FullName);//?.Split('\\').LastOrDefault();
            }
            catch
            {
                return;
            }
            if (ChatViewModel == null)
            {
                ChatViewModel = AppData.MainMV.ChatListVM.SelectedItem;
            }
            else if (_targetModel.MessageState == MessageStates.Fail)
            {
                if (_operateTask != null)
                {
                    _operateTask.Cancel();
                }
                AcioningItems.Remove(this);
            }

            if (_targetModel == null && this.DataContext is MessageModel item)
            {
                _targetModel = item;

                var target = FileItems.FirstOrDefault(info => info.MsgKey == item.MsgKey);

                if (target == null)
                {
                    target = item;
                    FileItems.Add(item);
                }

                if (string.IsNullOrEmpty(target.MsgKey))
                {
                    target.MsgKey = Guid.NewGuid().ToString();
                }
                this.DataContext = _targetModel = target;
            }

            if (this.IsMainView == false)
            {
                if (_targetModel.ResourceModel.FileState != FileStates.None)
                {
                    return;
                }
            }
            //是否发送者
            bool isSender = _targetModel.Sender.ID == AppData.Current.LoginUser.ID;

            _targetModel.ResourceModel.FileImg = Helper.FileHelper.GetFileImage(this.FullName, false);
            this.gridLayout.ToolTip            = System.IO.Path.GetFileName(this.FullName);
            if (File.Exists(this.FullName))
            {
                if (isSender && _targetModel.IsSending)
                {
                    if (this._targetModel.ResourceModel.FileState == FileStates.SendOffline || this._targetModel.ResourceModel.FileState == FileStates.SendOnline)
                    {
                    }
                    else
                    {
                        this.FileState = _targetModel.ResourceModel.FileState = FileStates.SendOnline;
                        this.OnlineSend();
                    }
                }
                else
                {
                    this.FileState = _targetModel.ResourceModel.FileState = FileStates.Completed;
                    _completeTime  = DateTime.Now.AddMinutes(-5);
                }
            }
            else
            {
                if (isSender) //发送者
                {
                    this.FileState = _targetModel.ResourceModel.FileState = FileStates.Completed;
                    _completeTime  = DateTime.Now.AddMinutes(-5);
                }
                else
                {
                    this.FileState = _targetModel.ResourceModel.FileState = FileStates.WaitForReceieve;
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Method to copy and move the files into the destination directory. Contains instructions for when errors occur as well
        /// </summary>
        /// <param name="source"> Source input </param>
        /// <param name="destination"> Destination input </param>
        /// <returns> boolean of whether the method ran all the way through </returns>
        public static bool CopyAndMove(string source, string destination)
        {
            FileStates filestate  = new FileStates();
            string     workingDir = Environment.CurrentDirectory;
            string     json       = Path.Combine(workingDir, "JsonMaintainState.json");

            filestate.DeSerialize(json);
            string[] allFiles = Directory.GetFiles(source, "*", SearchOption.AllDirectories);

            for (int i = 0; i < allFiles.Length; i++)
            {
                string filePath = allFiles[i];

                if (filestate.CopiedFiles != null)
                {
                    bool fileCopied = filestate.CopiedFiles.Contains(filePath);

                    if (fileCopied)
                    {
                        continue;
                    }
                }

                FileInfo file = new FileInfo(filePath);

                DateTime creationTime = file.CreationTime;
                string   year         = creationTime.Year.ToString();
                string   month        = creationTime.Month.ToString();
                string   day          = creationTime.Day.ToString();

                if (month.Length == 1)
                {
                    month = "0" + month;
                }

                if (day.Length == 1)
                {
                    day = "0" + day;
                }

                string fileName      = Path.GetFileName(filePath);
                string timeExtension = Path.Combine(year, month, day);
                string newDirPath    = Path.Combine(destination, timeExtension);
                string newFilePath   = Path.Combine(newDirPath, fileName);

                if (!Directory.Exists(newDirPath))
                {
                    Directory.CreateDirectory(newDirPath);
                }

                try
                {
                    File.Copy(filePath, newFilePath);
                    filestate.CopiedFiles.Add(filePath);
                }
                catch (IOException)
                {
                    if (!Crypto.HashComparison(filePath, newFilePath))
                    {
                        Console.WriteLine("The hashes are not similar. Something went wrong in the copy process");
                    }

                    continue;
                }

                if (!Crypto.HashComparison(filePath, newFilePath))
                {
                    Console.WriteLine("The hashes are not similar. Something went wrong in the copy process");
                    continue;
                }
            }

            filestate.Serialize(json);
            return(true);
        }
Exemplo n.º 10
0
 public IList <File> GetFilesByCatIds(string ownerID, string keyword, string parentID, string startTime, string endTime, IList <string> catIds, FileStates fileStates, FileTypes fileType, string orderBy, bool desc, int pageIndex, int pageSize, out int recordCount)
 {
     return(this.InnerGetFilesByCatIds(ownerID, keyword, parentID, startTime, endTime, catIds, fileStates, fileType, false, false, false, false, false, orderBy, desc, pageIndex, pageSize, out recordCount));
 }
Exemplo n.º 11
0
 public static IList <File> GetFilesWithoutExtendPropertyBy(string ownerID, string keyword, string parentID, string startTime, string endTime, FileStates fileStates, FileTypes fileType, bool displayInNotificationsOnly, bool publicReviewOnly, bool publicDownloadOnly, bool previewAfterPermitOnly, bool downloadAfterPermitOnly, string orderBy, bool desc, int pageIndex, int pageSize, out int recordCount)
 {
     return(FileSystemService.fileGateway.GetFilesBy(ownerID, keyword, parentID, startTime, endTime, fileStates, fileType, displayInNotificationsOnly, publicReviewOnly, publicDownloadOnly, previewAfterPermitOnly, downloadAfterPermitOnly, orderBy, desc, pageIndex, pageSize, out recordCount));
 }
Exemplo n.º 12
0
 public static IList <File> GetFilesByCatIds(string ownerID, string keyword, string parentID, string startTime, string endTime, IList <string> catIds, FileStates fileState, FileTypes fileType, string orderBy, bool desc, int pageIndex, int pageSize, out int recordCount)
 {
     return(FileSystemService.ReadExtendPropertiesOfFiles(FileSystemService.fileGateway.GetFilesByCatIds(ownerID, keyword, parentID, startTime, endTime, catIds, fileState, fileType, orderBy, desc, pageIndex, pageSize, out recordCount)));
 }
Exemplo n.º 13
0
        private void fileUploader_UploadFinished(object sender, EventArgs e)
        {
            _fileUploader = null;
            if (State != FileStates.Deleted && State != FileStates.Error)
            {
                State = FileStates.Finished;

                if (FileStream != null)
                {
                    FileStream.Close();
                    FileStream.Dispose();
                    FileStream = null;
                }
                FinishUpdate(sender, e);
            }
        }
Exemplo n.º 14
0
        public void Upload(string initParams, System.Windows.Threading.Dispatcher uiDispatcher)
        {
            State = FileStates.Uploading;

            _fileUploader = new HttpFileUploader(this, uiDispatcher);
            _fileUploader.StartUpload(initParams);
            _fileUploader.UploadFinished += new EventHandler(fileUploader_UploadFinished);
        }
Exemplo n.º 15
0
        private IList <File> InnerGetFilesByCatIds(string ownerID, string keyword, string parentID, string startTime, string endTime, IList <string> catIds, FileStates fileStates, FileTypes fileType, bool displayInNotificationsOnly, bool publicReviewOnly, bool publicDownloadOnly, bool previewAfterPermitOnly, bool downloadAfterPermitOnly, string orderBy, bool desc, int pageIndex, int pageSize, out int recordCount)
        {
            Conditions conditions = new Conditions();

            if (!StringHelper.isNullOrEmpty(ownerID))
            {
                conditions.ConditionExpressions.Add(new Condition("OwnerID", Operator.EqualTo, ownerID));
            }
            if (!StringHelper.isNullOrEmpty(parentID))
            {
                conditions.ConditionExpressions.Add(new Condition("ParentID", Operator.EqualTo, parentID));
            }
            if (fileType != FileTypes.NotSpecifiled)
            {
                conditions.ConditionExpressions.Add(new Condition("FileType", Operator.EqualTo, fileType));
            }
            if (fileStates != FileStates.NotSpecified)
            {
                conditions.ConditionExpressions.Add(new Condition("FileState", Operator.EqualTo, fileStates));
            }
            if (!StringHelper.isNullOrEmpty(startTime) && !StringHelper.isNullOrEmpty(endTime))
            {
                conditions.ConditionExpressions.Add(new Condition("CreateTime", Operator.Between, startTime, endTime));
            }
            if (displayInNotificationsOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("DisplayInNotifications", Operator.EqualTo, true));
            }
            if (publicReviewOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("PublicReviewOnly", Operator.EqualTo, true));
            }
            if (publicDownloadOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("PublicDownloadOnly", Operator.EqualTo, true));
            }
            if (previewAfterPermitOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("PreviewAfterPermit", Operator.EqualTo, true));
            }
            if (downloadAfterPermitOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("DownloadAfterPermit", Operator.EqualTo, true));
            }
            string text = "";

            if (catIds != null && catIds.Count > 0)
            {
                foreach (string current in catIds)
                {
                    text += string.Format(" CategoryQueryIds like '%|{0}|%' or", current);
                }
                if (text.EndsWith("or"))
                {
                    text = text.Substring(0, text.Length - 2);
                }
                text = "(" + text + ")";
            }
            conditions.Connector = Connector.AND;
            string text2 = string.Empty;

            if (!StringHelper.isNullOrEmpty(keyword))
            {
                text2 = string.Format("(OriginalFileName like '%{0}%' or Title like '%{0}%' or Keyword like '%{0}%' or Memo like '%{0}%' or RelativeProjectNames like '%{0}%' or RelativeUserNames like '%{0}%')", keyword);
            }
            OrderExpression orderExpression = null;

            if (!StringHelper.isNullOrEmpty(orderBy))
            {
                orderExpression = new OrderExpression(orderBy, desc);
            }
            IList <string> list = new List <string>();

            if (!StringHelper.isNullOrEmpty(text2))
            {
                list.Add(text2);
            }
            if (!StringHelper.isNullOrEmpty(text))
            {
                list.Add(text);
            }
            return(this.dbGateway.getRecords(pageIndex, pageSize, conditions, orderExpression, list, Connector.AND, out recordCount));
        }
Exemplo n.º 16
0
 public IList <File> GetFilesByUnknown(string ownerID, string keyword, string parentID, string startTime, string endTime, FileStates fileStates, FileTypes fileType, bool displayInNotificationsOnly, bool publicReviewOnly, bool publicDownloadOnly, bool previewAfterPermitOnly, bool downloadAfterPermitOnly, string orderBy, bool desc, int pageIndex, int pageSize, out int recordCount)
 {
     return(this.InnerGetFilesBy(ownerID, keyword, parentID, startTime, endTime, fileStates, fileType, displayInNotificationsOnly, publicReviewOnly, publicDownloadOnly, previewAfterPermitOnly, downloadAfterPermitOnly, orderBy, desc, pageIndex, pageSize, out recordCount));
 }
Exemplo n.º 17
0
        /// <summary>
        /// 另存为
        /// </summary>
        private void SaveAs()
        {
            if (_targetModel.ResourceModel.FileState == FileStates.WaitForReceieve)
            {
                if (AppData.CanInternetAction())
                {
                    Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
                    sfd.FileName = _targetModel.ResourceModel.FileName;
                    //sfd.Filter = System.IO.Path.GetExtension(_targetModel.ResourceModel.FileName);
                    if (sfd.ShowDialog() == true)
                    {
                        try
                        {
                            File.Delete(sfd.FileName);
                        }
                        catch
                        {
                            AppData.MainMV.TipMessage = "文件已被占用,替换失败!";
                            return;
                        }
                        this.FileState = FileStates.Receiving;
                        _operateTask   = new System.Threading.CancellationTokenSource();
                        AcioningItems.Add(this);
                        ChatViewModel chatVM = AppData.MainMV.ChatListVM.SelectedItem;
                        CSClient.Helper.MessageHelper.LoadFileContent(_targetModel, _operateTask, chatVM, (result) =>
                        {
                            AcioningItems.Remove(this);
                            if (_operateTask != null)
                            {
                                _operateTask.Cancel();
                                _operateTask = null;
                            }
                        }, sfd.FileName);
                    }
                }
            }
            else
            {
                if (FileExists())
                {
                    Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
                    dlg.FileName   = System.IO.Path.GetFileName(this.FullName);    // Default file name
                    dlg.DefaultExt = System.IO.Path.GetExtension(this.FullName);   // fileName.Split('.').LastOrDefault(); // Default file extension

                    dlg.Filter = string.Format("文件 (.{0})|*.{0}", dlg.DefaultExt); // // Filter files by extension

                    dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                    if (dlg.ShowDialog() == true)
                    {
                        try
                        {
                            File.Copy(this.FullName, dlg.FileName, true);
                        }
                        catch
                        {
                            AppData.MainMV.TipMessage = "文件已被占用,替换失败!";
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
 public static IList <File> GetFilesWithoutExtendPropertyBy(string ownerID, string keyword, string parentID, string startTime, string endTime, FileStates fileState, FileTypes fileType, string orderBy, bool desc, int pageIndex, int pageSize, out int recordCount)
 {
     return(FileSystemService.fileGateway.GetFilesBy(ownerID, keyword, parentID, startTime, endTime, fileState, fileType, orderBy, desc, pageIndex, pageSize, out recordCount));
 }
Exemplo n.º 19
0
        private void BlockListReadHttpResponseCallback(IAsyncResult asynchronousResult)
        {
            bool error = false;

            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse webResponse = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);
                StreamReader reader = new StreamReader(webResponse.GetResponseStream());

                string responsestring = reader.ReadToEnd();
                reader.Close();
            }
            catch(Exception ex)
            {
                error = true;
                State = FileStates.Error;
                ErrorMessage = ex.Message;

            }

            if (!error)
            {
                State = FileStates.Finished;
                Done = 100;
            }
        }
Exemplo n.º 20
0
        private void ReadHttpResponseCallback(IAsyncResult asynchronousResult)
        {
            bool error = false;

            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse webResponse = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);
                StreamReader reader = new StreamReader(webResponse.GetResponseStream());

                string responsestring = reader.ReadToEnd();
                reader.Close();
            }
            catch(Exception ex)
            {
                error = true;
                ErrorMessage = ex.Message;
                State = FileStates.Error;
            }

            if (!error)
            {
                blockIds.Add(currentBlockId);
            }

            // if there's more data, send another request
            if (_dataSent < _dataLength)
            {
                if (State != FileStates.Error && !error)
                {
                    StartUpload();
                }
            }
            else // all done
            {
                _fileStream.Close();
                _fileStream.Dispose();

                if (UseBlocks)
                {
                    PutBlockList(); // commit the blocks into the blob
                }
                else
                {
                    State = FileStates.Finished;
                }
            }
        }
Exemplo n.º 21
0
 public bool HasState(FileStates state)
 {
     return((this.state & state) != 0);
 }
Exemplo n.º 22
0
        private IList <File> InnerGetFilesBy(string ownerID, string keyword, string parentID, string startTime, string endTime, FileStates fileStates, FileTypes fileType, bool displayInNotificationsOnly, bool publicReviewOnly, bool publicDownloadOnly, bool previewAfterPermitOnly, bool downloadAfterPermitOnly, string orderBy, bool desc, int pageIndex, int pageSize, out int recordCount)
        {
            Conditions conditions = new Conditions();

            if (!StringHelper.isNullOrEmpty(ownerID))
            {
                conditions.ConditionExpressions.Add(new Condition("OwnerID", Operator.EqualTo, ownerID));
            }
            if (!StringHelper.isNullOrEmpty(parentID))
            {
                conditions.ConditionExpressions.Add(new Condition("ParentID", Operator.EqualTo, parentID));
            }
            if (fileType != FileTypes.NotSpecifiled)
            {
                conditions.ConditionExpressions.Add(new Condition("FileType", Operator.EqualTo, fileType));
            }
            if (fileStates != FileStates.NotSpecified)
            {
                conditions.ConditionExpressions.Add(new Condition("FileState", Operator.EqualTo, fileStates));
            }
            if (!StringHelper.isNullOrEmpty(startTime) && !StringHelper.isNullOrEmpty(endTime))
            {
                conditions.ConditionExpressions.Add(new Condition("CreateTime", Operator.Between, startTime, endTime));
            }
            if (displayInNotificationsOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("DisplayInNotifications", Operator.EqualTo, true));
            }
            if (publicReviewOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("PublicReviewOnly", Operator.EqualTo, true));
            }
            if (publicDownloadOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("PublicDownloadOnly", Operator.EqualTo, true));
            }
            if (previewAfterPermitOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("PreviewAfterPermit", Operator.EqualTo, true));
            }
            if (downloadAfterPermitOnly)
            {
                conditions.ConditionExpressions.Add(new Condition("DownloadAfterPermit", Operator.EqualTo, true));
            }
            conditions.Connector = Connector.AND;
            string value = string.Empty;

            if (!StringHelper.isNullOrEmpty(keyword))
            {
                value = string.Format("(OriginalFileName like '%{0}%' or Title like '%{0}%' or Keyword like '%{0}%' or Memo like '%{0}%' or RelativeProjectNames like '%{0}%' or RelativeUserNames like '%{0}%')", keyword);
            }
            OrderExpression orderExpression = null;

            if (!StringHelper.isNullOrEmpty(orderBy))
            {
                orderExpression = new OrderExpression(orderBy, desc);
            }
            return(this.dbGateway.getRecords(pageIndex, pageSize, conditions, orderExpression, StringHelper.BuildStringList(value), Connector.AND, out recordCount));
        }