Beispiel #1
0
        public static bool CreateProject(ProjectArgs args, IBasicPanel <Project> control, ref string message)
        {
            string path = Path.Combine(control.FSWorker.WorkDirectory, args.Project);

            using (var transaction = new TransactionScope())
            {
                if (!TransactionDirectory.CreateDirectory(path, ref message))
                {
                    Transaction.Current.Rollback();
                    return(false);
                }
                if (!TransactionDirectory.CreateDirectory(Path.Combine(path, SubFolder), ref message))
                {
                    Transaction.Current.Rollback();
                    return(false);
                }
                transaction.Complete();
            }
            string name = new DirectoryInfo(path).Name;

            if (!Save(control.Save(args.Project, control.SaveItemManager.DoSave(args)), Path.Combine(path, name + ProjectExtension), ref message))
            {
                Directory.Delete(path, true);
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        private bool Do(Happened happened, bool isFolder, EventArgs args, ref string message)
        {
            switch (happened)
            {
            case Happened.Created:
            {
                return(isFolder
                        ? BrowseSystem.CreateProject((ProjectArgs)args, Control, ref message)
                        : BrowseSystem.CreateFile((FileArgs)args, Control, ref message));
            }

            case Happened.Deleted:
            {
                return(isFolder
                        ? TransactionDirectory.RemoveDirectory(Path.Combine(Control.FSWorker.WorkDirectory, ((ProjectArgs)args).Project))
                        : TransactionFile.DeleteFiles((FileArgs)args));
            }
            }
            return(false);
        }
Beispiel #3
0
        public static bool RenameProject(ProjectArgs args, IBasicPanel <Project> control, ref string message)
        {
            string             path        = Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.From);
            ComplexTransaction transaction = new ComplexTransaction();

            transaction.AddOperation(() =>
                                     TransactionDirectory.CopyDirectory(path,
                                                                        Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To)), () =>
            {
                if (!TransactionDirectory.RemoveDirectory(
                        Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To)))
                {
                    Transaction.Current.Rollback();
                }
            });
            transaction.AddOperation(() =>
            {
                TransactionDirectory.RemoveDirectory(path);
            }, new List <string> {
                path
            });
            transaction.AddOperation(() =>
            {
                TransactionFile.DeleteFiles(
                    new FileArgs(
                        new List <string>
                {
                    Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To,
                                 args.RenamedArgs.From + ProjectExtension)
                }, args.RenamedArgs.From, Happened.Deleted,
                        (b, s, arg) => { }));
            }, new List <string>
            {
                Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To,
                             args.RenamedArgs.From + ProjectExtension)
            });
            transaction.DoOperation();
            return(Save(control.Save(args.RenamedArgs.To, control.SaveItemManager.DoSave(args)),
                        Path.Combine(control.FSWorker.WorkDirectory, args.RenamedArgs.To,
                                     args.RenamedArgs.To + ProjectExtension), ref message));
        }
Beispiel #4
0
 public static bool RemoveProject(string path, ref string message)
 {
     return(TransactionDirectory.RemoveDirectory(path));
 }