Example #1
0
        //*** Request handlers ***//

        public async Task <object> HandleFullSyncRequest(IDictionary <string, object> parameters, C8oResponseListener listener)
        {
            parameters = new Dictionary <string, object>(parameters);

            // Gets the project and the sequence parameter in order to know which database and which fullSyncrequestable to use
            string projectParameterValue = C8oUtils.PeekParameterStringValue(parameters, C8o.ENGINE_PARAMETER_PROJECT, true);

            if (!projectParameterValue.StartsWith(FULL_SYNC_PROJECT))
            {
                throw new ArgumentException(C8oExceptionMessage.InvalidParameterValue(projectParameterValue, "its don't start with " + FULL_SYNC_PROJECT));
            }

            string fullSyncRequestableValue = C8oUtils.PeekParameterStringValue(parameters, C8o.ENGINE_PARAMETER_SEQUENCE, true);
            // Gets the fullSync requestable and gets the response from this requestable
            FullSyncRequestable fullSyncRequestable = FullSyncRequestable.GetFullSyncRequestable(fullSyncRequestableValue);

            if (fullSyncRequestable == null)
            {
                throw new ArgumentException(C8oExceptionMessage.InvalidParameterValue(C8o.ENGINE_PARAMETER_PROJECT, C8oExceptionMessage.UnknownValue("fullSync requestable", fullSyncRequestableValue)));
            }

            // Gets the database name if this is not specified then if takes the default database name
            string databaseName = projectParameterValue.Substring(C8oFullSync.FULL_SYNC_PROJECT.Length);

            if (databaseName.Length < 1)
            {
                databaseName = c8o.DefaultDatabaseName;
                if (databaseName == null)
                {
                    throw new ArgumentException(C8oExceptionMessage.InvalidParameterValue(C8o.ENGINE_PARAMETER_PROJECT, C8oExceptionMessage.MissingValue("fullSync database name")));
                }
            }

            Object response;

            try
            {
                response = await fullSyncRequestable.HandleFullSyncRequest(this, databaseName, parameters, listener);
            }
            catch (C8oException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new C8oException(C8oExceptionMessage.FullSyncRequestFail(), e);
            }

            if (response == null)
            {
                throw new C8oException(C8oExceptionMessage.couchNullResult());
            }

            response = HandleFullSyncResponse(response, listener);
            return(response);
        }
Example #2
0
 internal static FullSyncRequestable GetFullSyncRequestable(String value)
 {
     FullSyncRequestable[] fullSyncRequestableValues = FullSyncRequestable.Values();
     foreach (FullSyncRequestable fullSyncRequestable in fullSyncRequestableValues)
     {
         if (fullSyncRequestable.value.Equals(value))
         {
             return(fullSyncRequestable);
         }
     }
     return(null);
 }