Пример #1
0
 private void BtnExport_Click(object sender, EventArgs e)
 {
     // throw new NotImplementedException();
     try
     {
         textViewTips.Text = "正在进行配置导出,请等待";
         JSONStringer   js             = new JSONStringer();
         var            dataService    = Singleton.GetDataService;
         string         Setting        = dataService.AllSettings.ToJson();
         string         LightExamGroup = dataService.AllLightExamItems.ToJson();
         string         Map            = dataService.GetAllMapLines().ToJson();
         string         config         = Setting + "@" + LightExamGroup + "@" + Map;
         File           file           = new File(DictoryPath, "config.config");
         BufferedWriter bw             = new BufferedWriter(new FileWriter(file, false));
         bw.Write(config);
         bw.Flush();
         textViewTips.Text = "配置导出成功";
     }
     catch (Exception ex)
     {
         textViewTips.Text = "一键导出失败";
         Logger.Error("一键导出", ex.Message);
     }
     //串口服务器//自己买一个呗//好简单的东西哟
     //一键导出把配置,灯光分组,以及地图都导出
 }
	  /// <summary>
	  /// Write an Android <seealso cref="android.os.Bundle Bundle"/> as a JSON string. </summary>
	  /// <param name="bundle"> the Bundle to convert into JSON. </param>
	  /// <returns> the JSON object representing the Bundle as a String. </returns>
	  /// <exception cref="IllegalArgumentException"> if bundle is null. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static String toString(android.os.Bundle bundle) throws IllegalArgumentException
	  public static string ToString(Bundle bundle)
	  {
		/* Throw an exception if bundle is null */
		if (bundle == null)
		{
		  throw new System.ArgumentException("bundle can not be null");
		}

		/* Launch JSON serializer */
		JSONStringer json = new JSONStringer();
		try
		{
		  convert(json, bundle);
		}
		catch (JSONException)
		{
		  /* Ignore this key */
		}

		/* Return the JSON string */
		return json.ToString();
	  }
        /// <summary>
        /// Write an Android <seealso cref="android.os.Bundle Bundle"/> as a JSON string. </summary>
        /// <param name="bundle"> the Bundle to convert into JSON. </param>
        /// <returns> the JSON object representing the Bundle as a String. </returns>
        /// <exception cref="IllegalArgumentException"> if bundle is null. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static String toString(android.os.Bundle bundle) throws IllegalArgumentException
        public static string ToString(Bundle bundle)
        {
            /* Throw an exception if bundle is null */
            if (bundle == null)
            {
                throw new System.ArgumentException("bundle can not be null");
            }

            /* Launch JSON serializer */
            JSONStringer json = new JSONStringer();

            try
            {
                convert(json, bundle);
            }
            catch (JSONException)
            {
                /* Ignore this key */
            }

            /* Return the JSON string */
            return(json.ToString());
        }
	  /// <summary>
	  /// Recursive function to write a value to JSON. </summary>
	  /// <param name="json"> the JSON serializer. </param>
	  /// <param name="value"> the value to write in JSON. </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void convert(org.json.JSONStringer json, Object value) throws org.json.JSONException
	  private static void convert(JSONStringer json, object value)
	  {
		/* Handle null */
		if (value == null)
		{
		  json.value(null);
		}

		/* The function is recursive if it encounters a bundle */
		else if (value is Bundle)
		{
		  /* Cast bundle */
		  Bundle bundle = (Bundle) value;

		  /* Open object */
		  json.@object();

		  /* Traverse bundle */
		  foreach (string key in bundle.Keys)
		  {
			/* Write key */
			json.key(key);

			/* Recursive call to write the value */
			convert(json, bundle.get(key));
		  }

		  /* End object */
		  json.endObject();
		}

		/* Handle array, write it as a JSON array */
		else if (value.GetType().IsArray)
		{
		  /* Open array */
		  json.array();

		  /* Recursive call on each value */
		  int length = Array.getLength(value);
		  for (int i = 0; i < length; i++)
		  {
			convert(json, Array.get(value, i));
		  }

		  /* Close array */
		  json.endArray();
		}

		/* Handle ArrayList, write it as a JSON array */
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: else if (value instanceof java.util.ArrayList<?>)
		else if (value is List<?>)
		{
		  /* Open array */
		  json.array();

		  /* Recursive call on each value */
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: java.util.ArrayList<?> arrayList = (java.util.ArrayList<?>) value;
		  List<?> arrayList = (List<?>) value;
		  foreach (object val in arrayList)
		  {
			convert(json, val);
		  }

		  /* Close array */
		  json.endArray();
		}

		/* Format throwable values with the stack trace */
		else if (value is Exception)
		{
		  Exception t = (Exception) value;
		  StringWriter text = new StringWriter();
		  t.printStackTrace(new PrintWriter(text));
		  json.value(text.ToString());
		}

		/* Other values are handled directly by JSONStringer (numerical, boolean and String) */
		else
		{
		  json.value(value);
		}
	  }
        /// <summary>
        /// Recursive function to write a value to JSON. </summary>
        /// <param name="json"> the JSON serializer. </param>
        /// <param name="value"> the value to write in JSON. </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static void convert(org.json.JSONStringer json, Object value) throws org.json.JSONException
        private static void convert(JSONStringer json, object value)
        {
            /* Handle null */
            if (value == null)
            {
                json.value(null);
            }

            /* The function is recursive if it encounters a bundle */
            else if (value is Bundle)
            {
                /* Cast bundle */
                Bundle bundle = (Bundle)value;

                /* Open object */
                json.@object();

                /* Traverse bundle */
                foreach (string key in bundle.Keys)
                {
                    /* Write key */
                    json.key(key);

                    /* Recursive call to write the value */
                    convert(json, bundle.get(key));
                }

                /* End object */
                json.endObject();
            }

            /* Handle array, write it as a JSON array */
            else if (value.GetType().IsArray)
            {
                /* Open array */
                json.array();

                /* Recursive call on each value */
                int length = Array.getLength(value);
                for (int i = 0; i < length; i++)
                {
                    convert(json, Array.get(value, i));
                }

                /* Close array */
                json.endArray();
            }

            /* Handle ArrayList, write it as a JSON array */
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: else if (value instanceof java.util.ArrayList<?>)
            else if (value is List <?> )
            {
                /* Open array */
                json.array();

                /* Recursive call on each value */
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: java.util.ArrayList<?> arrayList = (java.util.ArrayList<?>) value;
                List <?> arrayList = (List <?>)value;
                foreach (object val in arrayList)
                {
                    convert(json, val);
                }

                /* Close array */
                json.endArray();
            }

            /* Format throwable values with the stack trace */
            else if (value is Exception)
            {
                Exception    t    = (Exception)value;
                StringWriter text = new StringWriter();
                t.printStackTrace(new PrintWriter(text));
                json.value(text.ToString());
            }

            /* Other values are handled directly by JSONStringer (numerical, boolean and String) */
            else
            {
                json.value(value);
            }
        }