Ejemplo n.º 1
0
 private bool IsSingleConversionEnabled()
 {
     return((_isProcessing == false) &&
            !TexturePreview.IsEmpty &&
            !SourceDirectory.IsNullOrEmpty() &&
            !DestinationDirectory.IsNullOrEmpty());
 }
Ejemplo n.º 2
0
 private void UpdateDestinationDriveLetter(string driveName)
 {
     if (!string.IsNullOrWhiteSpace(driveName))
     {
         DestinationDirectory = driveName.Substring(0, 1) + DestinationDirectory.Substring(DestinationDirectory.IndexOf(':'));
     }
 }
Ejemplo n.º 3
0
        // --- private functions

        private static void MoveDestinationFilesToHistoryDirectory(
            BackupDbContext dbContext,
            DestinationDirectory dd,
            string dateFolder,
            ISet <long> usedSourceFileIds = null)
        {
            var movedFiles = new List <DestinationFile>();

            foreach (var df in dd.DestinationFiles)
            {
                if (usedSourceFileIds != null && usedSourceFileIds.Contains(df.SourceFileId))
                {
                    continue;
                }
                MoveToHistoryFile(dd.PathName, dateFolder, df.PathName);
                movedFiles.Add(df);
            }
            if (movedFiles.Any())
            {
                foreach (var df in movedFiles)
                {
                    dbContext.DestinationFiles.Remove(df);
                    dd.DestinationFiles.Remove(df);
                }
                DeleteEmptyDirectories(dd.PathName);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Runs the backup
        /// </summary>
        public void RunBackup()
        {
            _log.Info("Beginning backup");
            ClearProgressCounts();
            _cancelToken = new CancellationTokenSource();
            LastRunTime  = DateTime.Now;

            Task.Factory.StartNew(() =>
            {
                if (CheckDriveExists(DestinationDirectory.Substring(0, 1)))
                {
                    BuildActionQueue();
                    int nonFileActions = ActionQueue
                                         .Where(aq => aq.GetType() == typeof(CreateFolderAction))
                                         .Count();
                    TotalFileCount = SkipFileActionQueue.Count + ActionQueue.Count + DeleteActionStack.Count - nonFileActions;
                }
                else
                {
                    _cancelToken.Cancel();
                }
            })
            .ContinueWith((t) =>
            {
                ApplyActions();
            })
            .ContinueWith((t) =>
            {
                ProcessingStatus = _cancelToken.IsCancellationRequested ? BackupProcessingStatus.Cancelled :
                                   BackupProcessingStatus.Finished;
            });
        }
Ejemplo n.º 5
0
 private bool IsMultiConversionEnabled()
 {
     return((_isProcessing == false) &&
            !SourceDirectory.IsNullOrEmpty() &&
            !DestinationDirectory.IsNullOrEmpty() &&
            Textures.Any(node => node.IsPicked));
 }
Ejemplo n.º 6
0
 internal sealed record OptionArgs(
     SourcePath SourcePath,
     DestinationDirectory DestinationDirectory,
     DryRun DryRun,
     KeepGoing KeepGoing,
     SkipDateSubdirectory SkipDateSubdirectory,
     Overwrite Overwrite);
Ejemplo n.º 7
0
        public BackupSetViewModel(IBackupSet backupSet, IUIVisualizerService uiVisualizerService)
        {
            Argument.IsNotNull(() => backupSet);
            Argument.IsNotNull(() => uiVisualizerService);
            BackupSet            = backupSet;
            _uiVisualizerService = uiVisualizerService;
            _timer = new Timer(new TimerCallback((o) =>
            {
                RefreshLog();
            }), null, Timeout.Infinite, Timeout.Infinite);

            UpdateScheduleStatus();

            BrowseSourceCommand       = new Command(() => SourceDirectory = SetDirectory(SourceDirectory, "Select Source Directory"));
            BrowseDestinationCommand  = new Command(() => DestinationDirectory = SetDirectory(DestinationDirectory, "Select Destination Directory"));
            ExcludeDirectoriesCommand = new Command(OnExcludeDirectoriesExecute, () => !String.IsNullOrEmpty(SourceDirectory));
            RunBackupCommand          = new Command(() =>
            {
                if (BackupSet.DestinationType == BackupDestinationType.ExternalDrive)
                {
                    var typeFactory             = this.GetTypeFactory();
                    var driveSelectionViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion <DriveSelectionViewModel>();
                    driveSelectionViewModel.SetDefaultDrive(DestinationDirectory.Substring(0, 1));
                    if (_uiVisualizerService.ShowDialog(driveSelectionViewModel) == true)
                    {
                        UpdateDestinationDriveLetter(driveSelectionViewModel.SelectedDrive.Name);
                    }
                    else
                    {
                        return;
                    }
                }
                _timer.Change(1000, 1000);
                BackupSet.RunBackup();
            }
                                                    , () => CanRunBackup);

            CancelBackupCommand = new Command(() =>
            {
                _timer.Change(Timeout.Infinite, Timeout.Infinite);
                BackupSet.CancelBackup();
            }
                                              , () => CanCancelBackup);

            EditBackupSetCommand = new RelayCommand((o) =>
            {
                StateService.RequestBackupSetEdit((string)o);
            }
                                                    , (o) => ProcessingStatus == BackupProcessingStatus.NotStarted ||
                                                    ProcessingStatus == BackupProcessingStatus.Cancelled ||
                                                    ProcessingStatus == BackupProcessingStatus.Finished);

            FinishEditingBackupSetCommand = new RelayCommand((o) =>
            {
                StateService.RequestBackupSetEdit((string)o);
            });

            BackupSet.PropertyChanged += BackupSetPropertyChanged;
        }
Ejemplo n.º 8
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = (BottleName != null ? BottleName.GetHashCode() : 0);
         result = (result * 397) ^ (BottleDirectory != null ? BottleDirectory.GetHashCode() : 0);
         result = (result * 397) ^ (DestinationDirectory != null ? DestinationDirectory.GetHashCode() : 0);
         return(result);
     }
 }
