Example #1
0
        private void GetConstantsCallback(Constants constants)
        {
            // trace callback
            TraceHelper.AddMessage(String.Format("Finished Get Constants: {0}", constants == null ? "null" : "success"));

            if (constants != null)
            {
                retrievedConstants = true;
				
#if FALSE && !IOS
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
#endif
                    // no requests pending - we can use the Service constants as the authoritative ones
                    Constants = constants;

                    // reset priority names and colors inside the Item static arrays
                    // these static arrays are the most convenient way to make databinding work
                    int i = 0;
                    foreach (var pri in constants.Priorities)
                    {
                        Item.PriorityNames[i] = pri.Name;
                        Item.PriorityColors[i++] = pri.Color;
                    }

                    // initialize the static ItemTypes dictionary
                    ItemType.CreateDictionary(constants.ItemTypes);

                    // Chain the PlayQueue call to drain the queue and retrieve the user data
                    PlayQueue(RequestQueue.UserQueue);
#if FALSE && !IOS
                });
#endif
            }
            else
            {
                // refresh cycle interrupted - still need to signal the SyncComplete event if it was set
                if (SyncComplete != null)
                    SyncComplete(this, new SyncCompleteEventArgs(SyncCompleteArg));
                
            }
        }
Example #2
0
        public void LoadData()
        {
            // check if the data has already been loaded
            if (this.IsDataLoaded == true)
                return;

            // trace loading data
            TraceHelper.AddMessage("Load Data");

            // read the user credentials (can be null)
            this.User = StorageHelper.ReadUserCredentials();

            // read the folder types - and create them if they don't exist
            this.constants = StorageHelper.ReadConstants();
            if (this.constants == null || 
                this.constants.ActionTypes == null || this.constants.ActionTypes.Count == 0 ||
                this.constants.Colors == null || this.constants.Colors.Count == 0 ||
                this.constants.Permissions == null || this.constants.Permissions.Count == 0 ||
                this.constants.Priorities == null || this.constants.Priorities.Count == 0)
            {
                this.Constants = InitializeConstants();
            }

            // read the item types - and create them if they don't exist
            this.itemTypes = StorageHelper.ReadItemTypes();
            if (this.itemTypes == null || this.itemTypes.Count == 0)
            {
                this.ItemTypes = InitializeItemTypes();
            }
            else
            {
                // initialize the static ItemTypes dictionary
                ItemType.CreateDictionary(itemTypes);
            }

            // read the tags - and create them if they don't exist
            this.tags = StorageHelper.ReadTags();
            if (this.tags == null)
            {
                this.Tags = InitializeTags();
            }

            // create the FolderDictionary dictionary
            if (this.folderDictionary == null)
                this.FolderDictionary = new Dictionary<Guid, Folder>();

            // read the folders - and create it if it doesn't exist AND if the user credentials have never been set
            this.folders = StorageHelper.ReadFolders();
            if (this.folders == null || this.folders.Count == 0)
			{
				if (this.User == null || this.User.Synced == false)
	            {
	                // we don't want to create the "starter" data if we already have a sync relationship with the service
	                this.Folders = InitializeFolders();
	            }
				else
					this.Folders = new ObservableCollection<Folder>();
			}

            // load the contents of each folder 
            List<Guid> guidList = Folders.Select(f => f.ID).ToList<Guid>();
            foreach (Guid guid in guidList)
                LoadFolder(guid);

            // create the tags and values collections (client-only properties)
            if (folders != null)
            {
                foreach (Folder f in folders)
                {
                    if (f.Items != null)
                        foreach (Item i in f.Items)
                            i.CreateTags(tags);
                }
            }

            this.IsDataLoaded = true;

            // trace finished loading data
            TraceHelper.AddMessage("Finished Load Data");
        }