示例#1
0
        /// <summary>
        /// Method to retrieve all views defined as the root views from config. All these should be predefined and on one level i.e not one within another.
        /// </summary>
        /// <returns>The List of FolderElement objects representing the pre-configured views.</returns>
        public List <FolderElement> GetRootDocumentViews()
        {
            // Create FolderElement for each of the configured root views
            currentFolderContent = new List <FolderElement>();
            foreach (var item in rootFolderDefIds)
            {
                var view = vault.ViewOperations.GetView(item);
                var elm  = new FolderElement()
                {
                    ElementId   = item,
                    ElementName = view.Name,
                    ElementType = ElementType.ViewFolder
                };

                currentFolderContent.Add(elm);
            }
            ListCurrentFolderElements(currentFolderContent); // for testing!!
            return(currentFolderContent);
        }
示例#2
0
 /// <summary>
 /// Downloads the files of the desired FolderElement to a temporary location.
 /// </summary>
 /// <param name="elm">The FolderElement clicked in the user interface and passed to this function. FolderElement.ElementType has to be ElementType.Document.</param>
 /// <returns>String representing path to temporary file location.</returns>
 public String GetElementFiles(FolderElement elm)
 {
     //at this point the elm should have been populated with an objectId and type should be document
     if (elm.ElementType == ElementType.Document || elm.ElementType == ElementType.MultiFile)
     {
         //single- or multi-file document download the file and return the path
         var oId = new ObjID();
         oId.SetIDs(0, elm.ElementId);
         var objVer   = vault.ObjectOperations.GetLatestObjVerEx(oId, true);
         var objFiles = vault.ObjectFileOperations.GetFiles(objVer);
         if (objFiles.Count == 1)
         {
             //only one file
             var filedl = loc.DownloadFile(objFiles[1], vault);
             System.Diagnostics.Process.Start(filedl.TargetFile.FullName);
             return(filedl.TargetFile.FullName);
         }
         if (objFiles.Count > 1)
         {
             //several files
             var dirName = "";
             foreach (ObjectFile f in objFiles)
             {
                 var filedl = loc.DownloadFile(f, vault);
                 System.Diagnostics.Process.Start(filedl.TargetFile.FullName);
                 if (dirName == "")
                 {
                     dirName = filedl.TargetFile.DirectoryName;
                 }
             }
             return(dirName);
         }
         else
         {
             throw new ArgumentNullException(elm.ElementName, String.Format("The FolderElement {0} does not contain any files", elm.ElementName));
         }
     }
     else
     {
         throw new FolderElementTypeException(elm.ElementType.ToString());
     }
 }
示例#3
0
        /// <summary>
        /// Open desired FolderElement and retrieves its content.
        /// Functionality for the M-Files FolderContentItem types: traditonal folder and external folder has not been implemented.
        /// </summary>
        /// <param name="elm">The FolderElement clicked in the user interface and passed to this function. If the FolderElement passed does not contain a valid lookup id,
        /// the ElementName property is used for resolving the next level.</param>
        /// <returns>List of FolderElements that represent the contents of the clicked FolderElement.</returns>
        /// <throws>Exception if a FolderContentItem is of either traditional or external type</throws>
        public List <FolderElement> GetNextFolder(FolderElement elm)
        {
            // Sanity!!
            if (null == elm)
            {
                throw new ArgumentNullException();
            }
            FolderDef  fDef = new FolderDef();
            TypedValue tv   = new TypedValue();

            if (elm.ElementType == ElementType.ViewFolder)
            {
                if (0 != elm.ElementId)
                {
                    fDef.SetView(elm.ElementId);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed, containing an invalid elementId for the ViewFolder.", elm.ElementType.ToString()));
                }
            }
            if (elm.ElementType == ElementType.PropertyFolderVL)
            {
                if (0 != elm.ElementId)
                {
                    tv.SetValue(MFDataType.MFDatatypeLookup, elm.ElementId);
                    fDef.SetPropertyFolder(tv);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed, containing an invalid elementId for the PropertyFolder.", elm.ElementType.ToString()));
                }
            }
            if (elm.ElementType == ElementType.PropertyFolderText)
            {
                if (elm.ElementName != "")
                {
                    tv.SetValue(MFDataType.MFDatatypeText, elm.ElementName);
                    fDef.SetPropertyFolder(tv);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed, containing an empty ElementName property.", elm.ElementType.ToString()));
                }
            }
            if (elm.ElementType == ElementType.PropertyFolderInt)
            {
                if (elm.ElementName != "" && int.TryParse(elm.ElementName, out int res))
                {
                    tv.SetValue(MFDataType.MFDatatypeInteger, res);
                    fDef.SetPropertyFolder(tv);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed. Unable to parse the ElementName property: {1}, it is either not a number or an empty string.", elm.ElementType.ToString(), elm.ElementName));
                }
            }
            if (elm.ElementType == ElementType.PropertyFolderDbl)
            {
                if (elm.ElementName != "" && decimal.TryParse(elm.ElementName, out decimal res))
                {
                    tv.SetValue(MFDataType.MFDatatypeFloating, res);
                    fDef.SetPropertyFolder(tv);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed. Unable to parse the ElementName property: {1}, it is either not a decimal or an empty string.", elm.ElementType.ToString(), elm.ElementName));
                }
            }
            currentFolderDefs.Add(-1, fDef);
            return(GetElements(currentFolderDefs, elm));
        }
示例#4
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);
        }