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); }
// 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); }
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 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; } }
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); } }