Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public static string GetFldrPath(IManWorkspace ws, IManDocumentFolder fldr)
        {
            var iMFldr = (IManFolder)ws;

            var fldrPath = "";
            bool isFound = false;

            foreach (IManFolder childFldr in iMFldr.SubFolders)
            {
                fldrPath = childFldr.Name;

                if (childFldr.ObjectID.IsEquals(fldr.ObjectID))
                {
                    break;
                }

                HandleFolderTree(item =>
                {
                    if (item.ObjectID.IsEquals(fldr.ObjectID))
                    {
                        fldrPath = fldrPath + "/" + item.Name;
                        isFound = true;
                        return true;
                    }
                    else
                    {
                        if (item.SubFolders.Count > 0)
                        {
                            fldrPath = fldrPath + "/" + item.Name;
                        }
                        else
                        {
                            fldrPath = string.Join("/", fldrPath.Split('/').Take(fldrPath.Split('/').Length - 1));
                            fldrPath = string.IsNullOrWhiteSpace(fldrPath) ? childFldr.Name : fldrPath;
                        }
                        return false;
                    }

                }, childFldr, fldr.ObjectID);

                if (isFound)
                    break;
            }

            return fldrPath;
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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"));
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        private int? Create(string docNameWithLocalPath, IManWorkspace iMWs, IManDocumentFolder iMFolder, DateTime startTime, long step1TimeInSec)
        {
            IManDocument iMDoc = _iMUtility.GetIMDb.CreateDocument();

            iMDoc.SetAttributeByID(imProfileAttributeID.imProfileDescription, Path.GetFileName(docNameWithLocalPath));
            iMDoc.SetAttributeByID(imProfileAttributeID.imProfileType, GetIManDocumentType(Convert.ToString(iMDoc.GetAttributeValueByID(imProfileAttributeID.imProfileDescription))));

            iMDoc.SetAttributeByID(imProfileAttributeID.imProfileAuthor, KConfig.GetCurrentUser);
            iMDoc.SetAttributeByID(imProfileAttributeID.imProfileOperator, KConfig.GetCurrentUser);
            //iMDoc.SetAttributeByID(imProfileAttributeID.imProfileLastUser, KConfig.GetCurrentUser);

            iMDoc.SetAttributeByID(imProfileAttributeID.imProfileClass, IMConstant.CONST_IMPROFILECLASS);
            iMDoc.SetAttributeByID(imProfileAttributeID.imProfileCustom7, IMConstant.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, IMConstant.CONST_IMPROFILECUSTOM3);
            }

            foreach (IManAdditionalProperty imAddProp in iMFolder.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 != IMConstant.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
                    {
                        //EAUDIT ENGAGEMENT
                        //IManage.imProfileAttributeID.imProfileSubClass
                        //[NRTDocument ][SetAttributeValueByID ]No record found
                        if (imProfAttr == imProfileAttributeID.imProfileSubClass)
                        {

                        }
                        iMDoc.SetAttributeByID(imProfAttr, imAddProp.Value);
                    }
                }
                else
                {
                    iMDoc.SetAttributeByID(imProfAttr, iMFolder.Workspace.Profile.GetAttributeValueByID(imProfAttr));
                }
            }

            IManCheckinResult checkInResult = iMDoc.CheckInWithResults(docNameWithLocalPath, imCheckinDisposition.imCheckinNewDocument, imCheckinOptions.imDontKeepCheckedOut);

            if (checkInResult.Succeeded)
            {
                IMUtility2.RefileFldrSecurity2Doc(iMDoc, iMFolder);

                IManDocuments iMDocs = (IManDocuments)iMFolder.Contents;
                if (null != iMDocs)
                {
                    iMDocs.AddDocumentReference(checkInResult.Result);
                }

                if (IMConstant.CONST_IM_PROFILE_TYPE.Any(x => x.IsEquals((string)iMDoc.GetAttributeValueByID(imProfileAttributeID.imProfileType))))
                {
                    IMDBUtility.SetCOMINDEXtoY(iMDoc.Number);
                }

                CreateDocLog(docNameWithLocalPath,
                    iMWs.Profile.GetAttributeValueByID(imProfileAttributeID.imProfileCustom2).ToString(),
                    IMUtility2.GetFldrPath(iMWs, iMFolder),
                    startTime.ToTimeElapsedInSec(), step1TimeInSec, iMDoc.Number);

                return iMDoc.Number;
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 8
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);
            }
        }