Пример #1
0
        private int ReadDictionary(string input, int index)
        {
            index++;
            Content = new Dictionary<string, PrimitiveJSONObject>();
            while (true)
            {
                string key;
                if (input[index] == '\"')
                {
                    PrimitiveJSONObject sub = new PrimitiveJSONObject();
                    index = sub.Read(input, index);
                    key = sub.Value;
                }
                else if (input[index] == '}')
                {
                    return ++index;
                }
                else
                {
                    throw new Exception("Bad JSON format.");
                }

                if (input[index] == ':')
                {
                    index++;
                }
                else
                {
                    throw new Exception("Bad JSON format.");
                }

                if (input[index] == '{' || input[index] == '[' || input[index] == '\"')
                {
                    PrimitiveJSONObject sub = new PrimitiveJSONObject();
                    index = sub.Read(input, index);
                    Content[key] = sub;

                    if (input[index] == ',')
                    {
                        index++;
                    }
                }
                else
                {
                    int index2 = input.IndexOf(',', index);
                    Content[key] = new PrimitiveJSONObject("\"" + input.Substring(index, index2 - index) + "\"", 0);
                    index = index2 + 1;
                }
            }
        }
Пример #2
0
        private void GetInfoFieldID()
        {
            HttpClient client = new HttpClient();
            //client.BaseAddress = new Uri("http://www.elitegalaxyonline.com/gravityformsapi/forms/24/submissions");
            //client.PostAsync("http://www.elitegalaxyonline.com/gravityformsapi/forms/24/submissions", "");
            Task<HttpResponseMessage> task = client.GetAsync("http://www.elitegalaxyonline.com/api/ego_submissions/field_list/");
            task.Wait();
            HttpResponseMessage message = task.Result;
            Task<string> task2 = message.Content.ReadAsStringAsync();
            string test = task2.Result;

            field_id = new Dictionary<string, string>();
            PrimitiveJSONObject pjo = new PrimitiveJSONObject(test, 0);
            PrimitiveJSONObject[] array = pjo.Content["field_list"].Array;
            foreach (PrimitiveJSONObject obj in array)
            {
                field_id[obj.Content["field_name"].Value] = obj.Content["field_input_id"].Value;
            }


            starTypes = new Dictionary<string, string>();
            starTypes["ClassO"] = "Class O Star";
            starTypes["ClassB"] = "Class B Star";
            starTypes["ClassA"] = "Class A Star";
            starTypes["ClassF"] = "Class F Star";
            starTypes["ClassG"] = "Class G Star";
            starTypes["ClassK"] = "Class K Star";
            starTypes["ClassM"] = "Class M Star";
            starTypes["ClassL"] = "Class L Star";
            starTypes["ClassT"] = "Class T Star";
            starTypes["ClassY"] = "Class Y Star";
            starTypes["ClassTT"] = "T Tauri Type Star";
            starTypes["ClassS"] = "Class S Star";
            starTypes["ClassGK"] = "Orange Giant";
            starTypes["ClassGF"] = "Yellow-White Supergiant";
            starTypes["ClassGA"] = "Blue-White Supergiant";
            starTypes["ClassGM"] = "Red Giant";
            starTypes["ClassMS"] = "MS Class Star";
            starTypes["ClassC"]="Carbon Star";
            starTypes["ClassCN"] = "C-N Class Star";
            starTypes["ClassSGM"] = "Red Supergiant";
            starTypes["ClassH"] = "AE\\/BE Class Star";
            starTypes["ClassW"] = "Wolf-Rayet Star";
            starTypes["ClassDA"] = "White Dwarf - DA Class";
            starTypes["ClassDB"] = "White Dwarf - DB Class";
            starTypes["ClassDAB"] = "White Dwarf - DAB Class";
            starTypes["ClassDC"] = "White Dwarf - DC Class";
            starTypes["ClassDCV"] = "White Dwarf - DCV Class";
            starTypes["ClassN"]="Neutron Star";
            starTypes["ClassBH"]="Black Hole";
            starTypes["ClassSB"]="Supermassive Black Hole";

            giantTypes = new Dictionary<string, string>();
            giantTypes["Giant1"] = "Class I Gas Giant";
            giantTypes["Giant2"] = "Class II Gas Giant";
            giantTypes["Giant3"] = "Class III Gas Giant";
            giantTypes["Giant4"] = "Class IV Gas Giant";
            giantTypes["Giant5"] = "Class V Gas Giant";
            giantTypes["GiantH"] = "Helium-rich";
            giantTypes["GiantAL"] = "Gas giant with ammonia-based life";
            giantTypes["GiantWL"] = "Gas giant with water-based life";                                     
            giantTypes["GiantW"] = "Water Giant";

            planetTypes = new Dictionary<string, string>();
            planetTypes["PlanetI"] = "Icy planet";
            planetTypes["PlanetR"] = "Rocky planet";
            planetTypes["PlanetRI"] = "Rocky ice planet";
            planetTypes["PlanetM"] = "High metal content planet";
            planetTypes["PlanetMR"] = "Metal rich planet";
            planetTypes["PlanetW"] = "Water world";
            planetTypes["PlanetT"] = "Earth-like world";
            planetTypes["PlanetA"] = "Ammonia world";

            atmosphereTypes = new Dictionary<string, string>();
            atmosphereTypes["AMMONIA"] = "Ammonia";
            atmosphereTypes["AMMONIA AND OXYGEN"] = "Ammonia and Oxygen";
            atmosphereTypes["ARGON"] = "Argon";
            atmosphereTypes["ARGON-RICH"] = "Argon-Rich";
            atmosphereTypes["CARBON DIOXIDE"] = "Carbon Dioxide";
            atmosphereTypes["CARBON DIOXIDE-RICH"] = "Carbon Dioxide-Rich";
            atmosphereTypes["HELIUM"] = "Helium";
            atmosphereTypes["METHANE"] = "Methane";
            atmosphereTypes["METHANE-RICH"] = "Methane-Rich";
            atmosphereTypes["NEON"] = "Neon";
            atmosphereTypes["NEON-RICH"] = "Neon-Rich";
            atmosphereTypes["NITROGEN"] = "Nitrogen";
            atmosphereTypes["NITROGEN-RICH"] = "Nitrogen-Rich";
            atmosphereTypes["NO ATMOSPHERE"] = "No Atmosphere";
            atmosphereTypes["SILICATE VAPOUR"] = "Silicate Vapour";
            atmosphereTypes["SUITABLE FOR WATER BASED LIFE"] = "Suitable For Water-Based Life";
            atmosphereTypes["SULPHUR DIOXIDE"] = "Sulphur Dioxide";
            atmosphereTypes["WATER"] = "Water";
            atmosphereTypes["WATER-RIC"] = "Water-Rich";

            volcanismTypes = new Dictionary<string, string>();
            volcanismTypes["CARBON DIOXIDE GEYSERS"] = "Carbon Dioxide Geysers";
            volcanismTypes["IRON MAGMA"] = "Iron Magma";
            volcanismTypes["METHANE MAGMA"] = "Methane Magma";
            volcanismTypes["NITROGEN MAGMA"] = "Nitrogen Magma";
            volcanismTypes["NO VOLCANISM"] = "No Volcanism";
            volcanismTypes["SILICATE MAGMA"] = "Silicate Magma";
            volcanismTypes["SILICATE VAPOUR GEYSERS"] = "Silicate Vapour Geysers";
            volcanismTypes["WATER GEYSERS"] = "Water Geysers";
            volcanismTypes["WATER MAGMA"] = "Water Magma";

            compositionElements = new Dictionary<string, string>();
            compositionElements["ICE"] = "ice";
            compositionElements["ROCK"] = "rock";
            compositionElements["METAL"] = "metal";

            atmosphereElements = new Dictionary<string, string>();
            atmosphereElements["CARBON DIOXIDE"] = "carbon_dioxide";
            atmosphereElements["WATER"] = "water";
            atmosphereElements["NITROGEN"] = "nitrogen";
            atmosphereElements["HYDROGEN"] = "hydrogen";
            atmosphereElements["HELIUM"] = "helium";
            atmosphereElements["SULPHUR DIOXIDE"] = "sulphur_dioxide";
            atmosphereElements["ARGON"] = "argon";
            atmosphereElements["OXYGEN"] = "oxygen";
            atmosphereElements["AMMONIA"] = "ammonia";
            atmosphereElements["NEON"] = "neon";
            atmosphereElements["SILICATES"] = "silicates";
            atmosphereElements["IRON"] = "iron";

            compositionOrder = new List<string>(new string[] { "ICE", "ROCK", "METAL" });
            atmosphereOrder = new List<string>(new string[] { "CARBON DIOXIDE", "WATER", "NITROGEN", "HYDROGEN", "HELIUM", "SULPHUR DIOXIDE", 
                                             "ARGON", "OXYGEN", "METHANE", "AMMONIA", "NEON", "SILICATES", "IRON" });

        }
