Exemple #1
0
        public void OnJSONObjectReceived(JSONObject p0)
        {
            string option = p0.GetString("option");
            Intent intent;

            if (option == "add")
            {
                intent = new Intent(Activity, typeof(AddAMarkActivity));
                StartActivity(intent);
            }
            else if (option == "rate")
            {
                intent = new Intent(Activity, typeof(RateAMarkActivity));
                intent.PutExtra("markId", p0.GetString("markId"));
                StartActivity(intent);
            }
            else if (option == "getMarks")
            {
                double longitude = p0.GetDouble("longitude");
                double latitude  = p0.GetDouble("latitude");
                getMarks(longitude, latitude);
            }
            else if (option == "seen")
            {
                User.UpdateMarkSeen(p0.GetString("markId"));
            }
        }
Exemple #2
0
        public List <MyItem> read(Stream inputStream)
        {
            List <MyItem> items = new List <MyItem>();
            string        json  = new Scanner(inputStream).UseDelimiter(REGEX_INPUT_BOUNDARY_BEGINNING).Next();
            JSONArray     array = new JSONArray(json);

            for (int i = 0; i < array.Length(); i++)
            {
                string     title      = null;
                string     snippet    = null;
                JSONObject jsonObject = array.GetJSONObject(i);
                double     lat        = jsonObject.GetDouble("lat");
                double     lng        = jsonObject.GetDouble("lng");
                if (!jsonObject.IsNull("title"))
                {
                    title = jsonObject.GetString("title");
                }
                if (!jsonObject.IsNull("snippet"))
                {
                    snippet = jsonObject.GetString("snippet");
                }
                items.Add(new MyItem(lat, lng, title, snippet));
            }
            return(items);
        }
Exemple #3
0
        // Datasets from http://data.gov.au
        private List <LatLng> readItems(int resource)
        {
            List <LatLng> list        = new List <LatLng>();
            Stream        inputStream = Resources.OpenRawResource(resource);
            string        json        = new Scanner(inputStream).UseDelimiter("\\A").Next();
            JSONArray     array       = new JSONArray(json);

            for (int i = 0; i < array.Length(); i++)
            {
                JSONObject jsonObject = array.GetJSONObject(i);
                double     lat        = jsonObject.GetDouble("lat");
                double     lng        = jsonObject.GetDouble("lng");
                list.Add(new LatLng(lat, lng));
            }
            return(list);
        }
Exemple #4
0
        public void RatingDurumYenile()
        {
            new System.Threading.Thread(new System.Threading.ThreadStart(delegate
            {
                WebService webService = new WebService();
                var Donus             = webService.OkuGetir("locations/" + SecilenLokasyonn.LokID);
                if (Donus != null)
                {
                    var aa        = Donus.ToString();
                    JSONObject js = new JSONObject(Donus.ToString());
                    var Rating    = js.GetDouble("rating");

                    this.RunOnUiThread(() =>
                    {
                        SecilenLokasyonn.Rate = Rating;
                        if (Convert.ToDouble(SecilenLokasyonn.Rate) >= 10)
                        {
                            ratingButton.Text = "10";
                        }
                        else
                        {
                            ratingButton.Text = Math.Round(Convert.ToDouble(SecilenLokasyonn.Rate), 1).ToString();
                        }
                    });
                }
            })).Start();
        }
        /**
         * Makes four radar search requests for the given keyword, then parses the
         * json output and returns the search results as a collection of LatLng objects.
         *
         * @param keyword A string to use as a search term for the radar search
         * @return Returns the search results from radar search as a collection
         * of LatLng objects.
         */
        private List <LatLng> getPoints(string keyword)
        {
            Dictionary <string, LatLng> results = new Dictionary <string, LatLng>();

            // Calculate four equidistant points around Sydney to use as search centers
            //   so that four searches can be done.
            List <LatLng> searchCenters = new List <LatLng>(4);

            for (int heading = 45; heading < 360; heading += 90)
            {
                searchCenters.Add(SphericalUtil.ComputeOffset(SYDNEY, SEARCH_RADIUS / 2, heading));
            }

            for (int j = 0; j < 4; j++)
            {
                string jsonResults = getJsonPlaces(keyword, searchCenters[j]);
                try
                {
                    // Create a JSON object hierarchy from the results
                    JSONObject jsonObj         = new JSONObject(jsonResults);
                    JSONArray  pointsJsonArray = jsonObj.GetJSONArray("results");

                    // Extract the Place descriptions from the results
                    for (int i = 0; i < pointsJsonArray.Length(); i++)
                    {
                        if (!results.ContainsKey(pointsJsonArray.GetJSONObject(i).GetString("id")))
                        {
                            JSONObject location = pointsJsonArray.GetJSONObject(i)
                                                  .GetJSONObject("geometry").GetJSONObject("location");
                            results.Add(pointsJsonArray.GetJSONObject(i).GetString("id"),
                                        new LatLng(location.GetDouble("lat"),
                                                   location.GetDouble("lng")));
                        }
                    }
                }
                catch (JSONException)
                {
                    Toast.MakeText(this, "Cannot process JSON results", ToastLength.Short).Show();
                }
            }
            return(results.Values.ToList());
        }
