Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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);
            }
        }