Beispiel #1
0
        public int OnExecute(CommandLineApplication app, IConsole console)
        {
            var  c = ClientFactory.Create(Verbose);
            Guid uuid;

            if (Guid.TryParse(ObjectId, out uuid))
            {
                return(Helper.RunHttpCall(async() =>
                {
                    if (string.IsNullOrEmpty(Subpath))
                    {
                        var res = await c.GetObjectAsync(uuid);

                        var file = System.IO.Path.GetTempPath() + res.Uid.ToString() + ".json";

                        var json = JsonConvert.SerializeObject(res, Formatting.Indented);
                        File.WriteAllText(file, json);

                        ProcessStartInfo pi = new ProcessStartInfo("notepad.exe");
                        pi.Arguments = Path.GetFileName(file);
                        pi.UseShellExecute = true;
                        pi.WorkingDirectory = Path.GetDirectoryName(file);
                        Process.Start(pi).WaitForExit();

                        var newJson = File.ReadAllText(file);
                        if (newJson != json)
                        {
                            var edxo = JsonConvert.DeserializeObject <EmergencyObject>(newJson);
                            try
                            {
                                var resultObject = await c.UpdateObjectAsync(res.Uid.Value, edxo);
                                Console.Error.WriteLine("Object has been modified!");
                                Helper.DeserializeEmergencyObjectBody(resultObject);
                                Helper.DumpObjectToOutput(resultObject, OutputFormat);
                            }
                            catch (Exception ex)
                            {
                                Console.Error.WriteLine(ex.Message);
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("File not modified!");
                        }
                        File.Delete(file);
                    }
                    else
                    {
                        Subpath = Subpath.Replace('/', '.');
                        Subpath = Subpath.Replace('.', '/');

                        var res = await c.GetObjectPartAsync(uuid, Subpath);

                        var file = System.IO.Path.GetTempPath() + uuid.ToString() + "-part.json";

                        var json = JsonConvert.SerializeObject(res, Formatting.Indented);
                        File.WriteAllText(file, json);

                        ProcessStartInfo pi = new ProcessStartInfo("notepad.exe");
                        pi.Arguments = Path.GetFileName(file);
                        pi.UseShellExecute = true;
                        pi.WorkingDirectory = Path.GetDirectoryName(file);
                        Process.Start(pi).WaitForExit();

                        var newJson = File.ReadAllText(file);
                        if (newJson != json)
                        {
                            var edxo = JsonConvert.DeserializeObject(newJson);
                            try
                            {
                                var resultObject = await c.UpdatePartialObjectAsync(uuid, Subpath, edxo);
                                Console.Error.WriteLine("Object has been modified!");
                                Helper.DeserializeEmergencyObjectBody(resultObject);
                                Helper.DumpObjectToOutput(resultObject, OutputFormat);
                            }
                            catch (Exception ex)
                            {
                                Console.Error.WriteLine(ex.Message);
                            }
                        }
                        else
                        {
                            Console.Error.WriteLine("File not modified!");
                        }
                        File.Delete(file);
                    }
                }));
            }
            else
            {
                app.ShowHelp();
                return(-1);
            }
        }