Exemple #1
0
    public void Example()
    {
      JObject o1 = new JObject
        {
          {"String", "A string!"},
          {"Items", new JArray(1, 2)}
        };

      Console.WriteLine(o1.ToString());
      // {
      //   "String": "A string!",
      //   "Items": [
      //     1,
      //     2
      //   ]
      // }

      JObject o2 = (JObject) o1.DeepClone();

      Console.WriteLine(o2.ToString());
      // {
      //   "String": "A string!",
      //   "Items": [
      //     1,
      //     2
      //   ]
      // }

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

      Console.WriteLine(Object.ReferenceEquals(o1, o2));
      // false
    }
Exemple #2
0
		public JObject Interpolate(List<CallbackParameter> paras, JArray args, JObject scope)
		{
			var nscope = scope.DeepClone() as JObject;
			for (var i = 0; i < paras.Count(); i++)
			{
				nscope[paras[i].Name] = args[i];
			}
			return nscope;
		}
        public async Task<JObject> InsertAsync(JObject instance)
        {
            object id = MobileServiceSerializer.GetId(instance, ignoreCase: false, allowDefault: true);
            if (id == null)
            {
                id = Guid.NewGuid().ToString();
                instance = (JObject)instance.DeepClone();
                instance[MobileServiceSystemColumns.Id] = (string)id;
            }
            else
            {
                EnsureIdIsString(id);
            }

            await this.syncContext.InsertAsync(this.TableName, this.Kind, (string)id, instance);

            return instance;
        }
        private static void IterateAndFuzz(string url, JObject obj)
        {
            foreach (var pair in (JObject)obj.DeepClone()) {
                if (pair.Value.Type == JTokenType.String || pair.Value.Type == JTokenType.Integer) {
                    Console.WriteLine("Fuzzing key: " + pair.Key);

                    if (pair.Value.Type == JTokenType.Integer)
                        Console.WriteLine ("Converting int type to string to fuzz");

                    JToken oldVal = pair.Value;
                    obj[pair.Key] = pair.Value.ToString() + "'";

                    if (Fuzz (url, obj.Root))
                        Console.WriteLine ("SQL injection vector: " + pair.Key);
                    else
                        Console.WriteLine (pair.Key + " does not seem vulnerable.");

                    obj[pair.Key] = oldVal;
                }
            }
        }
 private JObject ExtractObjectJson(JObject json)
 {
     var clone = json.DeepClone() as JObject;
     var properties = clone.Properties().ToArray();
     for (int i = 0; i < properties.Length; i++)
     {
         if( IsObjectProperty(properties[i].Name) == false )
             clone.Remove(properties[i].Name);
     }
     return clone;
 }
        public HttpResponseMessage GetByTopic(string topic)
        {
            var topicPath = string.Empty;

            try
            {
                if (string.IsNullOrWhiteSpace(topic))
                {
                    throw new ArgumentNullException("Please specify a valid topic parameter in the form of /sample/<topic>.");
                }
                topicPath = HostingEnvironment.MapPath("~/" + topic);
                if (!Directory.Exists(topicPath))
                {
                    throw new FileNotFoundException("Could not find a topic named: " + topic);
                }
            }
            catch (ArgumentNullException ex)
            {
                return CreateErrorResponse(ex);
            }
            catch (FileNotFoundException ex)
            {
                return CreateErrorResponse(ex);
            }

            var directories = new DirectoryInfo(topicPath);
            var jArray = new JArray();

            foreach (var langDir in directories.GetDirectories())
            {
                var examples = new JArray();
                var files = langDir.GetFiles();
                var exampleFiles = files.Where(f => f.Extension != ".json");
                var rootObject = new JObject();
                rootObject["mode"] = langDir.Name;
                rootObject["content"] = string.Empty;
                rootObject["id"] = langDir.Name;
                var filePathRoot = "https://v1codesamples.azurewebsites.net/api/sample?path=" + topic + "/" + langDir.Name + "/";

                foreach (var file in exampleFiles)
                {
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.Name);
                    var properties = files.First(f => f.Name == fileNameWithoutExtension + ".json");
                    using (var reader = new StreamReader(properties.OpenRead()))
                    {
                        var json = reader.ReadToEnd();
                        var exampleRoot = rootObject.DeepClone() as JObject;
                        var mergeWith = JObject.Parse(json);
                        var example = new JObject(exampleRoot.Concat(mergeWith.AsJEnumerable()));
                        example["url"] = filePathRoot + file.Name;
                        // TODO: multiple examples per language support
                        //examples.Add(example);
                        jArray.Add(example);
                    }
                }
                // TODO: support multiple examples
                //jArray.Add(examples);
            }

            var content = jArray.ToString();

            var resp = new HttpResponseMessage(HttpStatusCode.OK);
            resp.Content = new StringContent(content, Encoding.UTF8, "text/plain");
            return resp;

        }
Exemple #7
0
        static JObject MakePackageDetailsContent(JObject package, IDictionary<int, JObject> packageDependencies, IDictionary<int, JObject> packageFrameworks, IDictionary<int, IList<int>> dependenciesByPackage, IDictionary<int, IList<int>> frameworksByPackage)
        {
            int packageKey = package.Value<int>("Key");

            package = (JObject)package.DeepClone();
            package.Remove("Key");
            package.Remove("PackageRegistrationKey");
            package.Remove("UserKey");

            JToken depenedencies = MakeDependencies(packageDependencies, dependenciesByPackage, packageKey);
            if (depenedencies != null)
            {
                package.Add("dependencies", depenedencies);
            }

            IList<int> frameworkKeys;
            if (frameworksByPackage.TryGetValue(packageKey, out frameworkKeys))
            {
                JArray frameworks = new JArray();
                foreach (int frameworkKey in frameworkKeys)
                {
                    JObject framework = (JObject)packageFrameworks[frameworkKey].DeepClone();
                    framework.Remove("Key");
                    framework.Remove("Package_Key");
                    frameworks.Add(framework);
                }
                package.Add("frameworks", frameworks);
            }

            return package;
        }
