public static async Task <Project> Create(string Path, string Name, bool addDefault) { var basePath = System.IO.Path.Combine(Path, Name); if (System.IO.Directory.Exists(basePath) && System.IO.Directory.GetFiles(basePath).Count() > 0) { var originalname = Name; bool isUnique = false; int counter = 1; while (!isUnique) { if (counter == 1) { basePath = System.IO.Path.Combine(Path, Name); } else { Name = originalname + counter.ToString(); basePath = System.IO.Path.Combine(Path, Name); } if (!System.IO.Directory.Exists(basePath)) { isUnique = true; } counter++; } } var Filepath = System.IO.Path.Combine(Path, Name, Name.Replace(" ", "_").Replace(".", "") + ".rpaproj"); if (string.IsNullOrEmpty(Filepath)) { bool isUnique = false; int counter = 1; while (!isUnique) { if (counter == 1) { Filepath = System.IO.Path.Combine(Path, Name, Name.Replace(" ", "_").Replace(".", "") + ".rpaproj"); } else { Filepath = System.IO.Path.Combine(Path, Name, Name.Replace(" ", "_").Replace(".", "") + counter.ToString() + ".rpaproj"); } if (!System.IO.File.Exists(Filepath)) { isUnique = true; } counter++; } } if (!System.IO.Directory.Exists(basePath)) { System.IO.Directory.CreateDirectory(basePath); } if (System.IO.Directory.GetFiles(basePath).Count() > 0) { throw new Exception(basePath + " is not empty"); } Project p = new Project { _type = "project", name = Name, Path = System.IO.Path.GetDirectoryName(Filepath), Filename = System.IO.Path.GetFileName(Filepath), Workflows = new System.Collections.ObjectModel.ObservableCollection <Workflow>() }; await p.Save(); if (addDefault) { var w = Workflow.Create(p, "New Workflow"); p.Workflows.Add(w); await w.Save(); } return(p); }