private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { LoadObjectsAsyncParams loadParams = (LoadObjectsAsyncParams)e.Argument; AccessIO.BackupHelper backup = new AccessIO.BackupHelper(loadParams.App.FileName); backup.DoBackUp(); string currentObjectName = null; try { List <IObjecOptions> selectedObjects = loadParams.SelectedObjects; int i = 0; foreach (IObjecOptions currentObject in selectedObjects) { currentObjectName = currentObject.Name; ((BackgroundWorker)sender).ReportProgress(i++ *100 / selectedObjects.Count, currentObject); AccessObject accessObject = AccessObject.CreateInstance(loadParams.App, currentObject.ObjectType, currentObject.ToString()); accessObject.Options = currentObject.Options; accessObject.Load(currentObjectName); } backup.Commit(); e.Result = selectedObjects.Count; } catch (Exception ex) { backup.RollBack(); string msg = String.Format(Properties.Resources.ErrorLoadingObject, currentObjectName, ex.Message); throw new Exception(msg, ex); } }
/// <summary> /// Save the selected objects to the <see cref="AccessApp.WorkingCopyPath"/> path /// </summary> /// <returns>Number of saved objects</returns> /// <remarks>It's recomended to use the async version</remarks> public int SaveSelectedObjects() { List <IObjecOptions> selectedObjects = this.SelectedNodes; foreach (IObjecOptions name in selectedObjects) { AccessObject accessObject = AccessObject.CreateInstance(this.App, name.ObjectType, name.Name); accessObject.Save(); } return(selectedObjects.Count); }
internal override CommandLine Run() { if (App == null && Objects.Count > 0) { InitializeAccessApplication(); } foreach (IObjecOptions currentObject in Objects) { Console.Write(Properties.Resources.Loading, currentObject); AccessObject accessObject = AccessObject.CreateInstance(App, currentObject.ObjectType, currentObject.ToString()); accessObject.Options = currentObject.Options; accessObject.Load(currentObject.Name); Console.WriteLine(Properties.Resources.ColonOk); } return(this); }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { //see http://msdn.microsoft.com/en-us/library/9hk12d4y.aspx for Event-based async pattern //see http://stackoverflow.com/questions/6184/how-do-i-make-event-callbacks-into-my-win-forms-thread-safe List <IObjecOptions> selectedObjects = (List <IObjecOptions>)e.Argument; int i = 0; foreach (IObjecOptions name in selectedObjects) { i++; ((BackgroundWorker)sender).ReportProgress(i * 100 / selectedObjects.Count, name); AccessObject accessObject = AccessObject.CreateInstance(this.App, name.ObjectType, name.Name); accessObject.Save(); } e.Result = selectedObjects.Count; }
internal override CommandLine Run() { if (App == null && Objects.Count > 0) { InitializeAccessApplication(); } foreach (IObjecOptions currentObject in Objects) { ObjectTypeExtension ote = App.AllowedContainers.Find(currentObject.ObjectType); Console.Write(Properties.Resources.Exporting, ote.FileExtension, currentObject); AccessObject accessObject = AccessObject.CreateInstance(App, currentObject.ObjectType, currentObject.ToString()); accessObject.Options = currentObject.Options; string outputFile = Path.Combine(RootPath, ote.Container.InvariantName, currentObject.ToString()) + String.Concat(".", ote.FileExtension, ".txt"); accessObject.Save(outputFile); Console.WriteLine(Properties.Resources.ColonOk); } App.Dispose(); return(this); }