5 Replies Latest reply on Apr 11, 2017 5:17 PM by Peter Brinkhuis

    Trying to Bulk Unlock from standalone c# application

    Sean Donnelly

      Hello,

      I am trying to check in (or unlock) all files for the logged in user via standalone c# application button. See my code below. It seems to be breaking at the point of the batchUnlocker. Any idea why?

       

              private void buttonCheckInFiles_Click(object sender, EventArgs e)

              {

                  IEdmVault7 vault2 = null;

                  if (vault1 == null)

                  {

                      vault1 = new EdmVault5();

                  }

                  vault2 = (IEdmVault7)vault1;

       

       

                  if (!vault1.IsLoggedIn)

                  {

                      vault1.LoginAuto("Test Vault for FETasks", this.Handle.ToInt32());

                  }

       

       

                  IEdmBatchUnlock2 batchUnlocker;

                  IEdmSelectionList6 fileList = null;

                  EdmSelectionObject poSel;

                  EdmSelItem[] ppoSelection = new EdmSelItem[11];

                  int fileCount = 0;

                  IEdmFile5 aFile;

                  IEdmFolder5 aFolder;

                  IEdmFolder5 ppoRetParentFolder;

                  IEdmPos5 aPos;

                  string str;

       

       

                  bool retVal;

       

       

                  //Declare an IEdmUserMgr5 object

                  IEdmUserMgr5 userMgr = default(IEdmUserMgr5);

       

       

                  //The IEdmUserMgr5 interface is implemented by the

                  //same class as the IEdmVault5 interface,

                  //so you can assign the value of

                  //the IEdmVault5 object

                  userMgr = (IEdmUserMgr5)vault2;

       

       

                  IEdmUser5 user = default(IEdmUser5);

                  user = userMgr.GetLoggedInUser();

       

       

                  MessageBox.Show(user.Name);

       

                     //Breaking right here

                  batchUnlocker = (IEdmBatchUnlock2)vault2.CreateUtility(EdmUtility.EdmUtil_BatchUnlock);

       

       

                  //Search for all text files in the vault

                  IEdmSearch5 Search = default(IEdmSearch5);

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

       

       

                  Search.FindLockedFiles = true;

                  Search.FindUnlockedFiles = false;

       

       

                  IEdmSearchResult5 Result = default(IEdmSearchResult5);

                  Result = Search.GetFirstResult();

       

       

                  int i = 0;

                  while (Result != null)

                  {

                      if (Result.LockedByUserName == user.Name)

                      {

                          aFile = vault2.GetFileFromPath(Result.Path, out ppoRetParentFolder);

                          MessageBox.Show(aFile.Name);

                          aPos = aFile.GetFirstFolderPosition();

                          aFolder = aFile.GetNextFolder(aPos);

                          ppoSelection[i] = new EdmSelItem();

                          ppoSelection[i].mlDocID = aFile.ID;

                          ppoSelection[i].mlProjID = aFolder.ID;

                      }

                      Result = Search.GetNextResult();

                      i++;

                  }

       

       

                  batchUnlocker.AddSelection((EdmVault5)vault2, ref ppoSelection);

       

       

                  if ((batchUnlocker != null))

                  {

                      batchUnlocker.CreateTree(this.Handle.ToInt32(), (int)EdmUnlockBuildTreeFlags.Eubtf_ShowCloseAfterCheckinOption + (int)EdmUnlockBuildTreeFlags.Eubtf_MayUnlock);

       

       

                      batchUnlocker.Comment = "Updates";

                      fileList = (IEdmSelectionList6)batchUnlocker.GetFileList((int)EdmUnlockFileListFlag.Euflf_GetUnlocked + (int)EdmUnlockFileListFlag.Euflf_GetUndoLocked + (int)EdmUnlockFileListFlag.Euflf_GetUnprocessed);

       

       

                      aPos = fileList.GetHeadPosition();

       

       

                      str = "Getting " + fileCount + " files: ";

                      while (!(aPos.IsNull))

                      {

                          fileList.GetNext2(aPos, out poSel);

                          str = str + Constants.vbLf + poSel.mbsPath;

                      }

       

       

                      //MsgBox(str)

       

       

                      retVal = batchUnlocker.ShowDlg(this.Handle.ToInt32());

       

       

                      object statuses = null;

                      if ((retVal))

                      {

                          batchUnlocker.UnlockFiles(this.Handle.ToInt32(), null);

                          statuses = batchUnlocker.GetStatus((int)EdmUnlockStatusFlag.Eusf_CloseAfterCheckinFlag);

                          Interaction.MsgBox("Close Files after Check In selected? " + statuses);

                      }

       

       

                  }

        • Re: Trying to Bulk Unlock from standalone c# application
          Peter Brinkhuis

          Don't you have to cast the enum value to an integer?

            • Re: Trying to Bulk Unlock from standalone c# application
              Sean Donnelly

              could you be a little more specific? I'm very new to EPDM APIs and C#. Thanks!

                • Re: Trying to Bulk Unlock from standalone c# application
                  Peter Brinkhuis

                  Sure. Functions often require integers as arguments. You're using enumerations (enums) like EdmUtility and EdmUnlockFileListFlag. Those things are enumerations of options and each option represents an integer value, a whole number. Now in C# at least, they are not immediately interchangeable. You have to cast (converting the variable type) the selected enum value to an integer, that is done by adding (int) in front of the enum name. You can see it here as well, three times even:

                   

                  fileList = (IEdmSelectionList6)batchUnlocker.GetFileList((int)EdmUnlockFileListFlag.Euflf_GetUnlocked + (int)EdmUnlockFileListFlag.Euflf_GetUndoLocked + (int)EdmUnlockFileListFlag.Euflf_GetUnprocessed);

                   

                  Now, I'm not completely sure that's the problem because you've given us no error message, but it might just be the issue here. What lines have you written, I guess most of it is copied from somewhere else?

                    • Re: Trying to Bulk Unlock from standalone c# application
                      Sean Donnelly

                      Correct on copying. I obviously need to tweak what I find and I learn best from doing so. I'm much further along than I was two weeks ago, but it's still a process and a niche community for questions (learned SQL this way, but the community is very large. No issues now and have complex queries ).

                       

                      Anyways, I have the code below functioning properly for checking in (unlocking) files. However, this is not batch. I assume batch check in would be faster and more efficient? The next steps I want to do in the near future are start understanding batches, emulators and faster searches. Any tips you may have will greatly help. If you only help with this issue though, no worries that is great! Thanks!

                       

                      IEdmVault7 vault2 = null;

                                  if (vault1 == null)

                                  {

                                      vault1 = new EdmVault5();

                                  }

                                  vault2 = (IEdmVault7)vault1;

                       

                       

                                  if (!vault1.IsLoggedIn)

                                  {

                                      //vault1.LoginAuto("FocalPoint Vault", this.Handle.ToInt32());

                                      vault1.LoginAuto("FocalPoint Vault", this.Handle.ToInt32());

                                  }

                       

                       

                                

                                  EdmSelItem[] ppoSelection = new EdmSelItem[11];

                                  int fileCount = 0;

                                  int fileNotCompCount = 0;

                                  IEdmFile5 aFile;

                                  //IEdmFolder5 aFolder;

                                  IEdmFolder5 ppoRetParentFolder;

                                  //IEdmPos5 aPos;

                                 

                                  //Declare an IEdmUserMgr5 object

                                  IEdmUserMgr5 userMgr = default(IEdmUserMgr5);

                       

                       

                                  //The IEdmUserMgr5 interface is implemented by the

                                  //same class as the IEdmVault5 interface,

                                  //so you can assign the value of

                                  //the IEdmVault5 object

                                  userMgr = (IEdmUserMgr5)vault2;

                       

                       

                                  IEdmUser5 user = default(IEdmUser5);

                                  user = userMgr.GetLoggedInUser();

                       

                       

                       

                       

                                  //Search for all text files in the vault

                                  IEdmSearch5 Search = default(IEdmSearch5);

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

                       

                       

                                  Search.FindLockedFiles = true;

                                  Search.FindUnlockedFiles = false;

                       

                       

                                  IEdmSearchResult5 Result = default(IEdmSearchResult5);

                                  Result = Search.GetFirstResult();

                                

                                  while (Result != null)

                                  {

                                      if (Result.LockedByUserName == user.Name && Result.LockedOnComputer == Environment.MachineName)

                                      {

                                          aFile = vault1.GetFileFromPath(Result.Path, out ppoRetParentFolder);

                                          aFile.UnlockFile(this.Handle.ToInt32(), "Checked-In via PDM Utility Tool");

                                          fileCount++;

                                      }

                                      else if (Result.LockedByUserName == user.Name && Result.LockedOnComputer != Environment.MachineName)

                                      {

                                          fileNotCompCount++;

                                      }

                                      Result = Search.GetNextResult();

                                  }

                                  if (fileCount > 1)

                                  {

                                      if (fileNotCompCount > 1)

                                      {

                                          MessageBox.Show(fileCount.ToString() + " files were checked in. \n " + fileNotCompCount + " files are checked out by you on another computer.\n Your current computer: " + Environment.MachineName);

                                      }

                                      else

                                      {

                                          MessageBox.Show(fileCount.ToString() + " files were checked in.");

                                      }

                                  }

                                  else

                                  {

                                      if (fileNotCompCount > 1)

                                      {

                                          MessageBox.Show(fileNotCompCount + " files are checked out by you on another computer.\n Your current computer: " + Environment.MachineName);

                                      }

                                      else

                                      {

                                          MessageBox.Show("There are no files to check in at this time.");

                                      }

                                  }