public void LoadProject(string path, IProjectProvider provider) { if (provider == null) { return; } // load new project var newProjectInfo = provider.Load(path); // new project not exist if (string.IsNullOrWhiteSpace(newProjectInfo?.Path)) { MessageBox.Show(Resources.ProjectFileNotExistText, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // confirm close old project if (CurrentProjectInfo != null) { if (!ConfirmCloseCurrentProject()) { return; } CloseCurrentProject(); } // update current project CurrentProjectInfo = newProjectInfo; }
public static string CalculateMapData(NamespaceReferenceInfo namespaceReferenceInfo, AddReferenceConfigInfo config) { ProjectInfoBase project = LanguageMapBase.GetCurrent.GetActiveProject(); List <MapDataClassInfo> MapDataClassInfoes = new List <MapDataClassInfo>(); List <string> attributesForAll = new List <string>(); StringBuilder builder = new StringBuilder(); builder.AppendLine($@"{{ {GetTabs(1)}""info"": {{ {GetTabs(2)}""_postman_id"": ""93f204d3-4545-471c-953c-092514b2ca22"", {GetTabs(2)}""name"": ""{config.ServiceNameSpace}"", {GetTabs(2)}""schema"": ""https://schema.getpostman.com/json/collection/v2.1.0/collection.json"" {GetTabs(1)}}}, {GetTabs(1)}""item"": ["); foreach (ClassReferenceInfo httpClassInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.HttpServiceLevel)) { builder.AppendLine($"{GetTabs(2)}{{"); GenerateHttpServiceClass(httpClassInfo, builder); builder.AppendLine($"{GetTabs(2)}}},"); } if (builder[builder.Length - 3] == ',') { builder.Remove(builder.Length - 3, 1); } builder.AppendLine($"{GetTabs(1)}]"); builder.AppendLine($"}}"); return(builder.ToString()); }
public bool CanCompile(ProjectInfoBase project) { if (!(project is CppProjectInfo)) { return(false); } if (!(project?.Provider is CppProjectProvider)) { return(false); } return(true); }
public void Compile(ProjectInfoBase project) { // get all files var files = new List <string>(); foreach (var projectFile in project.Files) { var extension = Path.GetExtension(projectFile.RealPath); if (string.Equals(extension, ".c", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".cxx", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".cc", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".cpp", StringComparison.OrdinalIgnoreCase)) { files.Add(projectFile.RealPath); } } // generate build command var buildCommand = "cl /EHsc"; buildCommand += " " + string.Join(" ", files.Select(p => $"\"{p}\"")); var cppProject = project as CppProjectInfo; var cppProvider = project.Provider as CppProjectProvider; if (cppProject == null) { return; } // libs buildCommand += " " + string.Join(" ", cppProject.PrebuiltLibraries.Select(p => $"\"{p}\"")); // TODO: libpath // includes buildCommand += " " + string.Join(" ", cppProject.IncludeDirectories.Select(p => $"/I\"{p}\"")); // output buildCommand += " " + $"/Fe:\"{cppProvider?.GetBinPath(cppProject)}\\{cppProject?.ProjectName}.exe\""; // reset data IsBusy = true; _compileErrors.Clear(); _compileWarnings.Clear(); // generate cl var cl = GenerateCl(buildCommand); // start cl StartCl(cl, cppProvider?.GetCompileDirectory(cppProject)); }
public ProjectInfoBase[] GetProjectByMemberUsername(string userName) { ProjectCollection projectsCollection = Project.GetProjectByMemberUsername(userName); ProjectInfoBase[] List = new ProjectInfoBase[projectsCollection.Count]; int i = 0; foreach (Project project in projectsCollection) { ProjectInfo projectInfo = new ProjectInfo(); projectInfo.Key = project.Id.ToString(); projectInfo.Name = project.Name; List[i] = projectInfo; i++; } return(List); }
public override async Task <IFile> Save(ProjectInfoBase info, IFolder projectFolder) { if (info is FactorioProjectInfo projectInfo) { var projectFileContent = JsonConvert.SerializeObject(projectInfo.Data, Formatting.Indented); var projectFile = projectFolder.GetFile($"info{ExtensionTypes.First().Extension}"); projectFile.WriteAllText(projectFileContent); var timeToLives = 2000; while (timeToLives > 0 && !projectFile.Exists) { await Task.Delay(25).ConfigureAwait(false); timeToLives -= 25; } return(projectFile); } return(new NonExistingFile("")); }
public string GetCompileDirectory(ProjectInfoBase project) { CreateExtensionDirectoriesIfNotExist(project.Path); return($"{Path.GetDirectoryName(project.Path)}\\Output\\obj"); }
public async Task <string> Save(ProjectInfoBase info, string path) { if (!(info is CppProjectInfo)) { return(string.Empty); } var cppInfo = (CppProjectInfo)info; var projectFile = new XDocument( new XDeclaration("1.0", "UTF-8", null), new XElement("Project", new XAttribute("Name", cppInfo.ProjectName), new XElement("FileGroup"), new XElement("FolderGroup"), new XElement("LibraryFileGroup"), new XElement("OutputGroup") )); var projectDirectory = Path.GetDirectoryName(path) ?? string.Empty; // load root var root = projectFile.Root; if (root == null) { return(string.Empty); } // save files var fileGroup = root.Element("FileGroup"); if (fileGroup != null) { foreach (var file in info.Files) { var realPath = file.RealPath; if (realPath.StartsWith(projectDirectory, StringComparison.OrdinalIgnoreCase)) { realPath = "." + realPath.Remove(0, projectDirectory.Length); } fileGroup.Add(new XElement("FileItem", new XElement("VirtualPath", file.VirtualPath), new XElement("RealPath", realPath) )); } } // save include directories var folderGroup = root.Element("FolderGroup"); if (folderGroup != null) { foreach (var folder in cppInfo.IncludeDirectories) { folderGroup.Add(new XElement("FolderItem", folder)); } } // save prebuilt libraries var libraryGroup = root.Element("LibraryFileGroup"); if (libraryGroup != null) { foreach (var libraryFile in cppInfo.PrebuiltLibraries) { libraryGroup.Add(new XElement("LibFileItem", libraryFile)); } } // save output types var outputGroup = root.Element("OutputGroup"); if (outputGroup != null) { outputGroup.Add(new XElement("OutputItem", cppInfo.OutputType.ToString())); } // save if (!ValidateExtension(path)) { path = Path.ChangeExtension(path, ProjectTypes.First().Extension); } projectFile.Save(path); // create extension directories CreateExtensionDirectoriesIfNotExist(path); var timeToLives = 2000; while (timeToLives > 0 && !File.Exists(path)) { await Task.Delay(25); timeToLives -= 25; } return(path); }
public abstract Task <IFile> Save(ProjectInfoBase info, IFolder projectFolder);
private async Task <bool> Compile(ICompiler compiler, ProjectInfoBase project) { //dependencies var shell = IoC.Get <IShell>(); var output = IoC.Get <IOutput>(); var errorList = IoC.Get <IErrorList>(); var statusBar = IoC.Get <IStatusBar>(); //semaphore and mutex for multi-processing var semaphore = 1; var completed = false; //final result var result = false; //show output shell.ShowTool(output); //reset output output.Clear(); output.AppendLine($"----- {Resources.CompileProjectStartOutput}"); // reset error list errorList.Clear(); // reset status bar first item if (statusBar.Items.Count == 0) { statusBar.AddItem(Resources.CompileSingleFileStartOutput, new System.Windows.GridLength(1, System.Windows.GridUnitType.Auto)); } else { statusBar.Items[0].Message = Resources.CompileSingleFileStartOutput; } //handle compile events EventHandler <string> outputReceivedHandler = delegate(object s, string data) { while (semaphore <= 0) { } semaphore--; if (!string.IsNullOrWhiteSpace(data)) { output.AppendLine($"> {data}"); } semaphore++; }; CompilerExitedEventHandler compileExitedHandler = null; compileExitedHandler = delegate(IEnumerable <CompileError> errors, IEnumerable <CompileError> warnings) { //check for errors var compileErrors = errors as IList <CompileError> ?? errors.ToList(); var compileWarnings = warnings as IList <CompileError> ?? warnings.ToList(); //show error(s) foreach (var error in compileErrors) { errorList.AddItem(ErrorListItemType.Error, error.Code, error.Description, error.Path, error.Line, error.Column); } //show warning(s) foreach (var warning in compileWarnings) { errorList.AddItem(ErrorListItemType.Warning, warning.Code, warning.Description, warning.Path, warning.Line, warning.Column); } if (compileErrors.Any() || compileWarnings.Any()) { shell.ShowTool(errorList); } //result if (!compileErrors.Any()) { //no error result = true; output.AppendLine($"----- {Resources.CompileProjectFinishSuccessfullyOutput}"); statusBar.Items[0].Message = Resources.CompileProjectFinishSuccessfullyOutput; } else { //has error(s) result = false; output.AppendLine($"----- {Resources.CompileProjectFailedOutput}"); statusBar.Items[0].Message = Resources.CompileProjectFailedOutput; } // release subcribed delegate compiler.OutputDataReceived -= outputReceivedHandler; compiler.OnExited -= compileExitedHandler; completed = true; }; compiler.OutputDataReceived += outputReceivedHandler; compiler.OnExited += compileExitedHandler; // compile compiler.Compile(project); // wait for compilation finish while (!completed) { await Task.Delay(25); } return(result); }
public void CalculateMapData(string savePath, NamespaceReferenceInfo namespaceReferenceInfo, string serviceName) { ProjectInfoBase project = LanguageMapBase.GetCurrent.GetActiveProject(); List <MapDataClassInfo> MapDataClassInfoes = new List <MapDataClassInfo>(); List <string> usingsOfClass = new List <string>(); string fileName = ""; //foreach (ProjectItemInfoBase projectItem in LanguageMapBase.GetCurrent.GetAllProjectItemsWithoutServices(project.ProjectItemsInfoBase)) //{ // if (projectItem.GetFileCount() == 0) // continue; // fileName = projectItem.GetFileName(0); // if (Path.GetExtension(fileName).ToLower() == ".swift") // { // string dir = Path.GetDirectoryName(fileName); // if (File.Exists(Path.Combine(dir, "setting.signalgo")) || !File.Exists(fileName)) // continue; // string fileText = File.ReadAllText(fileName, Encoding.UTF8); // if (fileText.Contains("ModelMappAttribute(") || fileText.Contains("ModelMapp(")) // { // using (StringReader streamReader = new StringReader(fileText)) // { // string line = ""; // bool lineReadClassStarted = false; // bool findStartBlock = false; // bool canSetBody = false; // int findEndBlock = int.MaxValue; // MapDataClassInfo mapDataClassInfo = new MapDataClassInfo(); // StringBuilder builder = new StringBuilder(); // while ((line = streamReader.ReadLine()) != null) // { // string lineResult = line; // //if (lineResult.Trim().StartsWith("using ") && lineResult.Trim().EndsWith(";") && !lineResult.Contains("(")) // //{ // // var uses = GetListOfUsing(lineResult); // // mapDataClassInfo.Usings.AddRange(uses); // // usingsOfClass.AddRange(uses); // //} // if (findStartBlock && (line.Contains("{") || line.Contains("}"))) // { // int countPlus = line.Count(x => x == '{') - line.Count(x => x == '}'); // if (findEndBlock == int.MaxValue) // findEndBlock = countPlus; // else // findEndBlock += countPlus; // if (findEndBlock <= 0) // { // mapDataClassInfo.Body = builder.ToString(); // builder.Clear(); // MapDataClassInfo find = MapDataClassInfoes.FirstOrDefault(x => x.Name == mapDataClassInfo.Name && (usingsOfClass.Contains(serviceName) || x.ServiceName == serviceName)); // if (find != null) // { // find.Body += Environment.NewLine + mapDataClassInfo.Body; // } // else // MapDataClassInfoes.Add(mapDataClassInfo); // lineReadClassStarted = false; // findStartBlock = false; // canSetBody = false; // findEndBlock = int.MaxValue; // mapDataClassInfo = new MapDataClassInfo(); // } // else // { // if (canSetBody) // builder.AppendLine(lineResult); // canSetBody = true; // } // } // else if (lineReadClassStarted && line.Contains(" class ")) // { // string[] splitInheritance = line.Split(':', ','); // //multiple inheritance // if (splitInheritance.Length > 1) // { // foreach (string item in splitInheritance.Skip(1)) // { // Tuple<string, string> nameSpaceAndName = GetNameSpaceAndName(item); // if (!string.IsNullOrEmpty(nameSpaceAndName.Item1)) // usingsOfClass.Add(nameSpaceAndName.Item1); // mapDataClassInfo.Inheritances.Add(nameSpaceAndName.Item2); // } // } // findStartBlock = true; // } // else if (!lineResult.TrimStart().StartsWith("//") && (lineResult.Contains("ModelMappAttribute(") || lineResult.Contains("ModelMapp("))) // { // int length = "ModelMappAttribute(".Length; // int index = lineResult.IndexOf("ModelMappAttribute("); // if (index == -1) // { // index = lineResult.IndexOf("ModelMapp("); // length = "ModelMapp(".Length; // } // string[] split = SplitWithIgnoreQuotes(lineResult.Substring(index + length), ","); // foreach (string item in split) // { // if (item.ToLower().Contains("maptotype") || item.Contains("typeof")) // { // Tuple<string, string> nameSpaceAndName = GetNameSpaceAndName(item.Split('=').LastOrDefault()); // if (!string.IsNullOrEmpty(nameSpaceAndName.Item1)) // { // usingsOfClass.Add(nameSpaceAndName.Item1); // mapDataClassInfo.ServiceName = nameSpaceAndName.Item1; // } // mapDataClassInfo.Name = nameSpaceAndName.Item2.Replace("typeof", "").Replace("(", "").Replace(")", "") // .Replace("[", "").Replace("]", "").Trim(); // } // else if (item.Contains("IsEnabledNotifyPropertyChangedBaseClass")) // { // if (item.Contains("false")) // mapDataClassInfo.IsEnabledNotifyPropertyChangedBaseClass = false; // } // else if (item.Contains("IsIncludeInheritances")) // { // if (item.Contains("false")) // mapDataClassInfo.IsIncludeInheritances = false; // } // else if (item.Contains("IgnoreProperties")) // { // Tuple<string, string> nameSpaceAndName = GetNameSpaceAndName(item.Split('=').LastOrDefault()); // Regex reg = new Regex("\".*?\""); // MatchCollection matches = reg.Matches(nameSpaceAndName.Item2); // foreach (object str in matches) // { // mapDataClassInfo.IgnoreProperties.Add(str.ToString().Replace("\"", "")); // } // } // } // lineReadClassStarted = true; // } // else if (canSetBody) // builder.AppendLine(lineResult); // } // } // } // } //} string folder = ""; foreach (IGrouping <string, ClassReferenceInfo> groupInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.ModelLevel || x.Type == ClassReferenceType.InterfaceLevel).GroupBy(x => x.NameSpace)) { //namespaces.Add(groupInfo.Key); folder = Path.Combine(savePath, groupInfo.Key); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } foreach (ClassReferenceInfo modelInfo in groupInfo) { //key is full name and value 1 is name space and value 2 is name Dictionary <string, Dictionary <string, string> > namespaces = new Dictionary <string, Dictionary <string, string> >(); StringBuilder builderResult = new StringBuilder(); builderResult.AppendLine(LanguageMapBase.GetCurrent.GetAutoGeneratedText()); //builderResult.AppendLine("*$-SignalGoNameSpaces-!*"); fileName = Path.Combine(folder, GetFileNameFromClassName(modelInfo.NormalizedName)); GenerateModelClass(modelInfo, " ", builderResult, MapDataClassInfoes.Where(x => x.Name == modelInfo.NormalizedName).FirstOrDefault(), serviceName, namespaces); //StringBuilder nameSpacesResult = new StringBuilder(); //foreach (KeyValuePair<string, Dictionary<string, string>> item in namespaces) //{ // foreach (KeyValuePair<string, string> keyValue in item.Value) // { // nameSpacesResult.AppendLine($"import {{{ keyValue.Value }}} from \"../{keyValue.Key}/{keyValue.Value}\""); // } //} //builderResult.Replace("*$-SignalGoNameSpaces-!*", nameSpacesResult.ToString()); File.WriteAllText(fileName, builderResult.ToString(), Encoding.UTF8); } } //foreach (ClassReferenceInfo httpClassInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.HttpServiceLevel)) //{ // //key is full name and value 1 is name space and value 2 is name // Dictionary<string, Dictionary<string, string>> namespaces = new Dictionary<string, Dictionary<string, string>>(); // StringBuilder builder = new StringBuilder(); // builder.AppendLine(LanguageMapBase.GetCurrent.GetAutoGeneratedText()); // builder.AppendLine("*$-SignalGoNameSpaces-!*"); // //builder.AppendLine("import { List } from 'src/app/SharedComponents/linqts';"); // GenerateHttpServiceClass(httpClassInfo, " ", builder, serviceName, namespaces); // StringBuilder nameSpacesResult = new StringBuilder(); // foreach (KeyValuePair<string, Dictionary<string, string>> item in namespaces) // { // foreach (KeyValuePair<string, string> keyValue in item.Value) // { // nameSpacesResult.AppendLine($"import {{{ keyValue.Value }}} from \"./{keyValue.Key}/{keyValue.Value}\""); // } // } // builder.Replace("*$-SignalGoNameSpaces-!*", nameSpacesResult.ToString()); // File.WriteAllText(Path.Combine(savePath, httpClassInfo.ServiceName.Replace("/", "").Replace("\\", "") + "Service.swift"), builder.ToString(), Encoding.UTF8); //} foreach (IGrouping <string, EnumReferenceInfo> groupInfo in namespaceReferenceInfo.Enums.GroupBy(x => x.NameSpace)) { folder = Path.Combine(savePath, groupInfo.Key); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } foreach (EnumReferenceInfo enumInfo in groupInfo) { StringBuilder builderResult = new StringBuilder(); builderResult.AppendLine(LanguageMapBase.GetCurrent.GetAutoGeneratedText()); fileName = Path.Combine(folder, GetFileNameFromClassName(enumInfo.Name)); GenerateModelEnum(enumInfo, " ", builderResult); File.WriteAllText(fileName, builderResult.ToString(), Encoding.UTF8); } } //folder = Path.Combine(savePath, "SignalGoReference.Models"); //if (!Directory.Exists(folder)) // Directory.CreateDirectory(folder); ////create base namespace //StringBuilder defaultSignalgoClasses = new StringBuilder(); //defaultSignalgoClasses.AppendLine(LanguageMapBase.GetCurrent.GetAutoGeneratedText()); //defaultSignalgoClasses.AppendLine(@" //export class Dictionary3<TKey,TValue> { // [Key: string]: TValue; //}"); //fileName = Path.Combine(folder, "Dictionary3.swift"); //File.WriteAllText(fileName, defaultSignalgoClasses.ToString(), Encoding.UTF8); //return builderResult.ToString(); }
public string CalculateMapData(string savePath, NamespaceReferenceInfo namespaceReferenceInfo, string serviceName) { namespaceReferenceInfo = JsonConvert.DeserializeObject <NamespaceReferenceInfo>(JsonConvert.SerializeObject(namespaceReferenceInfo)); ProjectInfoBase project = LanguageMapBase.GetCurrent.GetActiveProject(); List <MapDataClassInfo> MapDataClassInfoes = new List <MapDataClassInfo>(); List <string> usingsOfClass = new List <string>(); foreach (ProjectItemInfoBase projectItem in LanguageMapBase.GetCurrent.GetAllProjectItemsWithoutServices(project.ProjectItemsInfoBase)) { if (projectItem.GetFileCount() == 0) { continue; } string fileName = projectItem.GetFileName(0); if (Path.GetExtension(fileName).ToLower() == ".ts") { string dir = Path.GetDirectoryName(fileName); if (File.Exists(Path.Combine(dir, "setting.signalgo")) || !File.Exists(fileName)) { continue; } if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string fileText = File.ReadAllText(fileName, Encoding.UTF8); if (fileText.Contains("ModelMappAttribute(") || fileText.Contains("ModelMapp(")) { using (StringReader streamReader = new StringReader(fileText)) { string line = ""; bool lineReadClassStarted = false; bool findStartBlock = false; bool canSetBody = false; int findEndBlock = int.MaxValue; MapDataClassInfo mapDataClassInfo = new MapDataClassInfo(); StringBuilder builder = new StringBuilder(); while ((line = streamReader.ReadLine()) != null) { string lineResult = line; //if (lineResult.Trim().StartsWith("using ") && lineResult.Trim().EndsWith(";") && !lineResult.Contains("(")) //{ // var uses = GetListOfUsing(lineResult); // mapDataClassInfo.Usings.AddRange(uses); // usingsOfClass.AddRange(uses); //} if (findStartBlock && (line.Contains("{") || line.Contains("}"))) { int countPlus = line.Count(x => x == '{') - line.Count(x => x == '}'); if (findEndBlock == int.MaxValue) { findEndBlock = countPlus; } else { findEndBlock += countPlus; } if (findEndBlock <= 0) { mapDataClassInfo.Body = builder.ToString(); builder.Clear(); MapDataClassInfo find = MapDataClassInfoes.FirstOrDefault(x => x.Name == mapDataClassInfo.Name && (usingsOfClass.Contains(serviceName) || x.ServiceName == serviceName)); if (find != null) { find.Body += Environment.NewLine + mapDataClassInfo.Body; } else { MapDataClassInfoes.Add(mapDataClassInfo); } lineReadClassStarted = false; findStartBlock = false; canSetBody = false; findEndBlock = int.MaxValue; mapDataClassInfo = new MapDataClassInfo(); } else { if (canSetBody) { builder.AppendLine(lineResult); } canSetBody = true; } } else if (lineReadClassStarted && line.Contains(" class ")) { string[] splitInheritance = line.Split(':', ','); //multiple inheritance if (splitInheritance.Length > 1) { foreach (string item in splitInheritance.Skip(1)) { Tuple <string, string> nameSpaceAndName = GetNameSpaceAndName(item); if (!string.IsNullOrEmpty(nameSpaceAndName.Item1)) { usingsOfClass.Add(nameSpaceAndName.Item1); } mapDataClassInfo.Inheritances.Add(nameSpaceAndName.Item2); } } findStartBlock = true; } else if (!lineResult.TrimStart().StartsWith("//") && (lineResult.Contains("ModelMappAttribute(") || lineResult.Contains("ModelMapp("))) { int length = "ModelMappAttribute(".Length; int index = lineResult.IndexOf("ModelMappAttribute("); if (index == -1) { index = lineResult.IndexOf("ModelMapp("); length = "ModelMapp(".Length; } string[] split = SplitWithIgnoreQuotes(lineResult.Substring(index + length), ","); foreach (string item in split) { if (item.ToLower().Contains("maptotype") || item.Contains("typeof")) { Tuple <string, string> nameSpaceAndName = GetNameSpaceAndName(item.Split('=').LastOrDefault()); if (!string.IsNullOrEmpty(nameSpaceAndName.Item1)) { usingsOfClass.Add(nameSpaceAndName.Item1); mapDataClassInfo.ServiceName = nameSpaceAndName.Item1; } mapDataClassInfo.Name = nameSpaceAndName.Item2.Replace("typeof", "").Replace("(", "").Replace(")", "") .Replace("[", "").Replace("]", "").Trim(); } else if (item.Contains("IsEnabledNotifyPropertyChangedBaseClass")) { if (item.Contains("false")) { mapDataClassInfo.IsEnabledNotifyPropertyChangedBaseClass = false; } } else if (item.Contains("IsIncludeInheritances")) { if (item.Contains("false")) { mapDataClassInfo.IsIncludeInheritances = false; } } else if (item.Contains("IgnoreProperties")) { Tuple <string, string> nameSpaceAndName = GetNameSpaceAndName(item.Split('=').LastOrDefault()); Regex reg = new Regex("\".*?\""); MatchCollection matches = reg.Matches(nameSpaceAndName.Item2); foreach (object str in matches) { mapDataClassInfo.IgnoreProperties.Add(str.ToString().Replace("\"", "")); } } } lineReadClassStarted = true; } else if (canSetBody) { builder.AppendLine(lineResult); } } } } } } StringBuilder builderResult = new StringBuilder(); builderResult.AppendLine(LanguageMapBase.GetCurrent.GetAutoGeneratedText()); //builderResult.AppendLine("import { List } from 'src/app/SharedComponents/linqts';"); builderResult.AppendLine($"export module {serviceName} {{"); //builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".ServerServices"); //builderResult.AppendLine("{"); //foreach (var classInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.ServiceLevel)) //{ // GenerateServiceClass(classInfo, " ", builderResult, true, "ServiceType.ServerService"); //} //builderResult.AppendLine("}"); //builderResult.AppendLine(""); //builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".StreamServices"); //builderResult.AppendLine("{"); //foreach (var classInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.StreamLevel)) //{ // GenerateServiceClass(classInfo, " ", builderResult, true, "ServiceType.StreamService"); //} //builderResult.AppendLine("}"); //builderResult.AppendLine(""); //builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".OneWayServices"); //builderResult.AppendLine("{"); //foreach (var classInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.OneWayLevel)) //{ // GenerateOneWayServiceClass(classInfo, " ", builderResult, true, "ServiceType.OneWayService"); //} //builderResult.AppendLine("}"); //builderResult.AppendLine(""); //Dictionary<string, string> AddedModels = new Dictionary<string, string>(); //Dictionary<string, List<ClassReferenceInfo>> NeedToAddModels = new Dictionary<string, List<ClassReferenceInfo>>(); List <string> namespaces = new List <string>(); foreach (IGrouping <string, ClassReferenceInfo> groupInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.ModelLevel).GroupBy(x => x.NameSpace)) { namespaces.Add(groupInfo.Key); builderResult.AppendLine("export namespace " + groupInfo.Key + " {"); foreach (ClassReferenceInfo modelInfo in groupInfo) { GenerateModelClass(modelInfo, " ", builderResult, MapDataClassInfoes.Where(x => x.Name == modelInfo.NormalizedName).FirstOrDefault(), serviceName); } builderResult.AppendLine("}"); builderResult.AppendLine(""); } foreach (ClassReferenceInfo httpClassInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.HttpServiceLevel)) { StringBuilder builder = new StringBuilder(); builder.AppendLine(LanguageMapBase.GetCurrent.GetAutoGeneratedText()); //builder.AppendLine("import { List } from 'src/app/SharedComponents/linqts';"); GenerateHttpServiceClass(httpClassInfo, " ", builder, serviceName); string result = builder.ToString(); foreach (string space in namespaces) { if (result.Contains(serviceName + "." + space)) { continue; } result = result.Replace(space, serviceName + "." + space); } httpClassInfo.ServiceName = httpClassInfo.ServiceName.Replace("/", "").Replace("\\", ""); File.WriteAllText(Path.Combine(savePath, httpClassInfo.ServiceName + "Service.ts"), result, Encoding.UTF8); } //builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".ClientServices"); //builderResult.AppendLine("{"); //foreach (var callbackInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.CallbackLevel)) //{ // GenerateServiceClass(callbackInfo, " ", builderResult, false, "ServiceType.ClientService"); //} //builderResult.AppendLine("}"); //builderResult.AppendLine(""); foreach (IGrouping <string, EnumReferenceInfo> groupInfo in namespaceReferenceInfo.Enums.GroupBy(x => x.NameSpace)) { builderResult.AppendLine("export namespace " + groupInfo.Key + " {"); foreach (EnumReferenceInfo enumInfo in groupInfo) { GenerateModelEnum(enumInfo, " ", builderResult); } builderResult.AppendLine("}"); builderResult.AppendLine(""); } //create base namespace builderResult.AppendLine("export namespace SignalGoReference.Models {"); builderResult.AppendLine(""); builderResult.AppendLine(@" export class KeyValuePair<TKey,TValue>{ Key: TKey; Value: TValue; } export class Dictionary3<TKey,TValue> { [Key: string]: TValue; }"); builderResult.AppendLine("}"); builderResult.AppendLine("}"); return(builderResult.ToString()); }