Example #1
1
 public static JObject CSharpTest(RPCRequestInfo c, JObject p)
 {
     Thread.Sleep ((int)p ["ms"].AsNumber (0.0));
     return new JObject {
         { "hello", "world" }
     };
 }
Example #2
1
    public void LoadFromJson(JObject source)
    {
        // This is where the automatic deserialization takes place. We just tell the Jobject that we want an object of the type RelfectionData and it will handle the rest
        var reflectionDataObject = source.Deserialize<ReflectionData>();

        // This is just a simple method a created to read the data from reflectionDataObject back into this object
        reflectionDataObject.ToMonoBehavior(this);
    }
Example #3
1
        public TransactionInfo(JObject data) : base(data)
        {

            this.From = new Guid(data["From"].ToString());
            this.To = new Guid(data["To"].ToString());
            this.ConstraintKind = (ConstraintKinds)Enum.Parse(typeof(ConstraintKinds), data["ConstraintKind"].ToString());
            if (this.ConstraintKind != ConstraintKinds.None) this.Constraint = data["Constraint"].ToString();

        }
        public void Example()
        {
            #region Usage
            JObject o = new JObject
            {
                { "Cpu", "Intel" },
                { "Memory", 32 },
                {
                    "Drives", new JArray
                    {
                        "DVD",
                        "SSD"
                    }
                }
            };

            Console.WriteLine(o.ToString());
            // {
            //   "Cpu": "Intel",
            //   "Memory": 32,
            //   "Drives": [
            //     "DVD",
            //     "SSD"
            //   ]
            // }
            #endregion
        }
Example #5
0
 public RPCException(string code, string msg, RPCException orig, JObject data = null)
 {
     ErrorCode = code;
     ErrorMessage = msg + ": " + orig.ErrorMessage;
     ErrorData = data ?? new JObject ();
     ErrorData ["orig"] = orig.AsHeader ();
 }
Example #6
0
 public RPCException(string code, string msg, JObject data = null)
     : base(msg)
 {
     ErrorCode = code;
     ErrorMessage = msg;
     ErrorData = data;
 }
Example #7
0
        public Download(Uri uri, string key, CookieContainer cc, JObject song)
        {
            m_uri = uri;
            m_key = key;
            m_cc = cc;
            m_song = song;

            song["Status"] = "Opening file";
            string filename = (string)song["ArtistName"] + " - " + (string)song["Name"] + ".mp3";
            m_logger = new Logger(this.GetType().ToString() + " " + filename);
            string dst = "";
            string path = "";
            if (Main.PATH.Length != 0)
                path = Main.PATH + Path.DirectorySeparatorChar;
            dst = path + filename;
            try
            {
                m_path = dst;
                m_fs = new FileStream(dst, FileMode.Create);
            }
            catch (Exception ex)
            {
                char[] invalf = Path.GetInvalidFileNameChars();
                foreach (char c in invalf)
                    filename = filename.Replace(c, '_');
                dst = path + filename;
                try
                {
                    m_path = dst;
                    m_fs = new FileStream(dst, FileMode.Create);
                }
                catch (Exception exc)
                {
                    for (int i = 0; i < dst.Length; i++)
                    {
                        if (!Char.IsLetterOrDigit(dst[i]))
                            filename = filename.Replace(dst[i], '_');
                        dst = path + filename;
                    }
                    try
                    {
                        m_path = dst;
                        m_fs = new FileStream(dst, FileMode.Create);
                    }
                    catch (Exception exc2)
                    {
                        throw new Exception("Could not save the file buddy. (" + exc2.Message + ")");
                    }
                }
            }

            m_logger.Info("Starting download");
            song["Status"] = "Starting download";
            Segment s = new Segment(uri, cc, key, 0, SEGMENT_SIZE-1, m_path);
            m_segments.Add(s);
            s.Progress += new EventHandler(s_Progress);
            s.HeadersReceived += new Segment.HeadersReceivedHandler(s_HeadersReceived);
            s.Start();
            m_start = DateTime.Now;
        }
Example #8
0
 public JObject ToJson()
 {
     JObject json = new JObject();
     json["stack"] = StackScript.ToHexString();
     json["redeem"] = RedeemScript.ToHexString();
     return json;
 }
Example #9
0
 public ProccessDefination(JObject data) : base(data)
 {
     this.StartAlias = data["StartAlias"].ToString();
     this.FinishAlias = data["FinishAlias"].ToString();
     var rtIdData = data["RuntimeId"];
     if (rtIdData != null) this.RuntimeId = new Guid(rtIdData.ToString());
 }
