예제 #1
0
        /// <summary>
        /// Invoked when an unhandled DragDrop.DragEnter attached event reaches an element in its route that is derived from this class.
        /// </summary>
        /// <param name="dragEventArgs">The DragEventArgs that contains the event data.</param>
        protected override void OnDrop(DragEventArgs dragEventArgs)
        {
            // Close (and dereference) the window used to display the object being dragged.
            this.dragWindow.Close();
            this.dragWindow = null;

            // Attempt to find the element currently selected in the page.  This item will be the parent of any object dropped onto the surface.
            CategoryCollection parentItem = ExplorerHelper.FindExplorerItem(this.DataContext as CategoryCollection, this.Source) as CategoryCollection;

            if (parentItem != null)
            {
                // We can import files dropped onto the surface.  If the format specifies one or more files dragged from the Windows Explorer, then set call a
                // handler to import each filed based on the file type (that is, the extension).
                String[] paths = dragEventArgs.Data.GetData("FileDrop") as String[];
                if (paths != null)
                {
                    foreach (String path in paths)
                    {
                        ItemProperty externalObject;
                        if (CategoryPage.itemProperties.TryGetValue(Path.GetExtension(path).ToLower(), out externalObject))
                        {
                            CategoryPage.CreateItem(parentItem, path, externalObject);
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of a CategoryCollection class.
        /// </summary>
        /// <param name="parent">The parent of the category node.</param>
        /// <param name="rootRow">The data model record that provides a context for this Model View.</param>
        public CategoryCollection(CategoryCollection parent, DataSet.RootRow rootRow)
        {
            // Validate the parameters.
            if (rootRow == null)
            {
                throw new ArgumentNullException("rootRow");
            }

            // Extract the values from the record.
            this.Name            = rootRow.Name;
            this.Parent          = parent;
            this.rootIdField     = rootRow.RootId;
            this.typeIdField     = rootRow.TypeId;
            this.TypeDescription = rootRow.TypeRow.Name;

            // This will disassemble the icon and give us the basic image sizes supported by the application framework.
            Dictionary <ImageSize, ImageSource> images = ImageHelper.DecodeIcon(Convert.FromBase64String(rootRow.Image));

            this.SmallImageSource      = images[ImageSize.Small];
            this.MediumImageSource     = images[ImageSize.Medium];
            this.LargeImageSource      = images[ImageSize.Large];
            this.ExtraLargeImageSource = images[ImageSize.ExtraLarge];

            // These are the metadata properties of the item.
            foreach (DataSet.PropertyStoreRow propertyStoreRow in rootRow.GetPropertyStoreRows())
            {
                this.PropertyStore.Add(propertyStoreRow.PropertyId, propertyStoreRow.Value);
            }

            // This will dig into the relations and recursively construct a hierarchy of items.
            this.ExpandTree(rootRow);
        }
예제 #3
0
        /// <summary>
        /// Creates a data model entry for the given path element.
        /// </summary>
        /// <param name="categoryCollection"></param>
        /// <param name="path">The full file name of the object to be loaded.</param>
        /// <param name="externalObject">The properties used to build the object.</param>
        static void CreateItem(CategoryCollection categoryCollection, String path, ItemProperty externalObject)
        {
            // Create a new record for this object.
            DataSet.RootRow rootRow = DataModel.DataSet.Root.NewRootRow();
            rootRow.RootId = Guid.NewGuid();
            rootRow.Name   = Path.GetFileName(path);
            rootRow.TypeId = externalObject.typeId;

            // Create an image for this item.
            Stream       sourceStream = Application.GetResourceStream(new Uri(externalObject.IconUri, UriKind.Relative)).Stream;
            MemoryStream iconStream   = new MemoryStream();

            CategoryPage.Copy(sourceStream, iconStream);
            rootRow.Image = Convert.ToBase64String(iconStream.ToArray());

            // Add this new record to the data model.
            DataModel.DataSet.Root.AddRootRow(rootRow);

            // If a viewer was provided, then make a property for it.
            if (String.IsNullOrEmpty(externalObject.ViewerUri))
            {
                DataSet.PropertyStoreRow viewerPropertyRow = DataModel.DataSet.PropertyStore.NewPropertyStoreRow();
                viewerPropertyRow.PropertyId      = PropertyId.Viewer;
                viewerPropertyRow.PropertyStoreId = Guid.NewGuid();
                viewerPropertyRow.RootId          = rootRow.RootId;
                viewerPropertyRow.Value           = externalObject.ViewerUri;
                DataModel.DataSet.PropertyStore.AddPropertyStoreRow(viewerPropertyRow);
            }

            // Create the metadata for the creation date.
            DataSet.PropertyStoreRow dateCreatedPropertyRow = DataModel.DataSet.PropertyStore.NewPropertyStoreRow();
            dateCreatedPropertyRow.PropertyId      = PropertyId.DateCreated;
            dateCreatedPropertyRow.PropertyStoreId = Guid.NewGuid();
            dateCreatedPropertyRow.RootId          = rootRow.RootId;
            dateCreatedPropertyRow.Value           = DateTime.Now;
            DataModel.DataSet.PropertyStore.AddPropertyStoreRow(dateCreatedPropertyRow);

            // Create the metadata for the creation time.
            DataSet.PropertyStoreRow dateModifiedPropertyRow = DataModel.DataSet.PropertyStore.NewPropertyStoreRow();
            dateModifiedPropertyRow.PropertyId      = PropertyId.DateModified;
            dateModifiedPropertyRow.PropertyStoreId = Guid.NewGuid();
            dateModifiedPropertyRow.RootId          = rootRow.RootId;
            dateModifiedPropertyRow.Value           = DateTime.Now;
            DataModel.DataSet.PropertyStore.AddPropertyStoreRow(dateModifiedPropertyRow);

            // This will load a binary version of the file into the metadata.
            using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                MemoryStream memoryStream = new MemoryStream();
                CategoryPage.Copy(fileStream, memoryStream);
                DataSet.PropertyStoreRow dataPropertyRow = DataModel.DataSet.PropertyStore.NewPropertyStoreRow();
                dataPropertyRow.PropertyId      = PropertyId.Data;
                dataPropertyRow.PropertyStoreId = Guid.NewGuid();
                dataPropertyRow.RootId          = rootRow.RootId;
                dataPropertyRow.Value           = Convert.ToBase64String(memoryStream.GetBuffer(), 0, Convert.ToInt32(memoryStream.Length));
                DataModel.DataSet.PropertyStore.AddPropertyStoreRow(dataPropertyRow);
            }

            // This will create an association between the parent item and the object just created.
            DataSet.TreeRow treeRow = DataModel.DataSet.Tree.NewTreeRow();
            treeRow.ParentId = categoryCollection.RootId;
            treeRow.ChildId  = rootRow.RootId;
            treeRow.TreeId   = Guid.NewGuid();
            DataModel.DataSet.Tree.AddTreeRow(treeRow);

            // This will insert the new object in the View Model at the given location in the hierarchy.
            categoryCollection.Leaves.Add(new CategoryCollection(categoryCollection, rootRow));
        }