Пример #1
0
        public static object GetParameterJsonValue(IDictionary <string, object> parameters, string name, bool useName = false)
        {
            var parameter = GetParameter(parameters, name, useName);

            if (parameter.Key != null)
            {
                return(C8oUtils.GetParameterJsonValue(parameter));
            }
            return(null);
        }
Пример #2
0
        //*** PostDocument ***//

        public async override Task <object> HandlePostDocumentRequest(string databaseName, FullSyncPolicy fullSyncPolicy, IDictionary <string, object> parameters)
        {
            var fullSyncDatabase = await GetOrCreateFullSyncDatabase(databaseName);

            // Gets the subkey separator parameter
            string subkeySeparatorParameterValue = C8oUtils.GetParameterStringValue(parameters, FullSyncPostDocumentParameter.SUBKEY_SEPARATOR.name, false);

            if (subkeySeparatorParameterValue == null)
            {
                subkeySeparatorParameterValue = ".";
            }

            // Filters and modifies wrong properties
            var newProperties = new Dictionary <string, object>();

            foreach (var parameter in parameters)
            {
                string parameterName = parameter.Key;

                if (parameterName.Equals(C8oFullSync.FULL_SYNC__REV))
                {
                    newProperties[parameterName] = parameter.Value;
                }
                else if (!parameterName.StartsWith("__") && !parameterName.StartsWith("_use_"))
                {
                    // Retrieves ???
                    var objectParameterValue = C8oUtils.GetParameterJsonValue(parameter);
                    //Manager.SharedInstance. ow = null;

                    if (objectParameterValue is JObject)
                    {
                        objectParameterValue = (objectParameterValue as JObject).ToObject <Dictionary <string, object> > ();
                    }

                    // Checks if the parameter name is splittable
                    var paths = parameterName.Split(new String[] { subkeySeparatorParameterValue }, StringSplitOptions.None); // Regex.Split(parameterName, subkeySeparatorParameterValue);
                    if (paths.Length > 1)
                    {
                        // The first substring becomes the key
                        parameterName = paths[0];
                        // Next substrings create a hierarchy which will becomes json subkeys
                        int count = paths.Length - 1;
                        while (count > 0)
                        {
                            var tmpObject = new Dictionary <string, object>();
                            tmpObject[paths[count]] = objectParameterValue;
                            objectParameterValue    = tmpObject;
                            count--;
                        }
                        if (newProperties.ContainsKey(parameterName) && newProperties[parameterName] is IDictionary <string, object> )
                        {
                            FullSyncUtils.MergeProperties(objectParameterValue as IDictionary <string, object>, newProperties[parameterName] as IDictionary <string, object>);
                        }
                    }

                    newProperties[parameterName] = objectParameterValue;
                }
            }

            var    createdDocument = C8oFullSyncCblEnum.PostDocument(fullSyncPolicy, fullSyncDatabase.Database, newProperties);
            string documentId      = createdDocument.Id;
            string currentRevision = createdDocument.CurrentRevisionId;

            return(new FullSyncDocumentOperationResponse(documentId, currentRevision, true));
        }