Exemplo n.º 1
0
        public JSONRoot(string raw)
        {
            int i = 0;

            for (; i < raw.Length; i++)
            {
                if (JSONParseUtility.IsBlankChar(raw[i]) == true ||
                    raw[i] == JSONRow.JSONKeySeparator)
                {
                    continue;
                }

                int j = JSONParseUtility.IsOpener(raw[i]);

                if (j != -1)
                {
                    ++i;
                    this.child = new JSONObject(raw, ref i, raw.Length, j);
                    break;
                }
                else
                {
                    int startOffset = JSONParseUtility.DigestString(raw, ref i, raw.Length);

                    this.child = new JSONValue(raw.Substring(startOffset, i - startOffset + 1));
                    break;
                }
            }

            if (this.child != null)
            {
                this.child.Open = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// return true if the obj is not a number
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool IsNaN(IJSONObject obj)
        {
            if (obj == JNumber.JNaN)
            {
                return true;
            }

            return false;
        }
Exemplo n.º 3
0
 private void    ParseJSON()
 {
     if (this.root == null)
     {
         try
         {
             this.root = new JSONRoot(this.json);
         }
         catch
         {
             this.root = new JSONRoot(string.Empty);
             throw;
         }
     }
 }
Exemplo n.º 4
0
        public JSONPairKeyValue(string raw, ref int i, int max)
        {
            for (; i < max; i++)
            {
                if (JSONParseUtility.IsBlankChar(raw[i]) == true ||
                    raw[i] == JSONRow.JSONKeySeparator)
                {
                    continue;
                }

                if (raw[i] == JSONRow.JSONValueSeparator)
                {
                    break;
                }

                if (JSONParseUtility.IsCloser(raw[i]) != -1)
                {
                    --i;
                    break;
                }

                int j = JSONParseUtility.IsOpener(raw[i]);

                if (j != -1)
                {
                    ++i;
                    this.child = new JSONObject(raw, ref i, max, j);
                }
                else
                {
                    int startOffset = JSONParseUtility.DigestString(raw, ref i, max);

                    if (this.content == null)
                    {
                        this.content = raw.Substring(startOffset, i - startOffset + 1);
                    }
                    else
                    {
                        this.child = new JSONValue(raw.Substring(startOffset, i - startOffset + 1));
                        break;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void btnExportAsJSON_Click(object sender, RoutedEventArgs e)
        {
            string         dataframeName;
            string         outFile;
            IMapLayerInfos pMLInfos = null;
            IMapLayerInfo  pMLI     = null;

            //checking the existence of the output folder
            //DirectoryInfo outDirInfo = new DirectoryInfo(txtOutputFolder.Text);
            string outDir = txtOutputFolder.Text + "\\" + System.IO.Path.GetFileNameWithoutExtension(txtMXD.Text);

            if (Directory.Exists(outDir))
            {
                MessageBoxResult msgRes = System.Windows.MessageBox.Show(String.Format("Folder already exists \n{0}. \nDo you want to over write it?", outDir), "Output Folder", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (msgRes == MessageBoxResult.No)
                {
                    System.Windows.MessageBox.Show("Operation is cancelled", "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                else
                {
                    try
                    {
                        Directory.Delete(outDir, true);
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(String.Format("Failed to delete the folder \n{0}\n\n{1}", outDir, ex.Message), "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
            }
            Directory.CreateDirectory(outDir);

            prsProgress.IsIndeterminate = false;
            prsProgress.Visibility      = System.Windows.Visibility.Visible;

            TreeViewItem pTVIDataframe = null;

            for (int i = 0; i < m_pMapServer.MapCount; i++)
            {
                dataframeName = m_pMapServer.get_MapName(i);
                if (dataframeName != m_pMapServer.DefaultMapName)
                {
                    continue;
                }

                //ONLY for the default dataframe
                pTVIDataframe = tvwLayers.Items[0] as TreeViewItem;

                //getting REST resources including layer infos
                string     restOutputResource = Utils.GetLayersResource(m_pMapServer);
                JSONObject jObject            = new JSONObject();
                jObject.ParseString(restOutputResource);
                IJSONArray layers = null;
                jObject.TryGetValueAsArray("layers", out layers);

                pMLInfos            = m_pMapServer.GetServerInfo(dataframeName).MapLayerInfos;
                prsProgress.Maximum = pMLInfos.Count;
                for (int j = 0; j < pMLInfos.Count; j++)
                {
                    pMLI = pMLInfos.get_Element(j);
                    if (pMLI.IsFeatureLayer)
                    {
                        bool isSelected = false;
                        IsLayerSelectedForExport(pTVIDataframe, pMLI.ID, ref isSelected);
                        if (isSelected)
                        {
                            IJSONObject layer    = (IJSONObject)layers.get_Value(j);
                            String      renderer = Utils.GetRendererFromLayer(layer.ToJSONString(null));

                            outFile = string.Format(@"{0}\{1:000} {2}.json", outDir, pMLI.ID, Utils.ValidateFileName(pMLI.Name));
                            try
                            {
                                File.WriteAllText(outFile, renderer);
                            }
                            catch (Exception ex)
                            {
                                System.Windows.MessageBox.Show(String.Format("Failed to write content to the file\n{0}\n\n{1}", outFile, ex.Message), "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Error);
                                prsProgress.Visibility = System.Windows.Visibility.Hidden;
                                return;
                            }
                        }
                    }
                    prsProgress.Value += 1;
                }
            }

            prsProgress.Visibility = System.Windows.Visibility.Hidden;
            System.Windows.MessageBox.Show(String.Format("Conversion Completed\nOutput Path: {0}", outDir), "JSON Conversion", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Exemplo n.º 6
0
            /// <summary>
            /// Using this.Context to respond specified json data
            /// </summary>
            /// <param name="oJson"></param>
            /// <param name="sCallback">Callback function name</param>
            public void RespondJSON(IJSONObject oJson, string sCallback)
            {
                this.Context.Response.Buffer = true;

                string retJString = string.Empty;
                if (sCallback == null || sCallback.Trim() == string.Empty)
                {
                    retJString = oJson.ToJSON();
                }
                else
                {
                    retJString = sCallback + "(" + oJson.ToJSON() + ");" + "\r\n\r\n";

                }

                this.Context.Response.Write(retJString);
                this.Context.ApplicationInstance.CompleteRequest();
            }
Exemplo n.º 7
0
 /// <summary>
 /// Using this.Context to respond specified json data
 /// </summary>
 /// <param name="oJson"></param>
 public void RespondJSON(IJSONObject oJson)
 {
     RespondJSON(oJson, null);
 }
Exemplo n.º 8
0
            /// <summary>
            /// Response json data but not close the response
            /// </summary>
            /// <param name="oJson"></param>
            public void RespondComet(IJSONObject oJson, string sCallback)
            {
                this.Context.Response.Buffer = false;

                if (sCallback != null)
                {
                    this.Context.Response.Write(sCallback + "(" + oJson.ToJSON() + ");" + "\r\n\r\n");
                }
                else
                {
                    this.Context.Response.Write(oJson.ToJSON() + "\r\n\r\n");
                }

                this.Context.Response.Flush();
            }
Exemplo n.º 9
0
 /// <summary>
 /// Response json data but not close the response
 /// </summary>
 /// <param name="oJson"></param>
 public void RespondComet(IJSONObject oJson)
 {
     this.RespondComet(oJson, null);
 }