private static bool ValidateMoveInfo(Microsoft.Expression.Project.MoveInfo moveInfo, Microsoft.Expression.Project.MoveOptions moveOptions) { if (string.IsNullOrEmpty(moveInfo.Source) || string.IsNullOrEmpty(moveInfo.Destination)) { throw new ArgumentException("moveRequests"); } if (!Microsoft.Expression.Framework.Documents.PathHelper.FileOrDirectoryExists(moveInfo.Source)) { return(false); } moveInfo.Source = Microsoft.Expression.Framework.Documents.PathHelper.ResolvePath(moveInfo.Source); moveInfo.Destination = Microsoft.Expression.Framework.Documents.PathHelper.ResolvePath(moveInfo.Destination); if (moveInfo.Source.Equals(moveInfo.Destination, StringComparison.OrdinalIgnoreCase)) { return(false); } if (Microsoft.Expression.Framework.Documents.PathHelper.FileOrDirectoryExists(moveInfo.Destination)) { if ((moveOptions & Microsoft.Expression.Project.MoveOptions.OverwriteDestination) != Microsoft.Expression.Project.MoveOptions.OverwriteDestination) { throw new InvalidOperationException("Destination files exist"); } Microsoft.Expression.Framework.Documents.PathHelper.ClearFileOrDirectoryReadOnlyAttribute(moveInfo.Destination); } return(true); }
public static IList <MoveResult> MoveSafe(IEnumerable <Microsoft.Expression.Project.MoveInfo> moveRequests, Microsoft.Expression.Project.MoveOptions moveOptions, bool shouldThrowIOExceptions) { return(ProjectPathHelper.MoveSafeInternal(moveRequests, moveOptions, true, shouldThrowIOExceptions)); }
private static IList <MoveResult> MoveSafeInternal(IEnumerable <Microsoft.Expression.Project.MoveInfo> moveRequests, Microsoft.Expression.Project.MoveOptions moveOptions, bool isMove, bool shouldThrowIOExceptions) { IList <MoveResult> moveResults; if (moveRequests == null) { throw new ArgumentNullException("moveRequests"); } IList <MoveResult> moveResults1 = new List <MoveResult>(); if (!moveRequests.Any <Microsoft.Expression.Project.MoveInfo>()) { return(moveResults1); } List <Microsoft.Expression.Project.MoveInfo> list = ( from moveInfo in moveRequests where ProjectPathHelper.ValidateMoveInfo(moveInfo, moveOptions) select moveInfo).ToList <Microsoft.Expression.Project.MoveInfo>(); List <Microsoft.Expression.Project.MoveInfo> moveInfos = new List <Microsoft.Expression.Project.MoveInfo>(); List <Microsoft.Expression.Project.MoveInfo> .Enumerator enumerator = list.GetEnumerator(); try { while (enumerator.MoveNext()) { Microsoft.Expression.Project.MoveInfo current = enumerator.Current; try { bool flag = (moveOptions & Microsoft.Expression.Project.MoveOptions.OverwriteDestination) == Microsoft.Expression.Project.MoveOptions.OverwriteDestination; bool flag1 = isMove; if (Microsoft.Expression.Framework.Documents.PathHelper.IsDirectory(current.Source)) { if (ProjectPathHelper.HasContentAlreadyBeenMoved(moveInfos, current.Source)) { MoveResult moveResult = new MoveResult() { Source = current.Source, Destination = current.Destination, MovedSuccessfully = true }; moveResults1.Add(moveResult); } else { using (IEnumerator <MoveResult> enumerator1 = ProjectPathHelper.MoveDirectorySafe(current, flag1, flag).GetEnumerator()) { while (enumerator1.MoveNext()) { moveResults1.Add(enumerator1.Current); } } } moveInfos.Add(current); } else if (!ProjectPathHelper.HasContentAlreadyBeenMoved(moveInfos, current.Source)) { Microsoft.Expression.Framework.Documents.PathHelper.ClearFileOrDirectoryReadOnlyAttribute(current.Source); string directoryNameOrRoot = Microsoft.Expression.Framework.Documents.PathHelper.GetDirectoryNameOrRoot(current.Destination); if (!Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(directoryNameOrRoot)) { Directory.CreateDirectory(directoryNameOrRoot); } if (flag && Microsoft.Expression.Framework.Documents.PathHelper.FileExists(current.Destination)) { Microsoft.Expression.Framework.Documents.PathHelper.ClearFileOrDirectoryReadOnlyAttribute(current.Destination); } File.Copy(current.Source, current.Destination, flag); MoveResult moveResult1 = new MoveResult() { Source = current.Source, Destination = current.Destination, MovedSuccessfully = true }; moveResults1.Add(moveResult1); if (flag1) { File.Delete(current.Source); } } } catch (Exception exception) { if (!ProjectPathHelper.IsIOException(exception) || shouldThrowIOExceptions) { throw; } else { moveResults = null; return(moveResults); } } } return(moveResults1); } finally { ((IDisposable)enumerator).Dispose(); } return(moveResults); }
public static IList <MoveResult> CopySafe(IEnumerable <Microsoft.Expression.Project.MoveInfo> copyRequests, Microsoft.Expression.Project.MoveOptions copyOptions, bool shouldThrowIOExceptions) { return(ProjectPathHelper.MoveSafeInternal(copyRequests, copyOptions, false, shouldThrowIOExceptions)); }