예제 #1
0
        private static void DeletePreviousTasks(Mujin.ControllerClient controllerClient, Options options)
        {
            Dictionary <string, object> sceneTasks = controllerClient.GetSceneTasks(options.ScenePrimaryKey);

            foreach (Dictionary <string, object> sceneTask in (List <object>)sceneTasks["objects"])
            {
                if ((string)sceneTask["tasktype"] == taskType)
                {
                    try
                    {
                        controllerClient.DeleteSceneTask(options.ScenePrimaryKey, sceneTask["pk"].ToString());
                        Console.WriteLine("Deleted previous task: {0}", sceneTask["pk"].ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Faield to delete previous task: {0}: {0}", sceneTask["pk"].ToString(), ex);
                    }
                }
            }
        }
예제 #2
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;
            }
        }