//*** Other ***// /// <summary> /// Adds known parameters to the fullSync query. /// </summary> /// <param name="query"></param> /// <param name="parameters"></param> private static void AddParametersToQuery(Query query, IDictionary <string, object> parameters) { foreach (KeyValuePair <string, object> parameter in parameters) { FullSyncRequestParameter fullSyncRequestParameter = FullSyncRequestParameter.GetFullSyncRequestParameter(parameter.Key); // If the parameter corresponds to a FullSyncRequestParameter if (fullSyncRequestParameter != null) { object parameterValue = parameter.Value; Type type = fullSyncRequestParameter.type; if (type != typeof(object) && parameterValue is string) { parameterValue = C8oTranslator.StringToObject(parameterValue as string, type); } //object objectParameterValue = parameterValue; //if (parameterValue is String) //{ // // Passer par une fonction ??,, // objectParameterValue = JsonConvert.DeserializeObject(parameterValue as String, fullSyncRequestParameter.type); //} // fullSyncRequestParameter.AddToQuery(query, objectParameterValue); C8oFullSyncCblEnum.AddToQuery(query, fullSyncRequestParameter, parameterValue); } } }
//*** 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)); }