public static string GetDocLocation(IMInstance iMInstance, string engNum, double docNum) { using (new TransactionScope( TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted })) { using (var db = new IMDbContext(iMInstance)) { var docLoc = db.Set<DOCMASTER>(). Where(x => x.C2ALIAS.Equals(engNum, StringComparison.OrdinalIgnoreCase) && x.DOCNUM == docNum && x.VERSION == 1 ).Select(y => y.DOCLOC).ToList().FirstOrDefault(); var sp_docLoc = docLoc.Split(':'); var p1 = sp_docLoc[0].Trim(); var srvLoc = db.Set<DOCSERVER>(). Where(x => x.DOCSERVER1.Equals(p1, StringComparison.OrdinalIgnoreCase) ).Select(y => y.LOCATION).ToList().FirstOrDefault(); var result = string.Format("{0}{1}", srvLoc, sp_docLoc[1]); return result; } } }
public static string GetWsObjectID(IMInstance iMInstance, IMSession iMSession, IMWSObjectType iMWSObjectType, double objNum) { switch (iMWSObjectType) { case IMWSObjectType.File: return (string)string.Format("{0}!{1}:{2},1:", iMInstance.UseAdmin.GetValueOrDefault(false) ? iMSession.AdminDb(IMDbType.Active).ObjectID : iMSession.UserDb(IMDbType.Active).ObjectID, iMWSObjectType.ToEnumDesc<IMWSObjectType>(), objNum); case IMWSObjectType.Folder: return (string)string.Format("{0}!{1}:{2}:", iMInstance.UseAdmin.GetValueOrDefault(false) ? iMSession.AdminDb(IMDbType.Active).ObjectID : iMSession.UserDb(IMDbType.Active).ObjectID, iMWSObjectType.ToEnumDesc<IMWSObjectType>(), objNum); case IMWSObjectType.Workspace: return (string)string.Format("{0}!{1}:{2}:", iMInstance.UseAdmin.GetValueOrDefault(false) ? iMSession.AdminDb(IMDbType.Active).ObjectID : iMSession.UserDb(IMDbType.Active).ObjectID, iMWSObjectType.ToEnumDesc<IMWSObjectType>(), objNum); default: return null; } }
// INSERT INTO // ACTIVE.MHGROUP.DOCHISTORY //( // DOCNUM, // VERSION, // ACTIVITY, // ACTIVITY_CODE, // ACTIVITY_DATETIME, // DURATION, // PAGES_PRINTED, // DOCUSER, // APPNAME, // LOCATION //) // VALUES //( // @DocNum, // 1, // 'Export', // 18, // GETDATE(), // 0, // 0, // @UserID, // 'KPMGFileTransfer', // 'USMDCKDWB2001' //) public static void PutDocDownloadHistory(IMInstance iMInstance, double docNum) { //var docHistory = new DOCHISTORY { // DOCNUM = docNum, // VERSION = 1, // ACTIVITY = "Export", // ACTIVITY_CODE = 1, // ACTIVITY_DATETIME = DateTime.UtcNow, // DURATION = 0, // PAGES_PRINTED = 0, // NUM1 = null, // NUM2 = null, // NUM3 = null, // DATA1 = null, // DATA2 = null, // DOCUSER = iMInstance.UserId, // APPNAME = iMInstance.AppName_0, // LOCATION = iMInstance.AppName, // COMMENTS = "Downloaded from Audit Manager" //}; //using (var db = new IMDbContext(iMInstance)) //{ // var x = db.Database.SqlQuery<DOCHISTORY>("INSERT INTO MHGROUP.DOCHISTORY VALUES (" + docNum + ")").ToList(); //} var iMSession = new IMSession(iMInstance); var docId = IM.Wrapper.Utility.IMUtility.GetWsObjectID(iMInstance, iMSession, IMWSObjectType.File, docNum); IManDocument imDoc = iMInstance.UseAdmin.GetValueOrDefault(false) ? (IManDocument)iMSession.AdminSession().DMS.GetObjectByID(docId) : (IManDocument)iMSession.UserSession().DMS.GetObjectByID(docId); imDoc.HistoryList.Add(imHistEvent.imHistoryExport, 0, 0, iMInstance.AppName_0, "Downloaded from Audit Manager", iMInstance.AppName, "", "", null, null, null); }
public IMUtility(IMInstance iMInstance) { _IMInstance = iMInstance; }
public IMUtility(Env env, string userId = null, bool? useAdmin = false, bool? useConfig = false) { _IMInstance = new IMInstance(env, userId, useAdmin, useConfig); }
private static string GetDocLocation(IMInstance iMInstance, double docNum) { var iMSession = new IMSession(iMInstance); var docId = IM.Wrapper.Utility.IMUtility.GetWsObjectID(iMInstance, iMSession, IMWSObjectType.File, docNum); IManDocument imDoc = iMInstance.UseAdmin.GetValueOrDefault(false) ? (IManDocument)iMSession.AdminSession().DMS.GetObjectByID(docId) : (IManDocument)iMSession.UserSession().DMS.GetObjectByID(docId); var docLoc = imDoc.GetAttributeByID(imProfileAttributeID.imProfileLocation).ToString(); return docLoc; }
public IMSession(IMInstance iMInstance) { _IMInstance = iMInstance; }
private static dynamic GetWsId(IMInstance iMInstance, List<string> engNums) { using (new TransactionScope( TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted })) { using (var db = new IMDbContext(iMInstance)) { var result = ( from dm in db.Set<DOCMASTER>() join prj in db.Set<PROJECT>() on dm.DOCNUM equals prj.DOCNUM where engNums.Contains(dm.C2ALIAS) && dm.C_ALIAS.Equals("WEBDOC", StringComparison.OrdinalIgnoreCase) && dm.DOCNAME.Equals("", StringComparison.OrdinalIgnoreCase) select new { EngNum = dm.C2ALIAS, EngId = prj.PRJ_ID }).ToList(); return result; } } }
public static int? Upload(IMInstance iMInstance, string engNum, string fileNameWithLocalPath, string iMFolderPath) { if (!File.Exists(fileNameWithLocalPath)) return null; var projectIdForEngNum = GetWsId(iMInstance, new List<string> { engNum }); if (projectIdForEngNum.Count == 0) return null; var iMSession = new IMSession(iMInstance); var wsId = IM.Wrapper.Utility.IMUtility.GetWsObjectID(iMInstance, iMSession, IMWSObjectType.Workspace, (double)projectIdForEngNum[0].EngId); IManWorkspace imWs = iMInstance.UseAdmin.GetValueOrDefault(false) ? (IManWorkspace)iMSession.AdminSession().DMS.GetObjectByID(wsId) : (IManWorkspace)iMSession.UserSession().DMS.GetObjectByID(wsId); if (iMFolderPath.StartsWith("/") || iMFolderPath.StartsWith("\\")) { iMFolderPath = iMFolderPath.Substring(1); } IManDocumentFolder imFldr = GetIMDocFolder(imWs, iMFolderPath); if (imFldr == null) return null; IManDocument imDoc = imFldr.Database.CreateDocument(); imDoc.SetAttributeByID(imProfileAttributeID.imProfileDescription, Path.GetFileName(fileNameWithLocalPath)); imDoc.SetAttributeByID(imProfileAttributeID.imProfileType, GetIMDocType(imWs, Convert.ToString(imDoc.GetAttributeValueByID(imProfileAttributeID.imProfileDescription)))); //imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, imWs.Owner.Name); //imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, imWs.Owner.Name); imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, iMInstance.UserId); imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, iMInstance.UserId); //imDoc.SetAttributeByID(imProfileAttributeID.imProfileLastUser, iMInstance.UserId); imDoc.SetAttributeByID(imProfileAttributeID.imProfileClass, IMConst.CONST_IMPROFILECLASS); imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom7, IMConst.CONST_IMPROFILECUSTOM7); imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom1, imWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom1).ToString()); imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom2, imWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom2).ToString()); var engFunction = imWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom3).ToString(); if (!string.IsNullOrWhiteSpace(engFunction)) { imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom3, engFunction); } else { imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom3, IMConst.CONST_IMPROFILECUSTOM3); } foreach (IManAdditionalProperty imAddProp in imFldr.AdditionalProperties) { if (imAddProp == null) continue; int attID = Convert.ToInt32(imAddProp.Name.Substring(imAddProp.Name.LastIndexOf('_') + 1)); imProfileAttributeID imProfAttr = (imProfileAttributeID)attID; if (imProfAttr != imProfileAttributeID.imProfileAuthor && imProfAttr != imProfileAttributeID.imProfileAuthorDescription && imProfAttr != imProfileAttributeID.imProfileOperator && imProfAttr != imProfileAttributeID.imProfileOperatorDescription && imProfAttr != imProfileAttributeID.imProfileLastUser && imProfAttr != imProfileAttributeID.imProfileLastUserDescription) { } else { continue; } if (imAddProp.Value != IMConst.CONST_WORKSPACE_VALUE) { //Date if (imProfAttr == imProfileAttributeID.imProfileCustom21 || imProfAttr == imProfileAttributeID.imProfileCustom22 || imProfAttr == imProfileAttributeID.imProfileCustom23 || imProfAttr == imProfileAttributeID.imProfileCustom24) { DateTime parsedTime; if (DateTime.TryParse(imAddProp.Value, out parsedTime)) { imDoc.SetAttributeByID(imProfAttr, parsedTime); } else { imDoc.SetAttributeByID(imProfAttr, null); } } //Boolean else if (imProfAttr == imProfileAttributeID.imProfileCustom25 || imProfAttr == imProfileAttributeID.imProfileCustom26 || imProfAttr == imProfileAttributeID.imProfileCustom27 || imProfAttr == imProfileAttributeID.imProfileCustom28) { if (imAddProp.Value != null && imAddProp.Value.ToLower() == "true") { imDoc.SetAttributeByID(imProfAttr, true); } else { imDoc.SetAttributeByID(imProfAttr, false); } } else { imDoc.SetAttributeByID(imProfAttr, imAddProp.Value); } } else { imDoc.SetAttributeByID(imProfAttr, imFldr.Workspace.Profile.GetAttributeValueByID(imProfAttr)); } } IManCheckinResult checkInResult = imDoc.CheckInWithResults(fileNameWithLocalPath, imCheckinDisposition.imCheckinNewDocument, imCheckinOptions.imDontKeepCheckedOut); if (checkInResult.Succeeded) { AddSecurityToDoc(imDoc, imFldr); IManDocuments imDocs = (IManDocuments)imFldr.Contents; if (null != imDocs) { imDocs.AddDocumentReference(checkInResult.Result); } if (iMInstance.UseAdmin.GetValueOrDefault(false)) { using (var db = new IMDbContext(iMInstance)) { var original = db.DOCMASTER.Find(imDoc.Number, 1); //original.OPERATOR = iMInstance.UserId; //original.AUTHOR = iMInstance.UserId; original.LASTUSER = iMInstance.UserId; db.SaveChanges(); } } return imDoc.Number; } else { return null; } }