/// <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( ));
        }
Esempio n. 2
0
        public void SetConfigurationDefinedValue(Rock.Client.DefinedValue configDefinedValue, ConfigurationSet onConfigSet)
        {
            // extract the config template from the defined value
            ConfigurationTemplate configTemplate = ConfigurationTemplate.Template(configDefinedValue);

            configTemplate.VisualSettings.RemoveDownloadedImages( );

            // first get the theme images
            configTemplate.VisualSettings.DownloadImages(RockApi.BaseUrl,
                                                         delegate(bool imageResult)
            {
                if (imageResult == true)
                {
                    // start by sorting our attributes so we get the defined values correctly
                    configTemplate.SortAttributeLists( );

                    // get the family attribute definitions
                    DownloadAttributeDefinitions(configTemplate.FamilyAttributes, delegate(List <Rock.Client.Attribute> familyAttribDefines)
                    {
                        if (familyAttribDefines != null)
                        {
                            // finally, download the PERSON attribute definitions
                            DownloadAttributeDefinitions(configTemplate.PersonAttributes, delegate(List <Rock.Client.Attribute> personAttribDefines)
                            {
                                // it worked! we're done.
                                if (personAttribDefines != null)
                                {
                                    // it all worked, so store our values and save!
                                    CurrentConfigurationTemplate = configDefinedValue;

                                    _Instance.FamilyAttributeDefines = familyAttribDefines;
                                    _Instance.PersonAttributeDefines = personAttribDefines;

                                    // save to the device
                                    SaveToDevice( );
                                }

                                // and either way, return the result
                                onConfigSet(personAttribDefines != null ? true : false);
                            });
                        }
                        // failed to download family attributes
                        else
                        {
                            onConfigSet(false);
                        }
                    });
                }
                // failed to get the images
                else
                {
                    onConfigSet(false);
                }
            });
        }
Esempio n. 3
0
        public Config( )
        {
            FamilyAttributeDefines       = new List <Rock.Client.Attribute>();
            PersonAttributeDefines       = new List <Rock.Client.Attribute>();
            CurrentConfigurationTemplate = new Rock.Client.DefinedValue();

            // default recording first visits to true.
            RecordFirstVisit = true;

            // default auto-detecting the campus to true.
            AutoDetectCampus = true;
        }
Esempio n. 4
0
        public Config( )
        {
            FamilyAttributeDefines = new List<Rock.Client.Attribute>();
            PersonAttributeDefines = new List<Rock.Client.Attribute>();
            CurrentConfigurationTemplate = new Rock.Client.DefinedValue();

            // default recording first visits to true.
            RecordFirstVisit = true;

            // default auto-detecting the campus to true.
            AutoDetectCampus = true;
        }
        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);
                }
            });
        }
Esempio n. 6
0
        void HandleDownloadResult(string result)
        {
            // unhide the blocker
            BlockerView.Hide(
                delegate
            {
                Sync.Enabled = true;
                DisplaySyncResult(result);

                // reset the currently selected rows if necessary, so that the text color is visible
                if (CampusTableView.IndexPathForSelectedRow != null)
                {
                    ((CampusTableData)CampusTableView.Source).SetRowColor(CampusTableView, CampusTableView.IndexPathForSelectedRow, UIColor.Black);
                }

                if (TemplateTableView.IndexPathForSelectedRow != null)
                {
                    ((TemplateTableData)TemplateTableView.Source).SetRowColor(TemplateTableView, TemplateTableView.IndexPathForSelectedRow, UIColor.Black);
                }

                CampusTableView.ReloadData( );
                TemplateTableView.ReloadData( );

                // now set the appropriate campus selection
                if (Campuses.Count > 0)
                {
                    int campusIndex = 0;

                    // try to find the selected campus in the newly downloaded list.
                    Rock.Client.Campus campus = Campuses.Where(c => c.Id == Config.Instance.Campuses[Config.Instance.SelectedCampusIndex].Id).SingleOrDefault( );
                    if (campus != null)
                    {
                        // we found it, so take its index and set it.
                        campusIndex = Campuses.IndexOf(campus);

                        // update the table selections
                        NSIndexPath rowToSelect = NSIndexPath.FromRowSection(campusIndex, 0);
                        CampusTableView.SelectRow(rowToSelect, false, UITableViewScrollPosition.None);
                        ((CampusTableData)CampusTableView.Source).SetRowColor(CampusTableView, rowToSelect, UIColor.White);
                    }
                }


                // and theme
                if (ConfigurationTemplates.Count > 0)
                {
                    int themeIndex = 0;

                    // try to find the selected campus in the newly downloaded list.
                    Rock.Client.DefinedValue configTemplate = ConfigurationTemplates.Where(ct => ct.Id == Config.Instance.ConfigurationTemplateId).SingleOrDefault( );
                    if (configTemplate != null)
                    {
                        // we found it, so take its index and set it.
                        themeIndex = ConfigurationTemplates.IndexOf(configTemplate);

                        // update the table selections
                        NSIndexPath rowToSelect = NSIndexPath.FromRowSection(themeIndex, 0);
                        TemplateTableView.SelectRow(rowToSelect, false, UITableViewScrollPosition.None);
                        ((TemplateTableData)TemplateTableView.Source).SetRowColor(TemplateTableView, rowToSelect, UIColor.White);
                    }
                }

                // run this to see if we can enable the save button.
                RowSelected( );
            });
        }
 /// <summary>
 /// Extract the template's user readable name
 /// </summary>
 public static string TemplateName(Rock.Client.DefinedValue templateDefinedValue)
 {
     return(templateDefinedValue.Value);
 }
 /// <summary>
 /// Extract the Template's TYPE ID ( same for all ConfigurationTemplates)
 /// </summary>
 public static int TemplateTypeId(Rock.Client.DefinedValue templatedDefinedValue)
 {
     return(templatedDefinedValue.DefinedTypeId);
 }
 /// <summary>
 /// Extract the Template's unique ID
 /// </summary>
 public static int TemplateUniqueId(Rock.Client.DefinedValue templateDefinedValue)
 {
     return(templateDefinedValue.Id);
 }