Esempio n. 1
0
        internal void RestoreVersion(ListVersion version)
        {
            if (Subscriber == null)
            {
                return;
            }

            FileInfo fileInfoVersion = new FileInfo(version.Path);

            if (!DirFile.FileExists(fileInfoVersion))
            {
                return;
            }

            FileInfo tempFileVersion = new FileInfo(DirFile.GetTempFile());

            fileInfoVersion.CopyTo(tempFileVersion.FullName);
            tempFileVersion.LastWriteTime = DateTime.Now;

            FileInfo fileInfoRestore = new FileInfo(Subscriber.Path);

            tempFileVersion.CopyTo(fileInfoRestore.FullName, true);

            DirFile.DeleteFile(tempFileVersion);
        }
Esempio n. 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    SubscriberInfo = null;
                    Subscriber     = null;
                }

                foreach (FileInfo item in _tempFiles)
                {
                    try
                    {
                        DirFile.DeleteFile(item);
                    }
                    catch (Exception ex)
                    {
                        Errors.Save($"Не удалось удалить временный файл: {item.FullName}");
                        Errors.Save(ex);
                    }
                }
                _tempFiles.Clear();
                _tempFiles = null;

                disposedValue = true;
            }
        }
        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);
            }
        }