public static void SaveQuicktypeProperties(QuicktypeProperties quicktypeProperties)
        {
            EnsureSettingsFileExists();
            var settings = Newtonsoft.Json.JsonConvert.SerializeObject(quicktypeProperties);

            File.WriteAllText(settingsFilePath, settings);
        }
Example #2
0
        public static string GenerateClassCodeFromJson(string json, QuicktypeProperties quicktypeProperties)
        {
            File.WriteAllText(quicktypeProperties.JsonFilename, json);

            var startInfo         = CreateQuicktypeStartInfo(quicktypeProperties);
            var classCodeFromJson = GetClassCode(quicktypeProperties, startInfo);

            return(classCodeFromJson);
        }
Example #3
0
 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);
        }
Example #5
0
        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);
        }
Example #6
0
        private QuicktypeProperties GetSavedQuicktypeProperties()
        {
            QuicktypeProperties savedQuicktypeProperties = null;

            try
            {
                savedQuicktypeProperties = SettingsService.LoadQuicktypeProperties();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            return(savedQuicktypeProperties);
        }
Example #7
0
 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...");
     }
 }
Example #8
0
        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);
        }
Example #9
0
 private void InitializeQuicktype()
 {
     quicktypeProperties = GetSavedQuicktypeProperties() ?? new QuicktypeProperties(Path.GetTempFileName(), Path.Combine(Path.GetTempPath(), "EmptyClass.cs"));
 }