示例#1
0
        public void FileObj(List <BomShell> boomShellList, string pathpdf)
        {
            try
            {
                foreach (var item in boomShellList)
                {
                    if (item.FileName != "" && item.PartNumber != "")
                    {
                        IEdmFolder5 folder;

                        string    pathfile = item.FolderPath + @"\" + item.FileName;
                        IEdmFile5 file     = Vault.GetFileFromPath(pathfile, out folder);
                        file.GetFileCopy(0, 0, 0, (int)EdmGetFlag.EdmGet_Simple);

                        string filepath = file.GetLocalPath(folder.ID);

                        string pathdrw = item.FolderPath + @"\" + item.PartNumber + ".SLDDRW";

                        IEdmFile5 filedrw = Vault.GetFileFromPath(pathdrw, out folder);

                        if (filedrw != null)
                        {
                            filedrw.GetFileCopy(0, 0, 0, (int)EdmGetFlag.EdmGet_Simple);
                            var filepathdrw = filedrw.GetLocalPath(folder.ID);
                            int filedrwId   = filedrw.ID;

                            if (CheckPdf(filedrwId, filedrw, pathpdf) != 0)
                            {
                                CheckPdf(filedrwId, filedrw, pathpdf);
                            }
                            else
                            {
                                LoadPdf lp      = new LoadPdf();
                                string  newpath = lp.PdfLoad(filepathdrw, true, pathpdf);

                                byte[] bytes = BinaryPdf(newpath);
                                ProcCheck(file, filedrw, filedrw.CurrentVersion, bytes);
                            }
                        }
                    }
                }

                SolidWorksAdapter.KillProcsses("SLDWORKS");
                SolidWorksAdapter.DisposeSOLID();
                MessageBox.Show("PDF файлы успешно сохранены");
                this.Hide();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                throw;
            }
        }