Example #10
0
 private static JObject CreateResponse(JObject id)
 {
     JObject response = new JObject();
     response["jsonrpc"] = "2.0";
     response["id"] = id;
     return response;
 }
Example #11
0
        public void Example()
        {
            #region Usage
            JObject o = new JObject
            {
                { "name1", "value1" },
                { "name2", "value2" }
            };

            JsonWriter writer = o.CreateWriter();
            writer.WritePropertyName("name3");
            writer.WriteStartArray();
            writer.WriteValue(1);
            writer.WriteValue(2);
            writer.WriteEndArray();

            Console.WriteLine(o.ToString());
            // {
            //   "name1": "value1",
            //   "name2": "value2",
            //   "name3": [
            //     1,
            //     2
            //   ]
            // }
            #endregion
        }
Example #12
0
        public void Example()
        {
            #region Usage
            JValue s1 = new JValue("A string");
            JValue s2 = new JValue("A string");
            JValue s3 = new JValue("A STRING");

            Console.WriteLine(JToken.DeepEquals(s1, s2));
            // true

            Console.WriteLine(JToken.DeepEquals(s2, s3));
            // false

            JObject o1 = new JObject
            {
                { "Integer", 12345 },
                { "String", "A string" },
                { "Items", new JArray(1, 2) }
            };

            JObject o2 = new JObject
            {
                { "Integer", 12345 },
                { "String", "A string" },
                { "Items", new JArray(1, 2) }
            };

            Console.WriteLine(JToken.DeepEquals(o1, o2));
            // true

            Console.WriteLine(JToken.DeepEquals(s1, o1["String"]));
            // true
            #endregion
        }
		private IElasticCoreType GetTypeFromJObject(JObject po, JsonSerializer serializer)
		{
			JToken typeToken;
			serializer.TypeNameHandling = TypeNameHandling.None;
			if (po.TryGetValue("type", out typeToken))
			{
				var type = typeToken.Value<string>().ToLowerInvariant();
				switch (type)
				{
					case "string":
						return serializer.Deserialize(po.CreateReader(), typeof(StringMapping)) as StringMapping;
					case "float":
					case "double":
					case "byte":
					case "short":
					case "integer":
					case "long":
						return serializer.Deserialize(po.CreateReader(), typeof(NumberMapping)) as NumberMapping;
					case "date":
						return serializer.Deserialize(po.CreateReader(), typeof(DateMapping)) as DateMapping;
					case "boolean":
						return serializer.Deserialize(po.CreateReader(), typeof(BooleanMapping)) as BooleanMapping;
					case "binary":
						return serializer.Deserialize(po.CreateReader(), typeof(BinaryMapping)) as BinaryMapping;
				}
			}
			return null;
		}
Example #14
0
 public JObject ToJson()
 {
     JObject json = new JObject();
     json["usage"] = Usage;
     json["data"] = Data.ToHexString();
     return json;
 }
Example #15
0
        public static ProcessDefination FromJson(JObject data) {
            var entity = new ProcessDefination();
            entity.Id = new Guid(data["Id"].ToString());
            entity.ActivityDefinationId = new Guid(data["ActivityDefinationId"].ToString());
            entity.ActivityId = new Guid(data["ActivityId"].ToString());
            entity.Description = data["Description"].ToString();
            var arr = data["ActivedActivityIds"] as JArray;
            if (arr != null) {
                entity.ActivedActivityIds = new List<Guid>();
                foreach (JToken item in arr) {
                    entity.ActivedActivityIds.Add(new Guid(item.ToString()));
                }
            }
            var extra = data["Extra"] as JObject;
            if (extra != null)
            {
                entity.Extras = new Dictionary<string, string>();
                foreach (var pair in extra)
                {
                    entity.Extras.Add(pair.Key, pair.Value.ToString());
                }
            }

            return entity;
        }
        public TransactionDefination(JObject data) : base(data)
        {
            this.FromAlias = data["FromAlias"].ToString();
            this.ToAlias = data["ToAlias"].ToString();
            this.ConstraintKind = (ConstraintKinds)Enum.Parse(typeof(ConstraintKinds), data["ConstraintKind"].ToString());
            if (this.ConstraintKind != ConstraintKinds.None) this.Constraint = data["Constraint"]?.ToString();

        }
Example #17
0
File: LAPI.cs Project: 2Bmetro/IVLE
 // change the json string to json object
 public void toJObject(string feed, JObject JO)
 {
     JsonSerializer serializer = new JsonSerializer();
     using (JsonWriter writer = new JsonTextWriter(feed))
     {
         serializer.Serialize(writer, JO);
     }
 }
