예제 #1
0
        private ObservableCollection<Folder> InitializeFolders()
        {
            // get the default folders and enqueue an operation to insert each one of them and their subitems
            var folders = new ObservableCollection<Folder>(UserConstants.DefaultFolders(null));
            foreach (var folder in folders)
            {
                string queueName = folder.Name.StartsWith("$") ? RequestQueue.SystemQueue : RequestQueue.UserQueue;
                FolderDictionary.Add(folder.ID, folder);
                RequestQueue.EnqueueRequestRecord(queueName,
                    new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = folder, ID = folder.ID, IsDefaultObject = true });

                foreach (var item in folder.Items)
                {
                    RequestQueue.EnqueueRequestRecord(queueName,
                        new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = item, ID = item.ID, IsDefaultObject = true });

                }
                StorageHelper.WriteFolder(folder);
            }

            // extract the $Client folder and handle it specially
            var cf = folders.Single(f => f.Name == SystemEntities.Client);
            folders.Remove(cf);
            ClientFolder = cf;
            // extract the $PhoneClient folder and handle it specially
            var pcf = folders.Single(f => f.Name == SystemEntities.PhoneClient);
            folders.Remove(pcf);
            PhoneClientFolder = pcf;

            // initialize the SelectedCount for a few default folders and lists
            /*
            foreach (var folder in folders)
            {
                if (folder.Name == UserEntities.People ||
                    folder.Name == UserEntities.Places)
                {
                    ListMetadataHelper.IncrementListSelectedCount(pcf, folder);
                    continue;
                }
                foreach (var item in folder.Items)
                {
                    if (item.Name == UserEntities.Tasks ||
                        item.Name == UserEntities.Groceries)
                    {
                        ListMetadataHelper.IncrementListSelectedCount(pcf, item);
                        continue;
                    }
                }                
            }
            */

            return folders;
        }
예제 #2
0
        void CreateDefaultFolders(UserDataModel model)
        {
            try
            {
                List <Folder> folders = UserConstants.DefaultFolders(this.CurrentUser);
                foreach (var folder in folders)
                {
                    // child items must be added AFTER saving parent items
                    // EF cannot determine which items are dependent on eachother
                    List <Item> folderItems = new List <Item>();
                    List <Item> childItems  = new List <Item>();
                    foreach (var item in folder.Items)
                    {
                        if (item.ParentID == null)
                        {
                            folderItems.Add(item);
                        }
                        else
                        {
                            childItems.Add(item);
                        }
                    }
                    folder.Items = folderItems;
                    model.StorageContext.Folders.Add(folder);
                    model.StorageContext.SaveChanges();

                    if (childItems.Count > 0)
                    {
                        foreach (var item in childItems)
                        {
                            model.StorageContext.Items.Add(item);
                        }
                        model.StorageContext.SaveChanges();
                    }
                }

                // create an operation corresponding to the new user creation
                var operation = model.StorageContext.CreateOperation(this.CurrentUser, "POST", (int?)HttpStatusCode.Created, this.CurrentUser, null);

                // kick off the New User workflow
                WorkflowHost.WorkflowHost.InvokeWorkflowForOperation(model.StorageContext, null, operation);
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("CreateDefaultFolders failed", ex);
                throw;
            }
        }