Exemple #6
0
 static double GetDouble(JSONObject jsonObject, string name)
 {
     try
     {
         return(jsonObject.GetDouble(name));
     }
     catch
     {
         return(-1);
     }
 }
        private PolylineOptions JSONRuta()
        {
            PolylineOptions lineOptions = new PolylineOptions();


            try
            {
                JSONObject json = rutaEntreDosPuntos(getDirectionsUrl(currentLocation, new LatLng(lat, lng)));

                if (json != null)
                {
                    JSONArray ruta      = json.GetJSONArray("routes").GetJSONObject(0).GetJSONArray("legs").GetJSONObject(0).GetJSONArray("steps");
                    int       numTramos = ruta.Length();
                    for (int i = 0; i < numTramos; i++)
                    {
                        JSONObject puntosCodificados = ruta.GetJSONObject(i).GetJSONObject("start_location");
                        lineOptions.Add(new LatLng(puntosCodificados.GetDouble("lat"), puntosCodificados.GetDouble("lng")));

                        puntosCodificados = ruta.GetJSONObject(i).GetJSONObject("polyline");
                        List <LatLng> arr = decodePoly(puntosCodificados.GetString("points"));

                        foreach (LatLng pos in arr)
                        {
                            lineOptions.Add(pos);
                        }
                        puntosCodificados = ruta.GetJSONObject(i).GetJSONObject("end_location");
                        lineOptions.Add(new LatLng(puntosCodificados.GetDouble("lat"), puntosCodificados.GetDouble("lng")));
                    }
                }
            }
            catch (JSONException e)
            {
                throw e;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(lineOptions);
        }
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        private void VerifySubQueue(JSONObject info, string q, float parentAbsCapacity, float
                                    parentAbsMaxCapacity)
        {
            int  numExpectedElements = 13;
            bool isParentQueue       = true;

            if (!info.Has("queues"))
            {
                numExpectedElements = 25;
                isParentQueue       = false;
            }
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", numExpectedElements
                                            , info.Length());
            TestRMWebServicesCapacitySched.QueueInfo qi = isParentQueue ? new TestRMWebServicesCapacitySched.QueueInfo
                                                              (this) : new TestRMWebServicesCapacitySched.LeafQueueInfo(this);
            qi.capacity             = (float)info.GetDouble("capacity");
            qi.usedCapacity         = (float)info.GetDouble("usedCapacity");
            qi.maxCapacity          = (float)info.GetDouble("maxCapacity");
            qi.absoluteCapacity     = (float)info.GetDouble("absoluteCapacity");
            qi.absoluteMaxCapacity  = (float)info.GetDouble("absoluteMaxCapacity");
            qi.absoluteUsedCapacity = (float)info.GetDouble("absoluteUsedCapacity");
            qi.numApplications      = info.GetInt("numApplications");
            qi.queueName            = info.GetString("queueName");
            qi.state = info.GetString("state");
            VerifySubQueueGeneric(q, qi, parentAbsCapacity, parentAbsMaxCapacity);
            if (isParentQueue)
            {
                JSONArray arr = info.GetJSONObject("queues").GetJSONArray("queue");
                // test subqueues
                for (int i = 0; i < arr.Length(); i++)
                {
                    JSONObject obj = arr.GetJSONObject(i);
                    string     q2  = q + "." + obj.GetString("queueName");
                    VerifySubQueue(obj, q2, qi.absoluteCapacity, qi.absoluteMaxCapacity);
                }
            }
            else
            {
                TestRMWebServicesCapacitySched.LeafQueueInfo lqi = (TestRMWebServicesCapacitySched.LeafQueueInfo
                                                                    )qi;
                lqi.numActiveApplications  = info.GetInt("numActiveApplications");
                lqi.numPendingApplications = info.GetInt("numPendingApplications");
                lqi.numContainers          = info.GetInt("numContainers");
                lqi.maxApplications        = info.GetInt("maxApplications");
                lqi.maxApplicationsPerUser = info.GetInt("maxApplicationsPerUser");
                lqi.userLimit       = info.GetInt("userLimit");
                lqi.userLimitFactor = (float)info.GetDouble("userLimitFactor");
                VerifyLeafQueueGeneric(q, lqi);
            }
        }
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        private void VerifyClusterScheduler(JSONObject json)
        {
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject info = json.GetJSONObject("scheduler");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, info.Length());
            info = info.GetJSONObject("schedulerInfo");
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 6, info.Length());
            VerifyClusterSchedulerGeneric(info.GetString("type"), (float)info.GetDouble("usedCapacity"
                                                                                        ), (float)info.GetDouble("capacity"), (float)info.GetDouble("maxCapacity"), info
                                          .GetString("queueName"));
            JSONArray arr = info.GetJSONObject("queues").GetJSONArray("queue");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 2, arr.Length());
            // test subqueues
            for (int i = 0; i < arr.Length(); i++)
            {
                JSONObject obj = arr.GetJSONObject(i);
                string     q   = CapacitySchedulerConfiguration.Root + "." + obj.GetString("queueName");
                VerifySubQueue(obj, q, 100, 100);
            }
        }
