Exemplo n.º 1
0
        internal static void CheckInDoc(IManDocument imDoc)
        {
            //using (new TransactionScope(
            //        TransactionScopeOption.Required,
            //        new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted }))
            //{
            using (var db = new ActiveDbContext())
            {
                var itemToRemove = db.CHECKOUT.SingleOrDefault(x => x.DOCNUM == imDoc.Number);

                if (itemToRemove != null)
                {
                    db.CHECKOUT.Remove(itemToRemove);
                    db.SaveChanges();
                }

                var original = db.DOCMASTER.SingleOrDefault(x => x.DOCNUM == imDoc.Number);
                original.CHECKEDOUT = "N";
                original.DOCINUSE   = "N";
                original.INUSEBY    = null;
                db.SaveChanges();

                AddImHistoryInfo(imDoc, HistoryInfoType.CHECKIN);
            }
            //}
        }
Exemplo n.º 2
0
        private static void AddSecurityToDoc(IManDocument imDoc, IManDocumentFolder imFldr)
        {
            foreach (IManGroupACL fldrGroup in imFldr.Security.GroupACLs)
            {
                imDoc.Security.GroupACLs.Add(fldrGroup.Group.Name, fldrGroup.Right);
            }

            foreach (IManUserACL fldrUser in imFldr.Security.UserACLs)
            {
                bool addUser = false;
                try
                {
                    if (imDoc.Security.UserACLs.ItemByName(fldrUser.User.Name) == null)
                    {
                        addUser = false;
                    }
                }
                catch { addUser = true; }

                if (addUser)
                {
                    imDoc.Security.UserACLs.Add(fldrUser.User.Name, fldrUser.Right);
                }
            }

            imDoc.Update();
        }
Exemplo n.º 3
0
        public static WsDocDelStatusType ValidateDoc(IManDocument imDoc, imDocumentOperation imDocumentOperation)
        {
            var wsFile = Workspace.GetWsFile(imDoc);

            if (!imDoc.IsOperationAllowed(imDocumentOperation))
            {
                return(WsDocDelStatusType.InsufficientRights);
            }

            if (imDocumentOperation == IManage.imDocumentOperation.imDeleteDocumentOp && wsFile.IsUnderPreservation)
            {
                return(WsDocDelStatusType.WSUnderPreservation);
            }

            if (imDocumentOperation == IManage.imDocumentOperation.imDeleteDocumentOp && wsFile.IsDeleted)
            {
                return(WsDocDelStatusType.IsDeleted);
            }

            if (imDocumentOperation == IManage.imDocumentOperation.imDeleteDocumentOp && wsFile.IsRecord)
            {
                return(WsDocDelStatusType.IsRecord);
            }

            if (wsFile.IsCheckedOut || wsFile.IsLocked)
            {
                //return WsDocDelStatusType.IsCheckedOut;
                WsOperation.CheckInDoc(imDoc);
                imDoc.Update();
            }

            //if (wsFile.IsCheckedOut)
            //{
            //    //return WsDocDelStatusType.IsCheckedOut;
            //    WsOperation.CheckInDoc(imDoc);
            //    imDoc.Update();
            //}

            //if (wsFile.IsLocked)
            //{
            //    //return WsDocDelStatusType.IsLocked;
            //    WsOperation.CheckInDoc(imDoc);
            //    imDoc.Update();
            //}

            if (imDocumentOperation == IManage.imDocumentOperation.imDeleteDocumentOp && wsFile.VersionCount > 1)
            {
                return(WsDocDelStatusType.MultiVersion);
            }

            return(WsDocDelStatusType.Success);
        }
