Beispiel #1
0
        protected void AddFile(ObservableCollection <SystemItem> itemSource, List <string> paths)
        {
            var files = paths;

            if (files == null)
            {
                _fileBrowserDialog.Multiselect     = true;
                _fileBrowserDialog.CheckFileExists = true;
                _fileBrowserDialog.StartFolder     = FolderPath;
                _fileBrowserDialog.ShowDialog();
                if (_fileBrowserDialog.SelectedPaths != null)
                {
                    files = _fileBrowserDialog.SelectedPaths.ToList();
                }
                _fileBrowserDialog.Reset();
            }
            if (files == null)
            {
                return;
            }
            if (files.All(fileName => fileName.StartsWith(FolderPath)))
            {
                foreach (var file in files)
                {
                    var source      = file.Substring(FolderPath.Length + 1);
                    var destination = file.Substring(FolderPath.Length + 1);
                    itemSource.Add(FileSystemItem.Create(source, destination));
                }
            }
            else
            {
                _dialogCoordinator.ShowMessageAsync(this, "Error", "Allowed to add files and folders only from the project directory.").Wait(); //TODO: Localize
            }
        }
Beispiel #2
0
        private async Task <IEnumerable <SystemItem> > AddFileSystemItems(IEnumerable <string> paths)
        {
            var enumerable = paths.ToList();
            var returnList = new List <SystemItem>();

            if (enumerable.All(path => path != FolderPath))
            {
                if (enumerable.All(fileName => fileName.StartsWith(FolderPath)))
                {
                    foreach (var path in enumerable)
                    {
                        var source      = path.Substring(FolderPath.Length + 1);
                        var destination = path.Substring(FolderPath.Length + 1);
                        if (File.Exists(path))
                        {
                            returnList.Add(FileSystemItem.Create(source, destination));
                        }
                        else if (Directory.Exists(path))
                        {
                            returnList.Add(FolderSystemItem.Create(source, destination));
                        }
                    }
                }
                else
                {
                    await DialogCoordinator.Instance.ShowMessageAsync(this, "Error", "Allowed to add files and folders only from the project directory.");
                }
            }
            else
            {
                await DialogCoordinator.Instance.ShowMessageAsync(this, "Error", "You can't add root project path.");
            }
            return(returnList);
        }
        private void UpdateFile(ScribsDbContext db, TreeNodeModel model, Project project, Dictionary <string, TreeNodeModel> models)
        {
            models.Add(model.Key, model);
            Directory parent = model.ParentKey == project.Key ? project : project.GetDirectory(model.ParentKey);

            if (!project.TryGetFile(model.Key, out File file))
            {
                FileSystemItem.Create(parent, File.Type, model.label, model.Key, model.Index);
            }
            else
            {
                if (file.Parent != parent)
                {
                    file.Move(parent);
                }
                if (file.Index != model.Index)
                {
                    file.Index = model.Index;
                }
                if (file.Name.StartsWith(".") && file.Name != model.label)
                {
                    file.Rename(model.label);
                }
            }
        }
Beispiel #4
0
        private List <SystemItem> AddFileSystemItems(List <string> paths)
        {
            if (paths == null)
            {
                return(null);
            }
            var returnList      = new List <SystemItem>();
            var filesAndFolders = paths;

            if (filesAndFolders.Any(path => path == FolderPath))
            {
                _dialogCoordinator.ShowMessageAsync(this, "Error", "You can't add root project path.").Wait(); //TODO: Localize
            }
            else
            {
                if (filesAndFolders.All(fileName => fileName.StartsWith(FolderPath)))
                {
                    foreach (var path in filesAndFolders)
                    {
                        var        source      = path.Substring(FolderPath.Length + 1);
                        var        destination = path.Substring(FolderPath.Length + 1);
                        SystemItem item;
                        if (File.Exists(path))
                        {
                            item = FileSystemItem.Create(source, destination);
                        }
                        else
                        {
                            if (Directory.Exists(path))
                            {
                                item = FolderSystemItem.Create(source, destination);
                            }
                            else
                            {
                                throw new NotImplementedException();
                            }
                        }
                        returnList.Add(item);
                    }
                }
                else
                {
                    _dialogCoordinator.ShowMessageAsync(this, "Error", "Allowed to add files and folders only from the project directory.").Wait(); //TODO: Localize
                }
            }
            return(returnList);
        }
        private void UpdateDirectory(ScribsDbContext db, TreeNodeModel model, Project project, Dictionary <string, TreeNodeModel> models)
        {
            models.Add(model.Key, model);
            Directory directory = project;
            Directory parent    = null;

            if (model.ParentKey != null)
            {
                project.TryGetDirectory(model.ParentKey, out parent);
            }
            if (model.Key != project.Key)
            {
                if (!project.TryGetDirectory(model.Key, out directory))
                {
                    FileSystemItem.Create(parent, Directory.Type, model.label, model.Key, model.Index);
                }
                else
                {
                    if (directory.Parent != parent)
                    {
                        directory.Move(parent);
                    }
                    if (directory.Index != model.Index)
                    {
                        directory.Index = model.Index;
                    }
                    if (!directory.Name.StartsWith(".") && directory.Name != model.label)
                    {
                        directory.Rename(model.label);
                    }
                }
            }
            foreach (var child in model.children.Where(o => !o.IsLeaf))
            {
                UpdateDirectory(db, child, project, models);
            }
            foreach (var child in model.children.Where(o => o.IsLeaf))
            {
                UpdateFile(db, child, project, models);
            }
        }
