private void GetWorkingDirectories() { var dir = Directory.GetCurrentDirectory(); if (string.IsNullOrEmpty(WorkingDirectory)) { log("Using Default Working Directory {0}", dir); LocalWorkingDirs.Add(dir); return; } List <string> workingDirectories = WorkingDirectory.Split(';').ToList(); foreach (string workingDirectory in workingDirectories) { if (string.IsNullOrWhiteSpace(workingDirectory)) { continue; } var localdir = Path.Combine(dir, workingDirectory); if (!Directory.Exists(localdir)) { log("Working Directory does not exist {0}, creating..", localdir); Directory.CreateDirectory(localdir).Create(); } log("Adding Working Directory {0}", localdir); LocalWorkingDirs.Add(localdir); } }
private void CalculateLeastCommonParentFolder() { if (LocalWorkingDirs.Count == 1) { CommonParentDir = LocalWorkingDirs[0]; return; } CommonParentDir = ""; string referenceDir = LocalWorkingDirs[0]; int index = 0; // Compute least common substring while (LocalWorkingDirs.Aggregate(true, (same, next) => same && next.StartsWith(referenceDir.Substring(0, index)))) { index++; } if (index == 0) { log("Directories have no common parent. This will not work."); return; } CommonParentDir = referenceDir.Substring(0, index - 1); CommonParentDir = CommonParentDir.Replace(@"\", "/"); // Least common substring may contain partial folder names. Trim these off. if (!CommonParentDir.EndsWith("/")) { CommonParentDir = CommonParentDir.Substring(0, CommonParentDir.LastIndexOf('/') + 1); } }
public bool Execute() { log("Starting MTT ConvertService"); GetWorkingDirectories(); CalculateLeastCommonParentFolder(); GetConvertDirectory(); LocalWorkingDirs.ForEach(dir => LoadModels(dir)); try { BreakDown(); } catch (Exception e) { throw e; } Convert(); log("Finished MTT ConvertService"); return(true); }