private bool SaveProjectItems(bool promptBeforeSaving, bool saveActiveDocument) { Func <IProjectItem, Microsoft.Expression.Framework.Documents.DocumentReference> documentReference = null; Func <IProjectItem, bool> func = null; bool flag = true; ErrorHandling.HandleBasicExceptions(() => { IEnumerable <IProjectItem> dirtyProjectItems = SolutionBase.GetDirtyProjectItems(this.Projects); if (!saveActiveDocument) { IDocumentView activeView = this.Services.ViewService().ActiveView as IDocumentView; if (activeView != null) { IDocument document = activeView.Document; dirtyProjectItems = from item in dirtyProjectItems where item.Document != document select item; } } if (dirtyProjectItems.Any <IProjectItem>()) { if (promptBeforeSaving) { SaveFilesDialog saveFilesDialog = new SaveFilesDialog(this.Services, dirtyProjectItems); saveFilesDialog.InitializeDialog(); saveFilesDialog.ShowDialog(); if (saveFilesDialog.Result == ProjectDialog.ProjectDialogResult.Cancel) { flag = false; return; } if (saveFilesDialog.Result == ProjectDialog.ProjectDialogResult.Discard) { flag = true; return; } } if (this.IsSourceControlActive) { IEnumerable <IProjectItem> projectItems = dirtyProjectItems; if (documentReference == null) { documentReference = (IProjectItem item) => item.DocumentReference; } SourceControlHelper.UpdateSourceControl(projectItems.Select <IProjectItem, Microsoft.Expression.Framework.Documents.DocumentReference>(documentReference), UpdateSourceControlActions.Checkout, this.Services); } IEnumerable <IProjectItem> projectItems1 = dirtyProjectItems; if (func == null) { func = (IProjectItem item) => !item.SaveDocumentFile(); } flag = !projectItems1.Any <IProjectItem>(func); } }, (Exception exception) => this.Services.ShowErrorMessage(StringTable.SaveAllFailedDialogMessage, exception)); return(flag); }
public static bool AttemptToMakeWritable(DocumentReference documentReference, IProjectActionContext context) { bool flag; if (!documentReference.IsValidPathFormat || Microsoft.Expression.Framework.Documents.PathHelper.IsDirectory(documentReference.Path)) { return(false); } if (!Microsoft.Expression.Framework.Documents.PathHelper.FileOrDirectoryExists(documentReference.Path)) { return(true); } if (context == null) { return(false); } SourceControlHelper.UpdateSourceControl(EnumerableExtensions.AsEnumerable <DocumentReference>(documentReference), UpdateSourceControlActions.Checkout, context); try { FileAttributes attributes = File.GetAttributes(documentReference.Path); if ((attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly) { flag = true; } else if (!context.CanOverwrite(documentReference)) { ProjectLog.LogError(documentReference.Path, StringTable.ActionCanceled, StringTable.MakeWritableAction, new object[0]); flag = false; } else if (!Microsoft.Expression.Framework.Documents.PathHelper.ClearFileOrDirectoryReadOnlyAttribute(documentReference.Path)) { attributes = attributes & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Directory | FileAttributes.Archive | FileAttributes.Device | FileAttributes.Normal | FileAttributes.Temporary | FileAttributes.SparseFile | FileAttributes.ReparsePoint | FileAttributes.Compressed | FileAttributes.Offline | FileAttributes.NotContentIndexed | FileAttributes.Encrypted | FileAttributes.IntegrityStream | FileAttributes.NoScrubData); File.SetAttributes(documentReference.Path, attributes); ProjectLog.LogSuccess(documentReference.Path, StringTable.MakeWritableAction, new object[0]); flag = true; } else { ProjectLog.LogSuccess(documentReference.Path, StringTable.MakeWritableAction, new object[0]); flag = true; } } catch (Exception exception1) { Exception exception = exception1; ProjectLog.LogError(documentReference.Path, exception, StringTable.MakeWritableAction, new object[0]); if (!context.HandleException(documentReference, exception)) { throw; } return(false); } return(flag); }
internal static void UpdateSourceControl(IEnumerable <DocumentReference> paths, UpdateSourceControlActions updateSourceControlAction, IServiceProvider serviceProvider) { SourceControlHelper.UpdateSourceControl(paths, updateSourceControlAction, new HandlerBasedProjectActionContext(serviceProvider)); }