Пример #1
0
        public void saveToMemory(HttpResponseMessage response)
        {
            RobotGroup temp = JsonConvert.DeserializeObject <RobotGroup>(response.Content.ReadAsStringAsync().Result);

            id             = temp.id;
            robot_group_id = temp.robot_group_id;
        }
Пример #2
0
    /// <summary>
    /// Sends various parameters on start-up so that fleet is correct
    /// </summary>
    public static void initializeFleet()
    {
        logger(AREA, INFO, "Initializing Fleet Data: Robot, Mission and Charging Groups + Missions");

        if (resumingSession)
        {
            logger(AREA, INFO, "Resuming Previous Session, i.e: Using Existing Fleet Set-Up");
        }
        else
        {
            logger(AREA, INFO, "Starting A New Fleet Instance: Deploying Data To Fleet");

            //=========================================================|
            // Post All the Robot Groups                               |
            //=========================================================|
            try
            {
                logger(AREA, INFO, "Initializing Robot Groups");

                string sql = "SELECT * FROM robot_groups;";
                using var cmd             = new MySqlCommand(sql, db);
                using MySqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    Mirage.rest.RobotGroup temp = new Mirage.rest.RobotGroup();

                    string name       = rdr.GetString(1);
                    string desc       = rdr.GetString(2);
                    string allow_all  = rdr.GetString(3);
                    string created_by = rdr.GetString(4);

                    logger(AREA, DEBUG, "Row: " + rdr.GetInt32(0) + " - Name: " + name + " - Description: " + desc + "Allow All Mission: " + allow_all + "Created By: " + created_by);

                    //mirFleet.group[i] = new Mirage.rest.RobotGroup();
                    HttpRequestMessage tempReq = temp.postRequest(name, desc, allow_all, created_by);

                    mirFleet.fleetManager.sendRESTdata(tempReq);
                    Thread.Sleep(50);
                }
            }
            catch (Exception e)
            {
                logger(AREA, DEBUG, "Failed a query: ", e);
            }

            logger(AREA, DEBUG, "Robot Groups Sent To Fleet");

            //=========================================================|
            // Post the Mission Groups                                 |
            //=========================================================|
            try
            {
                logger(AREA, INFO, "Initializing Mission Groups");

                string sql = "SELECT * FROM mission_groups;";
                using var cmd             = new MySqlCommand(sql, db);
                using MySqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    string guid       = rdr.GetString(1);
                    string name       = rdr.GetString(2);
                    int    priority   = rdr.GetInt32(3);
                    string feature    = rdr.GetString(4);
                    string icon       = rdr.GetString(5);
                    string created_by = rdr.GetString(6);

                    logger(AREA, DEBUG, "Row: " + rdr.GetInt32(0) + " - GUID: " + guid + " - Name: " + name + "Priority: " + priority + "Feature: " + feature + " icon: " + icon + " Created by: " + created_by);

                    var plainTextBytes = Encoding.UTF8.GetBytes(icon);

                    string payload;
                    payload  = "{\"guid\": \"" + guid + "\", ";
                    payload += "\"name\": \"" + name + "\", ";
                    payload += "\"priority\": " + priority + ", ";
                    payload += "\"feature\": \"" + feature + "\", ";
                    payload += "\"icon\": \"" + Convert.ToBase64String(plainTextBytes) + "\"} ";
                    //payload += "\"created_by_id\": \"" + created_by + "\"}";

                    logger(AREA, DEBUG, payload);

                    string url = "http://" + fleetManagerIP + "/api/v2.0.0/mission_groups/";
                    Uri    uri = new Uri(url);

                    HttpRequestMessage request = new HttpRequestMessage
                    {
                        Content    = new StringContent(payload, Encoding.UTF8, "application/json"),
                        Method     = HttpMethod.Post,
                        RequestUri = uri
                    };

                    logger(AREA, DEBUG, request.Content.ToString());

                    mirFleet.fleetManager.sendRESTdata(request);

                    Thread.Sleep(50);
                }
            }
            catch (Exception e)
            {
                logger(AREA, DEBUG, "Failed a query: ", e);
            }

            logger(AREA, DEBUG, "Finished Initializing Mission Groups");
        }

        //=========================================================|
        // Post the Missions                                       |
        //=========================================================|
        try
        {
            logger(AREA, INFO, "Initializing Missions");

            string sql = "SELECT * FROM missions;";
            using var cmd             = new MySqlCommand(sql, db);
            using MySqlDataReader rdr = cmd.ExecuteReader();

            int i = 0;

            while (rdr.Read())
            {
                //mirFleet.fleetManager.Missions[i] = new Mirage.rest.Mission();
                string guid        = rdr.GetString(2);
                string name        = rdr.GetString(3);
                string description = rdr.GetString(4);
                string hidden      = rdr.GetString(5);
                string group_id    = rdr.GetString(6);
                string created_by  = rdr.GetString(7);
                string url_string  = rdr.GetString(8);

                mirFleet.fleetManager.Missions[i].missionNumber = i;
                mirFleet.fleetManager.Missions[i].guid          = guid;
                mirFleet.fleetManager.Missions[i].name          = name;
                mirFleet.fleetManager.Missions[i].description   = description;
                mirFleet.fleetManager.Missions[i].hidden        = hidden;
                mirFleet.fleetManager.Missions[i].group_id      = group_id;
                mirFleet.fleetManager.Missions[i].created_by_id = created_by;
                mirFleet.fleetManager.Missions[i].url_string    = url_string;

/*                if(i > 61)
 *              {
 *                  mirFleet.fleetManager.sendRESTdata(mirFleet.fleetManager.Missions[i].postRequest(true));
 *              }*/

                if (resumingSession == false)
                {
                    logger(AREA, DEBUG, "Row: " + rdr.GetInt32(0) + " - GUID: " + guid + " - Name: " + name + "Desc: " + description + "Hidden: " + hidden + " group_id: " + group_id + " created_by: " + created_by + " URL: " + url_string);

                    mirFleet.fleetManager.sendRESTdata(mirFleet.fleetManager.Missions[i].postRequest(true));
                }

                Thread.Sleep(50);
                i++;
            }

            logger(AREA, DEBUG, "Finished Initializing Missions");
        }
        catch (Exception e)
        {
            logger(AREA, DEBUG, "Failed a query: ", e);
        }

        mirFleet.getFleetRobotIDs();

        logger(AREA, INFO, "Finished Fleet Initialization");
    }