Exemple #8
0
        static JObject MakeOwnerContent(JObject user, IDictionary<int, JObject> packageRegistrations, IList<int> registrationsByOwner)
        {
            JObject owner = (JObject)user.DeepClone();

            owner.Remove("Key");

            owner.Add("@context", MakeOwnerContextUri());

            JArray registrations = new JArray();
            foreach (int packageRegistrationKey in registrationsByOwner)
            {
                JObject packageRegistration = packageRegistrations[packageRegistrationKey];

                JObject registration = new JObject();
                registration.Add("Id", packageRegistration["Id"]);
                registration.Add("Uri", MakePackageRegistrationUri(packageRegistration));
                registrations.Add(registration);
            }

            owner.Add("Packages", registrations);

            return owner;
        }
Exemple #9
0
        public void NewCommand(JObject newCommand)
        {
            JObject command = (JObject)newCommand.DeepClone();

            String json = command.ToString();
            String deviceId = command.GetValue("deviceId").ToString();

            using (IModel channel = connection.CreateModel())
            {
                channel.ExchangeDeclare("ex" + deviceId, ExchangeType.Direct);
                channel.QueueDeclare(deviceId, false, false, false, null);
                channel.QueueBind(deviceId, "ex" + deviceId, "", null);

                IBasicProperties props = channel.CreateBasicProperties();
                props.DeliveryMode = 2;

                Byte[] body = Encoding.UTF8.GetBytes(json);
                channel.BasicPublish("ex" + deviceId, "", props, body);
            }
        }
Exemple #10
0
        public void NewCommand(JObject newCommand)
        {
            JObject command = (JObject)newCommand.DeepClone();
            command.Add("creationTime", DateTime.Now);
            command.Add("delivered", false);

            String json = command.ToString();
            BsonDocument doc = BsonDocument.Parse(json);
            Task operation = new Task(() =>
            {
                collection.InsertOneAsync(doc);
            });
            operation.RunSynchronously();
        }
Exemple #11
0
        /// <summary>
        /// Validates that definition1 is a content equivalent subset of definition2
        /// </summary>
        private static bool IsDefinitionContentSubsetEquivalent(JObject definition1, JObject definition2)
        {
            JObject clonedDefinition1 = (JObject)definition1.DeepClone();
            JObject clonedDefinition2 = (JObject)definition2.DeepClone();

            RemoveIdentifiableInformation(clonedDefinition1, clonedDefinition2);

            // Compare only the child tokens present in the first definition to the corresponding contents of the second definition
            // The second definition may contain additional tokens which we don't care about.
            foreach(var childToken in clonedDefinition1.Children())
            {
                if(!JToken.DeepEquals(childToken.First, clonedDefinition2[childToken.Path]))
                {
                    return false;
                }
            }
            return true;
        }
Exemple #12
0
 public NetkanOverride(JObject metadata)
 {
     this.metadata = (JObject) metadata.DeepClone();
     version = new Version(metadata["version"].ToString());
 }
Exemple #13
0
        /// <summary>
        /// 初始化游戏规则数据
        /// </summary>
        /// <param name="data">游戏规则数据</param>
        protected virtual void Initialize( GameRulesBase rules, JObject data )
        {
            if ( data == null )
            throw new ArgumentNullException( "data" );

              Guid = (Guid) data.GuidValue( "ID" );
              Data = (JObject) data.DeepClone();
        }
Exemple #14
0
		async static void SENDLOCATION(JObject postData){
			var postitionData = (JObject) postData.DeepClone ();
			var position = await CrossGeolocator.Current.GetPositionAsync ();

			postitionData ["latit"] = position.Latitude;
			postitionData ["longit"] = position.Longitude;

			RestCall.POST (URLs.LOCATION, postitionData);

		}
        /// <summary>
        /// Removes all system properties (name start with '__') from the instance
        /// if the instance is determined to have a string id and therefore be for table that
        /// supports system properties.
        /// </summary>
        /// <param name="instance">The instance to remove the system properties from.</param>
        /// <param name="version">Set to the value of the version system property before it is removed.</param>
        /// <returns>
        /// The instance with the system properties removed.
        /// </returns>
        protected static JObject RemoveSystemProperties(JObject instance, out string version)
        {
            version = null;

            bool haveCloned = false;
            foreach (JProperty property in instance.Properties())
            {
                if (property.Name.StartsWith(MobileServiceSerializer.SystemPropertyPrefix))
                {
                    // We don't want to alter the original jtoken passed in by the caller
                    // so if we find a system property to remove, we have to clone first
                    if (!haveCloned)
                    {
                        instance = instance.DeepClone() as JObject;
                        haveCloned = true;
                    }

                    if (String.Equals(property.Name, MobileServiceSerializer.VersionSystemPropertyString, StringComparison.OrdinalIgnoreCase))
                    {
                        version = (string)instance[property.Name];
                    }

                    instance.Remove(property.Name);
                }
            }

            return instance;
        }