public static Dictionary <PropDef, object> getFilePropertiesDefs(VDF.Vault.Currency.Connections.Connection connection, File selectedFile) { Dictionary <PropDef, object> dictionary = new Dictionary <PropDef, object>(); try { using (WebServiceManager manager = connection.WebServiceManager) { FileIteration entity = new FileIteration(connection, selectedFile); PropDef[] propertyDefinitionsByEntityClassId = manager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE"); PropertyDefinitionDictionary dictionary2 = connection.PropertyManager.GetPropertyDefinitions("FILE", null, PropertyDefinitionFilter.IncludeAll); foreach (PropDef def in propertyDefinitionsByEntityClassId) { object obj2 = connection.PropertyManager.GetPropertyValue(entity, dictionary2[def.Id], null); dictionary.Add(def, (obj2 == null) ? "" : obj2); //Log.logger(string.Format("== LIB pro DICT == >> '{0}' = '{1}'", def.DispName.ToString(), (obj2 == null) ? "" : obj2.ToString())); } } } catch (SystemException exception) { //Log.logger(exception.ToString()); } return(dictionary); }
public static Dictionary <string, string> getFileProperties(VDF.Vault.Currency.Connections.Connection connection, File selectedFile) { Dictionary <string, string> dict = new Dictionary <string, string>(); try { using (WebServiceManager serviceManager = connection.WebServiceManager) //using will log out after usage { VDF.Vault.Currency.Entities.FileIteration fileInteration = new FileIteration(connection, selectedFile); PropDef[] propDefs = serviceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE"); var propDefsAlt = connection.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, null, VDF.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeAll); foreach (PropDef pdef in propDefs) { object propValue = connection.PropertyManager.GetPropertyValue(fileInteration, propDefsAlt[pdef.Id], null); //PropInst propinst = propcoll[0]; //string val = propinst.Val == null ? "" : propinst.Val.ToString(); dict.Add(pdef.DispName.ToString(), propValue == null ? "" : propValue.ToString()); logit.logger(string.Format("== LIB pro DICT == >> '{0}' = '{1}'", pdef.DispName.ToString(), propValue == null ? "" : propValue.ToString())); //PropInst[] propcoll = serviceManager.PropertyService.GetProperties("FILE", new long[] { selectedFile.Id }, new long[] { pdef.Id }); } } } catch (SystemException ex) { logit.logger(ex.ToString()); } return(dict); }
public static bool uploadFiletoVaultFolder(VDF.Vault.Currency.Connections.Connection connection, string destinationTempFolder, string folderID, string comment, string fileName, byte[] fileBytes) { try { VDF.Vault.Currency.Entities.Folder fld = FolderHelper.getFolderusingID(connection, folderID); List <FileAssocParam> fileAssocParamList = new List <FileAssocParam>(); FileAssocParam fileAssocArray = new FileAssocParam(); FileAssocParam[] paramArray = fileAssocParamList.ToArray(); BOM _bom = new BOM(); //string destinationFile = System.IO.Path.GetTempPath() + fileName; System.IO.File.WriteAllBytes(destinationTempFolder, fileBytes); VDF.Currency.FilePathAbsolute FPA = new VDF.Currency.FilePathAbsolute(destinationTempFolder); FileIteration FI = connection.FileManager.AddFile(fld, comment, paramArray, _bom, FileClassification.None, false, FPA); //cehck if file exists if (FI.FolderId.ToString() == folderID) { ZGHCC.writeLog("File uplaoded and it Exists: " + folderID + " | " + comment); boolRes = true; } else { boolRes = false; } } catch (SystemException ex) { ZGHCC.writeLog("uploadFiletoVaultFolder EX: " + ex.ToString()); statusMess = null; Debug.Write("\nError: " + ex.ToString()); statusMess = "Error: \n" + ex.ToString(); boolRes = false; } return(boolRes); }
public static Dictionary <string, string> PrintProperties(VDF.Vault.Currency.Connections.Connection connection, File selectedFile) { Dictionary <string, string> dict = new Dictionary <string, string>(); try { ZGHCC.writeLog("DesignVisAttmtStatus: " + selectedFile.DesignVisAttmtStatus.ToString()); VDF.Vault.Currency.Entities.FileIteration fileInteration = new FileIteration(connection, selectedFile); var propDefs = connection.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, null, VDF.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeAll); foreach (var key in propDefs.Keys) { // Print the Name from the Definition and the Value from the Property object propValue = connection.PropertyManager.GetPropertyValue(fileInteration, propDefs[key], null); dict.Add(propDefs[key].DisplayName.ToString(), propValue == null ? "" : propValue.ToString()); ZGHCC.writeLog(string.Format("== LIB 1 DICT == >> '{0}' = '{1}'", propDefs[key].DisplayName.ToString(), propValue == null ? "" : propValue.ToString())); } dict.Add("Id", fileInteration.EntityMasterId.ToString()); dict.Add("EntityClass", "File"); } catch (SystemException ex) { ZGHCC.writeLog(ex.ToString()); } return(dict); }
public void Test_Client_A() { ClientSetting clientSetting = new ClientSetting(); _fileIteration = new FileIteration(clientSetting); Assert.AreEqual(1001, clientSetting.ClientID); Assert.Pass(); }
private async Task <FileMaster> updateFile(Stream stream, CheckSum checkSum, IFormFile file, FileMaster duplicateFiles, string path) { FileIteration iteration = new FileIteration { Id = 0, FileMasterId = duplicateFiles.Id, IterationCheckSum = checkSum.CalcCRC32(stream), }; EntityEntry <FileIteration> entity = await _context.FileIterations.AddAsync(iteration); _context.SaveChanges(); duplicateFiles.DateUpdated = DateTime.UtcNow; duplicateFiles.Size = stream.Length; duplicateFiles.VersionNumber = duplicateFiles.VersionNumber + 1; duplicateFiles.FileIterations.Add(entity.Entity); EntityEntry <FileMaster> entry2 = _context.Files.Update(duplicateFiles); _context.SaveChanges(); duplicateFiles = entry2.Entity; string newFileName = duplicateFiles.Id + "_" + duplicateFiles.VersionNumber + Path.GetExtension(path); string thenPath = root + "/" + duplicateFiles.Location + "/" + newFileName; string newFilePath = FormatthePath(thenPath); entity.Entity.IterationName = newFileName; entity.Entity.IterationPath = newFilePath; EntityEntry <FileIteration> entry3 = _context.FileIterations.Update(entity.Entity); _context.SaveChanges(); //iteration = entry3.Entity; using (FileStream fileStream = System.IO.File.Create(newFilePath)) { await stream.CopyToAsync(fileStream); } await _context.SaveChangesAsync(); return(entry2.Entity); }
protected void AddFileToDownload(ADSK.File file, string filePath) { ChangeStatusMessage("Evaluating " + file.Name); // remove the read-only attribute if (System.IO.File.Exists(filePath)) { System.IO.File.SetAttributes(filePath, FileAttributes.Normal); } FileIteration fileIter = new FileIteration(m_conn, file); if (m_useWorkingFolder) { m_aquireFilesSettings.AddFileToAcquire(fileIter, AcquireFilesSettings.AcquisitionOption.Download); } else { m_aquireFilesSettings.AddFileToAcquire(fileIter, AcquireFilesSettings.AcquisitionOption.Download, new FilePathAbsolute(filePath)); } }
public TestOne() { _fileIteration = new FileIteration(); }
public ListBoxFileItem(FileIteration f) { file = f; }
private async Task <IActionResult> upNewFile(IFormFile file) { string fname = ""; Stream stream1 = file.OpenReadStream(); CheckSum objCheckSum = new CheckSum(); //string hafPath = Track.FolderLevels; Counter count = await _context.Counter.LastOrDefaultAsync(); for (int i = 0; i < 6; i++) { if (count.CounterNumber == 5) { await FormatFolders(count); } if (count.CounterNumber < 5) { fname = count.CounterNumber + ""; if (fname.Length < 2) { fname = "00" + i; } else if (fname.Length < 3) { fname = "0" + i; } else if (fname.Length < 4) { fname = i + ""; } if (!Directory.Exists(Track.FolderLevels + fname)) { break; } } } string nroot = Track.FolderLevels + fname; if (!Directory.Exists(nroot)) { Folder pholder = new Folder() { Id = 0, FolderName = fname, DateCreated = DateTime.UtcNow, Location = Path.GetRelativePath(Track.FolderLevels, nroot), ParentFolderId = null, }; EntityEntry <Folder> entry1 = await _context.Folders.AddAsync(pholder); _context.SaveChanges(); Directory.CreateDirectory(nroot); Counter lcount = await _context.Counter.LastOrDefaultAsync(); int lastCount = lcount.CounterNumber++; EntityEntry <Counter> entr = _context.Counter.Update(lcount); _context.SaveChanges(); } Folder uploadingfolder = _context.Folders.LastOrDefault(); int folId = uploadingfolder.Id; FileMaster theFile = new FileMaster { Id = 0, FileName = Path.GetFileName(file.FileName), //Name = Path.GetFileNameWithoutExtension(file.FileName), ClientFilePath = Path.GetFullPath(file.FileName), DateUploaded = DateTime.UtcNow, DateUpdated = DateTime.UtcNow, Location = ((await _context.Folders.FirstOrDefaultAsync(p => p.Id == folId)).Location), Type = Path.GetExtension(file.FileName), Size = file.Length, VersionNumber = 0, Folder = await _context.Folders.FirstOrDefaultAsync(p => p.Id == folId), FileIterations = new List <FileIteration>() }; EntityEntry <FileMaster> entry = await _context.Files.AddAsync(theFile); _context.SaveChanges(); string stName = entry.Entity.Id + "_" + entry.Entity.VersionNumber + Path.GetExtension(file.FileName); string stPath = Track.FolderLevels + uploadingfolder.FolderName + "/" + stName; FileIteration iter = new FileIteration { Id = 0, FileMasterId = entry.Entity.Id, IterationCheckSum = objCheckSum.CalcCRC32(stream1), IterationName = stName, IterationPath = stPath }; EntityEntry <FileIteration> entry2 = await _context.FileIterations.AddAsync(iter); _context.SaveChanges(); theFile.FileIterations.Add(entry2.Entity); //when the version of file is updated EntityEntry <FileMaster> entry3 = _context.Files.Update(theFile); _context.SaveChanges(); theFile = entry3.Entity; using (var stream = new FileStream(stPath, FileMode.Create)) { await file.CopyToAsync(stream); } return(Ok()); }
public JobOutcome Execute(IJobProcessorServices context, IJob job) { try { Inventor.InventorServer mInv = context.InventorObject as InventorServer; #region validate execution rules //pick up this job's context mConnection = context.Connection; Autodesk.Connectivity.WebServicesTools.WebServiceManager mWsMgr = mConnection.WebServiceManager; long mEntId = Convert.ToInt64(job.Params["EntityId"]); string mEntClsId = job.Params["EntityClassId"]; // only run the job for files; handle the scenario, that an item lifecycle transition accidently submitted the job if (mEntClsId != "FILE") { context.Log(null, "This job type is for files only."); return(JobOutcome.Failure); } // only run the job for ipt and iam file types, List <string> mFileExtensions = new List <string> { ".ipt", ".iam", "idw", "dwg" }; ACW.File mFile = mWsMgr.DocumentService.GetFileById(mEntId); if (!mFileExtensions.Any(n => mFile.Name.EndsWith(n))) { context.Log(null, "Skipped Job execution as file type did not match iLogic enabled files (ipt, iam, idw/dwg"); return(JobOutcome.Success); } //run iLogic for Inventor DWG file types/skip AutoCAD DWG files ACW.PropDef[] mPropDefs = mWsMgr.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE"); ACW.PropDef mPropDef = null; ACW.PropInst mPropInst = null; if (mFile.Name.EndsWith(".dwg")) { mPropDef = mPropDefs.Where(n => n.SysName == "Provider").FirstOrDefault(); mPropInst = (mWsMgr.PropertyService.GetPropertiesByEntityIds("FILE", new long[] { mFile.Id })).Where(n => n.PropDefId == mPropDef.Id).FirstOrDefault(); if (mPropInst.Val.ToString() != "Inventor DWG") { context.Log(null, "Skipped Job execution as DWG type did not match Inventor DWG"); return(JobOutcome.Success); } } ApplicationAddIns mInvSrvAddIns = mInv.ApplicationAddIns; ApplicationAddIn iLogicAddIn = mInvSrvAddIns.ItemById["{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"]; if (iLogicAddIn != null && iLogicAddIn.Activated != true) { iLogicAddIn.Activate(); } dynamic mAutomation = iLogicAddIn.Automation; if (mAutomation == null) { Trace.WriteLine("iLogic-AddIn automation is not available; exiting job processing"); context.Log(null, "iLogic-AddIn automation is not available"); return(JobOutcome.Failure); } #endregion validate execution rules #region VaultInventorServer IPJ activation //override InventorServer default project settings by your Vault specific ones Inventor.DesignProjectManager mInvIpjManager; Inventor.DesignProject mInvDfltProject, mInvVltProject; String mIpjPath = ""; String mWfPath = ""; String mIpjLocalPath = ""; ACW.File mIpj; VDF.Vault.Currency.Entities.FileIteration mIpjFileIter = null; //validate ipj setting, a single, enforced ipj is expected if (mWsMgr.DocumentService.GetEnforceWorkingFolder() && mWsMgr.DocumentService.GetEnforceInventorProjectFile()) { mIpjPath = mWsMgr.DocumentService.GetInventorProjectFileLocation(); mWfPath = mWsMgr.DocumentService.GetRequiredWorkingFolderLocation(); //Set mWfPath to alternate temporary working folder if needed, e.g. to delete all files after job execution } else { context.Log(null, "Job requires both settings enabled: 'Enforce Workingfolder' and 'Enforce Inventor Project'."); return(JobOutcome.Failure); } //download and activate the Inventor Project file in VaultInventorServer mIpj = (mWsMgr.DocumentService.FindLatestFilesByPaths(new string[] { mIpjPath })).FirstOrDefault(); try { String[] mIpjFullFileName = mIpjPath.Split(new string[] { "/" }, StringSplitOptions.None); String mIpjFileName = mIpjFullFileName.LastOrDefault(); //define download settings for the project file VDF.Vault.Settings.AcquireFilesSettings mAcqrIpjSettings = new VDF.Vault.Settings.AcquireFilesSettings(mConnection); mAcqrIpjSettings.LocalPath = new VDF.Currency.FolderPathAbsolute(mWfPath); mIpjFileIter = new VDF.Vault.Currency.Entities.FileIteration(mConnection, mIpj); mAcqrIpjSettings.AddFileToAcquire(mIpjFileIter, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download); //download project file and get local path VDF.Vault.Results.AcquireFilesResults mDownLoadResult; VDF.Vault.Results.FileAcquisitionResult fileAcquisitionResult; mDownLoadResult = mConnection.FileManager.AcquireFiles(mAcqrIpjSettings); fileAcquisitionResult = mDownLoadResult.FileResults.FirstOrDefault(); mIpjLocalPath = fileAcquisitionResult.LocalPath.FullPath; //activate this Vault's ipj mInvIpjManager = mInv.DesignProjectManager; mInvDfltProject = mInvIpjManager.ActiveDesignProject; mInvVltProject = mInvIpjManager.DesignProjects.AddExisting(mIpjLocalPath); mInvVltProject.Activate(); //[Optionally:] get Inventor Design Data settings and download all related files --------- } catch { context.Log(null, "Job was not able to activate Inventor project file. - Note: The ipj must not be checked out by another user."); return(JobOutcome.Failure); } #endregion VaultInventorServer IPJ activation #region download source file(s) //build download options including DefaultAcquisitionOptions VDF.Vault.Currency.Entities.FileIteration mFileIteration = new VDF.Vault.Currency.Entities.FileIteration(mConnection, mFile); VDF.Vault.Currency.Entities.FileIteration mNewFileIteration = null; VDF.Vault.Settings.AcquireFilesSettings mAcqrFlsSettings; VDF.Vault.Results.AcquireFilesResults mAcqrFlsResults2; VDF.Vault.Results.FileAcquisitionResult mFileAcqsResult2; string mLocalFileFullName = "", mExt = ""; if (mFileIteration.IsCheckedOut == true && mFileIteration.IsCheckedOutToCurrentUser == false) { //exit the job, as the job user is not able to edit the file reserved to another user mInvDfltProject.Activate(); context.Log(null, "Job stopped execution as the source file to process is checked-out by another user."); return(JobOutcome.Failure); } //download only if (mFileIteration.IsCheckedOut == true && mFileIteration.IsCheckedOutToCurrentUser == true) { mAcqrFlsSettings = CreateAcquireSettings(false); mAcqrFlsSettings.AddFileToAcquire(mFileIteration, mAcqrFlsSettings.DefaultAcquisitionOption); mAcqrFlsResults2 = this.mConnection.FileManager.AcquireFiles(mAcqrFlsSettings); mNewFileIteration = mFileIteration; mFileAcqsResult2 = mAcqrFlsResults2.FileResults.Where(n => n.File.EntityName == mFileIteration.EntityName).FirstOrDefault(); mLocalFileFullName = mFileAcqsResult2.LocalPath.FullPath; mExt = System.IO.Path.GetExtension(mLocalFileFullName); } //checkout and download if (mFileIteration.IsCheckedOut == false) { try { mAcqrFlsSettings = CreateAcquireSettings(true); //checkout (don't checkout related children) mAcqrFlsSettings.AddFileToAcquire(mFileIteration, mAcqrFlsSettings.DefaultAcquisitionOption); mAcqrFlsResults2 = this.mConnection.FileManager.AcquireFiles(mAcqrFlsSettings); mFileAcqsResult2 = mAcqrFlsResults2.FileResults.Where(n => n.File.EntityName == mFileIteration.EntityName).FirstOrDefault(); mNewFileIteration = mFileAcqsResult2.NewFileIteration; mAcqrFlsSettings = null; mAcqrFlsSettings = CreateAcquireSettings(false);//download (include related children) mAcqrFlsSettings.AddFileToAcquire(mNewFileIteration, mAcqrFlsSettings.DefaultAcquisitionOption); mAcqrFlsResults2 = this.mConnection.FileManager.AcquireFiles(mAcqrFlsSettings); mLocalFileFullName = mFileAcqsResult2.LocalPath.FullPath; mExt = System.IO.Path.GetExtension(mLocalFileFullName); } catch (Exception) { mInvDfltProject.Activate(); context.Log(null, "Job stopped execution as the source file to process did not download or check-out."); return(JobOutcome.Failure); } } #endregion download source file(s) #region capture dependencies //we need to return all relationships during later check-in List <ACW.FileAssocParam> mFileAssocParams = new List <ACW.FileAssocParam>(); ACW.FileAssocArray mFileAssocArray = mWsMgr.DocumentService.GetLatestFileAssociationsByMasterIds(new long[] { mFile.MasterId }, ACW.FileAssociationTypeEnum.None, false, ACW.FileAssociationTypeEnum.All, false, false, false, true).FirstOrDefault(); if (mFileAssocArray.FileAssocs != null) { foreach (ACW.FileAssoc item in mFileAssocArray.FileAssocs) { ACW.FileAssocParam mFileAssocParam = new ACW.FileAssocParam(); mFileAssocParam.CldFileId = item.CldFile.Id; mFileAssocParam.ExpectedVaultPath = item.ExpectedVaultPath; mFileAssocParam.RefId = item.RefId; mFileAssocParam.Source = item.Source; mFileAssocParam.Typ = item.Typ; mFileAssocParams.Add(mFileAssocParam); } } #endregion capture dependencies #region iLogic Configuration //avoid unplanned rule execution triggered by the document itself mAutomation.RulesOnEventsEnabled = false; mAutomation.RulesEnabled = false; //set the iLogic Advanced Configuration Settings dynamic mFileOptions = mAutomation.FileOptions; mFileOptions.AddinDirectory = mSettings.iLogicAddinDLLs; //add the job extension app path and configured external rule directories to the FileOptions.ExternalRuleDirectories for iLogic List <string> mExtRuleDirs = new List <string>(); mExtRuleDirs.Add(mAppPath); mExtRuleDirs.AddRange(mSettings.ExternalRuleDirectories.Split(',').ToList <string>()); mFileOptions.ExternalRuleDirectories = mExtRuleDirs.ToArray(); //enable iLogic logging dynamic mLogCtrl = mAutomation.LogControl; switch (mSettings.iLogicLogLevel) { case "None": mLogCtrl.Level = 0; break; case "Trace": mLogCtrl.Level = 1; break; case "Debug": mLogCtrl.Level = 2; break; case "Info": mLogCtrl.Level = 3; break; case "Warn": mLogCtrl.Level = 4; break; case "Error": mLogCtrl.Level = 5; break; case "Fatal": mLogCtrl.Level = 6; break; default: mLogCtrl.Level = 5; break; } //enable iLogic to save a log file for each job Id. string mILogicLogFileFullName = ""; if (mLogCtrl.Level != 0) { string mLogName = job.Id + "_" + mFile.Name + "_iLogicSampleJob.log"; System.IO.DirectoryInfo mLogDirInfo = new System.IO.DirectoryInfo(mSettings.iLogicLogDir); if (mLogDirInfo.Exists == false) { mLogDirInfo = System.IO.Directory.CreateDirectory(mSettings.iLogicLogDir); } mILogicLogFileFullName = System.IO.Path.Combine(mLogDirInfo.FullName, mLogName); } //read rule execution settings string mVaultRule = mSettings.VaultRuleFullFileName; string mExtRule = mSettings.ExternalRuleName; string mExtRuleFullName = null; string mIntRulesOption = mSettings.InternalRulesOption; if (mVaultRule != "") { ACW.File mRuleFile = mWsMgr.DocumentService.FindLatestFilesByPaths(new string[] { mVaultRule }).FirstOrDefault(); //build download options including DefaultAcquisitionOptions VDF.Vault.Currency.Entities.FileIteration mRuleFileIter = new VDF.Vault.Currency.Entities.FileIteration(mConnection, mRuleFile); VDF.Vault.Settings.AcquireFilesSettings mAcqrRuleSettings = CreateAcquireSettings(false); mAcqrRuleSettings.AddFileToAcquire(mRuleFileIter, mAcqrRuleSettings.DefaultAcquisitionOption); //download VDF.Vault.Results.AcquireFilesResults mAcqrRuleResults = this.mConnection.FileManager.AcquireFiles(mAcqrRuleSettings); //pick-up the new file iteration in case of check-out VDF.Vault.Results.FileAcquisitionResult mRuleAcqResult = mAcqrRuleResults.FileResults.Where(n => n.File.EntityName == mRuleFileIter.EntityName).FirstOrDefault(); if (mRuleAcqResult.LocalPath != null) { mExtRuleFullName = mRuleAcqResult.LocalPath.FullPath; System.IO.FileInfo fileInfo = new System.IO.FileInfo(mExtRuleFullName); if (fileInfo.Exists == false) { context.Log(null, "Job downloaded rule file but exited due to missing rule file: " + mExtRuleFullName + "."); mConnection.FileManager.UndoCheckoutFile(mNewFileIteration); return(JobOutcome.Failure); } else { mExtRule = fileInfo.Name; if (!mExtRuleDirs.Any(n => fileInfo.DirectoryName.Equals(n))) { context.Log(null, "Job downloaded rule file but exited due to missing iLogic External Rule Directory configuration: Add the path" + fileInfo.DirectoryName + " to the list of External Rule Directories."); mConnection.FileManager.UndoCheckoutFile(mNewFileIteration); return(JobOutcome.Failure); } } } else { context.Log(null, "Job could not download configured rule file and exited. Compare the 'VaultRuleFullFileName' setting and available rule in Vault."); return(JobOutcome.Failure); } } #endregion iLogic Configuration #region Run iLogic Rule(s) //Open Inventor Document Document mDoc = mInv.Documents.Open(mLocalFileFullName); //use case - apply external rule with arguments; additional Vault UDP, status or any information might fill rule arguments if (mExtRule != "") { //required rule arguments to continue Vault interaction within the rule (iLogic-Vault library) NameValueMap ruleArguments = mInv.TransientObjects.CreateNameValueMap(); ruleArguments.Add("ServerName", mConnection.Server); ruleArguments.Add("VaultName", mConnection.Vault); ruleArguments.Add("UserId", mConnection.UserID); ruleArguments.Add("Ticket", mConnection.Ticket); //additional rule arguments to build rule conditions evaluating Vault lifecycle information, properties, etc. if (mSettings.PropagateProps == "True") { ACW.PropInst[] mSourcePropInsts = mWsMgr.PropertyService.GetPropertiesByEntityIds("FILE", new long[] { mFileIteration.EntityIterationId }); string mPropDispName; string mThumbnailDispName = mPropDefs.Where(n => n.SysName == "Thumbnail").FirstOrDefault().DispName; foreach (ACW.PropInst item in mSourcePropInsts) { mPropDispName = mPropDefs.Where(n => n.Id == item.PropDefId).FirstOrDefault().DispName; //filter thumbnail property, as iLogic RuleArguments will fail reading it. if (mPropDispName != mThumbnailDispName) { ruleArguments.Add(mPropDispName, item.Val); } } } //call external rule with arguments; return value = 0 in case of successful execution mRuleSuccess = mAutomation.RunExternalRuleWithArguments(mDoc, mExtRule, ruleArguments); if (mRuleSuccess != 0) { context.Log(null, "Job failed due to failure in external rule: " + mExtRule + "."); mDoc.Close(true); mConnection.FileManager.UndoCheckoutFile(mNewFileIteration); mLogCtrl.SaveLogAs(mILogicLogFileFullName); return(JobOutcome.Failure); } else { mAllRulesTextWrp = "External Rule: " + mExtRule; } mDoc.Save2(false); } //use case - run all, all active or filtered document rules dynamic mDocRules = mAutomation.Rules(mDoc); List <dynamic> mRulesToExec = new List <dynamic>(); switch (mSettings.InternalRulesOption) { case "None": break; case "Active": if (mDocRules != null) { foreach (dynamic rule in mDocRules) { if (rule.IsActive == true) { mRulesToExec.Add(rule); } } } break; case "All": if (mDocRules != null) { foreach (dynamic rule in mDocRules) { mRulesToExec.Add(rule); } } break; default: foreach (dynamic rule in mDocRules) { if (rule.Name.Contains(mSettings.InternalRulesOption)) { mRulesToExec.Add(rule); } } break; } if (mRulesToExec.Count >= 1) { foreach (dynamic rule in mRulesToExec) { mRuleSuccess = mAutomation.RunRule(mDoc, rule.Name); if (mRuleSuccess != 0) { context.Log(null, "Job failed due to failure in internal rule: " + rule.Name + "."); mDoc.Close(true); mConnection.FileManager.UndoCheckoutFile(mNewFileIteration); mLogCtrl.SaveLogAs(mILogicLogFileFullName); return(JobOutcome.Failure); } else { mAllRules.Add(rule.Name); } } } mDoc.Save2(false); mDoc.Close(true); mLogCtrl.SaveLogAs(mILogicLogFileFullName); if (mAllRules.Count > 0) { mAllRulesTextWrp += "\n\r Internal Rule(s):"; foreach (string name in mAllRules) { mAllRulesTextWrp += "\r\n " + name; } } #endregion Run iLogic Rules #region Check-in result // checkin new file version VDF.Currency.FilePathAbsolute vdfPath = new VDF.Currency.FilePathAbsolute(mLocalFileFullName); FileIteration mUploadedFile = null; try { if (mFileAssocParams.Count > 0) { mUploadedFile = mConnection.FileManager.CheckinFile(mNewFileIteration, "Created by Custom Job executing iLogic : " + mAllRulesTextWrp, false, mFileAssocParams.ToArray(), null, true, null, mFileIteration.FileClassification, false, vdfPath); } else { mUploadedFile = mConnection.FileManager.CheckinFile(mNewFileIteration, "Created by Custom Job executing iLogic : " + mAllRulesTextWrp, false, null, null, false, null, mFileIteration.FileClassification, false, vdfPath); } } catch { context.Log(null, "Job could not check-in updated file: " + mUploadedFile.EntityName + "."); return(JobOutcome.Failure); } #endregion check-in result #region reset mInvDfltProject.Activate(); //delete temporary working folder if imlemented here #endregion reset return(JobOutcome.Success); } catch (Exception ex) { context.Log(ex, "Job failed by unhandled exception: " + ex.ToString() + " "); return(JobOutcome.Failure); } }
private void btnSync_Click(object sender, EventArgs e) { CleanAllFilesdb(); var rootFolder = m_connection.FolderManager.RootFolder; string[] pathes = { rootFolder.FolderPath }; //m_connection.FileManager. var foldersIds = m_connection.WebServiceManager.DocumentService.GetFolderIdsByParentIds(new long[] { 1 }, true); var files = new List <File>(); foreach (var folderid in foldersIds) { var folderfiles = m_connection.WebServiceManager.DocumentService.GetLatestFilesByFolderId(folderid, false); if (folderfiles != null) { files.AddRange(folderfiles); } } PropertyService propertyService = m_connection.WebServiceManager.PropertyService; var allProperties = m_connection.PropertyManager.GetPropertyDefinitions(null, null, PropertyDefinitionFilter.IncludeUserDefined); string propertySystemName = string.Empty; foreach (var property in allProperties) { if (property.Value.DisplayName == "Document Number") { propertySystemName = property.Value.SystemName; } } //var propertySystemName = "60821119-9640-4590-883a-024912c0393b"; var propDef = m_connection.PropertyManager.GetPropertyDefinitionBySystemName(propertySystemName); foreach (var file in files) { var fileIteration = new FileIteration(m_connection, file); var path0 = m_connection.WorkingFoldersManager.GetPathOfFileInWorkingFolder(fileIteration).ToString(); string path1 = "$" + path0.Substring(path0.IndexOf("Vault") + 5); var path = path1.Replace('\\', '/'); var pvs = new PropertyValueSettings(); var DocumentNumberValue = m_connection.PropertyManager.GetPropertyValue(fileIteration, propDef, pvs); var filedb = new DataLayer.Models.File() { FullPath = path, CreatorId = file.CreateUserId, CreationDate = file.CreateDate, EditorId = file.CheckedOut ? file.CkOutUserId : file.CreateUserId, LastRevisionDate = file.CheckedOut ? file.ModDate : file.CreateDate, LastRevisionID = file.Id, LastComment = file.Comm, LastState = DataLayer.Models.FileStates.a, DocumentNumber = DocumentNumberValue != null?DocumentNumberValue.ToString() : "", }; var createPersonDb = new DataLayer.Models.Person() { PersonID = file.CreateUserId, Name = file.CreateUserName }; if (db.PersonRipository.GetById(createPersonDb.PersonID) == null) { db.PersonRipository.Insert(createPersonDb); db.PersonRipository.save(); } //To Modify later //var EditPersonDb = new DataLayer.Models.Person() //{ // PersonID = file.CkOutUserId, // Name = file.cus //}; db.FileRipository.Insert(filedb); db.FileRipository.save(); } reloadGrid(); }