/// <summary> /// Extract the actual ConfigurationTemplate from the defined value /// </summary> public static ConfigurationTemplate Template(Rock.Client.DefinedValue templateDefinedValue) { ConfigurationTemplate configTemplate = null; if (templateDefinedValue.AttributeValues != null) { string configString = templateDefinedValue.AttributeValues["ConfigurationTemplate"].Value; try { configTemplate = JsonConvert.DeserializeObject <ConfigurationTemplate>(configString) as ConfigurationTemplate; } catch { Console.WriteLine("WARNING! Configuration Template Deserialization FAILED!"); configTemplate = null; } } else { Console.WriteLine("WARNING! Configuration Template Defined Value is EMPTY!"); } // if we failed to get it (maybe the templateDefinedValue is blank?) return an empty one. return(configTemplate != null ? configTemplate : new ConfigurationTemplate( )); }
public static void UpdateTemplate(Rock.Client.DefinedValue templateDefinedValue, OnTemplateUpdated onUpdated) { // get the Type and Specific Ids so we can request this specific template. int typeId = TemplateTypeId(templateDefinedValue); int uniqueId = TemplateUniqueId(templateDefinedValue); FamilyManagerApi.GetConfigurationTemplates(typeId, uniqueId, delegate(System.Net.HttpStatusCode statusCode, string statusDescription, List <Rock.Client.DefinedValue> definedValueModels) { if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true && definedValueModels != null && definedValueModels.Count > 0) { // extract the ConfigurationTemplate itself from both, and compare them. ConfigurationTemplate currentTemplate = Template(templateDefinedValue); currentTemplate.SortAttributeLists( ); ConfigurationTemplate downloadedTemplate = Template(definedValueModels[0]); downloadedTemplate.SortAttributeLists( ); // is it different? string currentVersion = JsonConvert.SerializeObject(currentTemplate); string downloadedVersion = JsonConvert.SerializeObject(downloadedTemplate); if (string.Compare(currentVersion, downloadedVersion) != 0) { // they're different, so provide the latest one onUpdated(true, definedValueModels[0]); } else { onUpdated(true, null); } } else { onUpdated(false, null); } }); }