Exemple #1
0
        //*** 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);
                }
            }
        }
Exemple #2
0
 internal static void SetReplication(FullSyncReplicationParameter replicationParameter, Replication replication, object value)
 {
     Init();
     // Checks if the value type is String and the request parameter type is not
     if (typeof(string).IsAssignableFrom(value.GetType()) && !typeof(string).IsAssignableFrom(replicationParameter.type))
     {
         try
         {
             // Tries to convert the string to the request parameter type
             value = C8oTranslator.StringToObject(value as string, replicationParameter.type);
         }
         catch (Exception e)
         {
             throw new C8oException(C8oExceptionMessage.ParseStringToObject(replicationParameter.type), e);
         }
     }
     // Checks if the type is valid
     if (replicationParameter.type.IsAssignableFrom(value.GetType()))
     {
         // No reasons to fail
         Action <Replication, object> setReplicationOp = null;
         if (fullSyncReplicationParameters.TryGetValue(replicationParameter, out setReplicationOp))
         {
             setReplicationOp(replication, value);
         }
     }
     else
     {
         throw new ArgumentException(C8oExceptionMessage.InvalidArgumentInvalidParameterType(replicationParameter.name, "" + replicationParameter.type, "" + value.GetType()));
     }
 }
Exemple #3
0
        public static bool TryGetParameterObjectValue <T>(IDictionary <string, object> parameters, string name, out T value, bool useName = false, T defaultValue = default(T))
        {
            KeyValuePair <string, object> parameter = GetParameter(parameters, name, useName);

            if (parameter.Key != null && parameter.Value != null)
            {
                if (parameter.Value is string && typeof(T) != typeof(string))
                {
                    value = (T)C8oTranslator.StringToObject(parameter.Value as string, typeof(T));
                }
                else
                {
                    value = (T)parameter.Value;
                }
                return(true);
            }
            value = defaultValue;
            return(false);
        }