Beispiel #6
0
 protected void TryAddFiles(ObservableCollection <SystemItem> itemSource, List <string> paths)
 {
     if (itemSource == null)
     {
         throw new ArgumentNullException(nameof(itemSource));
     }
     if (paths == null)
     {
         var fileBrowserDialog = new OpenFileDialog
         {
             Multiselect      = true,
             CheckFileExists  = true,
             InitialDirectory = FolderPath
         };
         if (fileBrowserDialog.ShowDialog() == DialogResult.OK && fileBrowserDialog.FileNames.Any())
         {
             paths = fileBrowserDialog.FileNames.ToList();
         }
     }
     if (paths == null)
     {
         return;
     }
     if (paths.All(fileName => fileName.StartsWith(FolderPath)))
     {
         foreach (var file in paths)
         {
             var source      = file.Substring(FolderPath.Length + 1);
             var destination = file.Substring(FolderPath.Length + 1);
             itemSource.Add(FileSystemItem.Create(source, destination));
         }
     }
     else
     {
         _dialogCoordinator.ShowMessageAsync(this, "Error", "Allowed to add files and folders only from the project directory.").Wait();
     }
 }
        public async Task <ProjectModel> Post(ProjectModel model)
        {
            using (var db = new ScribsDbContext()) {
                var user    = GetUser(db);
                int index   = user.GetProjects().Count();
                var project = new Project(user, model.Name, false);
                if (project.ExistsItem())
                {
                    throw new System.Exception("This project already exists");
                }
                project.CreateItem();
                project.Load();
                project.Type        = (Project.ProjectTypes)model.Type;
                project.Description = model.Description;
                project.Structure   = model.Structure.Aggregate((a, b) => a + ";" + b);
                project.Index       = 0;
                project.Key         = Guid.NewGuid().ToString();

                // Basic sheet templates
                var charTemplate = SheetTemplate.Factory.CreateInstance(db);
                charTemplate.User       = user;
                charTemplate.ProjectKey = project.Key;
                charTemplate.Name       = "Characters";
                int i = 0;
                foreach (string label in new List <string> {
                    "Name",
                    "Description",
                    "Personality",
                    "Occupation",
                    "Objective",
                    "Habits",
                    "Conflicts",
                    "Relatives",
                    "Notes"
                })
                {
                    var field = SheetTemplateField.Factory.CreateInstance(db);
                    field.Index         = i++;
                    field.Label         = label;
                    field.SheetTemplate = charTemplate;
                    charTemplate.SheetTemplateFields.Add(field);
                }
                var setTemplate = SheetTemplate.Factory.CreateInstance(db);
                setTemplate.User       = user;
                setTemplate.ProjectKey = project.Key;
                setTemplate.Name       = "Settings";
                i = 0;
                foreach (string label in new List <string> {
                    "Name",
                    "Description",
                    "Sights",
                    "Sounds",
                    "Smells",
                    "Notes"
                })
                {
                    var field = SheetTemplateField.Factory.CreateInstance(db);
                    field.Index         = i++;
                    field.Label         = label;
                    field.SheetTemplate = setTemplate;
                    setTemplate.SheetTemplateFields.Add(field);
                }
                await db.SaveChangesAsync();

                // Drafts
                var draftDirectory = FileSystemItem.Create(project, Directory.Type, ".Drafts", Guid.NewGuid().ToString(), 0) as Directory;
                FileSystemItem.Create(draftDirectory, File.Type, "Draft 1", Guid.NewGuid().ToString(), 0);

                // Structure generation
                var folders = model.Structure.Length > 1 ? model.Structure.Take(model.Structure.Length - 1) :
                              new List <string> {
                    "folder"
                };
                var file      = model.Structure.Length > 0 ? model.Structure.Last() : "file";
                var directory = project as Directory;
                foreach (string folder in folders)
                {
                    string directoryName = folder.Substring(0, 1).ToUpper() + folder.Substring(1, folder.Length - 1) + " 1";
                    directory = FileSystemItem.Create(directory, Directory.Type, directoryName, Guid.NewGuid().ToString(), 0) as Directory;
                }
                string fileName = file.Substring(0, 1).ToUpper() + file.Substring(1, file.Length - 1) + " 1";
                FileSystemItem.Create(directory, File.Type, fileName, Guid.NewGuid().ToString(), 0);

                project.Save();

                return(new ProjectModel {
                    Name = model.Name,
                    Discriminator = Discriminator.Directory,
                    Key = project.Key
                });
            }
        }