Exemplo n.º 1
0
        /// <summary>
        /// Deserializes a JSON string to a TSM
        /// PLB will be ignored
        /// WARNING: this is not used in the C-DEngine and migh
        /// </summary>
        /// <param name="pPayload"></param>
        /// <returns></returns>
        internal static TSM DeserializeJStringToObjectTSM(object pPayload)
        {
            if (pPayload == null)
            {
                return(null);
            }

            TSM tTSM = new TSM();   //Save not to set ORG or SID

            tTSM.SID = "";

            Dictionary <string, object> tdic = pPayload as Dictionary <string, object>;

            if (tdic == null)
            {
                fastJSON.JsonParser tParser = new fastJSON.JsonParser(pPayload.ToString(), false);
                tdic = tParser.Decode() as Dictionary <string, object>;
            }
            if (tdic != null)
            {
                foreach (string key in tdic.Keys)
                {
                    if (tdic[key] != null)
                    {
                        ValSetter2(ref tTSM, key, tdic[key], true);
                    }
                }
            }
            return(tTSM);
        }
Exemplo n.º 2
0
		private void StartCheckAndUpdate(object sender, EventArgs eventArg)
		{
			string deployUrl = Resource.ArcherDeploy
								+ "?r=a&info=" + System.Web.HttpUtility.UrlEncode(this.Text)
								+ "&os=" + Environment.OSVersion.Version.Major;

			Dictionary<string, string> deployInfo = new Dictionary<string, string>();

			if (bgwUpdateChecker != null && bgwUpdateChecker.IsBusy)
			{
				bgwUpdateChecker.CancelAsync();
				bgwUpdateChecker.Dispose();
			}

			bgwUpdateChecker = new BackgroundWorker();
			bgwUpdateChecker.WorkerSupportsCancellation = true;

			bgwUpdateChecker.DoWork += (o, e) =>
			{
				try
				{
					if (sender == null)
						System.Threading.Thread.Sleep(1000 * 60 * 3);

					WebClient client = new WebClient();

					WebRequest wr = WebRequest.Create(deployUrl);
					WebResponse re = wr.GetResponse();

					fastJSON.JsonParser jsonParser = new fastJSON.JsonParser(new StreamReader(re.GetResponseStream()).ReadToEnd());
					Dictionary<string, object> raw = jsonParser.Decode() as Dictionary<string, object>;

					foreach (var item in raw)
						deployInfo.Add(item.Key, item.Value as string);

					if (deployInfo["version"].CompareTo(resource.AssemblyVersion) > 0)
						e.Result = true;
					else
						e.Result = false;
				}
				catch (Exception)
				{
					e.Result = false;
				}
			};
			bgwUpdateChecker.RunWorkerCompleted += (o, e) =>
			{
				if ((bool)e.Result)
				{
					if (sender == null)
						notifyIcon.ShowBalloonTip(5000, Resource.NewerVersionFound,
							string.Format(Resource.NewVersionInfo,
								resource.AssemblyVersion,
								deployInfo["version"],
								deployInfo["info"]
							),
							ToolTipIcon.Info
						);

					notifyIcon.BalloonTipClicked -= balloonTipClicked;
					balloonTipClicked = (oo, ee) =>
					{
						string dir = AppDomain.CurrentDomain.BaseDirectory;
						string tempDir = Resource.ArcherTemp + Guid.NewGuid().ToString();
						string file = Resource.ArcherTemp + Guid.NewGuid().ToString() + ".zip";

						Downloader uw = new Downloader();
						uw.Show();
						uw.Completed += (ooo, eee) =>
						{
							ys.Common.RunTempScript(Resource.SelfUpdate, "vbs", tempDir, file, dir);
							this.Close();
						};
						uw.StartDownload(
							deployInfo["url"],
							file
						);
					};
					if (sender != null)
						balloonTipClicked(null, null);
					else
						notifyIcon.BalloonTipClicked += balloonTipClicked;
				}
				else if (sender != null)
				{
					notifyIcon.ShowBalloonTip(5000,
						Resource.NoNewerVersion,
						" ",
						ToolTipIcon.Info);
				}
			};
			bgwUpdateChecker.RunWorkerAsync();
		}
Exemplo n.º 3
0
 private static void DeserializeFastJson(int count)
 {
     for (int i = 0; i < count; i++)
     {
         var s2 = new fastJSON.JsonParser(TestJson);
         var x = (Dictionary<string, object>)s2.Decode();
         var s = new SimpleObject
                     {
                         Id = int.Parse((string)x["Id"]),
                         Name = (string)x["Name"],
                         Address = (string)x["Address"],
                         Scores = ((ArrayList)x["Scores"]).OfType<string>().Select(int.Parse).ToArray()
                     };
     }
 }