Пример #3
0
 private int ReadArray(string input, int index)
 {
     index++;
     List<PrimitiveJSONObject> objects = new List<PrimitiveJSONObject>();
     while (true)
     {
         if (input[index] == '{' || input[index] == '[' || input[index] == '\"')
         {
             PrimitiveJSONObject sub = new PrimitiveJSONObject();
             index = sub.Read(input, index);
             objects.Add(sub);
             if (input[index] == ',')
             {
                 index++;
             }
         }
         else if (input[index] == ']')
         {
             index++;
             break;
         }
         else
         {
             throw new Exception("Bad JSON format.");
         }
     }
     Array = objects.ToArray();
     return index;
 }
Пример #4
0
        public void WebTransferItems(TransferItem[] items)
        {
            if (field_id == null)
            {
                GetInfoFieldID();
            }

            errorString = "";
            Dictionary<string, string> requestValues = new Dictionary<string, string>();
            try
            {
                // Build dictionary of POST request items
                CreateRequestValues(items, requestValues);
            }
            catch (Exception ex)
            {
                if (errorString != "")
                {
                    MessageBox.Show(errorString);
                    return;
                }
                else
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }

            // Build string for the API POST request from the dictionary.
            string content = "{" + Environment.NewLine +
                "\"input_values\":{" + Environment.NewLine;
            foreach(string key in requestValues.Keys)
            {
                content += "\""+key + "\":\"" + requestValues[key]+"\","+Environment.NewLine;
            }
            content = content.Substring(0, content.Length - (1+Environment.NewLine.Length));
            content += "}"+Environment.NewLine+"}";

            string response = "";
            try
            {
                // Network interaction
                HttpClient client = new HttpClient();
                Task<HttpResponseMessage> task = client.PostAsync(Properties.Settings.Default.APIServer, new StringContent(content));
                task.Wait();
                HttpResponseMessage message = task.Result;
                Task<string> task2 = message.Content.ReadAsStringAsync();
                response = task2.Result;
            }
            catch(Exception ex)
            {
                MessageBox.Show("Server response was not processed: "+ex.Message);
            }

            try
            {
                // Parse the server response string.
                PrimitiveJSONObject json = new PrimitiveJSONObject(response, 0);
                string feedback = "";
                if (json.Content["status"].Value != "200")
                {
                    feedback = "Something went wrong with the network. HTTP says: "+json.Content["status"].Value;
                }
                else if (json.Content["response"].Content["is_valid"].Value != "true")
                {
                    feedback = "Not a valid submission. Error messages: " + Environment.NewLine;
                    foreach (PrimitiveJSONObject err in json.Content["response"].Content["validation_messages"].Content.Values)
                    {
                        feedback += err.Value + Environment.NewLine;
                    }
                }
                else
                {
                    feedback = "Success.";
                }

                MessageBox.Show(feedback);
            }
            catch
            {
                MessageBox.Show("Unable to parse server response:"+Environment.NewLine+response);
            }
        }