Ejemplo n.º 9
0
        public void LoadDestinationByNumbers()
        {
            if (TransferableNumbersList != null)
            {
                var dds = DestinationDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly);

                var innerGroupJoinQuery =
                    from dd in dds
                    join tnl in TransferableNumbersList on dd.Name equals tnl
                    select dd;
                var r = innerGroupJoinQuery.ToList();

                if (DestinationFilesList == null)
                {
                    DestinationFilesList = new List <FileInfoW>();
                }
                foreach (var ddir in innerGroupJoinQuery)
                {
                    DestinationFilesList.AddRange(lsToFileInfoW(ddir, "^(\\d{5}ГУ\\d{6})(?:_(.*))*_(\\d{8})(?:_(\\d{1,2}))*$"));
                }
                var yyy1 = DestinationFilesList.Where(sel => sel.Name.Number == null).ToList();
                CalcNumber(yyy1);
                foreach (var y in yyy1)
                {
                    y.NeedRename   = true;
                    y.Name.Date    = y.fileInfo.LastWriteTime.ToString("yyyyMMdd");
                    y.Name.Content = "";
                }
                var dgg =
                    from dfl in DestinationFilesList
                    where
                    dfl.NeedRename == false
                    group dfl by new { dfl.Name.Number, dfl.Name.Content, dfl.Name.Date } into dfl1
                where dfl1.Count() > 1
                select new { dfl1.Key.Number, dfl1.Key.Content, dfl1.Key.Date };
                var ttt = dgg.ToList();

                var dgg1 =
                    from dfl in DestinationFilesList
                    where
                    dfl.NeedRename == true
                    group dfl by new { Number = dfl.Name.Number, dfl.Name.Content, dfl.Name.Date } into dfl2
                where dfl2.Count() > 1
                select new { dfl2.Key.Number, dfl2.Key.Content, dfl2.Key.Date };;
                var ttt1 = dgg1.ToList();
                var dgg2 =
                    from ttt1i in ttt1.AsEnumerable()
                    join ttti in ttt.AsEnumerable() on ttt1i.Number equals ttti.Number
                    select new { ttti, ttt1i };
                var ttt2 = dgg2.ToList();
            }
        }
Ejemplo n.º 10
0
        private async Task PickDestinationDirectoryAsync()
        {
            var path = _directoryPicker.Pick(DestinationDirectory.IsNotNullOrEmpty()
                                                 ? DestinationDirectory
                                                 : null);

            if (path.IsNullOrEmpty())
            {
                return;
            }

            DestinationDirectory = path;
            await OnChangedAsync();
        }