Example #18
0
        public void WritePropertyWithNoValue()
        {
            var o = new JObject();
            o.Add(new JProperty("novalue"));

            StringAssert.Equal(@"{
  ""novalue"": null
}", o.ToString());
        }
Example #19
0
 public JObject ToJson(ushort index)
 {
     JObject json = new JObject();
     json["n"] = index;
     json["asset"] = AssetId.ToString();
     json["value"] = Value.ToDecimal();
     json["address"] = Wallet.ToAddress(ScriptHash);
     return json;
 }
Example #20
0
    public void MoveTo(int x, int y, int z)
    {
        JObject jRoot = new JObject();

        bool bRet = SavePosition(x, y, z);

        jRoot.Items.Add(KEY_RETURN, new JBoolean(bRet));
        jr.RespondJSON(jRoot);
    }
Example #21
0
        public ParallelActivityInfo(JObject data) :base(data){
            var parallels = data["ParallelActivities"] as JArray;
            if (parallels != null) {
                foreach (var idstr in parallels) {
                    this._parallelActivities.Add(new Guid(idstr));
                }
            }

        }
		private IElasticType GetTypeFromJObject(JObject po, JsonSerializer serializer)
		{
			JToken typeToken;
			JToken propertiesToken;
			JToken fieldsToken;
			var type = string.Empty;

			var hasType = po.TryGetValue("type", out typeToken);
			if (hasType)
				type = typeToken.Value<string>().ToLowerInvariant();
			else if (po.TryGetValue("properties", out propertiesToken))
				type = "object";

			var originalType = type;
			var hasFields = po.TryGetValue("fields", out fieldsToken);
			if (hasFields)
				type = "multi_field";

			serializer.TypeNameHandling = TypeNameHandling.None;

			switch (type)
			{
				case "string":
					return serializer.Deserialize(po.CreateReader(), typeof(StringMapping)) as StringMapping;
				case "float":
				case "double":
				case "byte":
				case "short":
				case "integer":
				case "long":
					return serializer.Deserialize(po.CreateReader(), typeof(NumberMapping)) as NumberMapping;
				case "date":
					return serializer.Deserialize(po.CreateReader(), typeof(DateMapping)) as DateMapping;
				case "boolean":
					return serializer.Deserialize(po.CreateReader(), typeof(BooleanMapping)) as BooleanMapping;
				case "binary":
					return serializer.Deserialize(po.CreateReader(), typeof(BinaryMapping)) as BinaryMapping;
				case "object":
					return serializer.Deserialize(po.CreateReader(), typeof(ObjectMapping)) as ObjectMapping;
				case "nested":
					return serializer.Deserialize(po.CreateReader(), typeof(NestedObjectMapping)) as NestedObjectMapping;
				case "multi_field":
					var m =serializer.Deserialize(po.CreateReader(), typeof(MultiFieldMapping)) as MultiFieldMapping;
					m.Type = originalType;
					return m;
				case "ip":
					return serializer.Deserialize(po.CreateReader(), typeof(IPMapping)) as IPMapping;
				case "geo_point":
					return serializer.Deserialize(po.CreateReader(), typeof(GeoPointMapping)) as GeoPointMapping;
				case "geo_shape":
					return serializer.Deserialize(po.CreateReader(), typeof(GeoShapeMapping)) as GeoShapeMapping;
				case "attachment":
					return serializer.Deserialize(po.CreateReader(), typeof(AttachmentMapping)) as AttachmentMapping;
			}

			return null;
		}
        public void Example()
        {
            #region Usage
            List<Post> posts = GetPosts();

            JObject rss =
                new JObject(
                    new JProperty("channel",
                        new JObject(
                            new JProperty("title", "James Newton-King"),
                            new JProperty("link", "http://james.newtonking.com"),
                            new JProperty("description", "James Newton-King's blog."),
                            new JProperty("item",
                                new JArray(
                                    from p in posts
                                    orderby p.Title
                                    select new JObject(
                                        new JProperty("title", p.Title),
                                        new JProperty("description", p.Description),
                                        new JProperty("link", p.Link),
                                        new JProperty("category",
                                            new JArray(
                                                from c in p.Categories
                                                select new JValue(c)))))))));

            Console.WriteLine(rss.ToString());

            // {
            //   "channel": {
            //     "title": "James Newton-King",
            //     "link": "http://james.newtonking.com",
            //     "description": "James Newton-King's blog.",
            //     "item": [
            //       {
            //         "title": "Json.NET 1.3 + New license + Now on CodePlex",
            //         "description": "Annoucing the release of Json.NET 1.3, the MIT license and being available on CodePlex",
            //         "link": "http://james.newtonking.com/projects/json-net.aspx",
            //         "category": [
            //           "Json.NET",
            //           "CodePlex"
            //         ]
            //       },
            //       {
            //         "title": "LINQ to JSON beta",
            //         "description": "Annoucing LINQ to JSON",
            //         "link": "http://james.newtonking.com/projects/json-net.aspx",
            //         "category": [
            //           "Json.NET",
            //           "LINQ"
            //         ]
            //       }
            //     ]
            //   }
            // }
            #endregion
        }
        public void AndExpressionTest()
        {
            CompositeExpression compositeExpression = new CompositeExpression
            {
                Operator = QueryOperator.And,
                Expressions = new List<QueryExpression>
                {
                    new BooleanQueryExpression
                    {
                        Operator = QueryOperator.Exists,
                        Path = new List<PathFilter>
                        {
                            new FieldFilter
                            {
                                Name = "FirstName"
                            }
                        }
                    },
                    new BooleanQueryExpression
                    {
                        Operator = QueryOperator.Exists,
                        Path = new List<PathFilter>
                        {
                            new FieldFilter
                            {
                                Name = "LastName"
                            }
                        }
                    }
                }
            };

            JObject o1 = new JObject
            {
                {"Title","Title!"},
                {"FirstName", "FirstName!"},
                {"LastName", "LastName!"}
            };

            Assert.True(compositeExpression.IsMatch(o1));

            JObject o2 = new JObject
            {
                {"Title","Title!"},
                {"FirstName", "FirstName!"}
            };

            Assert.False(compositeExpression.IsMatch(o2));

            JObject o3 = new JObject
            {
                {"Title","Title!"}
            };

            Assert.False(compositeExpression.IsMatch(o3));
        }