Exemple #10
0
        public static void SendEvent(BranchEvent e, Context c)
        {
            IO.Branch.Referral.Util.BranchEvent branchEvent = null;
            JSONObject parameters = new JSONObject(e.ToJsonString());


            if (parameters.Has("event_name"))
            {
                // try to create standart event
                foreach (IO.Branch.Referral.Util.BRANCH_STANDARD_EVENT type in IO.Branch.Referral.Util.BRANCH_STANDARD_EVENT.Values())
                {
                    if (type.Name.Equals(parameters.GetString("event_name")))
                    {
                        branchEvent = new IO.Branch.Referral.Util.BranchEvent(type);
                        break;
                    }
                }

                // if standart event can't be created, let's create custom event
                if (branchEvent == null)
                {
                    branchEvent = new IO.Branch.Referral.Util.BranchEvent(parameters.GetString("event_name"));
                }
            }
            else
            {
                return;
            }

            if (parameters.Has("transaction_id"))
            {
                branchEvent.SetTransactionID(parameters.GetString("transaction_id"));
            }

            if (parameters.Has("customer_event_alias"))
            {
                branchEvent.SetCustomerEventAlias(parameters.GetString("customer_event_alias"));
            }

            if (parameters.Has("affiliation"))
            {
                branchEvent.SetAffiliation(parameters.GetString("affiliation"));
            }

            if (parameters.Has("coupon"))
            {
                branchEvent.SetCoupon(parameters.GetString("coupon"));
            }

            if (parameters.Has("currency"))
            {
                branchEvent.SetCurrency(IO.Branch.Referral.Util.CurrencyType.GetValue(parameters.GetString("currency")));
            }

            if (parameters.Has("tax"))
            {
                branchEvent.SetTax(parameters.GetDouble("tax"));
            }

            if (parameters.Has("revenue"))
            {
                branchEvent.SetRevenue(parameters.GetDouble("revenue"));
            }

            if (parameters.Has("description"))
            {
                branchEvent.SetDescription(parameters.GetString("description"));
            }

            if (parameters.Has("shipping"))
            {
                branchEvent.SetRevenue(parameters.GetDouble("shipping"));
            }

            if (parameters.Has("search_query"))
            {
                branchEvent.SetSearchQuery(parameters.GetString("search_query"));
            }

            if (parameters.Has("custom_data"))
            {
                JSONObject          dict = parameters.GetJSONObject("custom_data");
                Java.Util.IIterator keys = dict.Keys();
                while (keys.HasNext)
                {
                    String key = keys.Next().ToString();
                    branchEvent.AddCustomDataProperty(key, dict.GetString(key));
                }
            }

            if (parameters.Has("content_items"))
            {
                JSONArray array = parameters.GetJSONArray("content_items");
                for (int i = 0; i < array.Length(); i++)
                {
                    branchEvent.AddContentItems(ToNativeBUO(new BranchUniversalObject(array.Get(i).ToString())));
                }
            }

            // log event
            branchEvent.LogEvent(c);
        }
