/// <summary>
        /// Search document by name and returns colection the FileModelPdm .
        /// </summary>
        /// <param name="segmentName"></param>
        /// <returns></returns>
        public IEnumerable <FileModelPdm> SearchDoc(string segmentName)
        {
            List <FileModelPdm> searchResult = new List <FileModelPdm>();

            try
            {
                IEdmSearch5 Search = default(IEdmSearch5);
                Search = (IEdmSearch5)(PdmExemplar as IEdmVault7).CreateUtility(EdmUtility.EdmUtil_Search);

                Search.FileName = segmentName;
                //Search.FindFiles = true;
                //Search.FindFolders = false;
                //Search.SetToken(EdmSearchToken.Edmstok_FindFolders, false);
                int count = 0;

                IEdmSearchResult5 Result = Search.GetFirstResult();

                while (Result != null)
                {
L1:
                    if (Result.Name.ToUpper().Contains(".SLDPRT") || Result.Name.ToUpper().Contains(".SLDASM"))
                    {
                        searchResult.Add(new FileModelPdm
                        {
                            FileName       = Result.Name,
                            IDPdm          = Result.ID,
                            FolderId       = Result.ParentFolderID,
                            Path           = Result.Path,
                            FolderPath     = Path.GetDirectoryName(Result.Path),
                            CurrentVersion = Result.Version
                        });
                        count++;
                    }
                    Result = Search.GetNextResult();
                    if (Result != null)
                    {
                        goto L1;
                    }
                }
                MessageObserver.Instance.SetMessage("Поиск успешно завершон, найдено объектов " + searchResult.Count + " по запросу " + segmentName);
            }
            catch (Exception exception)
            {
                MessageObserver.Instance.SetMessage("Поиск по запросу " + segmentName + " завершон c ошибкой: " + exception.ToString() + " в связи с чем возвращена пустая колекция FileModelPdm");
                MessageObserver.Instance.SetMessage("Поиск по запросу " + segmentName + " завершон c ошибкой: " + exception.ToString() + " в связи с чем возвращена пустая колекция FileModelPdm");
            }
            return(searchResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 【8】根据文件名称搜索路径,返回全部路径的集合,如果未搜索到返回null
        /// </summary>
        /// <param name="fileName">文件名称(不包含路径)</param>
        public static List <string> SearchPart(string fileName)
        {
            IEdmVault5 vault1 = new EdmVault5();

            vault1.Login(LogName, PWD, VaultName);
            IEdmVault7 vault2 = null;

            vault2 = (IEdmVault7)vault1;
            IEdmSearch5 Search = (IEdmSearch5)vault2.CreateUtility(EdmUtility.EdmUtil_Search);

            Search.FileName = "%" + fileName + "%";             //模糊搜索
            //Search.FileName = fileName;//命名搜索
            IEdmSearchResult5 Result = Search.GetFirstResult(); //搜索第一个
            List <string>     lst    = new List <string>();

            //string filePath = string.Empty;
            while (Result != null)
            {
                lst.Add(Result.Path);
                Result = Search.GetNextResult();//搜索下一个
            }
            return(lst);
        }
Exemplo n.º 3
0
        private void SearchFiles(IEdmVault5 vault, object Val1)
        {
            try

            {
                IEdmSearch5 search = null;
                IEdmFolder5 folder = null;

                folder = vault.GetFolderFromPath(@"C:\CDI Controlled Documents\drawings\part drawings- controlled");

                search               = vault.CreateSearch();
                search.FileName      = "%.%d%w%";
                search.StartFolderID = folder.ID;

                object Var1  = "Part Numbers";
                object State = "Approved for Production";


                search.AddVariable(Var1, Val1);

                search.set_State(State);
                search.FindHistoricStates = false;
                search.Recursive          = true;

                String message = string.Empty;



                List <IEdmSearchResult5> results = new List <IEdmSearchResult5>();

                IEdmSearchResult5 result = search.GetFirstResult();

                while (result != null)

                {
                    results.Add(result);
                    result = search.GetNextResult();
                }
                results = results.Distinct(new SearchResultComparer()).ToList();
                if (results.Count < 1)
                {
                    search.Clear();
                    search.FileName      = Val1 + ".%d%w%";
                    search.StartFolderID = folder.ID;
                    State = "Approved for Production";
                    search.set_State(State);
                    search.FindHistoricStates = false;
                    search.Recursive          = true;

                    result = search.GetFirstResult();
                    while (result != null)

                    {
                        results.Add(result);
                        result = search.GetNextResult();
                    }
                    results = results.Distinct(new SearchResultComparer()).ToList();
                }
                foreach (IEdmSearchResult5 item in results)
                {
                    //get latest version
                    IEdmFile5   file      = null;
                    IEdmFolder5 retFolder = default(IEdmFolder5);
                    file = vault.GetFileFromPath(item.Path, out retFolder);
                    file.GetFileCopy(0);
                    //System.Diagnostics.Process.Start(item.Path, @"C:\Program Files\SOLIDWORKS Corp\eDrawings\eDrawings.exe");
                    //OpenEdwg(item.Path);
                    OpenSaveSldrwPdf(item.Path);



                    message = message + "Filename: " + item.Name + ", Rev: " + file.CurrentRevision + "; \n";
                }



                MessageBox.Show(message);
            }



            catch (Exception ex)

            {
                MessageBox.Show(ex.Message);
            }
        }