private string GenerateBackAddress(EPActivity message, string defaultDisplayName, string defaultAddress, bool suspendCustomAddress)
            {
                if (message.Owner == null)
                {
                    return(string.IsNullOrEmpty(defaultDisplayName)
                                        ? defaultAddress
                                        : Mailbox.Create(defaultDisplayName, defaultAddress));
                }

                var records = PXSelectJoin <Users,
                                            LeftJoin <EPEmployee, On <EPEmployee.userID, Equal <Users.pKID> >,
                                                      LeftJoin <Contact, On <Contact.contactID, Equal <EPEmployee.defContactID> > > >,
                                            Where <Users.pKID, Equal <Required <Users.pKID> > > > .
                              SelectWindowed(_graph, 0, 1, message.Owner);

                if (records == null || records.Count == 0)
                {
                    return(defaultAddress);
                }

                var    row         = records[0];
                var    employee    = (Contact)row[typeof(Contact)];
                var    user        = (Users)row[typeof(Users)];
                string displayName = null;
                string address     = defaultAddress;

                if (user != null && user.PKID != null)
                {
                    var userDisplayName = user.FullName.With(_ => _.Trim());
                    if (!string.IsNullOrEmpty(userDisplayName))
                    {
                        displayName = userDisplayName;
                    }
                    var userAddress = user.Email.With(_ => _.Trim());
                    if (!suspendCustomAddress && !string.IsNullOrEmpty(userAddress))
                    {
                        address = userAddress;
                    }
                }
                if (employee != null && employee.BAccountID != null)
                {
                    var employeeDisplayName = employee.DisplayName.With(_ => _.Trim());
                    if (!string.IsNullOrEmpty(employeeDisplayName))
                    {
                        displayName = employeeDisplayName;
                    }
                    var employeeAddress = employee.EMail.With(_ => _.Trim());
                    if (!suspendCustomAddress && !string.IsNullOrEmpty(employeeAddress))
                    {
                        address = employeeAddress;
                    }
                }
                return(string.IsNullOrEmpty(displayName)
                                        ? address
                                        : Mailbox.Create(displayName, address).ToString());
            }
示例#2
0
        public void Test()
        {
            var checkCount = 10000;
            var queueCount = 10;
            var queueSet   = new List <Mailbox>(queueCount);

            for (int i = 0; i < queueCount; i++)
            {
                var mailbox  = Mailbox.Create();
                var checkSet = new HashSet <int>();
                mailbox.State = checkSet;
                mailbox.HookDoMailBefore.Add((message, state) => {
                    var value = (int)message;
                    var set   = (HashSet <int>)state;
                    var ret   = set.Add(value);
                    Assert.IsTrue(ret);
                });
                queueSet.Add(mailbox);
            }

            var threadPool = new ThreadPool();

            for (int i = 0; i < queueCount; i++)
            {
                for (int n = 0; n < checkCount; n++)
                {
                    var queue = queueSet[i];
                    var value = n;
                    threadPool.Post(() => queue.Recv(value));
                }
            }

            var rc = Thread.Wait(() => {
                var ret = 0;
                for (int i = 0; i < queueCount; i++)
                {
                    var set = (HashSet <int>)queueSet[i].State;
                    ret    += set.Count;
                }
                return(ret == queueCount * checkCount);
            }, 1000);

            Assert.IsTrue(rc);
            for (int i = 0; i < queueCount; i++)
            {
                var set = (HashSet <int>)queueSet[i].State;
                Assert.AreEqual(set.Count, checkCount, "queue: id: " + i);
                queueSet[i].Dispose();
            }

            threadPool.Stop();
        }