private void AddFilesInDataGridList(string[] arrayFilesName, bool notified = false)
        {
            if (arrayFilesName != null)
            {
                string[] addedFiles = new string[arrayFilesName.Count()];
                int      i          = 0;
                foreach (string file in arrayFilesName)
                {
                    if (!string.IsNullOrWhiteSpace(file))
                    {
                        FileSubscriber finded = listFiles.FirstOrDefault(f => f.Path == file);
                        if (finded != null)
                        {
                            Dialog.ShowMessage($"Выбранный файл уже контролируется:\n" +
                                               $"{file}");
                            continue;
                        }

                        FileSubscriber subscriber = AddFileInDataGrid(file, notified);
                        addedFiles[i++] = subscriber.FileName;
                    }
                }
                if (notified)
                {
                    _notifyIcon.AddFile(i, addedFiles);
                }
            }
        }
        private void AddSelectedFilesIndgList(string[] fileNames)
        {
            List <FileSubscriber> list = listFile.ToList();

            foreach (string file in fileNames)
            {
                FileSubscriber finded = list.Find(f => f.Path == file);

                if (finded != null)
                {
                    Dialog.ShowMessage($"Выбранный файл уже контролируется:\n" +
                                       $"{fileNames}");
                    return;
                }

                DirFile pathInfo = new DirFile(file);

                ulong sizeFile = pathInfo.GetFileSize();

                FileSubscriber fileChecked = new FileSubscriber()
                {
                    Checked    = true,
                    Path       = file,
                    Size       = sizeFile,
                    SizeString = pathInfo.GetSizeFormat(sizeFile)
                };

                _subscriber.SubscribeChangeFile(fileChecked);

                list.Add(fileChecked);
            }

            SetItemSouce(list);
        }
Ejemplo n.º 3
0
        private void ChangedFile(object sender, FileSystemEventArgs e)
        {
            try
            {
                Thread.Sleep(2 * 1000);

                var            keyWatcher = DictionaryWatcher.First(f => f.Key.Path == e.FullPath);
                FileSubscriber file       = keyWatcher.Key;

                FileInfo fileInfo = new FileInfo(file.Path);
                CreateNewVersionFile(fileInfo, file);

                var args = new ChangedFileEvent();
                if (args != null)
                {
                    foreach (EventHandler <ChangedFileEvent> deleg in ChangeFileEvent.GetInvocationList())
                    {
                        deleg.Invoke(this, args);
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 4
0
        private int GetNewVersion(FileInfo fileInfo, FileSubscriber file, string fileExtension)
        {
            int newVersion = GetCurrentVersionFile(fileInfo, file);

            newVersion++;

            return(newVersion);
        }
Ejemplo n.º 5
0
 private void Subscribe(FileSubscriber file)
 {
     if (file.Checked &&
         !String.IsNullOrWhiteSpace(file.Path))
     {
         EnableSubscription(file);
     }
 }
Ejemplo n.º 6
0
        internal void Call(FileSubscriber subscriber)
        {
            if (CallUpdateVersion == null)
            {
                return;
            }

            CallUpdateVersion(subscriber, NeedNotified);
        }
Ejemplo n.º 7
0
        public FormComment(FileSubscriber subscriber, int?numberVersion = null)
        {
            InitializeComponent();

            _subscriber = subscriber;
            Version     = numberVersion == null ? _subscriber.Version : (int)numberVersion;

            TextBlockHeader.Text = TextBlockHeader.Text.Replace("%1", Version.ToString());
        }
Ejemplo n.º 8
0
        public Comments(FileSubscriber subscriber, FileInfo fileInfo = null)
        {
            Subscriber = subscriber ?? throw new ArgumentNullException("subscriber");
            FileInfo   = fileInfo ?? new FileInfo(subscriber.Path);

            DirectoryInfo directoryInfo = new DirectoryInfo(Subscriber.DirectoryVersion);

            string pathFileComment = Path.Combine(directoryInfo.FullName, "comments.js");

            _fileInfoComment = new FileInfo(pathFileComment);
        }
        private void _notifyIcon_BalloonTipClicked(object sender, EventArgs e)
        {
            if (Subscriber == null)
            {
                return;
            }

            new Comments(Subscriber).OpenFormComment();

            Subscriber = null;
        }
        private void MiOpenDirectoryVersion_Click(object sender, RoutedEventArgs e)
        {
            FileSubscriber selectedRow = GetCurrentRow();

            if (selectedRow == null)
            {
                return;
            }

            Dialog.OpenDirectory(selectedRow.DirectoryVersion);
        }
Ejemplo n.º 11
0
        internal void Unsubscribe(FileSubscriber subscriber)
        {
            var keyWather = _listWather.FirstOrDefault(f => f.Key == subscriber);

            if (keyWather.Key == null)
            {
                return;
            }

            FileSystemWatcher watcher = keyWather.Value;

            watcher.EnableRaisingEvents = false;
            watcher.Dispose();

            _listWather.Remove(subscriber);
        }
Ejemplo n.º 12
0
        private void EnableSubscription(FileSubscriber file)
        {
            FileInfo fileInfo = new FileInfo(file.Path);

            file.DirectoryVersion = GetDirectoryVersion(fileInfo);

            FileSystemWatcher watcher = new FileSystemWatcher(fileInfo.DirectoryName, fileInfo.Name)
            {
                NotifyFilter = NotifyFilters.LastWrite
            };

            watcher.Changed            += new FileSystemEventHandler(ChangedFile);
            watcher.EnableRaisingEvents = true;

            DictionaryWatcher.Add(file, watcher);
        }
Ejemplo n.º 13
0
 internal void UnsubscribeChangeFile(FileSubscriber file)
 {
     try
     {
         var keyWatcher = DictionaryWatcher.FirstOrDefault(f => f.Key == file);
         if (keyWatcher.Key != null)
         {
             FileSystemWatcher watcher = keyWatcher.Value;
             watcher.EnableRaisingEvents = false;
             watcher.Dispose();
             DictionaryWatcher.Remove(keyWatcher.Key);
         }
     }
     catch (Exception)
     {
     }
 }
        private void MiDeleteFile_Click(object sender, RoutedEventArgs e)
        {
            FileSubscriber selectedRow = GetCurrentRow();

            if (selectedRow == null)
            {
                return;
            }

            List <FileSubscriber> list = listFile.ToList();

            _subscriber.UnsubscribeChangeFile(selectedRow);

            list.Remove(selectedRow);

            SetItemSouce(list);
        }
        private FileSubscriber AddFileInDataGrid(string file, bool notified = false)
        {
            FileSubscriber subscriber = new FileSubscriber()
            {
                Checked  = true,
                Path     = file,
                FileName = DirFile.GetFileName(file)
            };

            subscriber.SetCurrentSize();

            _subscriber.Subscribe(subscriber, notified);

            listFiles.Add(subscriber);

            return(subscriber);
        }
Ejemplo n.º 16
0
        private void Subscribe_Changed(object sender, FileSystemEventArgs e)
        {
            try
            {
                Thread.Sleep(1000);

                FileInfo fileInfo = new FileInfo(e.FullPath);

                FileSubscriber subscriber = _listSubscriber.First(f => f.Key.FullName == fileInfo.FullName).Value;

                string   tempFileName = DirFile.GetTempFile();
                FileInfo fileInfoTemp = fileInfo.CopyTo(tempFileName);
                string   fileName     = fileInfo.Name;
                string   extension    = fileInfo.Extension;
                fileInfo = null;

                Task.Run(() =>
                {
                    lock (_locker)
                    {
                        using (Versions versions = new Versions()
                        {
                            SubscriberInfo = fileInfoTemp,
                            Subscriber = subscriber,
                            FileName = fileName,
                            Extension = extension
                        })
                        {
                            versions.CreateNewVersionFile();
                        }

                        _callUpdate.NeedNotified = true;
                        _callUpdate.Call(subscriber);

                        DirFile.DeleteFile(fileInfoTemp);

                        fileInfoTemp = null;
                    }
                });
            }
            catch (Exception ex)
            {
                Errors.Save(ex);
            }
        }
 private void DataGridList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     _fileSubscriberCurrentRow = null;
     if (e.AddedItems.Count > 0)
     {
         if (e.AddedItems[0] is FileSubscriber subscriber)
         {
             _fileSubscriberCurrentRow = subscriber;
             LoadListVersion();
         }
         else
         {
             _listVersion.Clear();
         }
     }
     else if (_listVersion.Count > 0)
     {
         _listVersion.Clear();
     }
 }
        private async Task StartUpdateVersionFiles(FileSubscriber fileSubscriber = null)
        {
            List <FileSubscriber> listVersion = new List <FileSubscriber>();

            if (fileSubscriber == null)
            {
                listVersion = await _subscriber.LoadVersionFilesAsync(
                    listFile.ToList().FindAll(f => f.Checked));
            }
            else
            {
                listVersion = await _subscriber.LoadVersionFilesAsync(
                    listFile.ToList().FindAll(f => f == fileSubscriber));
            }

            if (listVersion.Count == 0)
            {
                return;
            }

            dgList.IsReadOnly = true;

            List <FileSubscriber> list = listFile.ToList();

            for (int i = 0; i < list.Count; i++)
            {
                FileSubscriber finded = listVersion.Find(f => f.Path == list[i].Path);
                if (finded != null)
                {
                    list[i].Version = finded.Version;
                }
                else
                {
                    list[i].Version = 0;
                }
            }

            SetItemSouce(list);

            dgList.IsReadOnly = false;
        }
Ejemplo n.º 19
0
        private int GetCurrentVersionFile(FileInfo fileInfo, FileSubscriber file, bool controlCurrentHash = true)
        {
            if (String.IsNullOrWhiteSpace(file.DirectoryVersion))
            {
                return(0);
            }

            GetFileNameWithoutExtension(fileInfo);
            GetFileNameWithVersion();

            FileInfo fileInfoMaxEdited = GetFileLastVersion(file, fileInfo.Extension, controlCurrentHash);

            if (fileInfoMaxEdited == null)
            {
                return(0);
            }
            else
            {
                return(GetNumberVersionIsFileName(fileInfoMaxEdited, fileInfo));
            }
        }
Ejemplo n.º 20
0
        private void CreateNewVersionFile(FileInfo fileInfo, FileSubscriber file, string newFileName = null)
        {
            if (String.IsNullOrWhiteSpace(newFileName))
            {
                newFileName = GetFileNameVersion(fileInfo, file);
            }

            if (!String.IsNullOrWhiteSpace(newFileName))
            {
                if (!new FileInfo(newFileName).Exists)
                {
                    try
                    {
                        fileInfo.CopyTo(newFileName);
                    }
                    catch (Exception ex)
                    {
                        //Dialog.ShowMessage($"Ошибка создания версии файла: {newFileName}");
                    }
                }
            }
        }
Ejemplo n.º 21
0
        private string GetFileNameVersion(FileInfo fileInfo, FileSubscriber file, int?version = null)
        {
            if (version == null)
            {
                version = GetNewVersion(fileInfo, file, fileInfo.Extension);
            }

            if (version == 0)
            {
                return(null);
            }

            string fileName =
                $"{_fileNameWithoutExtension} " +
                $"{_prefixNameVersion}" +
                $"{version}}}" +
                $"{fileInfo.Extension}";

            string fileNameVersion = Path.Combine(file.DirectoryVersion, fileName);

            return(fileNameVersion);
        }
Ejemplo n.º 22
0
        internal void Subscribe(FileSubscriber subscriber, bool notified = true)
        {
            if (subscriber.Checked &&
                !String.IsNullOrWhiteSpace(subscriber.Path))
            {
                if (_listWather.FirstOrDefault(f => f.Key == subscriber).Key != null)
                {
                    return;
                }

                FileInfo fileInfo = new FileInfo(subscriber.Path);

                FileSystemWatcher watcher = new FileSystemWatcher(fileInfo.DirectoryName, fileInfo.Name)
                {
                    NotifyFilter = NotifyFilters.LastWrite
                };

                _listSubscriber.Add(fileInfo, subscriber);

                watcher.Changed            += Subscribe_Changed;
                watcher.EnableRaisingEvents = true;

                _listWather.Add(subscriber, watcher);

                using (Versions versions = new Versions()
                {
                    SubscriberInfo = fileInfo,
                    Subscriber = subscriber
                })
                {
                    versions.CreateDirectoryVersion();
                }
                _callUpdate.NeedNotified = notified;
                _callUpdate.Call(subscriber);
            }
        }
        private void UpdateVersion(FileSubscriber subscriber, bool NeedNotified)
        {
            subscriber.SetCurrentVersion();
            subscriber.SetCurrentSize();

            if (!string.IsNullOrWhiteSpace(_callUpdate.CommentNewVersion))
            {
                new Versions()
                {
                    Subscriber = subscriber
                }
                .SetCommentFile(
                    subscriber.Version,
                    _callUpdate.CommentNewVersion);
                _callUpdate.CommentNewVersion = string.Empty;
            }

            if (NeedNotified)
            {
                if (subscriber.Version != subscriber.PreviousVersion)
                {
                    subscriber.CountVersionWithoutNotify++;
                }

                int userSettingsNotifyCount = UserSettings.GetUserSettings("NotifyVersionCreation");
                if (userSettingsNotifyCount > 0 &&
                    subscriber.CountVersionWithoutNotify >= userSettingsNotifyCount)
                {
                    _notifyIcon.Subscriber = subscriber;
                    _notifyIcon.CreateVersion();
                    subscriber.CountVersionWithoutNotify = 0;
                }
            }

            LoadListVersion();
        }
Ejemplo n.º 24
0
 private void UnsubscribeFile(FileSubscriber file)
 {
     file.Checked = false;
     UnsubscribeChangeFile(file);
 }
Ejemplo n.º 25
0
        private FileInfo GetFileLastVersion(FileSubscriber file, string fileExtension, bool controlCurrentHash = false)
        {
            string currentHash = GetMD5(file.Path);

            if (String.IsNullOrWhiteSpace(currentHash))
            {
                UnsubscribeFile(file);
                return(null);
            }

            FileInfo fileInfoPath = new FileInfo(file.Path);

            FileInfo[] filesVersions = null;
            try
            {
                filesVersions = new DirectoryInfo(file.DirectoryVersion).GetFiles($"{_fileNameWithVersion}*{fileExtension}");
            }
            catch (DirectoryNotFoundException)
            {
                CreateNewVersionFile(
                    fileInfoPath,
                    file,
                    GetFileNameVersion(
                        fileInfoPath,
                        file,
                        1));
                return(null);
            }
            catch (Exception)
            {
                UnsubscribeFile(file);
                return(null);
            }

            if (filesVersions == null)
            {
                return(null);
            }

            FileInfo fileInfoMaxEdited = null;

            if (filesVersions.Count() > 0)
            {
                DateTime dateTimeMaxEdited = DateTime.MinValue;
                foreach (FileInfo versionFile in filesVersions)
                {
                    string md5VersionFile = GetMD5(versionFile.FullName);
                    if (!String.IsNullOrWhiteSpace(md5VersionFile))
                    {
                        if (currentHash == md5VersionFile && controlCurrentHash)
                        {
                            return(null);
                        }

                        if (dateTimeMaxEdited <= versionFile.LastWriteTime)
                        {
                            fileInfoMaxEdited = versionFile;
                            dateTimeMaxEdited = versionFile.LastWriteTime;
                        }
                        ;
                    }
                }
                ;
            }
            else
            {
                CreateNewVersionFile(
                    fileInfoPath,
                    file,
                    GetFileNameVersion(
                        fileInfoPath,
                        file,
                        1));
            }

            return(fileInfoMaxEdited);
        }
Ejemplo n.º 26
0
 internal void SubscribeChangeFile(FileSubscriber file)
 {
     Subscribe(file);
 }
 private void DgList_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
 {
     FileSubscriber file = (FileSubscriber)dgList.CurrentItem;
 }