Exemplo n.º 4
0
        public static void Move_YrEnd_Audit_RET_N_ENG_To_ElecWp(double retDocNum, double engDocNum, double engNum)
        {
            IManDocument imRetDoc = WsUtility.GetObjectByID <IManDocument>(WsUtility.GetWsObjectTypeId(WsObjectType.File, retDocNum));
            IManDocument imEngDoc = WsUtility.GetObjectByID <IManDocument>(WsUtility.GetWsObjectTypeId(WsObjectType.File, engDocNum));

            IManWorkspace imWs = WsUtility.GetObjectByID <IManWorkspace>(WsUtility.GetWsObjectTypeId(WsObjectType.Workspace, engNum));

            IManDocumentFolder imFldrPeriodEndAudit = WsUtility.GetWsFldr(imWs, WsFldrType.PeriodEndAudit);
            IManDocumentFolder imRetFldr            = null;
            IManDocumentFolder imEngFldr            = null;
            IManDocumentFolder imElecWpFldr         = null;

            foreach (IManDocumentFolder docFldr in imFldrPeriodEndAudit.SubFolders)
            {
                if (docFldr.Name.Equals("RET Files", StringComparison.OrdinalIgnoreCase))
                {
                    imRetFldr = docFldr;
                }
                else if (docFldr.Name.Equals("ENG Files", StringComparison.OrdinalIgnoreCase))
                {
                    imEngFldr = docFldr;
                }
                else if (docFldr.Name.Equals("Electronic Workpapers (Maintained Outside of eAudIT)", StringComparison.OrdinalIgnoreCase))
                {
                    imElecWpFldr = docFldr;
                }
            }

            IManDocuments imElecWpDocs = imElecWpFldr == null ? null : (IManDocuments)imElecWpFldr.Contents;
            IManDocuments imRetDocs    = imRetFldr == null ? null : (IManDocuments)imRetFldr.Contents;
            IManDocuments imEngDocs    = imEngFldr == null ? null : (IManDocuments)imEngFldr.Contents;

            if (imElecWpDocs != null)
            {
                imElecWpDocs.AddDocumentReference(imRetDoc);
            }

            if (imRetDocs != null)
            {
                imRetDocs.RemoveByObject(imRetDoc);
            }

            if (imElecWpDocs != null)
            {
                imElecWpDocs.AddDocumentReference(imEngDoc);
            }

            if (imEngDocs != null)
            {
                imEngDocs.RemoveByObject(imEngDoc);
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        private static List <WsFile> GetWsFiles(IManContents imCons, string fldrPath, bool isAdmin = false)
        {
            List <WsFile> wsFiles = new List <WsFile>();

            foreach (IManContent imCon in imCons)
            {
                IManDocument imDoc  = WsUtility.GetObjectByID <IManDocument>(imCon.ObjectID, isAdmin: isAdmin);
                var          wsFile = GetWsFile(imDoc, fldrPath);

                if (!wsFile.IsDeleted)
                {
                    wsFiles.Add(wsFile);
                }
            }

            return(wsFiles);
        }
Exemplo n.º 7
0
        public static WsDocDelStatusType ValidateDoc(IManDocument imDoc, imDocumentOperation imDocumentOperation)
        {
            var wsFile = Workspace.GetWsFile(imDoc);

            if (!imDoc.IsOperationAllowed(imDocumentOperation))
                return WsDocDelStatusType.InsufficientRights;

            if (imDocumentOperation == IManage.imDocumentOperation.imDeleteDocumentOp && wsFile.IsUnderPreservation)
                return WsDocDelStatusType.WSUnderPreservation;

            if (imDocumentOperation == IManage.imDocumentOperation.imDeleteDocumentOp && wsFile.IsDeleted)
                return WsDocDelStatusType.IsDeleted;

            if (imDocumentOperation == IManage.imDocumentOperation.imDeleteDocumentOp && wsFile.IsRecord)
                return WsDocDelStatusType.IsRecord;

            if (wsFile.IsCheckedOut || wsFile.IsLocked)
            {
                //return WsDocDelStatusType.IsCheckedOut;
                WsOperation.CheckInDoc(imDoc);
                imDoc.Update();
            }

            //if (wsFile.IsCheckedOut)
            //{
            //    //return WsDocDelStatusType.IsCheckedOut;
            //    WsOperation.CheckInDoc(imDoc);
            //    imDoc.Update();
            //}

            //if (wsFile.IsLocked)
            //{
            //    //return WsDocDelStatusType.IsLocked;
            //    WsOperation.CheckInDoc(imDoc);
            //    imDoc.Update();
            //}

            if (imDocumentOperation == IManage.imDocumentOperation.imDeleteDocumentOp && wsFile.VersionCount > 1)
            {
                return WsDocDelStatusType.MultiVersion;
            }

            return WsDocDelStatusType.Success;
        }
Exemplo n.º 8
0
        public static WsFile GetWsFile(IManDocument imDoc, string fldrPath = null)
        {
            var wsFile = new WsFile
            {
                Author       = WsUtility.GetWsUser(imDoc.Author),
                IsCheckedOut = imDoc.CheckedOut,
                Description  = imDoc.Description,
                Extn         = imDoc.Type.ApplicationExtension,

                IsLocked        = imDoc.Locked,
                Name            = imDoc.Name,
                FilePath        = fldrPath,
                Number          = imDoc.Number,
                ObjectID        = imDoc.ObjectID,
                Operator        = WsUtility.GetWsUser(imDoc.Operator),
                Size            = imDoc.Size,
                Version         = imDoc.Version,
                VersionCount    = imDoc.Versions.Count,
                IsLatestVersion = imDoc.IsLatestVersion,

                CreationDate = imDoc.CreationDate.ToString("G", CultureInfo.CreateSpecificCulture("en-us")),
            };

            wsFile = PopulateCustomAttr(wsFile, imDoc);

            if (wsFile.IsRecord)
            {
                foreach (IManDocumentHistory docHistory in imDoc.HistoryList)
                {
                    if (docHistory.Operation.Equals("Declared", StringComparison.OrdinalIgnoreCase))
                    {
                        wsFile.RecordDate = docHistory.Date;
                        wsFile.RecordUser = docHistory.User;
                    }
                }
            }

            wsFile.IsUnderPreservation = wsFile.Status.Equals("UNDER PRESERVATION", StringComparison.OrdinalIgnoreCase);

            return(wsFile);
        }
Exemplo n.º 9
0
        private static void AddImHistoryInfo(IManDocument imDoc, HistoryInfoType historyInfoType)
        {
            switch (historyInfoType)
            {
            case HistoryInfoType.CHECKIN:
                //AddImHistoryInfo(imDoc, imHistEvent.imHistoryCheckin, AmConst.CONST_CHECKIN_COMMENT);
                AddImHistoryInfo(imDoc, imHistEvent.imHistoryRelease, AmConst.CONST_CHECKIN_COMMENT);
                break;

            case HistoryInfoType.DELETE:
                AddImHistoryInfo(imDoc, imHistEvent.imHistoryDelete, AmConst.CONST_DELETE_COMMENT);
                break;

            case HistoryInfoType.CLOSURE:
                AddImHistoryInfo(imDoc, imHistEvent.imHistoryFrozen, AmConst.CONST_CLOSURE_COMMENT);
                break;

            default:
                break;
            }
        }
Exemplo n.º 10
0
        //    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);
        }
Exemplo n.º 11
0
        private static T PopulateCustomAttr <T>(T type, dynamic imObj)
        {
            foreach (PropertyInfo pI in type.GetType().GetProperties())
            {
                if (Attribute.IsDefined(pI, typeof(ImProfileAttrInfo), false))
                {
                    var cA = (ImProfileAttrInfo)pI.GetCustomAttributes(typeof(ImProfileAttrInfo), false)[0];

                    dynamic imProfAttrVal = null;

                    if ((imObj as IManProfile) != null)
                    {
                        IManProfile imp = (IManProfile)imObj;
                        imProfAttrVal = imp.GetAttributeValueByID((imProfileAttributeID)Enum.Parse(typeof(imProfileAttributeID), cA.AttrImProfileEnum));
                    }
                    else if ((imObj as IManWorkspace) != null)
                    {
                        IManWorkspace imws = (IManWorkspace)imObj;
                        imProfAttrVal = imws.GetAttributeValueByID((imProfileAttributeID)Enum.Parse(typeof(imProfileAttributeID), cA.AttrImProfileEnum));
                    }
                    else if ((imObj as IManDocument) != null)
                    {
                        IManDocument imd = (IManDocument)imObj;
                        imProfAttrVal = imd.GetAttributeValueByID((imProfileAttributeID)Enum.Parse(typeof(imProfileAttributeID), cA.AttrImProfileEnum));
                    }
                    else
                    {
                        IManProfile imp = (IManProfile)imObj;
                        imProfAttrVal = imp.GetAttributeValueByID((imProfileAttributeID)Enum.Parse(typeof(imProfileAttributeID), cA.AttrImProfileEnum));
                    }

                    if (imProfAttrVal == null)
                    {
                        continue;
                    }

                    if (cA.AttrDataType == typeof(bool))
                    {
                        bool b;
                        if (bool.TryParse(imProfAttrVal.ToString(), out b))
                        {
                            pI.SetValue(type, b);
                        }
                        else
                        {
                            pI.SetValue(type, false);
                        }
                    }
                    else if (cA.AttrDataType == typeof(DateTime))
                    {
                        if (imProfAttrVal == null || imProfAttrVal.Date == null)
                        {
                            pI.SetValue(type, null);
                        }
                        else
                        {
                            DateTime dt;
                            if (DateTime.TryParse(imProfAttrVal.Date.ToString(), out dt))
                            {
                                pI.SetValue(type, dt);
                            }
                            else
                            {
                                pI.SetValue(type, null);
                            }
                        }
                    }
                    else
                    {
                        pI.SetValue(type, imProfAttrVal.ToString());
                    }
                }
            }

            return(type);
        }
Exemplo n.º 12
0
        public static void RefileFldrSecurity2Doc(IManDocument iMDoc, IManDocumentFolder iMFldr)
        {
            foreach (IManGroupACL fldrGroup in iMFldr.Security.GroupACLs)
            {
                iMDoc.Security.GroupACLs.Add(fldrGroup.Group.Name, fldrGroup.Right);
            }

            foreach (IManUserACL fldrUser in iMFldr.Security.UserACLs)
            {
                bool addUser = false;
                try
                {
                    if (iMDoc.Security.UserACLs.ItemByName(fldrUser.User.Name) == null)
                    {
                        addUser = false;
                    }
                }
                catch { addUser = true; }

                if (addUser)
                {
                    iMDoc.Security.UserACLs.Add(fldrUser.User.Name, fldrUser.Right);
                }
            }

            iMDoc.Update();
        }
Exemplo n.º 13
0
		private WsLinkSiteDocument CreateWsLinkSiteDocument(IManDocument doc)
		{
			var file = Path.Combine(LinkSiteTempDirectory, String.Format("{0}.{1}", doc.Description, doc.Extension.ToLower()));

			if (!File.Exists(file))
			{
				doc.GetCopy(file, imGetCopyOptions.imNativeFormat);
			}

			return new WsLinkSiteDocument(doc.ObjectID, file);
		}
Exemplo n.º 14
0
 private void AddHistory(IManDocument iMDoc, imHistEventCommentType imHistEventCommentType)
 {
     iMDoc.HistoryList.Add(imHistEventCommentType.ToString().ToEnum<imHistEvent>().Value, 0, 0, IMConstant.CONST_APP_NAME, imHistEventCommentType.ToEnumAttr<imHistEventCommentType, DescriptionAttribute>().Description, IMConstant.CONST_APP_NAME, "", "", null, null, null);
 }
Exemplo n.º 15
0
        private List<WsFileHistory> GetHistory(IManDocument iMDoc)
        {
            List<WsFileHistory> wsFileHistory = new List<WsFileHistory>();

            foreach (IManDocumentHistory iMDocHistory in iMDoc.HistoryList)
            {
                wsFileHistory.Add(new WsFileHistory
                {
                    Date = iMDocHistory.Date,
                    User = iMDocHistory.User,
                    Operation = iMDocHistory.Operation,
                    Application = iMDocHistory.Application,
                    Comment = iMDocHistory.Comment,
                });
            }

            wsFileHistory = wsFileHistory.OrderByDescending(x => x.Date).ToList();

            return wsFileHistory;
        }
Exemplo n.º 16
0
        private WsFile GetDoc(IManDocument iMDoc, bool detail = false)
        {
            WsFile wsFile = new WsFile
            {
                Name = iMDoc.GetDocName(),
                Number = iMDoc.Number,
                ObjectID = iMDoc.ObjectID,
                Size = iMDoc.Size,
                Location = IMDBUtility.GetDocLocation(iMDoc.GetAttributeByID(imProfileAttributeID.imProfileLocation).ToString()),

                IMAddProps = detail ? IMUtility2.GetIMAddProps(iMDoc.AdditionalProperties) : null,
                IMCustAttrs = detail ? IMUtility2.GetIMCustAttrs(iMDoc.CustomAttributes) : null,
                IMProfAttrs = detail ? IMUtility2.GetIMProfAttrs(iMDoc.Profile) : null,
            };

            return wsFile;
        }
Exemplo n.º 17
0
 private Tuple<string, string> GetAttribute(IManDocument iMDoc, imProfileAttributeIDType imProfileAttributeIDType)
 {
     if (imProfileAttributeIDType == imProfileAttributeIDType.imProfileLocation)
         return new Tuple<string, string>(iMDoc.GetDocName(),
             IMDBUtility.GetDocLocation(iMDoc.GetAttributeValueByID((imProfileAttributeID)imProfileAttributeIDType.ToString().ToEnum<imProfileAttributeID>()).ToString()));
     else
         return new Tuple<string, string>(iMDoc.GetDocName(),
             iMDoc.GetAttributeValueByID((imProfileAttributeID)imProfileAttributeIDType.ToString().ToEnum<imProfileAttributeID>()).ToString());
 }
Exemplo n.º 18
0
        //public static WsFile DeleteDoc(string wsId, string wsLogFldrID, string docObjId, string comment = null)
        public static WsFile DeleteDoc(string wsId, string docObjId, string comment = null, bool toValidate = true)
        {
            IManDocument imDoc = WsUtility.GetObjectByID <IManDocument>(docObjId, isAdmin: true);

            if (!toValidate || WsValidation.ValidateDoc(imDoc, imDocumentOperation.imDeleteDocumentOp) == WsDocDelStatusType.Success)
            {
                //imDoc.Update();
                imDoc.LockContent(false);
                //imDoc.UnlockContent();
                IManProfileUpdateResult status = imDoc.UpdateWithResults();

                if (status.Succeeded)
                {
                    //Set Custom27 to true (Marked for deletion attribute)
                    imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom27, true);

                    //Prefix document description with “DEL_”
                    if (!imDoc.Description.StartsWith(AmConst.CONST_DELETE_PREFIX))
                    {
                        imDoc.Description = AmConst.CONST_DELETE_PREFIX + imDoc.Description;
                    }

                    //Add a message to IWov history (see Autonomy’s documentation)
                    //imDoc.HistoryList.Add(imHistEvent.imHistoryDelete, 0, 0, AmConst.CONST_APP_NAME, AmConst.CONST_DELETE_COMMENT, "", "", "", null, null, null);
                    AddImHistoryInfo(imDoc, HistoryInfoType.DELETE);

                    //Store rollback information in the comments

                    //SELECT * FROM MHGROUP.GROUPS WHERE GROUPNUM IN (SELECT USER_GP_ID FROM MHGROUP.DOC_ACCESS WHERE DOCNUM = 897942)
                    //SELECT * FROM MHGROUP.GROUPS WHERE GROUPNUM IN (SELECT USER_GP_ID FROM MHGROUP.DOC_ACCESS WHERE DOCNUM = 897941)
                    //Grant right for NRTADMIN and Service Account to file.
                    //WsUtility.AddUserSecurity(imDoc, imAccessRight.imRightAll); -- Why?
                    WsUtility.AddGroupSecurity(imDoc, "NRTADMIN", imAccessRight.imRightAll);

                    imDoc.Security.DefaultVisibility = imSecurityType.imPrivate;

                    //Set owner and creator to DELETE USER
                    imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, imDoc.Database.GetUser(AmConst.CONST_DELETE_USER));
                    imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, imDoc.Database.GetUser(AmConst.CONST_DELETE_USER));

                    //Remove all security right and groups except for NRTADMIN group and Service Account -- Why?
                    foreach (IManUserACL userRight in imDoc.Security.UserACLs)
                    {
                        if (userRight.User.Name != "DELETEUSER")
                        {
                            //WsUtility.AddUserSecurity(imDoc, userRight.User.Name, imAccessRight.imRightNone);
                            userRight.Right = imAccessRight.imRightNone;
                        }
                    }

                    foreach (IManGroupACL groupRight in imDoc.Security.GroupACLs)
                    {
                        if (groupRight.Group.Name != "NRTADMIN")
                        {
                            //WsUtility.AddGroupSecurity(imDoc, groupRight.Group.Name, imAccessRight.imRightNone);
                            groupRight.Right = imAccessRight.imRightNone;
                        }
                    }

                    imDoc.Update();

                    imDoc.UnlockContent();

                    var wsGLog = new WsGenericLog();
                    wsGLog.ActionBy          = AmUtil.GetCurrentUser;
                    wsGLog.Id                = imDoc.Number;
                    wsGLog.Name              = imDoc.Description;
                    wsGLog.ActionInfo        = null;
                    wsGLog.AdditionalInfo    = null;
                    wsGLog.Comment           = comment;
                    wsGLog.OldValue          = null;
                    wsGLog.NewValue          = null;
                    wsGLog.WsLogActivityType = WsLogActivityType.DeleteFile;

                    WsUtility.CreateWsLog(wsId, wsGLog);
                }

                IManDocument imDocRet = WsUtility.GetObjectByID <IManDocument>(docObjId);

                return(Workspace.GetWsFile(imDocRet));
            }

            return(null);
        }