Ejemplo n.º 11
0
 private static void BackupToDestinationDirectory(
     SourceFile sf, string baseDir, DestinationDirectory dd, string dateFolder, CancellationToken cancellationToken)
 {
     try
     {
         var lastWrittenTimeUtc = File.GetLastWriteTimeUtc(sf.PathName);
         if (sf.ContentHash == null || lastWrittenTimeUtc != sf.LastWrittenTimeUtc)
         {
             sf.ContentHash        = HashCalculator.GetContentHash(sf.PathName);
             sf.LastWrittenTimeUtc = lastWrittenTimeUtc;
         }
         var df        = dd.DestinationFiles.SingleOrDefault(f => f.SourceFileId == sf.SourceFileId);
         var createnew = df == null;
         if (createnew || df.ContentHash != sf.ContentHash || !File.Exists(df.PathName))
         {
             string destPathName = CopyToDestinationFile(
                 dd.PathName, baseDir, dateFolder, sf.PathName, cancellationToken);
             if (!cancellationToken.IsCancellationRequested)
             {
                 if (createnew)
                 {
                     df = new DestinationFile
                     {
                         SourceFileId = sf.SourceFileId,
                     };
                     dd.DestinationFiles.Add(df);
                 }
                 df.PathName    = destPathName;
                 df.ContentHash = sf.ContentHash;
                 dd.Copied     += 1;
             }
         }
     }
     catch (Exception ex)
     {
         dd.CopyFailures.Add(new CopyFailure
         {
             SourceFileId = sf.SourceFileId,
             ErrorMessage = ex.Message
         });
     }
 }
Ejemplo n.º 12
0
        private void BuildActionQueue()
        {
            _log.Info("Building Action Queue");
            ProcessingStatus = BackupProcessingStatus.BuildingActionQueue;
            //Clear the action Queues
            ActionQueue.Clear();
            SkipFileActionQueue.Clear();
            DeleteActionStack.Clear();

            if (_cancelToken.IsCancellationRequested)
            {
                _log.Info("Building Action Queue Cancelled");
                ProcessingStatus = BackupProcessingStatus.Cancelled;
                return;
            }

            if (CheckDriveExists(SourceDirectory.Substring(0, 1)) &&
                CheckSourceRootExists() &&
                CheckDriveExists(DestinationDirectory.Substring(0, 1)))
            {
                if (BackupMode == BackupSetMode.Backup && RemoveDeleted)
                {
                    List <DirectoryInfo> destDirs = IOHelper.GetDirectoriesPostOrder(DestinationDirectory);
                    if (destDirs != null)
                    {
                        foreach (DirectoryInfo di in destDirs)
                        {
                            if (_cancelToken.IsCancellationRequested)
                            {
                                ProcessingStatus = BackupProcessingStatus.Cancelled;
                                return;
                            }
                            ProcessDestinationDirectoryForPossibleDelete(di);
                        }
                    }
                }

                var dirs = IOHelper.GetDirectories(SourceDirectory);
                if (dirs != null)
                {
                    foreach (DirectoryInfo di in dirs)
                    {
                        //Check if the directory should be excluded
                        if (ExcludedDirectories == null || !ExcludedDirectories.Contains(di.FullName))
                        {
                            if (_cancelToken.IsCancellationRequested)
                            {
                                ProcessingStatus = BackupProcessingStatus.Cancelled;
                                return;
                            }
                            ProcessDirectoryForActions(di);
                        }
                        else
                        {
                            IOHelper.GetFiles(di.FullName)
                            .ForEach(fi => SkipFileActionQueue.Enqueue(new SkipFileAction(fi.FullName)));
                        }
                    }
                }
            }
            _log.Info("Finished Building Action Queue");
            ProcessingStatus = BackupProcessingStatus.ActionQueueBuilt;
        }
        public override void RunFinishedExtention()
        {
            if (DestinationDirectory.EndsWith(SafeProjectName + Path.DirectorySeparatorChar + SafeProjectName))
            {
                //The projects were created under a seperate folder -- lets fix it

                //todo this appears to do something incorrect if create directory for solution was not selected

                //first move each projects up a directory
                var projectsObjects = new List <Project>();
                foreach (Project childProject in DTE.Solution.Projects)
                {
                    var fileName = childProject.FileName;
                    if (!string.IsNullOrEmpty(fileName)) //Solution Folder
                    {
                        var projectBadPath  = fileName;
                        var projectGoodPath = projectBadPath.Replace(
                            SafeProjectName + Path.DirectorySeparatorChar + SafeProjectName + Path.DirectorySeparatorChar,
                            SafeProjectName + Path.DirectorySeparatorChar);

                        DTE.Solution.Remove(childProject);

                        Directory.Move(Path.GetDirectoryName(projectBadPath), Path.GetDirectoryName(projectGoodPath));

                        DTE.Solution.AddFromFile(projectGoodPath);
                    }
                }
                //now add the references to the plugin project
                //because they got removed when we move the project folders
                Project pluginProject = null;
                foreach (Project childProject in DTE.Solution.Projects)
                {
                    var fileName = childProject.FileName;
                    if (!string.IsNullOrEmpty(fileName)) //Solution Folder
                    {
                        if (fileName.EndsWith(".Plugins.csproj"))
                        {
                            pluginProject = childProject;
                        }
                    }
                }
                foreach (Project childProject in DTE.Solution.Projects)
                {
                    var fileName = childProject.FileName;
                    if (!string.IsNullOrEmpty(fileName)) //Solution Folder
                    {
                        if (fileName.EndsWith(".Test.csproj") ||
                            fileName.EndsWith(".Console.csproj"))
                        {
                            VSProject vsProj = (VSProject)childProject.Object;
                            vsProj.References.AddProject(pluginProject);
                        }
                    }
                }
            }

            if (DestinationDirectory.EndsWith(SafeProjectName + Path.DirectorySeparatorChar + SafeProjectName))
            {
                DestinationDirectory = DestinationDirectory.Substring(0, DestinationDirectory.Length - (Path.DirectorySeparatorChar + SafeProjectName).Length);
            }

            var consoleFileName = DestinationDirectory + Path.DirectorySeparatorChar + SafeProjectName + ".Console" + Path.DirectorySeparatorChar + "Encrypt XRM Connection.bat";

            if (File.Exists(consoleFileName))
            {
                var read = File.ReadAllText(consoleFileName);
                read = read.Replace("$ext_safeprojectname$", SafeProjectName);
                File.WriteAllText(consoleFileName, read);
            }

            var visualStudioService = new VisualStudioService(DTE, useSolutionDirectory: DestinationDirectory);

            //add xrm connection and package settings to solution items
            visualStudioService.AddSolutionItem("xrmpackage.xrmsettings", XrmPackageSettings);
            if (XrmPackageSettings.Connections.Any())
            {
                visualStudioService.AddSolutionItem("solution.xrmconnection", XrmPackageSettings.Connections.First());
            }
            visualStudioService.CloseAllDocuments();

            RemoveEmptyFolders(DestinationDirectory);
        }
