示例#1
0
        public async Task CloneAsync(string oldId, string newId, bool newEnabled)
        {
            if (!Directories.Actual)
            {
                return;
            }
            if (oldId == null)
            {
                throw new ArgumentNullException(nameof(oldId));
            }

            // find object which is being renamed
            var wrapper = GetWrapperById(oldId);
            var obj     = wrapper?.Value as T;

            if (obj == null)
            {
                throw new ArgumentException(ToolsStrings.AcObject_IdIsWrong, nameof(oldId));
            }

            // files to move
            var    currentLocation = obj.Location;
            string newLocation;

            try {
                newLocation = Directories.GetLocation(newId, newEnabled);
            } catch (Exception) {
                throw new InformativeException(ToolsStrings.Common_CannotDo, ToolsStrings.AcObject_DisablingNotSupported_Commentary);
            }

            if (FileUtils.Exists(newLocation))
            {
                throw new ToggleException(ToolsStrings.AcObject_PlaceIsTaken);
            }

            var currentAttached = GetAttachedFiles(currentLocation).NonNull().ToList();
            var newAttached     = GetAttachedFiles(newLocation).NonNull().ToList();

            if (newAttached.Any(FileUtils.Exists))
            {
                throw new ToggleException(ToolsStrings.AcObject_PlaceIsTaken);
            }

            // let’s move!
            try {
                await CloneOverrideAsync(oldId, newId, currentLocation, newLocation, currentAttached.Zip(newAttached, Tuple.Create), newEnabled);

                AcObjectNew.MoveRatings <T>(oldId, newId, true);
            } catch (InformativeException) {
                throw;
            } catch (Exception e) {
                throw new ToggleException(e.Message);
            }
        }
示例#2
0
        public async Task RenameAsync([NotNull] string oldId, [NotNull] string newId, bool newEnabled)
        {
            if (!Directories.Actual)
            {
                return;
            }
            if (oldId == null)
            {
                throw new ArgumentNullException(nameof(oldId));
            }

            if (GetWrapperById(newId)?.Value.Enabled == newEnabled)
            {
                throw new ToggleException("Object with the same ID already exists.");
            }

            // find object which is being renamed
            var wrapper = GetWrapperById(oldId);
            var obj     = wrapper?.Value as T;

            if (obj == null)
            {
                throw new ArgumentException(ToolsStrings.AcObject_IdIsWrong, nameof(oldId));
            }

            // files to move
            var currentLocation = obj.Location;
            var newLocation     = Directories.GetLocation(newId, newEnabled);

            if (FileUtils.Exists(newLocation))
            {
                throw new ToggleException(ToolsStrings.AcObject_PlaceIsTaken);
            }

            var currentAttached = GetAttachedFiles(currentLocation).NonNull().ToList();
            var newAttached     = GetAttachedFiles(newLocation).NonNull().ToList();

            if (newAttached.Any(FileUtils.Exists))
            {
                throw new ToggleException(ToolsStrings.AcObject_PlaceIsTaken);
            }

            // let’s move!
            try {
                await MoveOverrideAsync(oldId, newId, currentLocation, newLocation, currentAttached.Zip(newAttached, Tuple.Create), newEnabled);

                AcObjectNew.MoveRatings <T>(oldId, newId, false);
            } catch (InformativeException) {
                throw;
            } catch (Exception e) {
                throw new ToggleException(e.Message);
            }
        }