Beispiel #1
0
        // Helper method to get FolderContentItems from the vault and convert them to FolderElements
        private List <FolderElement> GetElements(FolderDefs folderDefs, FolderElement elm = null)
        {
            currentFolderContent = new List <FolderElement>();
            // get the collection of FolderContentItems
            var content = vault.ViewOperations.GetFolderContents(folderDefs);

            if (content.Count == 0)
            {
                // the selscted FolderElement is an empty folder. Can be prevented by setting filter on View to only show documents.
                FolderElement e = new FolderElement()
                {
                    ElementId = 0, ElementName = "Nothing to see here!", ElementType = ElementType.PropertyFolderVL
                };
                currentFolderContent.Add(e);
                ListCurrentFolderElements(currentFolderContent); // for testing!!
                return(currentFolderContent);

                //Optionally we throw an exception
                throw new EmptyFolderException(folderDefs.Count, elm.ElementName);
            }
            foreach (var item in content)
            {
                FolderElement e = new FolderElement();
                if ((item as FolderContentItem).FolderContentItemType == MFFolderContentItemType.MFFolderContentItemTypePropertyFolder)
                {
                    //convert to FolderElement with appropriate data and add to list of folderelement
                    TypedValue tv = (item as FolderContentItem).PropertyFolder;
                    e.ElementName = tv.DisplayValue;
                    if (tv.DataType == MFDataType.MFDatatypeLookup)
                    {
                        e.ElementId   = tv.GetLookupID();
                        e.ElementType = ElementType.PropertyFolderVL;
                    }
                    else
                    {
                        e.ElementId = 0;
                    }
                    if (tv.DataType == MFDataType.MFDatatypeText)
                    {
                        e.ElementType = ElementType.PropertyFolderText;
                    }
                    if (tv.DataType == MFDataType.MFDatatypeInteger)
                    {
                        e.ElementType = ElementType.PropertyFolderInt;
                    }
                    if (tv.DataType == MFDataType.MFDatatypeFloating)
                    {
                        e.ElementType = ElementType.PropertyFolderDbl;
                    }
                    currentFolderContent.Add(e);
                    continue;
                }

                if ((item as FolderContentItem).FolderContentItemType == MFFolderContentItemType.MFFolderContentItemTypeViewFolder)
                {
                    //convert to FolderElement with appropriate data and add to list of folderelement
                    View v = (item as FolderContentItem).View;
                    e.ElementName = v.Name;
                    e.ElementId   = v.ID;
                    e.ElementType = ElementType.ViewFolder;

                    currentFolderContent.Add(e);
                    continue;
                }
                if ((item as FolderContentItem).FolderContentItemType == MFFolderContentItemType.MFFolderContentItemTypeObjectVersion)
                {
                    //convert to FolderElement with appropriate data and add to list of folderelement
                    ObjectVersion obj = (item as FolderContentItem).ObjectVersion;
                    // we will not display objects that are not documents. Depending on customers use, we may need  implement functionality that works for document collections
                    if (obj.ObjVer.Type != (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument || obj.FilesCount == 0)
                    {
                        continue;
                    }
                    e.ElementName = obj.Title;
                    e.ElementId   = obj.ObjVer.ID;
                    if (obj.FilesCount != 1 && obj.FilesCount > 0)
                    {
                        e.ElementType = ElementType.MultiFile;
                    }
                    else
                    {
                        e.ElementType = ElementType.Document;
                    }

                    currentFolderContent.Add(e);
                    continue;
                }
                else
                {
                    throw new NotImplementedException(String.Format("Unable to process FolderContentItem of type: {0}", (item as FolderContentItem).FolderContentItemType.ToString()));
                }


                //convert to FolderElement with appropriate data and add to list of folderelement
            }
            if (!(currentFolderContent.Count > 0))
            {
                //the selected folder contains only empty multi-file documents
                FolderElement e = new FolderElement()
                {
                    ElementId = 0, ElementName = "Nothing to see here!", ElementType = ElementType.PropertyFolderVL
                };
                currentFolderContent.Add(e);
                ListCurrentFolderElements(currentFolderContent); // for testing!!
                return(currentFolderContent);

                //Optionally we throw an exception
                throw new EmptyFolderException(folderDefs.Count, elm.ElementName);
            }
            ListCurrentFolderElements(currentFolderContent); // for testing!!
            // Set the global boolean canNavigateBackwards to true
            canNavigateBackwards = true;
            //return list of FolderElements
            return(currentFolderContent);
        }