Esempio n. 1
0
 public Tag(Tag tag)
 {
     Copy(tag);
 }
Esempio n. 2
0
        public void Copy(Tag obj)
        {
            if (obj == null)
                return;

            // copy all of the properties
            foreach (PropertyInfo pi in this.GetType().GetProperties())
            {
                var val = pi.GetValue(obj, null);
                pi.SetValue(this, val, null);
            }
        }
Esempio n. 3
0
        private void RenderEditItemTagList(TextBox taglist, Item item, PropertyInfo pi)
        {
            taglist.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };

            // build the comma delimited tag folder for this item
            bool addDelimiter = false;
            StringBuilder sb = new StringBuilder();
            var itemtags = (IEnumerable<ItemTag>)pi.GetValue(item, null);
            if (itemtags != null)
            {
                foreach (ItemTag tt in itemtags)
                {
                    if (addDelimiter)
                        sb.Append(",");
                    Tag tag = App.ViewModel.Tags.Single(t => t.ID == tt.TagID);
                    sb.Append(tag.Name);
                    addDelimiter = true;
                }
                taglist.Text = sb.ToString();
            }

            // retrieve the itemtags for the item, creating new tags along the way
            taglist.LostFocus += new RoutedEventHandler(delegate
            {
                //ObservableCollection<ItemTag> existingTags = (ObservableCollection<ItemTag>)pi.GetValue(item, null);
                ObservableCollection<ItemTag> newTags = new ObservableCollection<ItemTag>();
                string[] tags = taglist.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var tt in tags)
                {
                    string str = tt.Trim();
                    Tag tag;
                    try
                    {
                        tag = App.ViewModel.Tags.Single(t => t.Name == str);
                        newTags.Add(new ItemTag() { Name = str, TagID = tag.ID, ItemID = item.ID });
                    }
                    catch (Exception)
                    {
                        // this is a new tag that we need to create
                        tag = new Tag() { Name = str };
                        newTags.Add(new ItemTag() { Name = str, TagID = tag.ID, ItemID = item.ID });

                        // enqueue the Web Request Record
                        RequestQueue.EnqueueRequestRecord(RequestQueue.UserQueue,
                            new RequestQueue.RequestRecord()
                            {
                                ReqType = RequestQueue.RequestRecord.RequestType.Insert,
                                Body = new Tag(tag)
                            });

                        // add the tag to the tag folder
                        App.ViewModel.Tags.Add(tag);

                        // save the changes to local storage
                        StorageHelper.WriteTags(App.ViewModel.Tags);
                    }
                }

                // store the new ItemTag collection in the item
                pi.SetValue(item, newTags, null);

                // create the mirror Tags collection in the item
                item.CreateTags(App.ViewModel.Tags);
            });
        }
