/// <summary>
        /// This method checks if the view is indexed by requesting output with low priority
        /// </summary>
        /// <param name="designDocumentName"></param>
        /// <param name="isLive"></param>
        /// <param name="isTemporal"></param>
        /// <returns></returns>
        private async Task CheckDesignDocumentIndexation()
        {
            try
            {
                //Advice from cloudant.
                //Calling the view will make it build at an elevated rate versus the background level we do, 
                //so I would suggest adding a special HTTP header 'x-cloudant-io-priority: low', to ensure it runs at the background priority.
                HTTPRequestManager RequestManager = new HTTPRequestManager();
                if (String.IsNullOrEmpty(ViewURL))
                {

                    //start the get request
                    string response;

                    if (Debug)
                    {
                        OutputHelper.WriteProgress("step1: get view names for (" + DesignDocumentName + ")");
                        OutputHelper.WriteProgress("step1 (url): " + DesignDocumentURL);
                    }

                    //Check the  design document
                    response = await RequestManager.GetContent(DesignDocumentURL, null, "GET", Profile.GetEnvironment(DBEnvironmentName).APIKey, APIPassword);//900000
 
                    if (response == null)
                    {
                        OutputHelper.WriteProgress("No response received: design document not found (" + DesignDocumentName + ")");
                        throw new Exception("DesignDocument not found");
                    }


                    //Convert Response to model, to get revisionNumber.
                    DesignDocument designdoc = JsonConvert.DeserializeObject<DesignDocument>(response);

                    if (designdoc == null || designdoc.views == null || designdoc.views.Count() == 0)
                    {
                        OutputHelper.WriteProgress("Something went wrong in the publish and the design document was not found.(" + DesignDocumentName + ")");
                        throw new Exception("DesignDocument not found");
                    }

                    //Debug message
                    if (Debug)
                        OutputHelper.WriteProgress("step2: viewNames received (" + DesignDocumentName + ")");

                    //List viewnames
                    List<string> viewNames = designdoc.views.Select(x => x.Key).ToList();

                    //Create an viewurl to request.
                    ViewURL = DesignDocumentURL + "/_view/" + viewNames.FirstOrDefault();
                }

                //start the get request
                HttpWebResponse indexCheckResponse;

                // Check indexation
                indexCheckResponse = await RequestManager.SendRequest(ViewURL, null, "GET", Profile.GetEnvironment(DBEnvironmentName).APIKey, APIPassword);//900000


                if ((int)indexCheckResponse.StatusCode != 200)
                {
                    OutputHelper.WriteProgress("Received Bad response (" + (int)indexCheckResponse.StatusCode + ") on indexation check: " + DesignDocumentName);
                    OutputHelper.WriteProgress("Indexation of " + DesignDocumentName + " failed.");
                    throw new Exception("Index check Response != 200");
                }

                OutputHelper.WriteProgress("Successfully checked indexation on: " + DesignDocumentName);
                Succeeded = true;
            }
            catch (Exception exc)
            {
                //Notify that an error occured.. (Automaticly it will be restarted)
                OutputHelper.WriteProgress("Indexation of " + DesignDocumentName + " failed.");
            }
        }
        /// <summary>
        /// Deletes a list of temporal design documents. (cleanup)
        /// </summary>
        /// <param name="designDocuments"></param>
        /// <param name="isLive"></param>
        private async Task CleanupTemporalPublish(List<string> designDocuments, string dbEnvironment)
        {
            HTTPRequestManager RequestManager = new HTTPRequestManager();
            Console.WriteLine();
            OutputHelper.WriteProgress("Cleanup of temporal design documents started");
            foreach (string designDocumentName in designDocuments)
            {
                try
                {
                    //Rewrite document name to temporal documentName
                    string tempDesignDocumentName = TEMPORAL_PREFIX + designDocumentName;

                    // create deleteURL
                    string designDocumentURL = Profile.GetDesignDocumentURL(dbEnvironment, tempDesignDocumentName);

                    //Get revision for deletion
                    string response = await RequestManager.GetContent(designDocumentURL, null, "GET", Profile.GetEnvironment(dbEnvironment).APIKey, APIPassword);

                    //Convert Response to model, to get revisionNumber.
                    DesignDocument ddToDelete = JsonConvert.DeserializeObject<DesignDocument>(response);

                    // MAKE HTTP Delete request
                    HttpWebResponse deleteResponse = await RequestManager.SendRequest(designDocumentURL + "?rev=" + ddToDelete._rev, null, "DELETE", Profile.GetEnvironment(dbEnvironment).APIKey, APIPassword);

                    if ((int)deleteResponse.StatusCode == 200)
                    {
                        OutputHelper.WriteProgress("Design document " + tempDesignDocumentName + " successfully deleted");
                    }
                    else
                    {
                        OutputHelper.WriteProgress("Deletion of temporal design document: " + tempDesignDocumentName + " failed! Try manually.");
                    }
                }
                catch (Exception exc)
                {
                    OutputHelper.WriteProgress("Deletion of temporal design document: " + TEMPORAL_PREFIX + designDocumentName + " failed! Try manually.");
                }
            }

            OutputHelper.WriteProgress("Clean-up finished");
        }