Beispiel #1
0
        public void Save()
        {
            foreach (DataGridViewRow row in dataGridViewPlanet.Rows)
            {
                EDWorld edobj = (EDWorld)row.Tag;


                edobj.objectName = row.Cells[0].Value.ToString();


                foreach (var cell in row.Cells)
                {
                    if (cell is DataGridViewCheckBoxCell)
                    {
                        DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)cell;
                        if (chk.OwningColumn.Tag is Material)
                        {
                            Material mat = (Material)chk.OwningColumn.Tag;
                            //bool val = false;

                            //if (chk.Value != null && (bool)chk.Value == true)
                            //    val = true;

                            //edobj.materials[mat.material] = val;
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public ResponseData Delete(EDWorld obj)
 {
     if (obj.id > 0)
         return Delete(obj.id);
     else
         return new ResponseData(HttpStatusCode.NotFound);
 }
Beispiel #3
0
        public List<EDWorld> GetAll(string scope)
        {
            List<EDWorld> listObjects = new List<EDWorld>();
            string query = ApiNamespace + "/worlds";

            if (!String.IsNullOrEmpty(scope))
                query = query + "?" + scope;

            var response = RequestGet(query);
            var json = response.Body;

            JArray jArray = null;
            JObject jObject = null;
            if (json != null && json.Length > 5)
                jObject = (JObject)JObject.Parse(json);

            if (jObject == null)
                return listObjects;

            jArray = (JArray)jObject["data"];

            foreach (JObject jo in jArray)
            {
                EDWorld obj = new EDWorld();

                if (obj.ParseJson((JObject)jo))
                    listObjects.Add(obj);
            }

            return listObjects;
        }
Beispiel #4
0
 public ResponseData Delete(EDWorld obj)
 {
     if (obj.id > 0)
     {
         return(Delete(obj.id));
     }
     else
     {
         return(new ResponseData(HttpStatusCode.NotFound));
     }
 }
Beispiel #5
0
        public EDWorld GetForId(int id)
        {
            if (id > 0)
            {
                var request = RequestGet($"{ApiNamespace}/worlds/{id}");
                if (request.StatusCode == HttpStatusCode.OK)
                {
                    var     jo   = JObject.Parse(request.Body);
                    var     data = jo["data"];
                    EDWorld obj  = new EDWorld();

                    return((obj.ParseJson((JObject)data)) ? obj : null);
                }
            }

            return(null);
        }
Beispiel #6
0
        private void toolStripButtonAddPlanet_Click(object sender, EventArgs e)
        {
            int nr = dataGridViewPlanet.Rows.Add();

            DataGridViewRow newRow = (DataGridViewRow)dataGridViewPlanet.Rows[nr];

            DataGridViewComboBoxCell cmbCell = (DataGridViewComboBoxCell)newRow.Cells[1];

            cmbCell.Value = dictComboShortNames[0];
            cmbCell       = (DataGridViewComboBoxCell)newRow.Cells[3];
            cmbCell.Value = "Unknown";

            var edobj = new EDWorld();

            edobj.system = currentSystem;
            dataGridViewPlanet.Rows[nr].Tag = edobj;
        }
Beispiel #7
0
        public List <EDWorld> GetAll(string scope)
        {
            List <EDWorld> listObjects = new List <EDWorld>();
            string         query       = ApiNamespace + "/worlds";

            if (!String.IsNullOrEmpty(scope))
            {
                query = query + "?" + scope;
            }

            var response = RequestGet(query);
            var json     = response.Body;

            JArray  jArray  = null;
            JObject jObject = null;

            if (json != null && json.Length > 5)
            {
                jObject = (JObject)JObject.Parse(json);
            }

            if (jObject == null)
            {
                return(listObjects);
            }

            jArray = (JArray)jObject["data"];

            foreach (JObject jo in jArray)
            {
                EDWorld obj = new EDWorld();

                if (obj.ParseJson((JObject)jo))
                {
                    listObjects.Add(obj);
                }
            }

            return(listObjects);
        }
Beispiel #8
0
        public ResponseData Store(EDWorld edobj)
        {
            dynamic jo = new JObject();

            var joPost = new JObject {
                { "data", new JObject {
                      { "type", "worlds" },
                      { "attributes", new JObject {
                            { "system-name", edobj.system },
                            { "updater", EDDiscoveryForm.EDDConfig.CurrentCommander.Name },
                            { "world-type", edobj.Description },
                            { "mass", edobj.mass },
                            { "radius", edobj.radius },
                            { "gravity", edobj.gravity },
                            { "surface-temp", edobj.surfaceTemp },
                            { "surface-pressure", edobj.surfacePressure },
                            { "orbit-period", edobj.orbitPeriod },
                            { "rotation-period", edobj.rotationPeriod },
                            { "semi-major-axis", edobj.semiMajorAxis },
                            { "terrain-difficulty", edobj.terrain_difficulty },
                            { "vulcanism-type", edobj.vulcanism.ToNullSafeString() },
                            { "rock-pct", edobj.rockPct },
                            { "metal-pct", edobj.metalPct },
                            { "ice-pct", edobj.icePct },
                            { "reserve", edobj.Reserve },
                            { "arrival-point", edobj.arrivalPoint },
                            { "terraformable", edobj.terraformable },
                            { "atmosphere-type", edobj.atmosphere.ToNullSafeString() },
                            { "notes", edobj.notes },
                            { "images-url", edobj.imageUrl },
                        } }
                  } }
            };


            ResponseData response;

            if (edobj.id == 0)
            {
                response = RequestSecurePost(joPost.ToString(), $"{ApiNamespace}/worlds");
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject jo2 = (JObject)JObject.Parse(response.Body);
                    JObject obj = (JObject)jo2["data"];
                    edobj.id = obj["id"].Value <int>();
                }
                else if ((int)response.StatusCode == 422)
                {
                    var queryParams = $"system={jo.system}&world={jo.world}";
                    var response2   = RequestGet($"{ApiNamespace}/worlds?{queryParams}");
                    if (response2.StatusCode == HttpStatusCode.OK)
                    {
                        JObject jo2   = (JObject)JObject.Parse(response2.Body);
                        JArray  items = (JArray)jo2["data"];
                        if (items.Count > 0)
                        {
                            edobj.id = items[0]["id"].Value <int>();
                            JObject jData = (JObject)joPost["data"];
                            jData["id"] = edobj.id;
                            response2   = RequestSecurePatch(joPost.ToString(), $"{ApiNamespace}/worlds/" + edobj.id.ToString());
                            response    = response2;
                        }
                    }
                }
            }
            else
            {
                response = RequestSecurePatch(joPost.ToString(), $"{ApiNamespace}/worlds/" + edobj.id.ToString());
            }
            return(response);
        }
Beispiel #9
0
        public EDWorld GetForId(int id)
        {
            if (id > 0)
            {
                var request = RequestGet($"{ApiNamespace}/worlds/{id}");
                if (request.StatusCode == HttpStatusCode.OK)
                {
                    var jo = JObject.Parse(request.Body);
                    var data = jo["data"];
                    EDWorld obj = new EDWorld();

                    return (obj.ParseJson((JObject)data)) ? obj : null;
                }
            }

            return null;
        }
Beispiel #10
0
        public ResponseData Store(EDWorld edobj)
        {
            dynamic jo = new JObject();

            var joPost = new JObject {
                { "data", new JObject {
                    { "type", "worlds" },
                    { "attributes", new JObject {
                        { "system-name", edobj.system },
                        { "updater", EDDiscoveryForm.EDDConfig.CurrentCommander.Name },
                        { "world-type", edobj.Description },
                        { "mass", edobj.mass },
                        { "radius", edobj.radius },
                        { "gravity", edobj.gravity },
                        { "surface-temp", edobj.surfaceTemp },
                        { "surface-pressure", edobj.surfacePressure },
                        { "orbit-period", edobj.orbitPeriod },
                        { "rotation-period", edobj.rotationPeriod },
                        { "semi-major-axis", edobj.semiMajorAxis },
                        { "terrain-difficulty", edobj.terrain_difficulty },
                        { "vulcanism-type", edobj.vulcanism.ToNullSafeString() },
                        { "rock-pct", edobj.rockPct },
                        { "metal-pct", edobj.metalPct },
                        { "ice-pct", edobj.icePct },
                        { "reserve", edobj.Reserve },
                        { "arrival-point", edobj.arrivalPoint },
                        { "terraformable", edobj.terraformable },
                        { "atmosphere-type", edobj.atmosphere.ToNullSafeString() },
                        { "notes", edobj.notes },
                        { "images-url", edobj.imageUrl },
                    } }
                } }
            };

            ResponseData response;
            if (edobj.id == 0)
            {
                response = RequestSecurePost(joPost.ToString(), $"{ApiNamespace}/worlds");
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject jo2 = (JObject)JObject.Parse(response.Body);
                    JObject obj = (JObject)jo2["data"];
                    edobj.id = obj["id"].Value<int>();
                }
                    else if ((int)response.StatusCode == 422)
                {
                    var queryParams = $"system={jo.system}&world={jo.world}";
                    var response2 = RequestGet($"{ApiNamespace}/worlds?{queryParams}");
                    if (response2.StatusCode == HttpStatusCode.OK)
                    {
                        JObject jo2 = (JObject)JObject.Parse(response2.Body);
                        JArray items = (JArray)jo2["data"];
                        if (items.Count > 0)
                        {
                            edobj.id = items[0]["id"].Value<int>();
                            JObject jData = (JObject)joPost["data"];
                            jData["id"] = edobj.id;
                            response2 = RequestSecurePatch(joPost.ToString(), $"{ApiNamespace}/worlds/" + edobj.id.ToString());
                            response = response2;
                        }
                    }
                }
            }
            else
            {
                response = RequestSecurePatch(joPost.ToString(), $"{ApiNamespace}/worlds/" + edobj.id.ToString());
            }
            return response;
        }