示例#1
0
 private void OnRenamed(object source, RenamedEventArgs e)
 {
     if (FileRenamed != null)
     {
         FileRenamed.Invoke(e.OldFullPath, e.FullPath);
     }
 }
示例#2
0
        } // end RenameFiles

        #endregion

        #region Event Handlers

        #region SendRenamedFileToLog

        /// <summary>
        /// Sends a file renamed message inorder to log it.
        /// </summary>
        /// <param name="sender">Object throwing the event</param>
        /// <param name="e">Event arguements relating to a the File renaming operation</param>
        private void SendRenamedFileToLog(object sender, AttributeChangedEventArgs e)
        {
            if (FileRenamed != null)
            {
                FileRenamed.Invoke(sender, e);
            }
        } // end SendRenamedFileToLog
示例#3
0
        private void OnFileRenamed(object sender, RenamedEventArgs e)
        {
            Console.WriteLine(@"RENAMED EVENT: {0}", FilePath);
            var eventArgs = new BackupFileRenamedEventArgs()
            {
                NewName = e.FullPath, OriginalName = e.OldFullPath
            };

            FileRenamed?.Invoke(this, eventArgs);

            Regex oldFileRegex = _fileRegex;

            TeardownFileWatcher();
            InitializeForFile(e.FullPath);

            var oldBackups = GenerateListOfBackups(oldFileRegex);

            ReconcileExistingBackups(oldBackups, false);

            // Photoshop does some weird stuff...
            // When you change a file (possibly only large files?), we actually
            // get a renamed event. So we're going to give the user the option
            // to make a backup on rename too
            if (SideSaver.instance.Settings.SaveBackupOnRename)
            {
                CopyAndSaveFile(e.FullPath);
            }
        }
示例#4
0
 private void OnFileRenamed(string newName, string oldName)
 {
     if (FileRenamed != null)
     {
         FileRenamed.Invoke(newName, oldName);
     }
 }
 void fileWatcher_Renamed(object sender, RenamedEventArgs e)
 {
     ThreadManager.invoke(() =>
     {
         editorResourceProvider.ResourceCache.forceCloseResourceFile(e.OldName);
         if (FileRenamed != null)
         {
             FileRenamed.Invoke(e.Name, e.OldName, false);
         }
     });
 }
 void directoryWatcher_Renamed(object sender, RenamedEventArgs e)
 {
     ThreadManager.invoke(() =>
     {
         editorResourceProvider.ResourceCache.forceCloseResourcesInDirectroy(e.OldName);
         if (FileRenamed != null)
         {
             FileRenamed.Invoke(e.Name, e.OldName, true);
         }
     });
 }
示例#7
0
        private void FileRenamedHandler(string old_filename, string new_filename, DateTime when)
        {
            var lsfile = FindLspFile(old_filename, when);

            if (lsfile == null)
            {
                return;
            }
            lsfile.FullPath = new_filename;
            lsfile.OnFileRenamed(old_filename, lsfile, when);
            FileRenamed?.Invoke(old_filename, lsfile, when);
        }
示例#8
0
        private void Watcher_Renamed(object sender, RenamedEventArgs e)
        {
            var ext = Path.GetExtension(e.FullPath);

            if (ext.Length == 0)
            {
                FolderRenamed?.Invoke(e.FullPath);
            }
            else if (PassesFilter(e.FullPath))
            {
                FileRenamed?.Invoke(e.FullPath);
            }
        }
        private void OnRenamed(object source, RenamedEventArgs e)
        {
            string oldFileName = e.OldName;
            string newFileName = e.Name;

            if (PendingIds.Contains(oldFileName))
            {
                PendingIds.Remove(oldFileName);
            }

            // This will place the renamed file at the end of the list
            PendingIds.Add(newFileName);
            FileRenamed?.Invoke(oldFileName, newFileName);
        }
示例#10
0
 protected virtual void OnFileRenamed(FileChangedEventArgs e)
 {
     FileRenamed?.Invoke(this, e);
 }
示例#11
0
 internal void OnFileRenamed(FileCopyEventArgs args)
 {
     FileRenamed?.Invoke(this, args);
 }
示例#12
0
 protected virtual void OnFileRenamed(string newName)
 {
     FileRenamed?.Invoke(this, newName);
 }
示例#13
0
 public virtual void OnFileRenamed(string old_fullpath, LspFile file, DateTime @when)
 {
     FileRenamed?.Invoke(old_fullpath, file, when);
 }