Esempio n. 4
0
        // When page is navigated to set data context to selected item in itemType
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // trace data
            TraceHelper.AddMessage("ListPage: OnNavigatedTo");

            // handle list picker navigation cases
            if (sortPopupOpen == true)
            {
                SortPopup.IsOpen = true;
                return;
            }
            if (importPopupOpen == true)
            {
                ImportListPopup.IsOpen = true;
                return;
            }

            string IDString = "";
            Guid id;

            // get the type of list to display
            if (NavigationContext.QueryString.TryGetValue("type", out typeString) == false)
            {
                // trace page navigation
                TraceHelper.StartMessage("ListPage: Navigate back");

                // navigate back
                NavigateBack();
                return;
            }

            // get the ID of the object to display
            if (NavigationContext.QueryString.TryGetValue("ID", out IDString) == false)
            {
                // trace page navigation
                TraceHelper.StartMessage("ListPage: Navigate back");

                // navigate back
                NavigateBack();
                return;
            }

            // get the ID
            id = new Guid(IDString);

            switch (typeString)
            {
                case "Folder":
                    // get the folder and make it the datacontext
                    try
                    {
                        folder = App.ViewModel.LoadFolder(id);

                        // if the load failed, this folder has been deleted
                        if (folder == null)
                        {
                            // the folder isn't found - this can happen when the folder we were just
                            // editing was removed in FolderEditor, which then goes back to ListPage.
                            // this will send us back to the MainPage which is appropriate.

                            // trace page navigation
                            TraceHelper.StartMessage("ListPage: Navigate back");

                            // navigate back
                            NavigateBack();
                            return;
                        }

                        // get the ID of the list to display
                        if (NavigationContext.QueryString.TryGetValue("ParentID", out IDString) == false)
                        {
                            // trace page navigation
                            TraceHelper.StartMessage("ListPage: Navigate back");

                            // navigate back
                            NavigateBack();
                            return;
                        }

                        // get the ID
                        id = new Guid(IDString);

                        // get the current list name
                        string listName = null;
                        Guid? listID = null;
                        Guid itemTypeID;
                        if (id == Guid.Empty)
                        {
                            listName = folder.Name;
                            itemTypeID = folder.ItemTypeID;
                        }
                        else
                        {
                            var item = folder.Items.Single(i => i.ID == id);
                            listName = item.Name;
                            listID = (Guid?)id;
                            itemTypeID = item.ItemTypeID;

                            // change the "edit folder" appbar button title to "edit list"
                            ApplicationBarIconButton button = null;
                            for (int i = 0; i < ApplicationBar.Buttons.Count; i++)
                            {
                                button = (ApplicationBarIconButton)ApplicationBar.Buttons[i];
                                if (button.Text.StartsWith("edit", StringComparison.InvariantCultureIgnoreCase))
                                    break;
                            }
                            if (button.Text.StartsWith("edit", StringComparison.InvariantCultureIgnoreCase))
                                button.Text = "edit list";
                        }

                        // construct a synthetic item that represents the list of items for which the
                        // ParentID is the parent.  this also works for the root list in a folder, which
                        // is represented with a ParentID of Guid.Empty.
                        list = new Item()
                        {
                            ID = id,
                            Name = listName,
                            FolderID = folder.ID,
                            IsList = true,
                            ItemTypeID = itemTypeID,
                            Items = folder.Items.Where(i => i.ParentID == listID).ToObservableCollection()
                        };
                    }
                    catch (Exception ex)
                    {
                        // the folder isn't found - this can happen when the folder we were just
                        // editing was removed in FolderEditor, which then goes back to ListPage.
                        // this will send us back to the MainPage which is appropriate.

                        // trace page navigation
                        TraceHelper.StartMessage(String.Format("ListPage: Navigate back (exception: {0})", ex.Message));

                        // navigate back
                        NavigateBack();
                        return;
                    }
                    break;
                case "Tag":
                    // create a filter
                    try
                    {
                        tag = App.ViewModel.Tags.Single(t => t.ID == id);

                        // construct a synthetic item that represents the list of items which
                        // have this tag.
                        list = new Item()
                        {
                            ID = Guid.Empty,
                            Name = String.Format("items with {0} tag", tag.Name),
                            Items = App.ViewModel.Items.Where(t => t.ItemTags.Any(tg => tg.TagID == tag.ID)).ToObservableCollection()
                        };
                    }
                    catch (Exception)
                    {
                        // the tag isn't found - this can happen when the tag we were just
                        // editing was removed in TagEditor, which then goes back to ListPage.
                        // this will send us back to the MainPage which is appropriate.

                        // trace page navigation
                        TraceHelper.StartMessage("ListPage: Navigate back");

                        // navigate back
                        NavigateBack();
                        return;
                    }
                    break;
                default:
                    // trace page navigation
                    TraceHelper.StartMessage("ListPage: Navigate back");

                    // navigate back
                    NavigateBack();
                    return;
            }

            // set datacontext
            ListGrid.DataContext = list;

            // create the ListHelper
            ListHelper = new ListHelper(
                new RoutedEventHandler(CompleteCheckbox_Click),
                new RoutedEventHandler(Tag_HyperlinkButton_Click));

            // store the current listbox and ordering
            ListHelper.ListBox = ItemsListBox;
            ListHelper.OrderBy = ListMetadataHelper.GetListSortOrder(
                App.ViewModel.PhoneClientFolder,
                id == Guid.Empty ? (ClientEntity) folder : (ClientEntity) list);

            // trace data
            TraceHelper.AddMessage("Exiting ListPage OnNavigatedTo");
        }
Esempio n. 5
0
        void TagEditor_Loaded(object sender, RoutedEventArgs e)
        {
            // trace event
            TraceHelper.AddMessage("TagEditor: Loaded");

            ConnectedIconImage.DataContext = App.ViewModel;
            LayoutRoot.DataContext = App.ViewModel;

            string tagIDString = "";

            if (NavigationContext.QueryString.TryGetValue("ID", out tagIDString))
            {
                if (tagIDString == "new")
                {
                    // new tag
                    tagCopy = new Tag();
                    TitlePanel.DataContext = tagCopy;
                }
                else
                {
                    Guid tagID = new Guid(tagIDString);
                    tag = App.ViewModel.Tags.Single<Tag>(tl => tl.ID == tagID);

                    // make a deep copy of the tag for local binding
                    tagCopy = new Tag(tag);
                    TitlePanel.DataContext = tagCopy;

                    // add the delete button to the ApplicationBar
                    var button = new ApplicationBarIconButton() { Text = "Delete", IconUri = new Uri("/Images/appbar.delete.rest.png", UriKind.Relative) };
                    button.Click += new EventHandler(DeleteButton_Click);

                    // insert after the save button but before the cancel button
                    ApplicationBar.Buttons.Add(button);
                }
            }

            ColorListPicker.ItemsSource = App.ViewModel.Constants.Colors;
            ColorListPicker.DisplayMemberPath = "Name";
            try
            {
                BuiltSteady.Zaplify.Devices.ClientEntities.Color color = App.ViewModel.Constants.Colors.Single(c => c.ColorID == tagCopy.ColorID);
                ColorListPicker.SelectedIndex = App.ViewModel.Constants.Colors.IndexOf(color);
            }
            catch (Exception)
            {
            }
            //ColorListPicker.ExpansionMode = ExpansionMode.FullScreenOnly;
        }