Ejemplo n.º 1
0
        public static void StorePhoneSetting(Folder phoneClient, string setting, string value)
        {
            if (phoneClient == null)
            {
                return;
            }

            var     phoneSettingsItem = GetPhoneSettingsItem(phoneClient);
            var     settings          = phoneSettingsItem.GetFieldValue(FieldNames.Value, true);
            JObject jsonSettings      = null;

            if (settings != null && !String.IsNullOrEmpty(settings.Value))
            {
                jsonSettings = JObject.Parse(settings.Value);
            }
            else
            {
                jsonSettings = new JObject();
            }
            jsonSettings[setting] = value;
            settings.Value        = jsonSettings.ToString();

            // store the phone client folder
            StorageHelper.WritePhoneClient(phoneClient);
        }
Ejemplo n.º 2
0
        // helper for adding list item to either $Client or $PhoneClient folder
        private static Item GetOrCreateList(Folder folder, string name, Guid itemType)
        {
            if (folder == null)
            {
                return(null);
            }

            // get the list item
            Item listItem = null;

            if (folder.Items.Any(i => i.Name == name && i.ParentID == null))
            {
                listItem = folder.Items.First(i => i.Name == name && i.ParentID == null);
            }
            else
            {
                DateTime now = DateTime.UtcNow;
                listItem = new Item()
                {
                    Name         = SystemEntities.ListMetadata,
                    FolderID     = folder.ID,
                    IsList       = true,
                    ItemTypeID   = itemType,
                    Items        = new ObservableCollection <Item>(),
                    Created      = now,
                    LastModified = now
                };
                folder.Items.Add(listItem);

                // store the client or phone client folder
                if (folder.Name == SystemEntities.Client)
                {
                    StorageHelper.WriteClient(folder);
                }
                else if (folder.Name == SystemEntities.PhoneClient)
                {
                    StorageHelper.WritePhoneClient(folder);
                }

                // queue up a server request
                if (folder.ID != Guid.Empty)
                {
                    RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord()
                    {
                        ReqType         = RequestQueue.RequestRecord.RequestType.Insert,
                        Body            = listItem,
                        ID              = listItem.ID,
                        IsDefaultObject = true
                    });
                }
            }

            return(listItem);
        }
Ejemplo n.º 3
0
        public static Item GetPhoneSettingsItem(Folder phoneClient)
        {
            if (phoneClient == null)
            {
                return(null);
            }

            // get the list of phone settings
            Item phoneSettings = null;

            if (phoneClient.Items.Any(i => i.Name == SystemEntities.PhoneSettings))
            {
                phoneSettings = phoneClient.Items.Single(i => i.Name == SystemEntities.PhoneSettings);
            }
            else
            {
                DateTime now = DateTime.UtcNow;
                phoneSettings = new Item()
                {
                    Name         = SystemEntities.PhoneSettings,
                    FolderID     = phoneClient.ID,
                    ItemTypeID   = SystemItemTypes.NameValue,
                    FieldValues  = new ObservableCollection <FieldValue>(),
                    Created      = now,
                    LastModified = now
                };
                phoneClient.Items.Add(phoneSettings);

                // store the phone client folder
                StorageHelper.WritePhoneClient(phoneClient);

                // queue up a server request
                if (phoneClient.ID != Guid.Empty)
                {
                    RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord()
                    {
                        ReqType         = RequestQueue.RequestRecord.RequestType.Insert,
                        Body            = phoneSettings,
                        ID              = phoneSettings.ID,
                        IsDefaultObject = true
                    });
                }
            }

            return(phoneSettings);
        }
Ejemplo n.º 4
0
        public static void StoreListMetadataValue(Folder phoneClient, ClientEntity list, string fieldName, string value)
        {
            if (phoneClient == null)
            {
                return;
            }

            var listsMetadata = GetListMetadataList(phoneClient);
            var listID        = list.ID.ToString();

            if (phoneClient.Items.Any(i =>
                                      i.ParentID == listsMetadata.ID &&
                                      i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID)))
            {
                var metadataItem = phoneClient.Items.Single(i =>
                                                            i.ParentID == listsMetadata.ID &&
                                                            i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID));
                Item copy       = new Item(metadataItem);
                var  fieldValue = metadataItem.GetFieldValue(fieldName, true);
                fieldValue.Value = value;

                // queue up a server request
                if (phoneClient.ID != Guid.Empty)
                {
                    RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord()
                    {
                        ReqType = RequestQueue.RequestRecord.RequestType.Update,
                        Body    = new List <Item>()
                        {
                            copy, metadataItem
                        },
                        BodyTypeName    = "Item",
                        ID              = metadataItem.ID,
                        IsDefaultObject = true
                    });
                }
            }
            else
            {
                Guid     id           = Guid.NewGuid();
                DateTime now          = DateTime.UtcNow;
                var      metadataItem = new Item()
                {
                    ID           = id,
                    Name         = list.Name,
                    ItemTypeID   = SystemItemTypes.Reference,
                    FolderID     = phoneClient.ID,
                    ParentID     = listsMetadata.ID,
                    Created      = now,
                    LastModified = now,
                    FieldValues  = new ObservableCollection <FieldValue>()
                    {
                        new FieldValue()
                        {
                            ItemID    = id,
                            FieldName = FieldNames.EntityRef,
                            Value     = list.ID.ToString(),
                        },
                        new FieldValue()
                        {
                            ItemID    = id,
                            FieldName = FieldNames.EntityType,
                            Value     = list.GetType().Name,
                        },
                        new FieldValue()
                        {
                            ItemID    = id,
                            FieldName = fieldName,
                            Value     = value
                        }
                    }
                };
                phoneClient.Items.Add(metadataItem);

                // queue up a server request
                if (phoneClient.ID != Guid.Empty)
                {
                    RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord()
                    {
                        ReqType         = RequestQueue.RequestRecord.RequestType.Insert,
                        Body            = metadataItem,
                        ID              = metadataItem.ID,
                        IsDefaultObject = true
                    });
                }
            }

            // store the phone client folder
            StorageHelper.WritePhoneClient(phoneClient);
        }