private static string GetSignpostServerDataVersion(string signpostServer, out int signpostServerDataVersion) { signpostServerDataVersion = -1; // Build the web service url for the signpost server string url = signpostServer + "/DataVersion?secretkey=CDEF9B9357CD47B7A87CDF510674C327"; string responseJson = ""; // Call the web service on the signpost server if (!HttpHelper.RestGet(url, "application/json", out responseJson)) { return("Error connecting to " + url); } // Check for errors string errorMessage = SignpostServerSync.CheckForError(responseJson); if (errorMessage != null) { return(errorMessage); } // Extract the data version from the JSON returned by the signpost server SignPostServerVersion signPostServerVersion = JsonConvert.DeserializeObject <SignPostServerVersion>(responseJson); if (signPostServerVersion == null) { return("Data version missing from Signpost web service json: " + url + " " + responseJson); } signpostServerDataVersion = signPostServerVersion.Version; return(""); }
/// <summary> /// Must be called from the cloud signPost master. Syncs cloud SignPost master with all cloud signpost servers /// </summary> public static string ServerSync() { // Get the current data version string toVersionString = string.Empty; AndroAdminDataAccessFactory.GetSettingsDAO().GetByName("DataVersion", out toVersionString); int toVersion = 0; if (!int.TryParse(toVersionString, out toVersion)) { return("Internal error"); } // Get the signpost server names string signpostServerList = ConfigurationManager.AppSettings["SignPostServers"]; string[] signpostServers = signpostServerList.Split(','); string errorMessage = string.Empty; foreach (string signpostServer in signpostServers) { // 1) Ask the server for it's current data version int signpostServerDataVersion = -1; errorMessage = SignpostServerSync.GetSignpostServerDataVersion(signpostServer, out signpostServerDataVersion); if (errorMessage.Length == 0) { // 2) Generate a block of JSON that contains the sync data string exportJson = string.Empty; errorMessage = SignpostServerSync.GenerateExportJson(signpostServerDataVersion, out exportJson); if (errorMessage.Length != 0) { return(errorMessage); } // 3) Send sync XML to signpost server errorMessage = SignpostServerSync.DoSync(signpostServer, exportJson); if (errorMessage != null && errorMessage.Length != 0) { return(errorMessage); } // 4) Insert logs/audit data into Cloud Master. // Run out of time - future task } } return(errorMessage); }
private static string DoSync(string signpostServer, string syncJson) { // Build the web service url for the signpost server string url = signpostServer + "/sync?secretkey=CDEF9B9357CD47B7A87CDF510674C327"; string responseJson = ""; // Call the web service on the signpost server if (!HttpHelper.RestPost(url, syncJson, "application/json", null, out responseJson)) { return("Error connecting to " + url); } // Check for errors return(SignpostServerSync.CheckForError(responseJson)); }