Example #25
0
        public ActivityInfo(JObject data) :base(data){

            this.Deal = data["Deal"]?.ToString();
            this.StartMode = (ExecutionModes)Enum.Parse(typeof(ExecutionModes), data["StartMode"].ToString());
            this.FinishMode = (ExecutionModes)Enum.Parse(typeof(ExecutionModes), data["FinishMode"].ToString());
            this.StartConstraintKind = (ConstraintKinds)Enum.Parse(typeof(ConstraintKinds), data["StartConstraintKind"].ToString());
            this.FinishConstraintKind = (ConstraintKinds)Enum.Parse(typeof(ConstraintKinds), data["FinishConstraintKind"].ToString());
            if (this.StartConstraintKind != ConstraintKinds.None ) this.StartConstraint = data["StartConstraint"].ToString();
            if (this.FinishConstraintKind != ConstraintKinds.None ) this.FinishConstraint = data["FinishConstraint"].ToString();
        }
Example #26
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Department department = (Department)value;

            JObject o = new JObject();
            o["DepartmentId"] = new JValue(department.DepartmentId.ToString());
            o["Name"] = new JValue(new string(department.Name.Reverse().ToArray()));

            o.WriteTo(writer);
        }
Example #27
0
 public ProccessInfo(JObject data) : base(data)
 {
     this.BlockId = new Guid(data["BlockId"]);
     var actived = data["Activied"] as JArray;
     if (actived != null) {
         foreach (var idstr in actived) {
             this.Actived.Add(new Guid(idstr));
         }
     }
 }
 public static TransactionDefination FromJson(JObject data, TransactionDefination entity = null)
 {
     if (entity == null) entity = new TransactionDefination();
     Defination.FromJson(data, entity);
     entity.Constraint = data["Constraint"].ToString();
     entity.ConstraintKind = (ConstraintKinds)Enum.Parse(typeof(ConstraintKinds), data["ConstraintKind"].ToString());
     entity.From = new Guid(data["From"].ToString());
     entity.To = new Guid(data["To"].ToString());
     return entity;
 }
Example #29
0
 private static JObject CreateErrorResponse(JObject id, int code, string message, JObject data = null)
 {
     JObject response = CreateResponse(id);
     response["error"] = new JObject();
     response["error"]["code"] = code;
     response["error"]["message"] = message;
     if (data != null)
         response["error"]["data"] = data;
     return response;
 }
    public void JObjectDictionary()
    {
      Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
      JObject v11 = new JObject() { { "Test", new JValue(1) }, { "Test1", new JValue(1) } };
      JObject v12 = new JObject() { { "Test", new JValue(1) }, { "Test1", new JValue(1) } };

      dic[v11] = 1;
      dic[v12] += 1;
      Assert.AreEqual(2, dic[v11]);
    }