Exemple #11
0
 /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
 public virtual void VerifyHsTaskAttempt(JSONObject info, TaskAttempt att, TaskType
                                         ttype)
 {
     if (ttype == TaskType.Reduce)
     {
         NUnit.Framework.Assert.AreEqual("incorrect number of elements", 17, info.Length()
                                         );
     }
     else
     {
         NUnit.Framework.Assert.AreEqual("incorrect number of elements", 12, info.Length()
                                         );
     }
     VerifyTaskAttemptGeneric(att, ttype, info.GetString("id"), info.GetString("state"
                                                                               ), info.GetString("type"), info.GetString("rack"), info.GetString("nodeHttpAddress"
                                                                                                                                                 ), info.GetString("diagnostics"), info.GetString("assignedContainerId"), info.GetLong
                                  ("startTime"), info.GetLong("finishTime"), info.GetLong("elapsedTime"), (float)info
                              .GetDouble("progress"));
     if (ttype == TaskType.Reduce)
     {
         VerifyReduceTaskAttemptGeneric(att, info.GetLong("shuffleFinishTime"), info.GetLong
                                            ("mergeFinishTime"), info.GetLong("elapsedShuffleTime"), info.GetLong("elapsedMergeTime"
                                                                                                                  ), info.GetLong("elapsedReduceTime"));
     }
 }