Ejemplo n.º 14
0
        public override void RunFinishedExtention()
        {
            if (DestinationDirectory.EndsWith(SafeProjectName + Path.DirectorySeparatorChar + SafeProjectName))
            {
                //The projects were created under a seperate folder -- lets fix it

                //first move each projects up a directory
                var projectsObjects = new List <Project>();
                foreach (Project childProject in DTE.Solution.Projects)
                {
                    var fileName = childProject.FileName;
                    if (!string.IsNullOrEmpty(fileName)) //Solution Folder
                    {
                        var projectBadPath  = fileName;
                        var projectGoodPath = projectBadPath.Replace(
                            SafeProjectName + Path.DirectorySeparatorChar + SafeProjectName + Path.DirectorySeparatorChar,
                            SafeProjectName + Path.DirectorySeparatorChar);

                        DTE.Solution.Remove(childProject);

                        Directory.Move(Path.GetDirectoryName(projectBadPath), Path.GetDirectoryName(projectGoodPath));

                        DTE.Solution.AddFromFile(projectGoodPath);
                    }
                }
                //now add the references to the plugin project
                //because they got removed when we move the project folders
                Project pluginProject = null;
                foreach (Project childProject in DTE.Solution.Projects)
                {
                    var fileName = childProject.FileName;
                    if (!string.IsNullOrEmpty(fileName)) //Solution Folder
                    {
                        if (fileName.EndsWith(".Plugins.csproj"))
                        {
                            pluginProject = childProject;
                        }
                    }
                }
                foreach (Project childProject in DTE.Solution.Projects)
                {
                    var fileName = childProject.FileName;
                    if (!string.IsNullOrEmpty(fileName)) //Solution Folder
                    {
                        if (fileName.EndsWith(".Test.csproj") ||
                            fileName.EndsWith(".Console.csproj"))
                        {
                            VSProject vsProj = (VSProject)childProject.Object;
                            vsProj.References.AddProject(pluginProject);
                        }
                    }
                }
            }

            if (DestinationDirectory.EndsWith(SafeProjectName + Path.DirectorySeparatorChar + SafeProjectName))
            {
                DestinationDirectory = DestinationDirectory.Substring(0, DestinationDirectory.Length - (Path.DirectorySeparatorChar + SafeProjectName).Length);
            }

            //okay so lets update the encrypt connection bat and the xrmsetting.txt files in the console project
            var consoleProjectPath = DestinationDirectory + Path.DirectorySeparatorChar + SafeProjectName + ".Console";
            var encryptBatFileName = consoleProjectPath + Path.DirectorySeparatorChar + "Encrypt XRM Connection.bat";

            if (File.Exists(encryptBatFileName))
            {
                var read = File.ReadAllText(encryptBatFileName);
                read = read.Replace("$ext_safeprojectname$", SafeProjectName);
                File.WriteAllText(encryptBatFileName, read);
            }
            var consoleConnectionFileName = consoleProjectPath + Path.DirectorySeparatorChar + "XrmSetting.txt";

            if (File.Exists(consoleConnectionFileName))
            {
                if (XrmPackageSettings != null && XrmPackageSettings.Connections != null && XrmPackageSettings.Connections.Any())
                {
                    try
                    {
                        var connection = XrmPackageSettings.Connections.First();
                        var serialise  = ObjectToJsonString(connection);
                        File.WriteAllText(consoleConnectionFileName, serialise);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error setting console application connection: " + ex.DisplayString());
                    }
                }
            }

            var visualStudioService = new VisualStudioService(DTE, useSolutionDirectory: DestinationDirectory);

            //add xrm connection and package settings to solution items
            visualStudioService.AddSolutionItem("xrmpackage.xrmsettings", XrmPackageSettings);
            if (XrmPackageSettings.Connections.Any())
            {
                visualStudioService.AddSolutionItem("solution.xrmconnection", XrmPackageSettings.Connections.First());
            }
            visualStudioService.CloseAllDocuments();

            RemoveEmptyFolders(DestinationDirectory);
        }
