예제 #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            Button button1 = (Button)sender;

            button1.Enabled   = false;
            richTextBox1.Text = "Starting backup task ...";
            try
            {
                string command = "Backup";
                if (radioButton2_syncmasterfile.Checked)
                {
                    command = "SyncMasterFile";
                }
                string controllerurl      = controllerurl_input.Text;
                string controllerusername = username_input.Text;
                string controllerpassword = password_input.Text;
                string ftpusername        = ftpusername_input.Text;
                string ftppassword        = ftppassword_input.Text;
                string ftphost            = ftphost_input.Text;
                string ftpport            = ftpport_input.Text;
                string ftpremotePath      = ftpremotePath_input.Text;
                string masterFilePath     = masterFilePath_input.Text;

                Dictionary <string, string> config = new Dictionary <string, string>()
                {
                    { "controllerurl", controllerurl },
                    { "controllerusername", controllerusername },
                    { "controllerpassword", controllerpassword },
                    { "ftpusername", ftpusername },
                    { "ftppassword", ftppassword },
                    { "ftphost", ftphost },
                    { "ftpport", ftpport },
                    { "ftpremotePath", ftpremotePath },
                    { "masterFilePath", masterFilePath }
                };
                System.IO.File.WriteAllText("config.json", JSON.ToNiceJSON(config));

                // initialize mujincontrollerclient
                Mujin.ControllerClient c = new Mujin.ControllerClient(controllerusername, controllerpassword, controllerurl);

                // get scene pk
                string scenepk = c.GetCurrentSceneURI().Substring("mujin:/".Length);

                // create a new task
                Dictionary <string, object> taskdata = new Dictionary <string, object>();
                if (command == "Backup")
                {
                    taskdata = new Dictionary <string, object>()
                    {
                        {
                            "taskparameters", new Dictionary <string, object>()
                            {
                                { "fileStorageInfo", new Dictionary <string, object>()
                                  {
                                      { "type", "ftp" },
                                      { "username", ftpusername },
                                      { "password", ftppassword },
                                      { "host", ftphost },
                                      { "port", ftpport },
                                      { "remotePath", ftpremotePath },
                                  } },
                                { "command", "Backup" }
                            }
                        },
                        { "name", String.Format("registration-backup-{0}", DateTime.Now.ToString(@"yyyyMMdd-hhmmss")) },
                        { "tasktype", "registration" },
                    };
                }
                else if (command == "SyncMasterFile")
                {
                    taskdata = new Dictionary <string, object>()
                    {
                        {
                            "taskparameters", new Dictionary <string, object>()
                            {
                                { "fileStorageInfo", new Dictionary <string, object>()
                                  {
                                      { "type", "ftp" },
                                      { "username", ftpusername },
                                      { "password", ftppassword },
                                      { "host", ftphost },
                                      { "port", ftpport },
                                      { "remotePath", ftpremotePath },
                                  } },
                                { "command", "SyncMasterFile" },
                                { "remoteMasterFilePath", masterFilePath }
                            }
                        },
                        { "name", String.Format("registration-syncmasterfile-{0}", DateTime.Now.ToString(@"yyyyMMdd-hhmmss")) },
                        { "tasktype", "registration" },
                    };
                }

                // delete previous task
                Dictionary <string, object> sceneTasks = c.GetSceneTasks(scenepk);
                foreach (Dictionary <string, object> task in (List <object>)sceneTasks["objects"])
                {
                    if ((string)task["tasktype"] == "registration")
                    {
                        try
                        {
                            c.DeleteSceneTask(scenepk, (string)task["pk"]);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Faield to delete previous task: {0}", ex);
                        }
                    }
                }
                Dictionary <string, object> response = c.CreateSceneTask(scenepk, taskdata);
                string taskpk = (string)response["id"];
                // trigger task to execute
                Dictionary <string, object> runTaskResponse = c.RunScenetaskAsync(scenepk, taskpk);
                await Progress(scenepk, taskpk, (string)runTaskResponse["jobpk"]);

                MessageBox.Show(button1, "Done!");
            }
            catch (Exception ex)
            {
                richTextBox1.Text = ex.ToString();
            }
            finally
            {
                button1.Enabled = true;
            }
        }
예제 #2
0
        private static void Run(Options options)
        {
            Console.OutputEncoding = Encoding.GetEncoding(options.ConsoleEncoding);

            string command = "";

            if (options.Backup)
            {
                if (command.Length > 0)
                {
                    throw new ArgumentException("Cannot specify both --backup and --syncMasterFile at the same time.");
                }
                command = "Backup";
            }
            if (options.MasterFilePath.Length > 0)
            {
                if (command.Length > 0)
                {
                    throw new ArgumentException("Cannot specify both --backup and --syncMasterFile at the same time.");
                }
                command = "SyncMasterFile";
            }
            if (command.Length == 0)
            {
                throw new ArgumentException("Have to specify either --backup or --syncMasterFile in command line.");
            }

            string taskName = String.Format("registration-{0}-{1}", command.ToLower(), DateTime.Now.ToString(@"yyyyMMdd-HHmmss"));

            Console.WriteLine("Using task name: {0}", taskName);

            if (options.OutputFilename.Length == 0)
            {
                options.OutputFilename = String.Format("{0}.json", taskName);
            }

            Mujin.ControllerClient controllerClient = new Mujin.ControllerClient(options.ControllerUsername, options.ControllerPassword, options.ControllerUrl);

            // cancel previous running jobs
            CancelPreviousJobs(controllerClient, options);

            // get scenepk
            if (options.ScenePrimaryKey.Length == 0)
            {
                options.ScenePrimaryKey = controllerClient.GetCurrentSceneURI().Substring("mujin:/".Length);
                Console.WriteLine("Using current scene: {0}", options.ScenePrimaryKey);
            }

            // delete previous task
            DeletePreviousTasks(controllerClient, options);

            // create new task
            string taskPrimaryKey = CreateTask(controllerClient, options, command, taskName);

            Console.WriteLine("Task created: {0}", taskPrimaryKey);

            // trigger task to execute
            string jobPrimaryKey = RunTaskAsync(controllerClient, options, taskPrimaryKey);

            Console.WriteLine("Task started: {0}", jobPrimaryKey);

            // wait for job
            WaitForJob(controllerClient, options, jobPrimaryKey);
            Console.WriteLine("Task finished");

            // wait until result is written
            Dictionary <string, object> result = WaitForTaskResult(controllerClient, options, taskPrimaryKey);

            Console.WriteLine("Result fetched");

            // write to file
            System.IO.File.WriteAllText(options.OutputFilename, JSON.ToNiceJSON(result));
            Console.WriteLine("Output written to file: {0}", options.OutputFilename);
        }