Exemplo n.º 19
0
        public static WsFile GetWsFile(double fileNum)
        {
            IManDocument imDoc = WsUtility.GetObjectByID <IManDocument>(WsUtility.GetWsObjectTypeId(WsObjectType.File, fileNum));

            return(IM.Mgr.Workspace.GetWsFile(imDoc));
        }
Exemplo n.º 20
0
        public static void InitiateClosure(InitiateClosureWsModel initiateClosureWsModel)
        {
            var wsModelIn     = initiateClosureWsModel.WsModel;
            var largeRetFiles = initiateClosureWsModel.LargeRetFiles;
            var comment       = initiateClosureWsModel.Comment;

            IManWorkspace imWs = null;

            var wsModel = Workspace.GetWs(wsModelIn.ObjectID, out imWs, WsLoadType.ALL);

            //List<WsFile> wsFiles = new List<WsFile>();

            //WsFldr wsFldr = new WsFldr();
            //wsFldr.WsFldrs = wsModelIn.WsFldrs;

            //WsUtility.GetWsFiles(item =>
            //{
            //    if (item.WsFiles != null && item.WsFiles.Count > 0)
            //    {
            //        foreach (var wsFile in item.WsFiles)
            //        {
            //            if (wsFile.IsIncludedInClosure)
            //                wsFiles.Add(wsFile);
            //        }
            //    }
            //}, wsFldr);

            List <WsFile> wsFiles = GetAllFilesFromWs(wsModelIn);

            wsFiles = wsFiles.Where(x => x.IsIncludedInClosure).ToList();

            var wsGLog = new WsGenericLog();

            wsGLog.ActionBy          = AmUtil.GetCurrentUser;
            wsGLog.Id                = null;
            wsGLog.Name              = null;
            wsGLog.ActionInfo        = null;
            wsGLog.AdditionalInfo    = null;
            wsGLog.Comment           = comment;
            wsGLog.OldValue          = null;
            wsGLog.NewValue          = null;
            wsGLog.WsLogActivityType = WsLogActivityType.Closure;

            var sbFileInfo = new StringBuilder();

            sbFileInfo.AppendLine("Event trigger Date for this closure: " + wsModelIn.WsProfile.EventTrgDate);
            sbFileInfo.AppendLine();
            sbFileInfo.AppendLine(AmUtil.GetLineSeperator);
            sbFileInfo.AppendLine();
            var sbClosureMailInfo = new StringBuilder();

            foreach (var item in wsFiles)
            {
                IManDocument imDoc = WsUtility.GetObjectByID <IManDocument>(item.ObjectID, isAdmin: true);
                if (WsValidation.ValidateDoc(imDoc, imDocumentOperation.imFreezeDocumentOp) == WsDocDelStatusType.Success)
                {
                    var wsFile = Workspace.GetWsFile(imDoc);

                    //if (wsFile.IsLocked) { }

                    //if (wsFile.IsCheckedOut)
                    //{
                    //    CheckInDoc(imDoc);
                    //}

                    //if (wsFile.IsDeleted) { }

                    //if (wsFile.IsRecord) { }

                    sbFileInfo.AppendLine("DocNum: " + wsFile.Number);
                    sbFileInfo.AppendLine("DocName: " + wsFile.Description.FileNameWithExtn(wsFile.Extn));
                    sbFileInfo.AppendLine("DocPath: " + item.FilePath);
                    sbFileInfo.AppendLine("IsLocked: " + wsFile.IsLocked);
                    sbFileInfo.AppendLine("IsCheckedOut: " + wsFile.IsCheckedOut);
                    sbFileInfo.AppendLine("IsDeleted: " + wsFile.IsDeleted);
                    sbFileInfo.AppendLine("IsRecord: " + wsFile.IsRecord);
                    sbFileInfo.AppendLine();

                    imDoc.SetAttributeByID(imProfileAttributeID.imProfileFrozen, true);

                    //imDoc.HistoryList.Add(imHistEvent.imHistoryFrozen, 0, 0, "Audit Manager", "eAudit closure", String.Empty, String.Empty, String.Empty);
                    AddImHistoryInfo(imDoc, HistoryInfoType.CLOSURE);

                    IManProfileUpdateResult res = imDoc.UpdateWithResults();
                    if (res.Succeeded)
                    {
                        sbFileInfo.AppendLine("ClosureStatus: Success");
                    }
                    else
                    {
                        sbFileInfo.AppendLine("ClosureStatus: Failure");
                    }

                    sbFileInfo.AppendLine();
                    sbFileInfo.AppendLine(AmUtil.GetLineSeperator);
                    sbFileInfo.AppendLine();

                    sbClosureMailInfo.Append("<tr><td align='center' valign='middle'>");
                    sbClosureMailInfo.Append(wsFile.Description.FileNameWithExtn(wsFile.Extn));
                    sbClosureMailInfo.Append("</td><td align='center' valign='middle'>");
                    sbClosureMailInfo.Append(item.FilePath.Remove(0, 4));
                    sbClosureMailInfo.Append("</td><td align='center' valign='middle'>");
                    if (wsFile.IsRecord)
                    {
                        sbClosureMailInfo.Append("X");
                    }
                    sbClosureMailInfo.Append("</td></tr>");
                }
            }

            if (largeRetFiles != null && largeRetFiles.Count > 0)
            {
                int idx = 0;
                sbFileInfo.AppendLine("Large Retention file included in the closure.");
                sbFileInfo.AppendLine();
                largeRetFiles.ForEach(x => sbFileInfo.AppendLine(++idx + ". " + x));

                foreach (var item in largeRetFiles)
                {
                    sbClosureMailInfo.Append("<tr align='center'><td><p>");
                    sbClosureMailInfo.Append(item);
                    sbClosureMailInfo.Append("</p></td><td><p>");
                    sbClosureMailInfo.Append("Large file retention server");
                    sbClosureMailInfo.Append("</p></td><td align='center' valign='middle'><p>");
                    sbClosureMailInfo.Append("</p></td></tr>");
                }
            }

            wsGLog.AdditionalInfo = sbFileInfo.ToString();

            WsUtility.CreateWsLog(wsModelIn.ObjectID, wsGLog);

            var recepients = WsUtility.GetEmailRecepients(wsModel, EmailRecepientType.MANAGER_N_PARTNER_N_ADMIN);

            var mailBody = AmUtil.SendMail_Closure(WsActivityType.CLOSURE_INITIATE.ToString(), wsModel.WsProfile.EngNum, wsModel.Name, recepients, sbClosureMailInfo.ToString());

            wsGLog.WsLogActivityType = WsLogActivityType.ClosureConfirmEmail;
            WsUtility.CreateEmailLog(wsModelIn.ObjectID, mailBody, wsGLog);

            WsUtility.SaveClosureInfo(wsModel.WsProfile.EngNum,
                                      string.Format("{0}|{1}", string.Join(",", wsFiles.Select(x => x.Number).ToList()),
                                                    ((initiateClosureWsModel.LargeRetFiles == null || initiateClosureWsModel.LargeRetFiles.Count == 0) ?
                                                     string.Empty : string.Join(",", initiateClosureWsModel.LargeRetFiles))
                                                    ),
                                      string.Join(",", recepients.Select(x => x.Item2).ToList()),
                                      mailBody, initiateClosureWsModel.Comment,
                                      initiateClosureWsModel.LargeRetFiles == null ? false : (initiateClosureWsModel.LargeRetFiles.Count > 0));

            //return IM.Mgr.Workspace.GetWs(wsModelIn.ObjectID);
        }
