Example #1
0
        public bool AddUserSensitiveMailQueue(Guid transactionid, SensitiveMailInfo sensitiveMailInfo, out ErrorCodeInfo error)
        {
            bool bResult = true;

            error = new ErrorCodeInfo();
            string message = string.Empty;

            try
            {
                do
                {
                    SensitiveMailDBProvider provider       = new SensitiveMailDBProvider();
                    UserProvider            userProvider   = new UserProvider();
                    DirectoryEntry          ouEntry        = new DirectoryEntry();
                    DirectoryEntry          item           = new DirectoryEntry();
                    CommonProvider          commonProvider = new CommonProvider();

                    for (int j = 0; j < sensitiveMailInfo.Objects.Count; j++)
                    {
                        if (sensitiveMailInfo.Objects[j].ObjectType == NodeType.organizationalUnit)
                        {
                            if (!commonProvider.GetADEntryByGuid(sensitiveMailInfo.Objects[j].ObjectID, out ouEntry, out message))
                            {
                                Log4netHelper.Error($"ID:{sensitiveMailInfo.Objects[j].ObjectID},ObjectName:{sensitiveMailInfo.Objects[j].ObjectName},ObjectType:{sensitiveMailInfo.Objects[j].ObjectType.ToString()},GetADEntryByGuid Error:{message}");
                                continue;
                            }

                            DirectoryEntry de = null;
                            de = new DirectoryEntry(ouEntry.Path);
                            DirectorySearcher deSearch = new DirectorySearcher(de);
                            deSearch.SearchRoot = de;
                            string strFilter = commonProvider.GetSearchType(SearchType.MailUser, string.Empty);
                            deSearch.Filter          = strFilter;
                            deSearch.SearchScope     = SearchScope.Subtree;
                            deSearch.SizeLimit       = 20000;
                            deSearch.ServerTimeLimit = TimeSpan.FromSeconds(600);
                            deSearch.ClientTimeout   = TimeSpan.FromSeconds(600);
                            SearchResultCollection results = deSearch.FindAll();

                            if (results != null && results.Count > 0)
                            {
                                foreach (SearchResult Result in results)
                                {
                                    item = Result.GetDirectoryEntry();
                                    UserInfo user = new UserInfo();
                                    user.UserID         = item.Guid;
                                    user.UserAccount    = item.Properties["userPrincipalName"].Value == null ? "" : Convert.ToString(item.Properties["userPrincipalName"].Value);
                                    user.SAMAccountName = item.Properties["sAMAccountName"].Value == null ? "" : Convert.ToString(item.Properties["sAMAccountName"].Value);
                                    provider.AddUserSensitiveMailQueue(transactionid, sensitiveMailInfo, user, out error);
                                }
                            }
                        }
                        else if (sensitiveMailInfo.Objects[j].ObjectType == NodeType.user)
                        {
                            if (!commonProvider.GetADEntryByGuid(sensitiveMailInfo.Objects[j].ObjectID, out item, out message))
                            {
                                Log4netHelper.Error($"ID:{sensitiveMailInfo.Objects[j].ObjectID},ObjectName:{sensitiveMailInfo.Objects[j].ObjectName},ObjectType:{sensitiveMailInfo.Objects[j].ObjectType.ToString()},GetADEntryByGuid Error:{message}");
                                continue;
                            }
                            UserInfo user = new UserInfo();
                            user.UserID = item.Guid;
                            provider.AddUserSensitiveMailQueue(transactionid, sensitiveMailInfo, user, out error);
                        }
                    }
                } while (false);
            }
            catch (Exception ex)
            {
                Log4netHelper.Error($"RemoveSensitiveMailQueue Exception: {ex.ToString()}");
            }
            return(bResult);
        }