public static string[] GetCustomNameSpaces(AddReferenceConfigInfo config) { if (!string.IsNullOrEmpty(config.CustomNameSpaces)) { return(Regex.Split(config.CustomNameSpaces, "\r\n")); } return(null); }
public static string ReplaceGlobalNameSpace(string nameSpace, AddReferenceConfigInfo config) { if (config.ReplaceNameSpaces != null) { var find = config.ReplaceNameSpaces.FirstOrDefault(x => x.IsGlobal); if (find != null && config.InternalNameSpaces.Any(x => x.Equals(nameSpace, StringComparison.OrdinalIgnoreCase))) { return(find.To + "." + nameSpace); } } return(nameSpace); }
public static string ReplaceNameSpace(string nameSpace, AddReferenceConfigInfo config) { if (config.ReplaceNameSpaces != null) { var find = config.ReplaceNameSpaces.FirstOrDefault(x => x.From == nameSpace); if (find != null) { return(ReplaceGlobalNameSpace(find.To, config)); } } return(ReplaceGlobalNameSpace(nameSpace, config)); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { try { EnvDTE.DTE dte = Package.GetGlobalService(typeof(SDTE)) as EnvDTE.DTE; var projectItem = dte.SelectedItems.Item(1).ProjectItem; var directory = Path.GetDirectoryName(projectItem.FileNames[0]); var settingFile = Path.Combine(directory, "setting.signalgo"); if (File.Exists(settingFile)) { AddReferenceConfigInfo config = null; try { config = JsonConvert.DeserializeObject <AddReferenceConfigInfo>(File.ReadAllText(settingFile, Encoding.UTF8)); } catch (Exception ex) { config = new AddReferenceConfigInfo(); var lines = File.ReadAllLines(settingFile, Encoding.UTF8); if (lines.Length <= 1) { MessageBox.Show("Setting file is empty! please try to recreate your service!", "error", MessageBoxButton.OK, MessageBoxImage.Error); return; } config.ServiceUrl = lines[0]; config.ServiceNameSpace = lines[1]; config.LanguageType = int.Parse(lines[2]); } if (Uri.TryCreate(config.ServiceUrl, UriKind.Absolute, out Uri uri)) { LanguageMap.Current.DownloadService(directory, config); MessageBox.Show("Update success!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Service address is not true", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("setting file not found!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public override async Task <string> DownloadService(string servicePath, AddReferenceConfigInfo config) { string fullFilePath = ""; if (config.ServiceType == 0) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(config.ServiceUrl); webRequest.ContentType = "SignalGo Service Reference"; webRequest.Headers.Add("servicenamespace", config.ServiceNameSpace); webRequest.Headers.Add("selectedLanguage", config.LanguageType.ToString()); webRequest.Method = "POST"; PostToServerInfo postToServerInfo = new PostToServerInfo(); postToServerInfo.SkipAssemblies = config.SkipAssemblies; var jsonBinary = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(postToServerInfo)); var requestStream = await webRequest.GetRequestStreamAsync(); await requestStream.WriteAsync(jsonBinary, 0, jsonBinary.Length); WebResponse response = await webRequest.GetResponseAsync(); if (response.ContentLength <= 0) { throw new Exception("Url ContentLength is not set!"); } else if (response.Headers["Service-Type"] == null || response.Headers["Service-Type"] != "SignalGoServiceType") { throw new Exception("Url file type is not support!"); } Stream stream = response.GetResponseStream(); using (MemoryStream streamWriter = new MemoryStream()) { streamWriter.SetLength(0); byte[] bytes = new byte[1024 * 10]; while (streamWriter.Length != response.ContentLength) { int readCount = await stream.ReadAsync(bytes, 0, bytes.Length); if (readCount <= 0) { break; } await streamWriter.WriteAsync(bytes, 0, readCount); } string json = Encoding.UTF8.GetString(streamWriter.ToArray()); if (Context != null) { await Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Download comepleted."); await Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Generating code..."); } //var namespaceReferenceInfo = (NamespaceReferenceInfo)JsonConvert.DeserializeObject(json, typeof(NamespaceReferenceInfo), new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Converters = new List<JsonConverter>() { new DataExchangeConverter(LimitExchangeType.IncomingCall) { Server = null, Client = null, IsEnabledReferenceResolver = true, IsEnabledReferenceResolverForArray = true } }, Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }); NamespaceReferenceInfo namespaceReferenceInfo = (NamespaceReferenceInfo)JsonConvert.DeserializeObject(json, typeof(NamespaceReferenceInfo), new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }); //csharp if (config.LanguageType == 0) { fullFilePath = Path.Combine(servicePath, "Reference.cs"); File.WriteAllText(fullFilePath, CsharpLanguageMap.CalculateMapData(namespaceReferenceInfo, config), Encoding.UTF8); } //angular else if (config.LanguageType == 1) { //string oldPath = Path.Combine(servicePath, "OldAngular"); //string newPath = Path.Combine(servicePath, "NewAngular"); //fullFilePath = Path.Combine(oldPath, "Reference.ts"); //if (!Directory.Exists(oldPath)) // Directory.CreateDirectory(oldPath); //TypeScriptLanguageMap typeScriptLanguageMap = new TypeScriptLanguageMap(); //File.WriteAllText(fullFilePath, typeScriptLanguageMap.CalculateMapData(oldPath, namespaceReferenceInfo, config.ServiceNameSpace), Encoding.UTF8); AngularTypeScriptLanguageMap angularTypeScriptLanguageMap = new AngularTypeScriptLanguageMap(); angularTypeScriptLanguageMap.CalculateMapData(servicePath, namespaceReferenceInfo, config.ServiceNameSpace); } //blazor else if (config.LanguageType == 2) { fullFilePath = Path.Combine(servicePath, "Reference.cs"); File.WriteAllText(fullFilePath, BlazorLanguageMap.CalculateMapData(namespaceReferenceInfo, config.ServiceNameSpace, config), Encoding.UTF8); } //java android else if (config.LanguageType == 3) { JavaAndroidLanguageMap javaAndroidLanguageMap = new JavaAndroidLanguageMap(); javaAndroidLanguageMap.CalculateMapData(servicePath, namespaceReferenceInfo, config.ServiceNameSpace); } //swift else if (config.LanguageType == 4) { SwiftLanguageMap swiftLanguageMap = new SwiftLanguageMap(); swiftLanguageMap.CalculateMapData(servicePath, namespaceReferenceInfo, config.ServiceNameSpace); } //dart else if (config.LanguageType == 5) { DartFlutterLanguageMap dartFlutterLanguageMap = new DartFlutterLanguageMap(); dartFlutterLanguageMap.CalculateMapData(servicePath, namespaceReferenceInfo, config.ServiceNameSpace); } //Postman else if (config.LanguageType == 6) { fullFilePath = Path.Combine(servicePath, $"{namespaceReferenceInfo.Name}.postman_collection.json"); File.WriteAllText(fullFilePath, PostmanLanguageMap.CalculateMapData(namespaceReferenceInfo, config), Encoding.UTF8); } } } else { if (config.LanguageType > 0) { throw new NotSupportedException("this language for this type not supported now!"); } XMLToCsharp2 xmlCsharp = new XMLToCsharp2(); xmlCsharp.Generate(config.ServiceUrl); string csharpCode = xmlCsharp.GeneratesharpCode(config.ServiceNameSpace); fullFilePath = Path.Combine(servicePath, "Reference.cs"); File.WriteAllText(fullFilePath, csharpCode, Encoding.UTF8); } return(fullFilePath); }
public static string DownloadService(string servicePath, AddReferenceConfigInfo config) { string fullFilePath = ""; if (config.ServiceType == 0) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(config.ServiceUrl); webRequest.ContentType = "SignalGo Service Reference"; webRequest.Headers.Add("servicenamespace", config.ServiceNameSpace); webRequest.Headers.Add("selectedLanguage", config.LanguageType.ToString()); WebResponse response = webRequest.GetResponse(); if (response.ContentLength <= 0) { throw new Exception("Url ContentLength is not set!"); } else if (response.Headers["Service-Type"] == null || response.Headers["Service-Type"] != "SignalGoServiceType") { throw new Exception("Url file type is not support!"); } Stream stream = response.GetResponseStream(); using (MemoryStream streamWriter = new MemoryStream()) { streamWriter.SetLength(0); byte[] bytes = new byte[1024 * 10]; while (streamWriter.Length != response.ContentLength) { int readCount = stream.Read(bytes, 0, bytes.Length); if (readCount <= 0) { break; } streamWriter.Write(bytes, 0, readCount); } string json = Encoding.UTF8.GetString(streamWriter.ToArray()); //var namespaceReferenceInfo = (NamespaceReferenceInfo)JsonConvert.DeserializeObject(json, typeof(NamespaceReferenceInfo), new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Converters = new List<JsonConverter>() { new DataExchangeConverter(LimitExchangeType.IncomingCall) { Server = null, Client = null, IsEnabledReferenceResolver = true, IsEnabledReferenceResolverForArray = true } }, Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }); NamespaceReferenceInfo namespaceReferenceInfo = (NamespaceReferenceInfo)JsonConvert.DeserializeObject(json, typeof(NamespaceReferenceInfo), new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }); if (config.LanguageType == 0) { fullFilePath = Path.Combine(servicePath, "Reference.cs"); File.WriteAllText(fullFilePath, CsharpLanguageMap.CalculateMapData(namespaceReferenceInfo, config), Encoding.UTF8); } else if (config.LanguageType == 1) { var oldPath = Path.Combine(servicePath, "OldAngular"); var newPath = Path.Combine(servicePath, "NewAngular"); fullFilePath = Path.Combine(oldPath, "Reference.ts"); if (!Directory.Exists(oldPath)) { Directory.CreateDirectory(oldPath); } TypeScriptLanguageMap typeScriptLanguageMap = new TypeScriptLanguageMap(); File.WriteAllText(fullFilePath, typeScriptLanguageMap.CalculateMapData(oldPath, namespaceReferenceInfo, config.ServiceNameSpace), Encoding.UTF8); AngularTypeScriptLanguageMap angularTypeScriptLanguageMap = new AngularTypeScriptLanguageMap(); angularTypeScriptLanguageMap.CalculateMapData(newPath, namespaceReferenceInfo, config.ServiceNameSpace); } else if (config.LanguageType == 2) { fullFilePath = Path.Combine(servicePath, "Reference.cs"); File.WriteAllText(fullFilePath, BlazorLanguageMap.CalculateMapData(namespaceReferenceInfo, config.ServiceNameSpace), Encoding.UTF8); } } } else { if (config.LanguageType > 0) { throw new NotSupportedException("this language for this type not supported now!"); } CsharpWebService.XMLToCsharp xmlCsharp = new CsharpWebService.XMLToCsharp(); xmlCsharp.Generate(config.ServiceUrl); string csharpCode = xmlCsharp.GeneratesharpCode(); fullFilePath = Path.Combine(servicePath, "Reference.cs"); StringBuilder builder = new StringBuilder(); builder.AppendLine($"namespace {config.ServiceNameSpace}"); builder.AppendLine("{"); builder.AppendLine(csharpCode); builder.AppendLine("}"); File.WriteAllText(fullFilePath, builder.ToString(), Encoding.UTF8); } return(fullFilePath); }
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 abstract Task <string> DownloadService(string servicePath, AddReferenceConfigInfo config);
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { try { EnvDTE.DTE dte = Package.GetGlobalService(typeof(SDTE)) as EnvDTE.DTE; EnvDTE.ProjectItem projectItem = dte.SelectedItems.Item(1).ProjectItem; string directory = Path.GetDirectoryName(projectItem.FileNames[0]); string settingFile = Path.Combine(directory, "setting.signalgo"); if (File.Exists(settingFile)) { AddReferenceConfigInfo config = null; try { config = JsonConvert.DeserializeObject <AddReferenceConfigInfo>(File.ReadAllText(settingFile, Encoding.UTF8)); } catch (Exception ex) { config = new AddReferenceConfigInfo(); string[] lines = File.ReadAllLines(settingFile, Encoding.UTF8); if (lines.Length <= 1) { MessageBox.Show("Setting file is empty! please try to recreate your service!", "error", MessageBoxButton.OK, MessageBoxImage.Error); return; } config.ServiceUrl = lines[0]; config.ServiceNameSpace = lines[1]; config.LanguageType = int.Parse(lines[2]); } AddServiceWindow addServiceWindow = new AddServiceWindow() { Width = 400, Height = 150, ResizeMode = System.Windows.ResizeMode.NoResize, WindowState = System.Windows.WindowState.Normal, WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen }; AddOrUpdateServiceConfig content = addServiceWindow.Content as AddOrUpdateServiceConfig; content.txtServiceAddress.Text = config.ServiceUrl; content.txtServiceName.Text = config.ServiceNameSpace; content.cboLanguage.SelectedIndex = config.LanguageType; content.cboServiceType.SelectedIndex = config.ServiceType; content.chkJustServices.IsChecked = config.IsJustGenerateServices; content.chkAsyncMethods.IsChecked = config.IsGenerateAsyncMethods; content.rdoIsAutomaticDetection.IsChecked = config.IsAutomaticSyncAndAsyncDetection; content.rdoIsRealMethods.IsChecked = !config.IsAutomaticSyncAndAsyncDetection; content.customNameSpaces.Text = config.CustomNameSpaces; if (config.ReplaceNameSpaces != null) { foreach (var item in config.ReplaceNameSpaces) { content.ReplaceNameSpaces.Add(item); } } if (config.SkipAssemblies != null) { foreach (var item in config.SkipAssemblies) { content.SkipAssemblies.Add(item); } } addServiceWindow.ShowDialog(); } else { MessageBox.Show("setting file not found!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnAddService_Click(object sender, RoutedEventArgs e) { Dispatcher.VerifyAccess(); try { Project project = ((ProjectInfo)LanguageMap.Current.GetActiveProject()).Project; string projectPath = project.FullName; string servicesFolder = Path.Combine(Path.GetDirectoryName(projectPath), "Connected Services"); if (!Directory.Exists(servicesFolder)) { project.ProjectItems.AddFolder("Connected Services"); } Uri uri = null; string serviceNameSpace = txtServiceName.Text.Trim(); string serviceURI = txtServiceAddress.Text.Trim(); if (string.IsNullOrEmpty(serviceNameSpace)) { MessageBox.Show("Please fill your service name", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } else if (!Uri.TryCreate(serviceURI, UriKind.Absolute, out uri)) { MessageBox.Show("Service address is not true", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } string servicePath = Path.Combine(servicesFolder, Path.GetFileNameWithoutExtension(serviceNameSpace)); if (!Directory.Exists(servicePath)) { Directory.CreateDirectory(servicePath); } AddReferenceConfigInfo config = new AddReferenceConfigInfo { ServiceUrl = serviceURI, ServiceNameSpace = serviceNameSpace, LanguageType = cboLanguage.SelectedIndex, ServiceType = cboServiceType.SelectedIndex, IsGenerateAsyncMethods = chkAsyncMethods.IsChecked.Value, IsJustGenerateServices = chkJustServices.IsChecked.Value, IsAutomaticSyncAndAsyncDetection = rdoIsAutomaticDetection.IsChecked.Value, ReplaceNameSpaces = ReplaceNameSpaces.ToList(), SkipAssemblies = SkipAssemblies.ToList(), CustomNameSpaces = customNameSpaces.Text }; string fullFilePath = LanguageMap.Current.DownloadService(servicePath, config); string signalGoSettingPath = Path.Combine(servicePath, "setting.signalgo"); File.WriteAllText(signalGoSettingPath, JsonConvert.SerializeObject(config), Encoding.UTF8); if (!string.IsNullOrEmpty(fullFilePath)) { project.ProjectItems.AddFromFile(fullFilePath); } FinishedAction?.Invoke(); MessageBox.Show($"Service {serviceNameSpace} generated", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static string CalculateMapData(NamespaceReferenceInfo namespaceReferenceInfo, AddReferenceConfigInfo config) { Project project = BaseLanguageMap.GetActiveProject(); List <MapDataClassInfo> MapDataClassInfoes = new List <MapDataClassInfo>(); List <string> usingsOfClass = new List <string>(); foreach (ProjectItem projectItem in BaseLanguageMap.GetAllProjectItemsWithoutServices(project.ProjectItems)) { if (projectItem.FileCount == 0) { continue; } string fileName = projectItem.FileNames[0]; if (Path.GetExtension(fileName).ToLower() == ".cs") { string dir = Path.GetDirectoryName(fileName); if (File.Exists(Path.Combine(dir, "setting.signalgo"))) { 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("(")) { string[] 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(config.ServiceNameSpace) || x.ServiceName == config.ServiceNameSpace)); 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; //builder.AppendLine(lineResult); } 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(BaseLanguageMap.GetAutoGeneratedText()); foreach (string item in namespaceReferenceInfo.Usings) { builderResult.AppendLine("using " + item + ";"); } builderResult.AppendLine("using System;"); usingsOfClass.Add(namespaceReferenceInfo.Name + ".Interfaces"); usingsOfClass.Add(namespaceReferenceInfo.Name + ".ServerServices"); usingsOfClass.Add(namespaceReferenceInfo.Name + ".HttpServices"); //usingsOfClass.Add(namespaceReferenceInfo.Name + ".Models"); usingsOfClass.Add(namespaceReferenceInfo.Name + ".ClientServices"); //usingsOfClass.Add(namespaceReferenceInfo.Name + ".Enums"); foreach (string item in usingsOfClass.Where(x => !namespaceReferenceInfo.Usings.Contains(x)).Distinct()) { builderResult.AppendLine("using " + item + ";"); } builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".Interfaces"); builderResult.AppendLine("{"); builderResult.AppendLine(""); List <string> interfaces = new List <string>(); foreach (ClassReferenceInfo item in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.ServiceLevel || x.Type == ClassReferenceType.StreamLevel)) { if (interfaces.Contains(item.Name)) { continue; } interfaces.Add(item.Name); GenerateServiceInterface(item, " ", builderResult, config.IsGenerateAsyncMethods, GetServiceType(item.Type, item.Name)); } foreach (ClassReferenceInfo item in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.HttpServiceLevel || x.Type == ClassReferenceType.OneWayLevel)) { if (interfaces.Contains(item.Name)) { continue; } interfaces.Add(item.Name); GenerateServiceInterface(item, " ", builderResult, config.IsGenerateAsyncMethods, GetServiceType(item.Type, item.Name)); } builderResult.AppendLine("}"); builderResult.AppendLine(""); builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".ServerServices"); builderResult.AppendLine("{"); foreach (ClassReferenceInfo classInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.ServiceLevel)) { GenerateServiceClass(classInfo, " ", builderResult, config.IsGenerateAsyncMethods, "ServiceType.ServerService"); } builderResult.AppendLine("}"); builderResult.AppendLine(""); builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".StreamServices"); builderResult.AppendLine("{"); foreach (ClassReferenceInfo classInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.StreamLevel)) { GenerateServiceClass(classInfo, " ", builderResult, config.IsGenerateAsyncMethods, "ServiceType.StreamService"); } builderResult.AppendLine("}"); builderResult.AppendLine(""); builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".OneWayServices"); builderResult.AppendLine("{"); foreach (ClassReferenceInfo classInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.OneWayLevel)) { GenerateOneWayServiceClass(classInfo, " ", builderResult, config.IsGenerateAsyncMethods, "ServiceType.OneWayService"); } builderResult.AppendLine("}"); builderResult.AppendLine(""); builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".HttpServices"); builderResult.AppendLine("{"); foreach (ClassReferenceInfo httpClassInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.HttpServiceLevel)) { GenerateHttpServiceClass(httpClassInfo, " ", config.IsGenerateAsyncMethods, builderResult); } builderResult.AppendLine("}"); builderResult.AppendLine(""); builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".ClientServices"); builderResult.AppendLine("{"); foreach (ClassReferenceInfo callbackInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.CallbackLevel)) { GenerateServiceInterface(callbackInfo, " ", builderResult, false, "ServiceType.ClientService"); } builderResult.AppendLine("}"); builderResult.AppendLine(""); if (!config.IsJustGenerateServices) { foreach (IGrouping <string, ClassReferenceInfo> groupInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.ModelLevel).GroupBy(x => x.NameSpace)) { builderResult.AppendLine("namespace " + groupInfo.Key); builderResult.AppendLine("{"); foreach (ClassReferenceInfo modelInfo in groupInfo) { GenerateModelClass(modelInfo, " ", builderResult, MapDataClassInfoes.Where(x => x.Name == modelInfo.Name).FirstOrDefault()); } builderResult.AppendLine("}"); builderResult.AppendLine(""); } foreach (IGrouping <string, EnumReferenceInfo> groupInfo in namespaceReferenceInfo.Enums.GroupBy(x => x.NameSpace)) { builderResult.AppendLine("namespace " + groupInfo.Key); builderResult.AppendLine("{"); foreach (EnumReferenceInfo enumInfo in groupInfo) { GenerateModelEnum(enumInfo, " ", builderResult); } builderResult.AppendLine("}"); builderResult.AppendLine(""); } } return(builderResult.ToString()); }
public static string CalculateMapData(NamespaceReferenceInfo namespaceReferenceInfo, string serviceName, AddReferenceConfigInfo config) { var project = LanguageMapBase.GetCurrent.GetActiveProject(); List <MapDataClassInfo> MapDataClassInfoes = new List <MapDataClassInfo>(); List <string> usingsOfClass = new List <string>(); foreach (var projectItem in LanguageMapBase.GetCurrent.GetAllProjectItemsWithoutServices(project.ProjectItemsInfoBase)) { if (projectItem.GetFileCount() == 0) { continue; } string fileName = projectItem.GetFileName(0); if (Path.GetExtension(fileName).ToLower() == ".cs") { string dir = Path.GetDirectoryName(fileName); if (File.Exists(Path.Combine(dir, "setting.signalgo"))) { 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("(")) { string[] uses = CsharpLanguageMap.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 = CsharpLanguageMap.GetNameSpaceAndName(item); if (!string.IsNullOrEmpty(nameSpaceAndName.Item1)) { usingsOfClass.Add(nameSpaceAndName.Item1); } mapDataClassInfo.Inheritances.Add(nameSpaceAndName.Item2); } } findStartBlock = true; //builder.AppendLine(lineResult); } 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 = CsharpLanguageMap.SplitWithIgnoreQuotes(lineResult.Substring(index + length), ","); foreach (string item in split) { if (item.ToLower().Contains("maptotype") || item.Contains("typeof")) { Tuple <string, string> nameSpaceAndName = CsharpLanguageMap.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 = CsharpLanguageMap.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()); string[] usings = new string[] { "System", "System.Collections.Generic", "System.Net", "System.Net.Http.Headers", "System.Net.Http", "System.Text", "System.ComponentModel", }; foreach (var item in usings) { if (!namespaceReferenceInfo.Usings.Any(x => x.Equals(item, StringComparison.OrdinalIgnoreCase))) { namespaceReferenceInfo.Usings.Add(item); } } foreach (string item in namespaceReferenceInfo.Usings) { if (item.StartsWith("SignalGo.".Trim())) { continue; } builderResult.AppendLine("using " + item + ";"); } usingsOfClass.Add(namespaceReferenceInfo.Name + ".ServerServices"); usingsOfClass.Add(namespaceReferenceInfo.Name + ".HttpServices"); //usingsOfClass.Add(namespaceReferenceInfo.Name + ".Models"); usingsOfClass.Add(namespaceReferenceInfo.Name + ".ClientServices"); //usingsOfClass.Add(namespaceReferenceInfo.Name + ".Enums"); foreach (string item in usingsOfClass.Where(x => !namespaceReferenceInfo.Usings.Contains(x)).Distinct()) { builderResult.AppendLine("using " + item + ";"); } builderResult.AppendLine(""); builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".ServerServices"); builderResult.AppendLine("{"); //foreach (ClassReferenceInfo 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 (ClassReferenceInfo 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 (ClassReferenceInfo classInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.OneWayLevel)) //{ // GenerateOneWayServiceClass(classInfo, " ", builderResult, true, "ServiceType.OneWayService"); //} builderResult.AppendLine("}"); builderResult.AppendLine(""); builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".HttpServices"); builderResult.AppendLine("{"); builderResult.AppendLine(@" /// <summary> /// reponse of http request /// </summary> public class HttpClientResponse { /// <summary> /// status /// </summary> public HttpStatusCode Status { get; set; } = HttpStatusCode.OK; /// <summary> /// data of response /// </summary> public string Data { get; set; } /// <summary> /// response headers /// </summary> public HttpResponseHeaders ResponseHeaders { get; set; } } /// <summary> /// a parameter data for method call /// </summary> public class ParameterInfo { /// <summary> /// type of parameter /// </summary> public string Name { get; set; } /// <summary> /// value of parameter /// </summary> public string Value { get; set; } } public class SignalGoBlazorHttpClient { public HttpRequestHeaders RequestHeaders { get; set; } = new HttpRequestMessage().Headers; public async Task<HttpClientResponse> PostAsync(string url, ParameterInfo[] parameterInfoes) { Microsoft.AspNetCore.Blazor.Browser.Http.BrowserHttpMessageHandler browserHttpMessageHandler = new Microsoft.AspNetCore.Blazor.Browser.Http.BrowserHttpMessageHandler(); using (HttpClient httpClient = new System.Net.Http.HttpClient(browserHttpMessageHandler)) { foreach (KeyValuePair<string, IEnumerable<string>> item in RequestHeaders) { httpClient.DefaultRequestHeaders.Add(item.Key, item.Value); } MultipartFormDataContent form = new MultipartFormDataContent(); foreach (ParameterInfo item in parameterInfoes) { StringContent jsonPart = new StringContent(item.Value.ToString(), Encoding.UTF8, ""application/json""); jsonPart.Headers.ContentDisposition = new ContentDispositionHeaderValue(""form-data""); jsonPart.Headers.ContentDisposition.Name = item.Name; jsonPart.Headers.ContentType = new MediaTypeHeaderValue(""application/json""); form.Add(jsonPart); } HttpResponseMessage httpresponse = await httpClient.PostAsync(url, form); if (!httpresponse.IsSuccessStatusCode) { // Unwrap the response and throw as an Api Exception: throw new Exception(await httpresponse.Content.ReadAsStringAsync()); } else { httpresponse.EnsureSuccessStatusCode(); return new HttpClientResponse() { Data = await httpresponse.Content.ReadAsStringAsync(), ResponseHeaders = httpresponse.Headers, Status = httpresponse.StatusCode }; } } } }"); foreach (ClassReferenceInfo httpClassInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.HttpServiceLevel)) { GenerateHttpServiceClass(httpClassInfo, " ", builderResult); } builderResult.AppendLine("}"); builderResult.AppendLine(""); //Dictionary<string, string> AddedModels = new Dictionary<string, string>(); //Dictionary<string, List<ClassReferenceInfo>> NeedToAddModels = new Dictionary<string, List<ClassReferenceInfo>>(); foreach (IGrouping <string, ClassReferenceInfo> groupInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.ModelLevel).GroupBy(x => x.NameSpace)) { builderResult.AppendLine("namespace " + groupInfo.Key); builderResult.AppendLine("{"); foreach (ClassReferenceInfo modelInfo in groupInfo) { CsharpLanguageMap.GenerateModelClass(modelInfo, " ", builderResult, MapDataClassInfoes.Where(x => x.Name == modelInfo.NormalizedName).FirstOrDefault(), config, new List <string>()); } builderResult.AppendLine("}"); builderResult.AppendLine(""); //if (AddedModels.ContainsKey(modelInfo.Name)) //{ // var find = NeedToAddModels.Where(x => !x.Value.Any(y => y.Name == modelInfo.Name)).Select(x => x.Value).FirstOrDefault(); // if (find != null) // find.Add(modelInfo); // else // { // var list = new List<ClassReferenceInfo>(); // NeedToAddModels.Add(nameSpaceName + (NeedToAddModels.Count + 2), list); // list.Add(modelInfo); // } //} //else //{ // AddedModels.Add(modelInfo.Name, nameSpaceName); //} } //builderResult.AppendLine("}"); //builderResult.AppendLine(""); //add duplicate models name to another name spaces //foreach (var item in NeedToAddModels) //{ // nameSpaceName = item.Key; // builderResult.AppendLine(nameSpaceName); // builderResult.AppendLine("{"); // foreach (var modelInfo in item.Value) // { // GenerateModelClass(modelInfo, " ", builderResult, MapDataClassInfoes.Where(x => x.Name == modelInfo.Name).FirstOrDefault()); // } // builderResult.AppendLine("}"); // builderResult.AppendLine(); //} builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".ClientServices"); builderResult.AppendLine("{"); //foreach (ClassReferenceInfo callbackInfo in namespaceReferenceInfo.Classes.Where(x => x.Type == ClassReferenceType.CallbackLevel)) //{ // GenerateServiceClass(callbackInfo, " ", builderResult, false, "ServiceType.ClientService"); //} builderResult.AppendLine("}"); builderResult.AppendLine(""); //builderResult.AppendLine("namespace " + namespaceReferenceInfo.Name + ".Enums"); //builderResult.AppendLine("{"); foreach (IGrouping <string, EnumReferenceInfo> groupInfo in namespaceReferenceInfo.Enums.GroupBy(x => x.NameSpace)) { builderResult.AppendLine("namespace " + groupInfo.Key); builderResult.AppendLine("{"); foreach (EnumReferenceInfo enumInfo in groupInfo) { CsharpLanguageMap.GenerateModelEnum(enumInfo, " ", builderResult); } builderResult.AppendLine("}"); builderResult.AppendLine(""); } //builderResult.AppendLine("}"); //builderResult.AppendLine(""); return(builderResult.ToString()); }
//public override async Task<AddServiceInstanceResult> AddServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken cancellationToken) //{ // var instance = (Instance)context.ServiceInstance; // await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Adding service instance for \"{instance.ServiceConfig.Endpoint}\"..."); // // await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Checking prerequisites..."); // // await CheckingPrerequisitesAsync(context, instance); // var codeGenDescriptor = await GenerateCodeAsync(context, instance); // context.SetExtendedDesignerData(instance.ServiceConfig); // await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Adding service instance complete!"); // return new AddServiceInstanceResult(context.ServiceInstance.Name, new Uri(Constants.Website)); //} //public override async Task<UpdateServiceInstanceResult> UpdateServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken cancellationToken) //{ // var instance = (Instance)context.ServiceInstance; // await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Re-adding service instance for \"{instance.ServiceConfig.Endpoint}\"..."); // // await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Checking prerequisites..."); // // await CheckingPrerequisitesAsync(context, instance); // var codeGenDescriptor = await ReGenerateCodeAsync(context, instance); // context.SetExtendedDesignerData(instance.ServiceConfig); // await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Re-Adding service instance complete!"); // return await base.UpdateServiceInstanceAsync(context, cancellationToken); //} //private static async Task<BaseCodeGenDescriptor> GenerateCodeAsync(ConnectedServiceHandlerContext context, Instance instance) //{ // var codeGenDescriptor = new NSwagCodeGenDescriptor(context, instance); // await codeGenDescriptor.AddNugetPackagesAsync(); // var nswagFilePath = await codeGenDescriptor.AddGeneratedNswagFileAsync(); // var clientFilePath = await codeGenDescriptor.AddGeneratedCodeAsync(); // return codeGenDescriptor; //} //private static async Task<BaseCodeGenDescriptor> ReGenerateCodeAsync(ConnectedServiceHandlerContext context, Instance instance) //{ // var codeGenDescriptor = new NSwagCodeGenDescriptor(context, instance); // var nswagFilePath = await codeGenDescriptor.AddGeneratedNswagFileAsync(); // var clientFilePath = await codeGenDescriptor.AddGeneratedCodeAsync(); // return codeGenDescriptor; //} #endregion public override async Task <AddServiceInstanceResult> AddServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct) { await new JoinableTaskFactory(ThreadHelper.JoinableTaskContext).SwitchToMainThreadAsync(ct); Project project = ((ProjectInfo)LanguageMap.Current.GetActiveProject()).Project; string projectPath = project.FullName; string servicesFolder = Path.Combine(Path.GetDirectoryName(projectPath), "Connected Services"); if (!Directory.Exists(servicesFolder)) { project.ProjectItems.AddFolder("Connected Services"); } Uri uri = null; string serviceNameSpace = GlobalConfigWizardViewModel.ViewModel.ServiceDefaultNamespace.Trim(); string serviceURI = GlobalConfigWizardViewModel.ViewModel.ServiceAddress.Trim(); if (string.IsNullOrEmpty(serviceNameSpace)) { throw new Exception("Please fill your service name"); } else if (!Uri.TryCreate(serviceURI, UriKind.Absolute, out uri)) { throw new Exception("Service address is not true"); } string servicePath = Path.Combine(servicesFolder, Path.GetFileNameWithoutExtension(serviceNameSpace)); if (!Directory.Exists(servicePath)) { Directory.CreateDirectory(servicePath); } AddReferenceConfigInfo config = new AddReferenceConfigInfo { ServiceUrl = serviceURI, ServiceNameSpace = serviceNameSpace, LanguageType = SettingsWizardViewModel.ViewModel.SelectedLanguageType, ServiceType = SettingsWizardViewModel.ViewModel.SelectedServiceType, IsGenerateAsyncMethods = SettingsWizardViewModel.ViewModel.IsGenerateAsyncMethods, IsJustGenerateServices = SettingsWizardViewModel.ViewModel.IsJustServices, IsAutomaticSyncAndAsyncDetection = SettingsWizardViewModel.ViewModel.IsAutomaticSyncAndAsyncDetection, ReplaceNameSpaces = ManageNamespacesWizardViewModel.ViewModel.ReplaceNameSpaces.ToList(), SkipAssemblies = ManageSkipAssembliesWizardViewModel.ViewModel.SkipAssemblies.ToList(), CustomNameSpaces = ManageNamespacesWizardViewModel.ViewModel.CustomNamespaces }; await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Configuration passed"); await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Collecting data from {serviceURI}"); LanguageMap.Current.Context = context; string fullFilePath = await LanguageMap.Current.DownloadService(servicePath, config); string signalGoSettingPath = Path.Combine(servicePath, "setting.signalgo"); File.WriteAllText(signalGoSettingPath, JsonConvert.SerializeObject(config), Encoding.UTF8); if (!string.IsNullOrEmpty(fullFilePath)) { project.ProjectItems.AddFromFile(fullFilePath); } await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Service {serviceNameSpace} generated successfully"); return(new AddServiceInstanceResult(Path.GetFileName(servicePath), null)); }