Exemplo n.º 21
0
        private static void AddSecurityToDoc(IManDocument imDoc, IManDocumentFolder imFldr)
        {
            foreach (IManGroupACL fldrGroup in imFldr.Security.GroupACLs)
            {
                imDoc.Security.GroupACLs.Add(fldrGroup.Group.Name, fldrGroup.Right);
            }

            foreach (IManUserACL fldrUser in imFldr.Security.UserACLs)
            {
                bool addUser = false;
                try
                {
                    if (imDoc.Security.UserACLs.ItemByName(fldrUser.User.Name) == null)
                    {
                        addUser = false;
                    }
                }
                catch { addUser = true; }

                if (addUser)
                {
                    imDoc.Security.UserACLs.Add(fldrUser.User.Name, fldrUser.Right);
                }
            }

            imDoc.Update();
        }
Exemplo n.º 22
0
        public static void UploadDocument(string engNum, string fileNameWithLocalPath, string iMFolderPath)
        {
            //
            var projectIdForEngNum = WsUtility.GetEngIdForEngNum(new List <string> {
                engNum
            });

            if (projectIdForEngNum.Count == 0)
            {
                return;
            }

            var wsId = WsUtility.GetWsObjectTypeId(WsObjectType.Workspace, projectIdForEngNum[0].EngId);
            //

            IManWorkspace imWs = WsUtility.GetObjectByID <IManWorkspace>(wsId, isAdmin: true);

            IManDocumentFolder imFldr = GetWsFldr(imWs, iMFolderPath);

            IManDocument imDoc = imFldr.Database.CreateDocument();

            WsProfile wsProfile = Workspace.GetWsProfile(imWs.Profile, imWs);

            imDoc.SetAttributeByID(imProfileAttributeID.imProfileDescription, Path.GetFileName(fileNameWithLocalPath));

            imDoc.SetAttributeByID(imProfileAttributeID.imProfileType, GetWsDocType(imWs, Convert.ToString(imDoc.GetAttributeValueByID(imProfileAttributeID.imProfileDescription))));

            imDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, imWs.Owner.Name);
            imDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, imWs.Owner.Name);
            imDoc.SetAttributeByID(imProfileAttributeID.imProfileClass, AmConst.CONST_IMPROFILECLASS);
            imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom7, AmConst.CONST_IMPROFILECUSTOM7);
            imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom1, wsProfile.Client);
            imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom2, wsProfile.EngNum);

            if (!string.IsNullOrWhiteSpace(wsProfile.EngFunction))
            {
                imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom3, wsProfile.EngFunction);
            }
            else
            {
                imDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom3, AmConst.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 (imAddProp.Value != AmConst.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));
                }
            }

            //string tempFile = System.IO.Path.GetTempFileName();
            //System.IO.File.WriteAllText(tempFile, wsLog.WsLogUseWhat == WsLogUseWhat.Email ? wsLog.MailBody : wsLog.ToString());

            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);
                }
            }
            else
            {
                //throw new LogOnlyException(string.Format("Error creating IManage log file => {0}", checkInResult.ErrorMessage));
                //AuditManager.Common.DbLog.LogToElmah(string.Format("Error creating IManage log file => {0}", checkInResult.ErrorMessage), httpContext);
            }

            //AuditManager.Common.DbLog.LogToElmah(string.Format("Error creating IManage log file => {0}", "checkInResult.ErrorMessage"), httpContext);
            //throw new LogOnlyException(string.Format("Error creating IManage log file => {0}", "checkInResult.ErrorMessage"));
        }
Exemplo n.º 23
0
 private static void AddImHistoryInfo(IManDocument imDoc, imHistEvent imHistEvent, string amConstComment)
 {
     imDoc.HistoryList.Add(imHistEvent, 0, 0, AmConst.CONST_APP_NAME, amConstComment, "", "", "", null, null, null);
 }
Exemplo n.º 24
0
        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);
            }
        }