public static void SaveQuicktypeProperties(QuicktypeProperties quicktypeProperties) { EnsureSettingsFileExists(); var settings = Newtonsoft.Json.JsonConvert.SerializeObject(quicktypeProperties); File.WriteAllText(settingsFilePath, settings); }
public static string GenerateClassCodeFromJson(string json, QuicktypeProperties quicktypeProperties) { File.WriteAllText(quicktypeProperties.JsonFilename, json); var startInfo = CreateQuicktypeStartInfo(quicktypeProperties); var classCodeFromJson = GetClassCode(quicktypeProperties, startInfo); return(classCodeFromJson); }
private static ProcessStartInfo CreateQuicktypeStartInfo(QuicktypeProperties quicktypeProperties) { return(new ProcessStartInfo() { UseShellExecute = false, CreateNoWindow = true, FileName = "/bin/bash", Arguments = $"-c \"{quicktypeProperties.GenerateArguments()}\"" }); }
public static QuicktypeProperties LoadQuicktypeProperties() { EnsureSettingsFileExists(); var settings = File.ReadAllText(settingsFilePath); QuicktypeProperties quicktypeProperties = null; if (!string.IsNullOrEmpty(settings)) { quicktypeProperties = Newtonsoft.Json.JsonConvert.DeserializeObject <QuicktypeProperties>(settings); } return(quicktypeProperties); }
public static string GenerateClassCodeFromJson(string json) { var jsonFilename = Path.GetTempFileName(); File.WriteAllText(jsonFilename, json); var outputFile = Path.Combine(Path.GetTempPath(), "EmptyClass.cs"); var quicktypeProperties = new QuicktypeProperties(jsonFilename, outputFile); var startInfo = CreateQuicktypeStartInfo(quicktypeProperties); var classCodeFromJson = GetClassCode(quicktypeProperties, startInfo); return(classCodeFromJson); }
private QuicktypeProperties GetSavedQuicktypeProperties() { QuicktypeProperties savedQuicktypeProperties = null; try { savedQuicktypeProperties = SettingsService.LoadQuicktypeProperties(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } return(savedQuicktypeProperties); }
private void SaveQuicktypeSettings() { try { LoadQuicktypePropertiesFromGUI(); SettingsService.SaveQuicktypeProperties(quicktypeProperties); quicktypeProperties = SettingsService.LoadQuicktypeProperties(); IdeApp.Workbench.StatusBar.ShowMessage("Saved settings"); } catch (Exception) { IdeApp.Workbench.StatusBar.ShowError("Ouch! Something has happened..."); } }
private static string GetClassCode(QuicktypeProperties quicktypeProperties, ProcessStartInfo startInfo) { string result = string.Empty; using (var process = Process.Start(startInfo)) { process.WaitForExit(); if (process.ExitCode == 127) { throw new UninstalledQuicktypeException(); } if (process.ExitCode != 0) { throw new Exception(process.ExitCode.ToString()); } result = File.ReadAllText(quicktypeProperties.OutputFile); } return(result); }
private void InitializeQuicktype() { quicktypeProperties = GetSavedQuicktypeProperties() ?? new QuicktypeProperties(Path.GetTempFileName(), Path.Combine(Path.GetTempPath(), "EmptyClass.cs")); }