Exemple #12
0
 /**
  * read maps packages list
  * @param maps a list of maps objects that will be read from JSON file
  * @param packagesArray packages array
  */
 private void readMapsPackages(List <MapDownloadResource> maps, JSONArray packagesArray)
 {
     for (int i = 0; i < packagesArray.Length(); i++)
     {
         JSONObject currentPackageObject = null;
         try
         {
             currentPackageObject = packagesArray.GetJSONObject(i);
         }
         catch (JSONException ex)
         {
             SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
         }
         if (currentPackageObject != null)
         {
             MapDownloadResource currentMap = new MapDownloadResource();
             try
             {
                 currentMap.Code = (currentPackageObject.GetString(PACKAGE_CODE_ID));
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             try
             {
                 currentMap.setSubType(GetMapType(currentPackageObject.GetInt(TYPE_ID)));
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             try
             {
                 JSONArray currentMapNames = currentPackageObject.GetJSONArray(LANGUAGES_ID);
                 if (currentMapNames != null)
                 {
                     for (int j = 0; j < currentMapNames.Length(); j++)
                     {
                         JSONObject currentMapNameObject = currentMapNames.GetJSONObject(j);
                         if (currentMapNameObject != null)
                         {
                             String currentMapName = currentMapNameObject.GetString(TL_NAME_ID);
                             if (currentMapName != null)
                             {
                                 currentMap.setName(currentMapName, currentMapNameObject.GetString(LNG_CODE_ID));
                             }
                         }
                     }
                 }
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             try
             {
                 JSONObject currentMapBoundingBox = currentPackageObject.GetJSONObject(BBOX_ID);
                 if (currentMapBoundingBox != null)
                 {
                     currentMap.setBbLatMax(currentMapBoundingBox.GetDouble(LAT_MAX_ID));
                     currentMap.setBbLatMin(currentMapBoundingBox.GetDouble(LAT_MIN_ID));
                     currentMap.setBbLongMax(currentMapBoundingBox.GetDouble(LONG_MAX_ID));
                     currentMap.setBbLongMin(currentMapBoundingBox.GetDouble(LONG_MIN_ID));
                 }
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             try
             {
                 currentMap.setSkmFileSize(currentPackageObject.GetLong(SKM_SIZE_ID));
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             try
             {
                 currentMap.setSkmFilePath(currentPackageObject.GetString(FILE_ID));
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             try
             {
                 currentMap.setZipFilePath(currentPackageObject.GetString(NB_ZIP_ID));
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             try
             {
                 currentMap.setUnzippedFileSize(currentPackageObject.GetLong(UNZIP_SIZE_ID));
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             try
             {
                 JSONObject currentMapTXGDetails = currentPackageObject.GetJSONObject(TEXTURE_ID);
                 if (currentMapTXGDetails != null)
                 {
                     currentMap.setTXGFilePath(currentMapTXGDetails.GetString(TEXTURES_BIG_FILE_ID));
                     currentMap.setTXGFileSize(currentMapTXGDetails.GetLong(SIZE_BIG_FILE_ID));
                 }
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             try
             {
                 currentMap.setSkmAndZipFilesSize(currentPackageObject.GetLong(SIZE_ID));
             }
             catch (JSONException ex)
             {
                 SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug);
             }
             if ((currentMap.Code != null) && (currentMap.getSubType() != null))
             {
                 removeNullValuesIfExist(currentMap);
                 maps.Add(currentMap);
             }
         }
     }
 }
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        public virtual void VerifyClusterSchedulerFifo(JSONObject json)
        {
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject info = json.GetJSONObject("scheduler");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, info.Length());
            info = info.GetJSONObject("schedulerInfo");
            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 11, info.Length()
                                            );
            VerifyClusterSchedulerFifoGeneric(info.GetString("type"), info.GetString("qstate"
                                                                                     ), (float)info.GetDouble("capacity"), (float)info.GetDouble("usedCapacity"), info
                                              .GetInt("minQueueMemoryCapacity"), info.GetInt("maxQueueMemoryCapacity"), info.GetInt
                                                  ("numNodes"), info.GetInt("usedNodeCapacity"), info.GetInt("availNodeCapacity"),
                                              info.GetInt("totalNodeCapacity"), info.GetInt("numContainers"));
        }
 /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
 public virtual void VerifyAMSingleTask(JSONObject info, Task task)
 {
     NUnit.Framework.Assert.AreEqual("incorrect number of elements", 9, info.Length());
     VerifyTaskGeneric(task, info.GetString("id"), info.GetString("state"), info.GetString
                           ("type"), info.GetString("successfulAttempt"), info.GetLong("startTime"), info.GetLong
                           ("finishTime"), info.GetLong("elapsedTime"), (float)info.GetDouble("progress"),
                       info.GetString("status"));
 }