// Main: /// <summary>Entry point for application.</summary> /// <returns>An <c>int</c> value corresponding to a <c>Program.ExitCode</c> enum value, indicating the application's success or failure.</returns> /// <param name="args">An array of all the arguments specified on the command line.</param> static int Main(string[] args) { // Set up objects containing the configuration info for this run and the UI object for output. Configuration config; ConsoleOutput userInterface = new ConsoleOutput(ConsoleOutput.Verbosity.NormalEvents); // Fill in the configuration object for this run, based on reading the command-line arguments. try { config = OptionsProcessor.getRuntimeConfiguration(args); } catch (ErrorManagement.OptionsException e) { // There was an invalid option specified or an error was encountered reading from the specified sources file. Tell the user and exit with an error code. userInterface.report("", ConsoleOutput.Verbosity.ErrorsAndWarnings); userInterface.report($"Error: {e.Message}", ConsoleOutput.Verbosity.ErrorsAndWarnings); printUsage(userInterface); return((int)ExitCode.Error_Usage); } catch (OutOfMemoryException e) { // There was an invalid option specified or an error was encountered reading from the specified sources file. Tell the user and exit with an error code. userInterface.report("", ConsoleOutput.Verbosity.ErrorsAndWarnings); userInterface.report($"Out of memory error: {e.Message}", ConsoleOutput.Verbosity.ErrorsAndWarnings); return((int)ExitCode.Error_General); } // CHANGE CODE HERE: ADD ERROR-HANDLING for backup process itself // Create a BackupProcessor object, set it to use the current run-time configuration and UI object, // and run the backup process. BackupProcessor backupProcessor = new BackupProcessor(config, userInterface); backupProcessor.doBackup(); // Job is complete; exist the application returning a success code. return((int)ExitCode.Success); } // end Main()
private void LoadAppsIntoViewThread(object p) { var param = p as LoadAppsIntoViewParam; var parser = param.parser; //DebugShow(0); if (IsBackupMode) { BackupProcessor.GetApplicationInfo(param.srcPath); } //DebugShow(1); parser.LoadFromFile(param.srcPath + "\\ApplicationInfo.txt", IsBackupMode ? null : param.ViewModel); //DebugShow(2); parser.Applications.Sort(new ApplicationInfoSorter()); //DebugShow(3); this.Dispatcher.BeginInvoke(new Action(delegate() { if (param.action != null) { param.action(parser.Applications); } listApplications.ItemsSource = parser.Applications; IsWorking = false; })); //DebugShow(4); }
/// <summary> /// Process Request. /// </summary> /// <param name="request">The request to process.</param> public override void ProcessRequest(Request request) { if (request.Cost < 1000.00d) { request.IsApproved = true; Console.WriteLine($"The request, {request.Title} ID:{request.Id}, was processed by the {nameof(LowLevelProcessor)}.{Environment.NewLine}" + $"Approved: {request.IsApproved}{Environment.NewLine}"); } else if (BackupProcessor != null) { Console.WriteLine($"The request, {request.Title} ID:{request.Id}, is too costly to be approved by the {nameof(LowLevelProcessor)} and was passed to the backup processor."); BackupProcessor.ProcessRequest(request); } }
static void Main(string[] args) { if (args.Length == 2) { var path = args[0]; var username = args[1]; System.Console.WriteLine("Starting Backup Process for {0} to {1}...", username, path); var processor = new BackupProcessor(username); processor.SaveZipToDisk(-1, path); System.Console.WriteLine("Finished With Backup."); } else { System.Console.WriteLine("Usage: InstaBackup.Console.exe <full-zip-path> <instagram-username>"); System.Console.WriteLine("Example: InstaBackup.Console.exe C:\\Temp\\nicholaslamb.zip nicholaslamb"); } }
/// <summary> /// Process Request. /// </summary> /// <param name="request">The request to process.</param> public override void ProcessRequest(Request request) { if (request.Cost < 25000000.00d) { request.IsApproved = true; Console.WriteLine($"The request, {request.Title} ID:{request.Id}, was processed by the {nameof(HighLevelProcessor)}.{Environment.NewLine}" + $"Approved: {request.IsApproved}{Environment.NewLine}"); } else if (BackupProcessor != null) { Console.WriteLine($"The request, {request.Title} ID:{request.Id}, is too costly to be approved by the {nameof(HighLevelProcessor)} and was passed to the backup processor."); BackupProcessor.ProcessRequest(request); } else { Console.WriteLine($"The request, {request.Title} ID:{request.Id}, seems to have a very high cost and cannot be approved by a single processor.{Environment.NewLine}" + $"All right stop, collaborate and listen."); } }
private void RestoreThread(object p) { var vm = p as MainViewModel; this.Dispatcher.BeginInvoke(new Action(delegate() { vm.IsBusy = true; })); var proc = new BackupProcessor(); var param = new BackupProcessor.BackupActionParameter(); param.OutputFilePath = vm.OutputFilePath; param.DeviceTempFolderPath = BackupProcessor.DeviceTempFolderPath; param.TempFolderPath = BackupProcessor.TempFolderPath; param.SourceFilePath = vm.CurrentFilePath; param.SourceFolderPath = BackupProcessor.SourceFolderPath; param.RegistryStore = new RegistryStore(); proc.ActionSettings = vm.ActionSettings; Action<BackupProcessor.CancellationStateCheck> cancellationCheck = new Action<BackupProcessor.CancellationStateCheck>(delegate(BackupProcessor.CancellationStateCheck check) { lock (CancellationPendingLock) { check.isCancelled = CancellationPending; } }); param.CheckCancellationState = cancellationCheck; int count = 0, currentAction = 0; for (int i = 0; i < BackupProcessor.RestoreActions.Count; ++i) { var action = BackupProcessor.RestoreActions[i]; if (String.IsNullOrEmpty(action.SettingName) || (proc.ActionSettings.ContainsKey(action.SettingName) && proc.ActionSettings[action.SettingName].IsEnabled)) { count++; } } bool cancelled = false; string errorText = null; for (int i = 0; i < BackupProcessor.RestoreActions.Count; ++i) { lock (CancellationPendingLock) { if (CancellationPending) { cancelled = true; break; } } var action = BackupProcessor.RestoreActions[i]; if (String.IsNullOrEmpty(action.SettingName) || (proc.ActionSettings.ContainsKey(action.SettingName) && proc.ActionSettings[action.SettingName].IsEnabled)) { param.IsCancelledByAction = false; param.Error = null; if (proc.ActionSettings.ContainsKey(action.SettingName)) param.Setting = proc.ActionSettings[action.SettingName]; else param.Setting = null; this.Dispatcher.BeginInvoke(new Action(delegate() { vm.ProgressText = action.Name; double val = 100 / count * currentAction; val = Math.Floor(val); vm.ProgressValue = (int)val; })); try { action.Execute(param); if (param.IsCancelledByAction) { cancelled = true; break; } if (param.Error != null) { errorText = param.Error; break; } } catch (OpenNETCF.Desktop.Communication.RAPIException ex) { errorText = ex.ToString(); break; } currentAction++; } } this.Dispatcher.BeginInvoke(new Action(delegate() { vm.ProgressText = LocalizedResources.Finished; vm.ProgressValue = 100; if (errorText != null) { var pg = new pageError(ViewModel); pg.SetErrorDescText(errorText); ViewModel.Navigate(pg); } else { if (!cancelled) { var pg = new pageSuccess(ViewModel); pg.IsBackupMode = false; ViewModel.Navigate(pg); } else { var pg = new pageCancelled(ViewModel); pg.IsBackupMode = false; ViewModel.Navigate(pg); } } vm.IsBusy = false; })); }
void Refresh() { ViewModel.Refresh(); txtComment.Text = (ViewModel.TempFile != null) ? BackupProcessor.FromBase64(ViewModel.TempFile.File.Comment) : ""; }
public void Start() { BackupProcessor.Start(this); }
public void TestSaveZip() { var processor = new BackupProcessor("nicholaslamb"); processor.SaveZipToDisk(-1, @"C:\temp\test.zip"); }
private void RestoreThread(object p) { var vm = p as MainViewModel; this.Dispatcher.BeginInvoke(new Action(delegate() { vm.IsBusy = true; })); var proc = new BackupProcessor(); var param = new BackupProcessor.BackupActionParameter(); param.OutputFilePath = vm.OutputFilePath; param.DeviceTempFolderPath = BackupProcessor.DeviceTempFolderPath; param.TempFolderPath = BackupProcessor.TempFolderPath; param.SourceFilePath = vm.CurrentFilePath; param.SourceFolderPath = BackupProcessor.SourceFolderPath; param.RegistryStore = new RegistryStore(); proc.ActionSettings = vm.ActionSettings; Action <BackupProcessor.CancellationStateCheck> cancellationCheck = new Action <BackupProcessor.CancellationStateCheck>(delegate(BackupProcessor.CancellationStateCheck check) { lock (CancellationPendingLock) { check.isCancelled = CancellationPending; } }); param.CheckCancellationState = cancellationCheck; int count = 0, currentAction = 0; for (int i = 0; i < BackupProcessor.RestoreActions.Count; ++i) { var action = BackupProcessor.RestoreActions[i]; if (String.IsNullOrEmpty(action.SettingName) || (proc.ActionSettings.ContainsKey(action.SettingName) && proc.ActionSettings[action.SettingName].IsEnabled)) { count++; } } bool cancelled = false; string errorText = null; for (int i = 0; i < BackupProcessor.RestoreActions.Count; ++i) { lock (CancellationPendingLock) { if (CancellationPending) { cancelled = true; break; } } var action = BackupProcessor.RestoreActions[i]; if (String.IsNullOrEmpty(action.SettingName) || (proc.ActionSettings.ContainsKey(action.SettingName) && proc.ActionSettings[action.SettingName].IsEnabled)) { param.IsCancelledByAction = false; param.Error = null; if (proc.ActionSettings.ContainsKey(action.SettingName)) { param.Setting = proc.ActionSettings[action.SettingName]; } else { param.Setting = null; } this.Dispatcher.BeginInvoke(new Action(delegate() { vm.ProgressText = action.Name; double val = 100 / count * currentAction; val = Math.Floor(val); vm.ProgressValue = (int)val; })); try { action.Execute(param); if (param.IsCancelledByAction) { cancelled = true; break; } if (param.Error != null) { errorText = param.Error; break; } } catch (OpenNETCF.Desktop.Communication.RAPIException ex) { errorText = ex.ToString(); break; } currentAction++; } } this.Dispatcher.BeginInvoke(new Action(delegate() { vm.ProgressText = LocalizedResources.Finished; vm.ProgressValue = 100; if (errorText != null) { var pg = new pageError(ViewModel); pg.SetErrorDescText(errorText); ViewModel.Navigate(pg); } else { if (!cancelled) { var pg = new pageSuccess(ViewModel); pg.IsBackupMode = false; ViewModel.Navigate(pg); } else { var pg = new pageCancelled(ViewModel); pg.IsBackupMode = false; ViewModel.Navigate(pg); } } vm.IsBusy = false; })); }
public IBackup CreateBackup() { log.Info("Preparing Backup"); var backup = new BackupProcessor(RootPath); backup.ExamineComponents(); return backup; }
public bool Write(string fileName, string comment = "") { if (_file != null) { _file.Dispose(); } _file = new ZipFile(); if (_file != null) { _file.UseUnicodeAsNecessary = true; _file.UseZip64WhenSaving = Zip64Option.Always; _file.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed; _file.Comment = BackupProcessor.ToBase64(comment); FixInternalNames(); var openedStreams = new List <Stream>(); string indexContent = ""; // adding files to output zip. foreach (var item in _list) { var file = item.Value; if (!file.IsFolder) { if (file.PcSidePath == null) { throw new Exception("PcSidePath isn't set for \r\nInternalPath: " + file.InternalPath + "\r\nDeviceSidePath: " + file.DeviceSidePath); } var stream = new FileStream(file.PcSidePath, FileMode.Open, FileAccess.Read); if (stream == null) { continue; } openedStreams.Add(stream); _file.AddEntry(file.InternalPath, "", stream); } indexContent += (file.IsFolder ? "dir" : file.InternalPath) + "=" + file.DeviceSidePath + "\r\n"; } // adding index file byte[] b = Encoding.Unicode.GetBytes(indexContent); var indexStream = new MemoryStream(); if (indexStream == null) { throw new Exception("Couldn't open stream for index.wpb file"); } indexStream.Write(b, 0, b.Length); indexStream.Seek(0, SeekOrigin.Begin); openedStreams.Add(indexStream); _file.AddEntry("index.wpb", "", indexStream); _file.Save(fileName); foreach (var stream in openedStreams) { stream.Close(); } return(true); } return(false); }