Ejemplo n.º 15
0
        public TextureManagementWindowViewModel(
            DomainActionBuilder actionBuilder,
            IDirectoryPicker directoryPicker,
            IEventPublisher eventPublisher,
            IFilePicker filePicker,
            IFindTextureManagementSettingsQuery findTextureManagementSettingsQuery,
            IImageProvider emptyImageProvider,
            ITaskRunner dispatcher)
        {
            _actionBuilder   = actionBuilder;
            _directoryPicker = directoryPicker;
            _eventPublisher  = eventPublisher;
            _filePicker      = filePicker;
            _findTextureManagementSettingsQuery = findTextureManagementSettingsQuery;
            _eventPublisher.Register(this);

            StatusViewModel = new StatusViewModel(dispatcher);
            TexturePreview  = new TexturePreviewViewModel(_actionBuilder, _eventPublisher, this, emptyImageProvider);

            AbortCommand         = new ActionCommand(AbortConversion, IsAbortConversionEnabled);
            CheckAllCommand      = new ActionCommand(CheckAll, IsCheckAllEnabled);
            ConvertMultiCommand  = new ActionCommand(() => _queue.QueueTask(ConvertMultiAsync), IsMultiConversionEnabled);
            ConvertSingleCommand = new ActionCommand(() => _queue.QueueTask(ConvertSingleAsync), IsSingleConversionEnabled);
            MoveToDestinationDirectoryCommand = new ActionCommand(MoveToDestinationDirectory, () => !DestinationDirectory.IsNullOrEmpty());
            MoveToSourceDirectoryCommand      = new ActionCommand(MoveToSourceDirectory, () => !SourceDirectory.IsNullOrEmpty());
            MultiChangedCommand             = new ActionCommand(() => _queue.QueueTask(OnChangedAsync), () => true);
            PickDestinationDirectoryCommand = new ActionCommand(() => _queue.QueueTask(PickDestinationDirectoryAsync), () => true);
            PickSourceDirectoryCommand      = new ActionCommand(() => _queue.QueueTask(PickSourceDirectoryAsync), () => true);
            SingleChangedCommand            = new ActionCommand(() => _queue.QueueTask(OnSingleChangedAsync), () => true);
            UncheckAllCommand = new ActionCommand(UncheckAll, IsUncheckAllEnabled);
        }
Ejemplo n.º 16
0
 private void DeleteDestinationDirectory()
 {
     LogManager.Instance().LogInfoMessage("Deleting destination directory [" + DestinationDirectory + "].");
     DestinationDirectory.DeleteDirectory(true);
     LogManager.Instance().LogInfoMessage("Deleted destination directory [" + DestinationDirectory + "].");
 }
Ejemplo n.º 17
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((BottleDirectory != null ? BottleDirectory.GetHashCode() : 0) * 397) ^ (DestinationDirectory != null ? DestinationDirectory.GetHashCode() : 0));
     }
 }