示例#14
0
        public void Receiver()
        {
            try
            {
                string conversationId       = "";
                string id                   = "";
                bool   notifyContactPersons = false;
                string emailId              = "";
                string emailAddress         = "";
                while (_client.Connected)
                {
                    byte response = _reader.ReadByte();
                    switch (response)
                    {
                    case MessageDictionary.NewNotification:
                        _writer.Write(MessageDictionary.OK);

                        List <string> referenceFields = new List <string>();

                        string   notificationId   = _reader.ReadString();
                        string   notificationText = _reader.ReadString();
                        DateTime notificationDate = DateTime.ParseExact(_reader.ReadString(), "dd-MM-yyyy HH:mm:ss",
                                                                        CultureInfo.InvariantCulture);
                        int referenceFieldCount = _reader.ReadInt32();

                        for (int i = 0; i < referenceFieldCount; i++)
                        {
                            referenceFields.Add(_reader.ReadString());
                        }

                        if (_reader.Read() == MessageDictionary.EndOfMessage)
                        {
                            switch (_reader.ReadByte())
                            {
                                #region NewMessage

                            case MessageDictionary.NewMessage:
                                id             = _reader.ReadString();
                                conversationId = _reader.ReadString();
                                string authorId          = _reader.ReadString();
                                string authorFrom        = _reader.ReadString();
                                string initialDateString = _reader.ReadString();

                                byte[] previewData = ReceiveFile();

                                List <string> attachmentIds = new List <string>();

                                int attachmentCount = _reader.ReadInt32();

                                for (int j = 0; j < attachmentCount; j++)
                                {
                                    attachmentIds.Add(_reader.ReadString());
                                }

                                MemoryStream stream = new MemoryStream(previewData);

                                BitmapImage previewImage = new BitmapImage();
                                previewImage.BeginInit();
                                previewImage.StreamSource = stream;
                                previewImage.EndInit();
                                previewImage.Freeze();

                                byte type = _reader.ReadByte();

                                DateTime initialDate = DateTime.ParseExact(initialDateString,
                                                                           "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                                ConversationMessageModel message = new ConversationMessageModel(id,
                                                                                                conversationId,
                                                                                                authorId,
                                                                                                authorFrom, initialDate, true, previewImage, false, attachmentIds);

                                switch (type)
                                {
                                case MessageDictionary.MessageTypeEmail:
                                    string subject = _reader.ReadString();
                                    string content = _reader.ReadString();

                                    ConversationEmailMessageModel emailMessage =
                                        new ConversationEmailMessageModel(message,
                                                                          subject, content);
                                    message = emailMessage;
                                    break;

                                case MessageDictionary.MessageTypePhoneCall:
                                    string recipientPhoneNumber = _reader.ReadString();
                                    string description          = _reader.ReadString();
                                    bool   answered             = _reader.ReadBoolean();

                                    ConversationPhoneMessageModel phoneMessage =
                                        new ConversationPhoneMessageModel(message, recipientPhoneNumber,
                                                                          description, answered);
                                    message = phoneMessage;
                                    break;
                                }

                                NewConversationMessageArrived?.Invoke(this,
                                                                      new NewConversationMessageArrivedEventArgs()
                                {
                                    Message      = message,
                                    Notification =
                                        new NotificationModel(notificationId, notificationText,
                                                              referenceFields,
                                                              notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RenameConversation

                            case MessageDictionary.RenameConversation:
                                conversationId = _reader.ReadString();
                                string oldName = _reader.ReadString();
                                string newName = _reader.ReadString();

                                ConversationRenamed?.Invoke(this, new ConversationRenamedEventArgs()
                                {
                                    ConversationId = conversationId,
                                    OldName        = oldName,
                                    NewName        = newName,
                                    Notification   = new NotificationModel(notificationId, notificationText,
                                                                           referenceFields,
                                                                           notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RenameFile

                            case MessageDictionary.RenameFile:
                                conversationId = _reader.ReadString();
                                oldName        = _reader.ReadString();
                                newName        = _reader.ReadString();

                                FileRenamed?.Invoke(this, new FileRenamedEventArgs()
                                {
                                    FileId       = conversationId,
                                    OldName      = oldName,
                                    NewName      = newName,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region AddConversationMembers

                            case MessageDictionary.AddConversationMembers:
                                conversationId = _reader.ReadString();
                                string personId    = _reader.ReadString();
                                string personColor = _reader.ReadString();

                                ConversationMembersAdded?.Invoke(this,
                                                                 new ConversationMembersAddedEventArgs()
                                {
                                    ConversationId = conversationId,
                                    PersonId       = personId,
                                    PersonColor    = personColor,
                                    Notification   = new NotificationModel(notificationId, notificationText,
                                                                           referenceFields,
                                                                           notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RemoveConversationMember

                            case MessageDictionary.RemoveConversationMember:
                                conversationId = _reader.ReadString();
                                personId       = _reader.ReadString();

                                ConversationMemberRemoved?.Invoke(this,
                                                                  new ConversationMemberRemovedEventArgs()
                                {
                                    ConversationId = conversationId,
                                    PersonId       = personId,
                                    Notification   = new NotificationModel(notificationId, notificationText,
                                                                           referenceFields,
                                                                           notificationDate, false)
                                });
                                break;

                                #endregion

                                #region ConversationSettingsChanged

                            case MessageDictionary.ChangeConversationSettings:
                                conversationId       = _reader.ReadString();
                                notifyContactPersons = _reader.ReadBoolean();
                                ConversationSettingsChanged?.Invoke(this,
                                                                    new ConversationSettingsChangedEventArgs()
                                {
                                    ConversationId       = conversationId,
                                    NotifyContactPersons = notifyContactPersons,
                                    Notification         = new NotificationModel(notificationId, notificationText,
                                                                                 referenceFields,
                                                                                 notificationDate, false)
                                });
                                break;

                                #endregion

                                #region NewCompany

                            case MessageDictionary.NewCompany:
                                string companyId   = _reader.ReadString();
                                string companyName = _reader.ReadString();

                                NewCompanyArrived?.Invoke(this, new NewCompanyEventArgs()
                                {
                                    Company      = new CompanyModel(companyId, companyName),
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RenameCompany

                            case MessageDictionary.RenameCompany:
                                companyId = _reader.ReadString();
                                newName   = _reader.ReadString();

                                CompanyRenamed?.Invoke(this, new CompanyRenamedEventArgs()
                                {
                                    CompanyId    = companyId,
                                    NewName      = newName,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region RemoveCompanyEvent

                            case MessageDictionary.RemoveCompany:
                                companyId = _reader.ReadString();

                                CompanyRemoved?.Invoke(this, new CompanyRemovedEventArgs()
                                {
                                    CompanyId    = companyId,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region UpdatePersonDetails

                            case MessageDictionary.UpdatePersonDetails:

                                string PersonId         = _reader.ReadString();
                                string PersonFirstName  = _reader.ReadString();
                                string PersonLastName   = _reader.ReadString();
                                string PersonGenderCode = _reader.ReadString();
                                string PersonCompanyId  = _reader.ReadString();

                                Gender PersonGender = (Gender)Convert.ToInt32(PersonGenderCode);

                                PersonModel contactPerson = new PersonModel(PersonId, PersonFirstName, PersonLastName,
                                                                            PersonGender,
                                                                            PersonCompanyId, true);

                                int emailAddressCount = _reader.ReadInt32();

                                for (int j = 0; j < emailAddressCount; j++)
                                {
                                    emailId = _reader.ReadString();
                                    string emailName = _reader.ReadString();
                                    emailAddress = _reader.ReadString();

                                    EmailAddressModel emailAddressModel = new EmailAddressModel(emailId,
                                                                                                emailAddress,
                                                                                                emailName);
                                    contactPerson.EmailAddresses.Add(emailAddressModel);
                                }

                                int phoneNumberCount = _reader.ReadInt32();

                                for (int j = 0; j < phoneNumberCount; j++)
                                {
                                    string phoneNumberId = _reader.ReadString();
                                    string phoneName     = _reader.ReadString();
                                    string phoneNumber   = _reader.ReadString();

                                    PhoneNumberModel phoneNumberModel = new PhoneNumberModel(phoneNumberId, phoneNumber,
                                                                                             phoneName);
                                    contactPerson.PhoneNumbers.Add(phoneNumberModel);
                                }

                                ContactDetailsUpdated?.Invoke(this, new ContactDetailsUpdatedEventArgs()
                                {
                                    NewData      = contactPerson,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region NewExternalContact

                            case MessageDictionary.NewExternalContact:
                                _writer.Write(MessageDictionary.OK);

                                PersonId         = _reader.ReadString();
                                PersonFirstName  = _reader.ReadString();
                                PersonLastName   = _reader.ReadString();
                                PersonGenderCode = _reader.ReadString();
                                PersonCompanyId  = _reader.ReadString();

                                PersonGender = (Gender)Convert.ToInt32(PersonGenderCode);

                                contactPerson = new PersonModel(PersonId, PersonFirstName, PersonLastName,
                                                                PersonGender,
                                                                PersonCompanyId, true);

                                emailAddressCount = _reader.ReadInt32();

                                for (int j = 0; j < emailAddressCount; j++)
                                {
                                    emailId = _reader.ReadString();
                                    string emailName = _reader.ReadString();
                                    emailAddress = _reader.ReadString();

                                    EmailAddressModel emailAddressModel = new EmailAddressModel(emailId, emailAddress,
                                                                                                emailName);
                                    contactPerson.EmailAddresses.Add(emailAddressModel);
                                }

                                phoneNumberCount = _reader.ReadInt32();

                                for (int j = 0; j < phoneNumberCount; j++)
                                {
                                    string phoneNumberId = _reader.ReadString();
                                    string phoneName     = _reader.ReadString();
                                    string phoneNumber   = _reader.ReadString();

                                    PhoneNumberModel phoneNumberModel = new PhoneNumberModel(phoneNumberId, phoneNumber,
                                                                                             phoneName);
                                    contactPerson.PhoneNumbers.Add(phoneNumberModel);
                                }

                                NewExternalContact?.Invoke(this, new NewExternalContactEventArgs()
                                {
                                    NewData      = contactPerson,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;

                                #endregion

                                #region NewExternalContact

                            case MessageDictionary.RemoveExternalContact:

                                personId = _reader.ReadString();

                                ExternalContactRemoved?.Invoke(this, new ExternalContactRemovedEventArgs()
                                {
                                    PersonId     = personId,
                                    Notification = new NotificationModel(notificationId, notificationText,
                                                                         referenceFields,
                                                                         notificationDate, false)
                                });
                                break;
                                #endregion

                                #region RemoveConversation
                            case MessageDictionary.RemoveConversation:
                                _writer.Write(MessageDictionary.OK);
                                conversationId = _reader.ReadString();

                                ConversationRemoved?.Invoke(this, new ConversationRemovedEventArgs()
                                {
                                    ConversationId = conversationId,
                                    Notification   = new NotificationModel(notificationId, notificationText,
                                                                           referenceFields,
                                                                           notificationDate, false)
                                });
                                break;
                                #endregion
                            }
                        }
                        break;

                        #region NewFiles

                    case MessageDictionary.NewFiles:
                        List <FileModel> files = new List <FileModel>();
                        files.Clear();
                        _writer.Write(MessageDictionary.OK);
                        int fileCount = _reader.ReadInt32();

                        for (int i = 0; i < fileCount; i++)
                        {
                            conversationId = _reader.ReadString();
                            id             = _reader.ReadString();
                            string    name        = _reader.ReadString();
                            string    contentType = _reader.ReadString();
                            long      size        = _reader.ReadInt64();
                            string    dateAdded   = _reader.ReadString();
                            FileModel file        = new FileModel(id, name, new ContentType(contentType), size,
                                                                  DateTime.ParseExact(dateAdded, "dd-MM-yyyy", CultureInfo.InvariantCulture))
                            {
                                ConversationId = conversationId
                            };

                            files.Add(file);
                        }

                        NewFilesArrived?.Invoke(this, new NewFilesArrivedEventArgs()
                        {
                            Files = files
                        });
                        break;

                        #endregion

                        #region NewConversation

                    case MessageDictionary.NewConversation:
                        _writer.Write(MessageDictionary.OK);

                        conversationId = _reader.ReadString();
                        string conversationName  = _reader.ReadString();
                        string visibleId         = _reader.ReadString();
                        string dateCreatedString = _reader.ReadString();
                        notifyContactPersons = _reader.ReadBoolean();


                        DateTime dateCreated = DateTime.ParseExact(dateCreatedString, "dd-MM-yyyy HH:mm:ss",
                                                                   CultureInfo.InvariantCulture);

                        int memberCount = _reader.ReadInt32();

                        List <string> memberIds    = new List <string>();
                        List <string> memberColors = new List <string>();
                        for (int j = 0; j < memberCount; j++)
                        {
                            string memberId    = _reader.ReadString();
                            string memberColor = _reader.ReadString();

                            memberIds.Add(memberId);
                            memberColors.Add(memberColor);
                        }

                        List <ConversationMessageModel> messages = new List <ConversationMessageModel>();

                        if (_reader.Read() == MessageDictionary.OK)
                        {
                            int messageCount = _reader.ReadInt32();
                            for (int i = 0; i < messageCount; i++)
                            {
                                id = _reader.ReadString();
                                string  authorId          = _reader.ReadString();
                                string  authorFrom        = _reader.ReadString();
                                string  initialDateString = _reader.ReadString();
                                Boolean received          = _reader.ReadBoolean();

                                byte[] previewData = ReceiveFile();

                                List <string> attachmentIds = new List <string>();

                                int attachmentCount = _reader.ReadInt32();

                                for (int j = 0; j < attachmentCount; j++)
                                {
                                    attachmentIds.Add(_reader.ReadString());
                                }

                                MemoryStream stream       = new MemoryStream(previewData);
                                BitmapImage  previewImage = new BitmapImage();
                                previewImage.BeginInit();
                                previewImage.StreamSource = stream;
                                previewImage.EndInit();

                                previewImage.Freeze();

                                DateTime initialDate = DateTime.ParseExact(initialDateString, "dd-MM-yyyy HH:mm:ss",
                                                                           CultureInfo.InvariantCulture);
                                ConversationMessageModel message = new ConversationMessageModel(id, conversationId,
                                                                                                authorId,
                                                                                                authorFrom, initialDate, received, previewImage, false, attachmentIds);

                                byte type = _reader.ReadByte();

                                if (type == MessageDictionary.MessageTypeEmail)
                                {
                                    string subject = _reader.ReadString();
                                    string content = _reader.ReadString();

                                    ConversationEmailMessageModel emailMessage =
                                        new ConversationEmailMessageModel(message,
                                                                          subject, content);
                                    message = emailMessage;
                                }
                                else if (type == MessageDictionary.MessageTypePhoneCall)
                                {
                                    string recipientPhoneNumber = _reader.ReadString();
                                    string callDescription      = _reader.ReadString();
                                    bool   callAnswered         = _reader.ReadBoolean();
                                    ConversationPhoneMessageModel phoneMessage =
                                        new ConversationPhoneMessageModel(message, recipientPhoneNumber,
                                                                          callDescription, callAnswered);
                                    message = phoneMessage;
                                }

                                if (message != null)
                                {
                                    messages.Add(message);
                                }
                            }

                            if (_reader.Read() == MessageDictionary.EndOfMessage)
                            {
                                ConversationModel conversation = new ConversationModel(conversationId,
                                                                                       conversationName, visibleId, dateCreated,
                                                                                       memberIds, memberColors, notifyContactPersons);
                                messages.ForEach(obj => conversation.AddMessage(obj));
                                NewConversationArrived?.Invoke(this,
                                                               new NewConversationArrivedEventArgs()
                                {
                                    Conversation = conversation
                                });
                            }
                        }
                        break;

                        #endregion

                        #region RemoveConversation

                    case MessageDictionary.RemoveConversation:
                        _writer.Write(MessageDictionary.OK);
                        conversationId = _reader.ReadString();
                        ConversationRemoved?.Invoke(this,
                                                    new ConversationRemovedEventArgs()
                        {
                            ConversationId = conversationId
                        });
                        break;

                        #endregion

                        #region NewEmailAddress

                    case MessageDictionary.AddEmailAddress:
                        _writer.Write(MessageDictionary.OK);

                        emailId      = _reader.ReadString();
                        emailAddress = _reader.ReadString();
                        string login       = _reader.ReadString();
                        string imapHost    = _reader.ReadString();
                        int    imapPort    = _reader.ReadInt32();
                        bool   imapUseSel  = _reader.ReadBoolean();
                        string smtpHost    = _reader.ReadString();
                        int    smtpPort    = _reader.ReadInt32();
                        bool   smtpUseSsl  = _reader.ReadBoolean();
                        string addressName = _reader.ReadString();

                        NewEmailAddress?.Invoke(this, new NewEmailAddressEventArgs()
                        {
                            Id         = emailId,
                            Login      = login,
                            Address    = emailAddress,
                            ImapHost   = imapHost,
                            ImapPort   = imapPort,
                            ImapUseSsl = imapUseSel,
                            SmtpHost   = smtpHost,
                            SmtpPort   = smtpPort,
                            SmtpUseSsl = smtpUseSsl,
                            Name       = addressName
                        });

                        break;

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
                ErrorHelper.LogError(ex);
                Logout();
            }
        }