示例#2
0
 private static bool TryGetFileLocalCopy(IEdmFile5 file)
 {
     try
     {
         object version = file.CurrentVersion;
         Log.WriteLog(version.ToString());
         file.GetFileCopy(0, ref version);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
示例#3
0
        /// <summary>
        /// Registration or unregistation files by their paths and registration status.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="isRegistration"></param>
        public void CheckInOutPdm(string pathToFile, bool registration)
        {
            var retryCount = 5;

            try
            {
                IEdmFolder5 oFolder;
                IEdmFile5   edmFile5 = PdmExemplar.GetFileFromPath(pathToFile, out oFolder);
                edmFile5.GetFileCopy(0, 0, oFolder.ID, (int)EdmGetFlag.EdmGet_Simple);
                if (!registration) // Разрегистрировать
                {
                    while (!edmFile5.IsLocked && retryCount > 0)
                    {
                        edmFile5.LockFile(oFolder.ID, 0);
                        retryCount--;
                    }
                }
                if (registration) // Зарегистрировать
                {
                    while (edmFile5.IsLocked && retryCount > 0)
                    {
                        edmFile5.UnlockFile(oFolder.ID, "");
                        retryCount--;
                        Thread.Sleep(50);
                    }
                }
            }

            catch (Exception exception)
            {
                retryCount--;
                Thread.Sleep(200);
                if (retryCount == 0)
                {
                    //
                }
                throw exception;
            }
        }
        /// <summary>
        /// Registration or unregistation files by their paths and registration status.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="isRegistration"></param>
        public void CheckInOutPdm(string pathToFile, bool registration)
        {
            #region not working code
            //foreach (var file in filesList)
            //{
            //    try
            //    {
            //        IEdmFolder5 oFolder;
            //        IEdmFile5 edmFile5 = edmVault5.GetFileFromPath(file.FullName, out oFolder);

            //        var batchGetter = (IEdmBatchGet)(edmVault5 as IEdmVault7).CreateUtility(EdmUtility.EdmUtil_BatchGet);
            //        batchGetter.AddSelectionEx(edmVault5, edmFile5.ID, oFolder.ID, 0);
            //        if ((batchGetter != null))
            //        {
            //            batchGetter.CreateTree(0, (int)EdmGetCmdFlags.Egcf_SkipUnlockedWritable);
            //            batchGetter.GetFiles(0, null);
            //        }

            //        // Разрегистрировать
            //        if (!registration)
            //        {

            //            if (!edmFile5.IsLocked)
            //            {


            //                edmFile5.LockFile(oFolder.ID, 0);
            //                Thread.Sleep(50);
            //            }
            //        }
            //        else if (registration)
            //            if (edmFile5.IsLocked)
            //            {
            //                edmFile5.UnlockFile(oFolder.ID, "");
            //                Thread.Sleep(50);
            //            }
            //    }

            //    catch (Exception exception)
            //    {
            //       //Observer.MessageObserver.Instance.SetMessage(exception.ToString() + "\n" + exception.StackTrace + "\n" + exception.Source);
            //    }
            //}



            //foreach (var eachFile in files)
            //{
            //    try
            //    {
            //        IEdmFolder5 folderPdm;
            //        IEdmFile5 filePdm = edmVault5.GetFileFromPath(eachFile.FullName, out folderPdm);

            //        if (filePdm == null)
            //        {
            //            filePdm.GetFileCopy(0, 0, folderPdm.ID, (int)EdmGetFlag.EdmGet_Simple);
            //        }

            //        // Разрегистрировать
            //        if (registration == false)
            //        {
            //            if (!filePdm.IsLocked)
            //            {
            //                filePdm.LockFile(folderPdm.ID, 0);
            //                Thread.Sleep(50);
            //            }
            //        }
            //        else
            //        {
            //            if (filePdm.IsLocked)
            //            {
            //                filePdm.UnlockFile(folderPdm.ID, "");
            //                Thread.Sleep(50);
            //            }
            //        }
            //    }

            //    catch (Exception exception)
            //    {
            //       //Observer.MessageObserver.Instance.SetMessage(exception.ToString() + "\n" + exception.StackTrace + "\n" + exception.Source);
            //    }
            //}

            #endregion

            var retryCount = 2;
            var success    = false;
            while (!success && retryCount > 0)
            {
                try
                {
                    IEdmFolder5 oFolder;
                    IEdmFile5   edmFile5 = PdmExemplar.GetFileFromPath(pathToFile, out oFolder);
                    edmFile5.GetFileCopy(0, 0, oFolder.ID, (int)EdmGetFlag.EdmGet_Simple);
                    // Разрегистрировать
                    if (registration == false)
                    {
m1:
                        edmFile5.LockFile(oFolder.ID, 0);
                        //Observer.MessageObserver.Instance.SetMessage(edmFile5.Name);
                        Thread.Sleep(50);
                        var j = 0;
                        if (!edmFile5.IsLocked)
                        {
                            j++;
                            if (j > 5)
                            {
                                goto m3;
                            }
                            goto m1;
                        }
                    }
                    // Зарегистрировать
                    if (registration)
                    {
                        try
                        {
m2:
                            edmFile5.UnlockFile(oFolder.ID, "");
                            Thread.Sleep(50);
                            var i = 0;
                            if (edmFile5.IsLocked)
                            {
                                i++;
                                if (i > 5)
                                {
                                    goto m4;
                                }
                                goto m2;
                            }
                        }
                        catch (Exception exception)
                        {
                            MessageObserver.Instance.SetMessage(exception.ToString());
                        }
                    }
m3:
m4:
                    //LoggerInfo(string.Format("В базе PDM - {1}, зарегестрирован документ по пути {0}", file.FullName, vaultName), "", "CheckInOutPdm");
                    success = true;
                }


                catch (Exception exception)
                {
                    //  Логгер.Ошибка($"Message - {exception.ToString()}\nfile.FullName - {file.FullName}\nStackTrace - {exception.StackTrace}", null, "CheckInOutPdm", "SwEpdm");
                    retryCount--;
                    Thread.Sleep(200);
                    if (retryCount == 0)
                    {
                        //
                    }
                    throw exception;
                }
            }
            if (!success)
            {
                //LoggerError($"Во время регистрации документа по пути {file.FullName} возникла ошибка\nБаза - {vaultName}. {exception.ToString()}", "", "CheckInOutPdm");
            }
        }
示例#5
0
        /// <summary>
        /// Syncs local version of a file with the current version in the vault
        /// </summary>
        /// <param name="Part"></param>
        /// <param name="vault"></param>
        /// <returns></returns>
        public bool UpdateItemRef(EdmCmdData file,IEdmFile5 Part, IEdmVault7 vault)
        {
            bool retval = false;

            if (!HaveUpToDateItemRef(file,Part, vault))
            {
                DialogResult dr = MessageBox.Show("This requires that you get the latest version of this file. Continue?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dr == DialogResult.Yes)
                {
                    Part.GetFileCopy(0, 0, 0, (int)EdmGetFlag.EdmGet_RefsVerLatest, "");

                    retval = true;
                }
                else
                    retval = false;
            }
            else
                retval = true;

            return retval;
        }
示例#6
0
文件: PDM.cs 项目: JameyEvans/CMDemo
        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);
            }
        }