Esempio n. 1
0
 private static bool TryLockFile(IEdmFile5 file, IEdmFolder5 parentFolder, out int?edmResultCode)
 {
     try
     {
         file.LockFile(parentFolder.ID, 0, (int)EdmLockFlag.EdmLock_Simple);
         edmResultCode = null;
         return(true);
     }
     catch (System.Runtime.InteropServices.COMException ex)
     {
         edmResultCode = ex.ErrorCode;
         return(false);
     }
 }
Esempio n. 2
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;
            }
        }
        public IEdmFile5 CopyFileIntoVault(string path, string Destination)
        {
            IEdmFile5 Outfile = vault.GetFileFromPath(Destination, out IEdmFolder5 fld);

            if (Outfile != null)
            {
                if (!Outfile.IsLocked)
                {
                    Outfile.LockFile(fld.ID, 0, 0);
                }
                System.IO.File.Copy(path, Destination, true);
                return(Outfile);
            }
            else
            {
                fld = vault.GetFolderFromPath(Path.GetDirectoryName(Destination));
                if (fld != null)
                {
                    int id = ((IEdmFolder8)fld).AddFile2(0, path, out int err, "", (int)EdmAddFlag.EdmAdd_UniqueVarDelayCheck);
                    return((IEdmFile5)vault.GetObject(EdmObjectType.EdmObject_File, id));
                }
                return(null);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 【7】将文件复制到指定路径(硬盘)——导出
 /// </summary>
 /// <param name="PathInVault">库文件夹根目录下相对路径</param>
 /// <param name="PathOutVault">本地具体路径</param>
 public static void CheckoutAndCopy(string PathInVault, string PathOutVault)
 {
     try
     {
         EdmVault5 vault = new EdmVault5();
         vault.Login(LogName, PWD, VaultName);
         IEdmFile5   file   = default(IEdmFile5);
         IEdmFolder5 folder = null;
         file = vault.GetFileFromPath(vault.RootFolderPath + PathInVault, out folder);//读取指定文件的位置,PathInVault库文件夹根目录下相对路径
         file.LockFile(folder.ID, new System.Windows.Forms.Control().Handle.ToInt32());
         file.UndoLockFile(new System.Windows.Forms.Control().Handle.ToInt32(), true);
         //Copy the file
         IEdmEnumeratorVersion5 verEnum = default(IEdmEnumeratorVersion5);
         verEnum = (IEdmEnumeratorVersion5)file;
         int Version = 0;
         Version = file.GetLocalVersionNo(folder.ID);
         IEdmVersion5 ver = default(IEdmVersion5);
         ver = verEnum.GetVersion(Version);
         ver.GetFileCopy(new System.Windows.Forms.Control().Handle.ToInt32(), PathOutVault);//PathOutVault本地具体路径
     }
     catch (System.Runtime.InteropServices.COMException ex)
     {
         if (ex.ErrorCode.ToString() == "-2147220949")
         {
             MessageBox.Show("The selected file is not located in a file vault.");
         }
         else
         {
             MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        /// <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");
            }
        }
Esempio n. 6
0
        public void GetVars_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                IEdmVault7 vault2 = null;
                if (vault1 == null)
                {
                    vault1 = new EdmVault5();
                }
                vault2 = (IEdmVault7)vault1;
                if (!vault1.IsLoggedIn)
                {
                    //Log into selected vault as the current user
                    vault1.LoginAuto(VaultsComboBox.Text, this.Handle.ToInt32());
                }

                IEdmFile5   aFile = default(IEdmFile5);
                IEdmFolder5 ppoRetParentFolder = null;
                aFile = vault2.GetFileFromPath(ListBox.Items[0].ToString(), out ppoRetParentFolder);

                //Get card variables only from a file checked into the vault
                if (!aFile.IsLocked)
                {
                    aFile.LockFile(vault2.RootFolderID, this.Handle.ToInt32(), (int)EdmLockFlag.EdmLock_Simple);

                    IEdmEnumeratorVariable5 varEnum = default(IEdmEnumeratorVariable5);
                    varEnum = aFile.GetEnumeratorVariable();

                    object[] valueList = null;
                    varEnum.GetUpdateVars(aFile.LockedInFolderID, out valueList);

                    int idx = 0;
                    idx = Information.LBound(valueList);
                    int upper = 0;
                    upper = Information.UBound(valueList);

                    string msg = null;
                    msg = "Card variables for " + aFile.Name + " in configuration, @:" + Constants.vbLf + Constants.vbLf;

                    IEdmVariableMgr5 varMgr = default(IEdmVariableMgr5);
                    varMgr = (IEdmVariableMgr5)aFile.Vault;

                    IEdmVariable5      var   = default(IEdmVariable5);
                    IEdmVariableValue6 value = default(IEdmVariableValue6);
                    while (idx <= upper)
                    {
                        value = (IEdmVariableValue6)valueList[idx];
                        idx   = idx + 1;
                        var   = varMgr.GetVariable(value.VariableID);
                        msg   = msg + value.VariableName + " = > " + value.GetValue("@").ToString() + Constants.vbLf;
                        msg   = msg + "EdmVariableFlags: " + var.Flags + ", EdmVariableType: " + var.VariableType + Constants.vbLf + Constants.vbLf;
                        //msg = msg & "EdmVariableFlags: " & value.VariableFlags & ", EdmVariableType: " & value.VariableType & vbLf & vbLf
                    }

                    MessageBox.Show(msg);

                    aFile.UndoLockFile(this.Handle.ToInt32());
                }
                else
                {
                    //User selected a checked-out file
                    MessageBox.Show("Please select a checked-in file.");
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }