public static bool ContainsComponent(this ICollection <PoolEntity> entities,
                                             int componentId)
        {
            PoolEntity unused = null;

            return(entities.ContainsComponent(componentId, out unused));
        }
Beispiel #2
0
 public static void DestroyEntityIfEmpty(this PoolContext context,
                                         PoolEntity entity)
 {
     if (entity.GetComponentIndices().Length == 0)
     {
         context.DestroyEntity(entity);
     }
 }
Beispiel #3
0
    void OnGameBoardElementAdded(IGroup <PoolEntity> group, PoolEntity entity,
                                 int index, IComponent component)
    {
        var grid = pool.gameBoardCache.grid;
        var pos  = entity.position;

        grid.Add(pos.x, pos.y, entity);
        pool.ReplaceGameBoardCache(grid);
    }
        protected void bnSavePopup_Click(object sender, EventArgs e)
        {
            var pe = new PoolEntity
            {
                Id       = int.Parse(hfPoolId.Value),
                PoolName = tbPoolName.Text,
                Active   = cbActive.Checked
            };

            SaveDataToDataBase(pe);
        }
Beispiel #5
0
    void OnGameBoardElementUpdated(IGroup <PoolEntity> group, PoolEntity entity,
                                   int index, IComponent previousComponent,
                                   IComponent newComponent)
    {
        var prevPos = (PositionComponent)previousComponent;
        var newPos  = (PositionComponent)newComponent;
        var grid    = pool.gameBoardCache.grid;

        grid.Remove(prevPos.x, prevPos.y, entity);
        grid.Add(newPos.x, newPos.y, entity);
        pool.ReplaceGameBoardCache(grid);
    }
Beispiel #6
0
    void OnAudioAdded(IGroup <PoolEntity> group, PoolEntity entity, int index,
                      IComponent component)
    {
        pool.DestroyEntity(entity);


        var originalPitch = efxSource.pitch;

        efxSource.pitch = Random.Range(lowPitchRange, highPitchRange);
        efxSource.Play();
        efxSource.pitch = originalPitch;
        return;
    }
Beispiel #7
0
    void OnGameBoardElementRemoved(IGroup <PoolEntity> group, PoolEntity entity,
                                   int index, IComponent component)
    {
        var pos = component as PositionComponent;

        if (pos == null)
        {
            pos = entity.position;
        }
        var grid = pool.gameBoardCache.grid;

        grid.Remove(pos.x, pos.y, entity);
        pool.ReplaceGameBoardCache(grid);
    }
Beispiel #8
0
    void OnAudioAdded(IGroup <PoolEntity> group, PoolEntity entity, int index,
                      IComponent component)
    {
        var audioComponent = (AudioComponent)component;
        var audioName      = audioComponent.clipNames.Random();
        var audioClip      = Resources.Load <AudioClip>("Audio/" + audioName);

        if (audioClip != null)
        {
            Play(audioClip, audioComponent.randomizePitch);
        }

        // only play once
        pool.DestroyEntity(entity);
    }
 public static bool ContainsComponent(this ICollection <PoolEntity> entities,
                                      int componentId,
                                      out PoolEntity entity)
 {
     foreach (var e in entities)
     {
         if (e.HasComponent(componentId))
         {
             entity = e;
             return(true);
         }
     }
     entity = null;
     return(false);
 }
Beispiel #10
0
        private void DeleteMessageOnServer(string hostname, int port, bool useSsl, PoolEntity pool, List <CommunicationPoolEntity> mailList,
                                           List <string> mailMsgIds, JobTaskResult taskResult)
        {
            if (mailList != null && mailList.Count > 0)
            {
                Task.Factory.StartNew(() => Parallel.ForEach(mailList,
                                                             new ParallelOptions {
                    MaxDegreeOfParallelism = WebConfig.GetTotalCountToProcess()
                },
                                                             x =>
                {
                    lock (sync)
                    {
                        Logger.Info(_logMsg.Clear().SetPrefixMsg("Delete Mail On Server").Add("Subject", x.Subject)
                                    .Add("SenderAddress", x.SenderAddress).Add("MessageNumber", x.MessageNumber).ToInputLogString());

                        try
                        {
                            string decryptedstring = StringCipher.Decrypt(pool.Password, Constants.PassPhrase);
                            this.DeleteMail(hostname, port, useSsl, pool.Email, decryptedstring, mailMsgIds);
                            Logger.Info(_logMsg.Clear().SetPrefixMsg("Delete Mail On Server").ToSuccessLogString());
                        }
                        catch (Exception ex)
                        {
                            Logger.Info(_logMsg.Clear().SetPrefixMsg("Delete Mail On Server").Add("Error Message", ex.Message).ToFailLogString());
                            Logger.Error("Exception occur:\n", ex);

                            _commPoolDataAccess = new CommPoolDataAccess(_context);
                            if (_commPoolDataAccess.DeleteMailContent(x, taskResult))
                            {
                                Logger.Info(_logMsg.Clear().SetPrefixMsg("Delete Communication Pool").Add("JobId", x.JobId).Add("SRId", x.SRId).ToSuccessLogString());
                            }
                            else
                            {
                                Logger.Info(_logMsg.Clear().SetPrefixMsg("Delete Communication Pool").Add("JobId", x.JobId).Add("SRId", x.SRId).ToFailLogString());
                            }
                        }
                    }
                })).Wait();

                // Override status response
                if (taskResult.NumFailedDelete > 0)
                {
                    taskResult.StatusResponse.Status      = Constants.StatusResponse.Failed;
                    taskResult.StatusResponse.Description = "Unable to delete emails";
                }
            }
        }
Beispiel #11
0
    static IEnumerator SmoothMovement(PoolEntity entity)
    {
        var gameObject           = entity.view.gameObject;
        var transform            = gameObject.transform;
        var rigidBody2d          = gameObject.GetComponent <Rigidbody2D>();
        var end                  = new Vector3(entity.position.x, entity.position.y, 0f);
        var inverseMoveTime      = 1f / entity.smoothMove.moveTime;
        var sqrRemainingDistance = (transform.position - end).sqrMagnitude;

        while (sqrRemainingDistance > float.Epsilon)
        {
            Vector2 newPostion = Vector2.MoveTowards(rigidBody2d.position, end, inverseMoveTime * Time.deltaTime);
            rigidBody2d.MovePosition(newPostion);
            sqrRemainingDistance = (transform.position - end).sqrMagnitude;
            yield return(null);
        }
        entity.isSmoothMoveInProgress = false;
    }
Beispiel #12
0
        public string UpdatePool(PoolEntity pe)
        {
            var countryId = DataContext.CMS_POOLs.Single(d => d.cms_pool_id == pe.Id).COUNTRy1.CountryId;


            var poolAlreadyExistsInCountry = PoolEntityCheck.DoesPoolNameExistForCountry(DataContext, pe.PoolName,
                                                                                         countryId, pe.Id);

            if (poolAlreadyExistsInCountry)
            {
                return(PoolEntityCheck.PoolAlreadyExistsForCountry);
            }

            var poolDbEntry = DataContext.CMS_POOLs.Single(d => d.cms_pool_id == pe.Id);

            poolDbEntry.cms_pool1 = pe.PoolName;
            poolDbEntry.IsActive  = pe.Active;

            var returned = SubmitDbChanges();

            return(returned);
        }
        private void SaveDataToDataBase(PoolEntity pe)
        {
            string message;

            if (pe.Id == 0)
            {
                pe.CountryId = int.Parse(ddlCountry.SelectedValue);
                using (var dataAccess = new MappingDeleteAndCreate())
                {
                    message = dataAccess.CreateNewPool(pe);
                }
            }
            else
            {
                using (var dataAccess = new MappingSingleUpdate())
                {
                    message = dataAccess.UpdatePool(pe);
                }
            }

            ProcessDatabaseReply(message, UpdatePoolSuccess, AdminMappingEnum.CmsPool, lblMessage);
        }
        public string CreateNewPool(PoolEntity pe)
        {
            var poolAlreadyExistsInCountry = PoolEntityCheck.DoesPoolNameExistForCountry(DataContext, pe.PoolName,
                                                                                         pe.CountryId);

            if (poolAlreadyExistsInCountry)
            {
                return(PoolEntityCheck.PoolAlreadyExistsForCountry);
            }

            var countryCode   = DataContext.COUNTRies.Single(d => d.CountryId == pe.CountryId).country1;
            var newPoolEnitiy = new CMS_POOL
            {
                IsActive  = true,
                cms_pool1 = pe.PoolName,
                country   = countryCode,
            };

            DataContext.CMS_POOLs.InsertOnSubmit(newPoolEnitiy);

            var returned = SubmitDbChanges();

            return(returned);
        }
Beispiel #15
0
        private List <CommunicationPoolEntity> FetchAllMessages(string hostname, int port, bool useSsl, PoolEntity pool, out List <string> mailMsgIds)
        {
            var allMessages = new List <CommunicationPoolEntity>();

            _commPoolDataAccess = new CommPoolDataAccess(_context);
            List <ChannelEntity> channels = _commPoolDataAccess.GetActiveChannels();

            // Authenticate ourselves towards the server
            string      decryptedstring = StringCipher.Decrypt(pool.Password, Constants.PassPhrase);
            List <Mime> mailMessages    = this.GetEmails(hostname, port, useSsl, pool.Email, decryptedstring, out mailMsgIds);

            //// Get the number of messages in the inbox
            //int messageCount = mailMessages != null ? mailMessages.Count : 0;
            //int maxRetriveMail = this.GetMaxRetrieveMail();
            //int totalEmails = messageCount > maxRetriveMail ? maxRetriveMail : messageCount;
            int totalEmails = mailMessages != null ? mailMessages.Count : 0;

            if (totalEmails <= 0)
            {
                goto Outer;
            }

            //Messages are numbered in the interval: [1, messageCount]
            //Ergo: message numbers are 1-based.
            //Most servers give the latest message the highest number
            Task.Factory.StartNew(() => Parallel.For(0, totalEmails, new ParallelOptions {
                MaxDegreeOfParallelism = WebConfig.GetTotalCountToProcess()
            },
                                                     k =>
            {
                lock (sync)
                {
                    Mime message = mailMessages[k];
                    CommunicationPoolEntity mail = GetMailContent(message, k);
                    mail.PoolEntity = pool;

                    vc = new ValidationContext(mail, null, null);
                    var validationResults = new List <ValidationResult>();
                    bool valid            = Validator.TryValidateObject(mail, vc, validationResults, true);

                    if (!valid)
                    {
                        string errorMsg = validationResults.Select(x => x.ErrorMessage).Aggregate((i, j) => i + Environment.NewLine + j);
                        Logger.DebugFormat("I:--START--:--Validate Email Subject--:Subject/{0}:Sender:/{1}:Error Message/{2}", mail.Subject, mail.SenderAddress, errorMsg);
                    }
                    else
                    {
                        string mailSubject = mail.Subject.Replace(" ", String.Empty);
                        Match match        = Regex.Match(mailSubject, @";\s*[0-9]{1,}\s*;", RegexOptions.IgnoreCase);
                        var emailChannel   = channels.FirstOrDefault(x => Constants.ChannelCode.Email.Equals(x.Code));

                        if (emailChannel == null)
                        {
                            Logger.ErrorFormat("O:--FAILED--:--Do not configure email channel--:EmailChannelCode/{0}", Constants.ChannelCode.Email);
                            throw new CustomException("ERROR: Do not configure email channel");
                        }

                        if (!match.Success)
                        {
                            mail.ChannelEntity = channels.FirstOrDefault(x => x.Email == mail.SenderAddress) ?? emailChannel;

                            #region "Get Contact Name from KKWebsite"

                            if (Constants.ChannelCode.KKWebSite.Equals(mail.ChannelEntity.Code))
                            {
                                string s = mail.PlainText;

                                if (!string.IsNullOrWhiteSpace(s))
                                {
                                    Logger.Debug("I:--START--:--Get Contact Name from KKWebsite--");

                                    try
                                    {
                                        IList <object> lines = StringHelpers.ConvertStringToList(s, '\n');
                                        mail.ContactName     = (lines.FirstOrDefault(x => x.ToString().Contains(Resource.Lbl_CommFirstname)) as string).ExtractDataField(Resource.Lbl_CommFirstname);
                                        mail.ContactSurname  = (lines.FirstOrDefault(x => x.ToString().Contains(Resource.Lbl_CommSurname)) as string).ExtractDataField(Resource.Lbl_CommSurname);
                                        Logger.DebugFormat("I:--SUCCESS--:--Get Contact Name from KKWebsite--:Contact Name/{0}:Contact Surname/{1}", mail.ContactName, mail.ContactSurname);
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.DebugFormat("O:--FAILED--:--Get Contact Name from KKWebsite--:MainContent/{0}:Error Message/{1}", s, ex.Message);
                                        Logger.Error("Exception occur:\n", ex);
                                    }
                                }

                                // Clear value
                                mail.PlainText = null;
                            }

                            #endregion
                        }
                        else
                        {
                            mail.SRNo          = mailSubject.ExtractSRNo();
                            mail.SRStatusCode  = mailSubject.ExtractSRStatus();
                            mail.ChannelEntity = emailChannel;
                        }

                        allMessages.Add(mail);
                    }
                }
            })).Wait();

            // Now return the fetched messages
Outer:
            var orderedList = allMessages.OrderBy(x => x.SendDateTime).ToList();
            return(orderedList);
        }
Beispiel #16
0
        public ActionResult Edit(PoolViewModel poolVM)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Save CommunicationPool").Add("CommPoolId", poolVM.PoolId)
                        .Add("PoolName", poolVM.PoolName).Add("PoolDesc", poolVM.PoolDesc).ToInputLogString());

            try
            {
                bool skipValidate = false;

                if (poolVM.PoolId != null && string.IsNullOrWhiteSpace(poolVM.Password) &&
                    string.IsNullOrWhiteSpace(poolVM.ConfirmPasswd))
                {
                    ModelState.Remove("Password");
                    ModelState.Remove("ConfirmPasswd");
                    skipValidate = true;
                }

                if (!string.IsNullOrWhiteSpace(poolVM.Password) && !string.IsNullOrWhiteSpace(poolVM.ConfirmPasswd) &&
                    !poolVM.ConfirmPasswd.Equals(poolVM.Password))
                {
                    ModelState.AddModelError("ConfirmPasswd", Resource.ValError_InvalidConfirmPasswd);
                }

                if (ModelState.IsValid)
                {
                    List <PoolBranchEntity> selectedBranch = poolVM.SelectedBranch;

                    // Validate select at least one branch
                    if (!poolVM.SelectedBranch.Any(x => x.IsDelete == false))
                    {
                        ViewBag.ErrorMessage = string.Format(CultureInfo.InvariantCulture, Resource.ValErr_AtLeastOneItemWithField, Resource.Lbl_Branch);
                        goto Outer;
                    }

                    // Save CommPool
                    PoolEntity poolEntity = new PoolEntity
                    {
                        PoolId          = poolVM.PoolId,
                        PoolName        = poolVM.PoolName,
                        PoolDesc        = poolVM.PoolDesc,
                        Email           = poolVM.Email,
                        Status          = poolVM.Status,
                        CreateUser      = UserInfo, //When save the program will select to save this parameter
                        UpdateUser      = UserInfo,
                        ReplyMail       = poolVM.ReplyMail,
                        EmailTemplateId = poolVM.PoolEmailTemplateId
                    };

                    if (!skipValidate)
                    {
                        string encryptedstring = StringCipher.Encrypt(poolVM.Password, Constants.PassPhrase);
                        poolEntity.Password = encryptedstring;
                    }

                    _commPoolFacade = new CommPoolFacade();

                    #region "Check Duplicate"
                    // Check Duplicate
                    if (_commPoolFacade.IsDuplicateCommPool(poolEntity) == true)
                    {
                        ViewBag.ErrorMessage = Resource.Error_SaveFailed_CommPoolDuplicate;
                        goto Outer;
                    }
                    #endregion

                    bool success = _commPoolFacade.SaveCommPool(poolEntity, selectedBranch);

                    if (success)
                    {
                        return(RedirectToAction("Search", "CommPool"));
                    }

                    ViewBag.ErrorMessage = Resource.Error_SaveFailed;
                }

Outer:
                TempData["PoolVM"] = poolVM;
                return(InitEdit());
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Save CommunicationPool").ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Beispiel #17
0
        public ActionResult InitEdit(int?commPoolId = null)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("InitEdit CommunicationPool").Add("CommPoolId", commPoolId).ToInputLogString());

            try
            {
                PoolViewModel poolVM = null;

                if (TempData["PoolVM"] != null)
                {
                    poolVM = (PoolViewModel)TempData["PoolVM"];
                }
                else
                {
                    poolVM = new PoolViewModel {
                        PoolId = commPoolId
                    };
                }

                _commonFacade   = new CommonFacade();
                _commPoolFacade = new CommPoolFacade();

                var statusList = _commonFacade.GetStatusSelectList();
                poolVM.StatusList = new SelectList((IEnumerable)statusList, "Key", "Value", string.Empty);
                var replyMailList = _commonFacade.GetReplyMailSelectList();
                poolVM.ReplyMailList      = new SelectList((IEnumerable)replyMailList, "Key", "Value", string.Empty);
                poolVM.PoolEmailTemplates = _commPoolFacade.GetPoolEmailTemplates().Select(c => new SelectListItem {
                    Text = c.Name, Value = c.PoolEmailTemplateId + ""
                }).ToList();

                if (poolVM.PoolId != null)
                {
                    PoolEntity poolEntity = _commPoolFacade.GetPoolByID(poolVM.PoolId.Value);
                    poolVM.PoolName            = poolEntity.PoolName;
                    poolVM.PoolDesc            = poolEntity.PoolDesc;
                    poolVM.Email               = poolEntity.Email;
                    poolVM.Status              = poolEntity.Status;
                    poolVM.ReplyMail           = poolEntity.ReplyMail;
                    poolVM.PoolEmailTemplateId = poolEntity.EmailTemplateId;

                    poolVM.CreateUser  = poolEntity.CreateUser != null ? poolEntity.CreateUser.FullName : string.Empty;
                    poolVM.UpdateUser  = poolEntity.UpdateUser != null ? poolEntity.UpdateUser.FullName : string.Empty;
                    poolVM.CreatedDate =
                        poolEntity.CreatedDate.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                    poolVM.UpdateDate =
                        poolEntity.Updatedate.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);

                    var poolBranches = _commPoolFacade.GetPoolBranchList(poolVM.PoolId.Value);
                    poolVM.PoolBranchList = poolBranches;
                    poolVM.JsonBranch     = JsonConvert.SerializeObject(poolBranches);
                }
                else
                {
                    poolVM.PoolBranchList = _commPoolFacade.GetPoolBranchList(poolVM.SelectedBranch)
                                            .Where(x => x.IsDelete == false).ToList();

                    // default UserLogin
                    if (this.UserInfo != null)
                    {
                        var today = DateTime.Now;
                        poolVM.CreateUser  = this.UserInfo.FullName;
                        poolVM.CreatedDate = today.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                        poolVM.UpdateDate  = today.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                        poolVM.UpdateUser  = this.UserInfo.FullName;
                    }
                }

                return(View("~/Views/CommPool/Edit.cshtml", poolVM));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("InitEdit CommunicationPool").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Beispiel #18
0
        public JobTaskResult AddMailContent(string hostname, int port, bool useSsl, PoolEntity pool)
        {
            JobTaskResult taskResult = new JobTaskResult();

            taskResult.StatusResponse = new StatusResponse();
            taskResult.Username       = pool.Email;

            try
            {
                if (string.IsNullOrWhiteSpace(pool.Password))
                {
                    throw new CustomException("Password is required");
                }

                int           refNumOfSR    = 0;
                int           refNumOfFax   = 0;
                int           refNumOfWeb   = 0;
                int           refNumOfEmail = 0;
                List <string> mailMsgIds    = null;

                _commPoolDataAccess = new CommPoolDataAccess(_context);
                List <CommunicationPoolEntity> mailList = this.FetchAllMessages(hostname, port, useSsl, pool);

                Logger.Info(_logMsg.Clear().SetPrefixMsg("Add Mail Content").Add("Username", pool.Email).Add("MailList Size", mailList.Count).ToInputLogString());

                taskResult.TotalEmailRead = mailList.Count;
                bool success = _commPoolDataAccess.AddMailContent(mailList, ref refNumOfSR, ref refNumOfFax, ref refNumOfWeb, ref refNumOfEmail);
                taskResult.NumOfSR         = refNumOfSR;
                taskResult.NumOfFax        = refNumOfFax;
                taskResult.NumOfKKWebSite  = refNumOfWeb;
                taskResult.NumOfEmail      = refNumOfEmail;
                taskResult.NumFailedDelete = mailList.Count(x => x.IsDeleted == false);

                if (success)
                {
                    if (mailList.Any(x => x.IsDeleted))
                    {
                        mailMsgIds = mailList.Where(x => x.IsDeleted).Select(x => x.UID).ToList();

                        #region "Delete mail list from user's mailboxes"

                        this.DeleteMessageOnServer(hostname, port, useSsl, pool, mailList, mailMsgIds, taskResult);

                        #endregion
                    }

                    if (taskResult.NumFailedDelete == 0)
                    {
                        taskResult.StatusResponse.Status      = Constants.StatusResponse.Success;
                        taskResult.StatusResponse.Description = string.Empty;
                    }
                    else
                    {
                        taskResult.StatusResponse.Status      = Constants.StatusResponse.Failed;
                        taskResult.StatusResponse.Description = "Unable to delete emails";
                    }

                    Logger.Info(_logMsg.Clear().SetPrefixMsg("Add Mail Content").ToSuccessLogString());
                }
                else
                {
                    taskResult.StatusResponse.Status      = Constants.StatusResponse.Failed;
                    taskResult.StatusResponse.Description = "Failed to save data";
                    Logger.Info(_logMsg.Clear().SetPrefixMsg("Add Mail Content").Add("Error Message", taskResult.StatusResponse.Description).ToFailLogString());
                }

                return(taskResult);
            }
            catch (CustomException cex)
            {
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Add Mail Content").Add("Error Message", cex.Message).ToFailLogString());
                Logger.Error("Exception occur:\n", cex);
                taskResult.StatusResponse.Status      = Constants.StatusResponse.Failed;
                taskResult.StatusResponse.Description = cex.Message;
            }
            catch (Exception ex)
            {
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Add Mail Content").Add("Error Message", ex.Message).ToFailLogString());
                Logger.Error("Exception occur:\n", ex);
                taskResult.StatusResponse.Status      = Constants.StatusResponse.Failed;
                taskResult.StatusResponse.Description = ex.Message;
            }

            return(taskResult);
        }
Beispiel #19
0
        private List <CommunicationPoolEntity> FetchAllMessages(string hostname, int port, bool useSsl, PoolEntity pool)
        {
            var allMessages = new List <CommunicationPoolEntity>();

            _commPoolDataAccess = new CommPoolDataAccess(_context);
            List <ChannelEntity> channels = _commPoolDataAccess.GetActiveChannels();

            // Authenticate ourselves towards the server
            string decryptedstring = StringCipher.Decrypt(pool.Password, Constants.PassPhrase);
            ConcurrentDictionary <string, Mail_Message> mailMessages = this.GetEmails(hostname, port, useSsl, pool.Email, decryptedstring);

            // Get the number of messages in the inbox
            int k           = 0;
            int totalEmails = mailMessages != null ? mailMessages.Count : 0;

            if (totalEmails <= 0)
            {
                goto Outer;
            }

            //Messages are numbered in the interval: [1, messageCount]
            //Ergo: message numbers are 1-based.
            //Most servers give the latest message the highest number
            Task.Factory.StartNew(() => Parallel.ForEach(mailMessages, new ParallelOptions {
                MaxDegreeOfParallelism = WebConfig.GetTotalCountToProcess()
            },
                                                         kvp =>
            {
                lock (sync)
                {
                    try
                    {
                        string msgKey = kvp.Key;
                        Logger.Info(_logMsg.Clear().SetPrefixMsg("Prepared CommuPool Object").Add("KeyPairValue (UID)", (!string.IsNullOrWhiteSpace(msgKey) ? msgKey : "NULL")).ToInputLogString());

                        Mail_Message message;
                        mailMessages.TryGetValue(msgKey, out message);

                        CommunicationPoolEntity mail = GetMailContent(message, k);
                        mail.PoolEntity = pool;
                        mail.UID        = msgKey;

                        string mailSubject = !string.IsNullOrWhiteSpace(mail.Subject) ? mail.Subject.Replace(" ", string.Empty) : string.Empty;
                        Match match        = Regex.Match(mailSubject, @";\s*[0-9]{1,}\s*;", RegexOptions.IgnoreCase);
                        var emailChannel   = channels.FirstOrDefault(x => Constants.ChannelCode.Email.Equals(x.Code));

                        if (emailChannel == null)
                        {
                            Logger.ErrorFormat("O:--FAILED--:--Do not configure email channel--:EmailChannelCode/{0}", Constants.ChannelCode.Email);
                            throw new CustomException("ERROR: Do not configure email channel");
                        }

                        if (match.Success && ApplicationHelpers.IsValidEmailDomain(mail.SenderAddress))
                        {
                            mail.SRNo          = mailSubject.ExtractSRNo();
                            mail.SRStatusCode  = mailSubject.ExtractSRStatus();
                            mail.ChannelEntity = emailChannel;
                        }
                        else
                        {
                            mail.ChannelEntity = channels.FirstOrDefault(x => x.Email != null && x.Email.ToUpperInvariant() == mail.SenderAddress.ToUpperInvariant()) ?? emailChannel;

                            #region "Get Contact Name from KKWebsite"

                            if (mail.ChannelEntity != null && Constants.ChannelCode.KKWebSite.Equals(mail.ChannelEntity.Code))
                            {
                                string s = mail.PlainText;

                                if (!string.IsNullOrWhiteSpace(s))
                                {
                                    Logger.DebugFormat("I:--START--:--Get Contact Name from KKWebsite--:PlainText/{0}", s);

                                    try
                                    {
                                        IList <object> lines = StringHelpers.ConvertStringToList(s, '\n');
                                        mail.ContactName     = (lines.FirstOrDefault(x => x.ToString().Contains(Resource.Lbl_CommFirstname)) as string).ExtractDataField(Resource.Lbl_CommFirstname);
                                        mail.ContactSurname  = (lines.FirstOrDefault(x => x.ToString().Contains(Resource.Lbl_CommSurname)) as string).ExtractDataField(Resource.Lbl_CommSurname);
                                        Logger.DebugFormat("I:--SUCCESS--:--Get Contact Name from KKWebsite--:Contact Name/{0}:Contact Surname/{1}", mail.ContactName, mail.ContactSurname);
                                    }
                                    catch (Exception ex)
                                    {
                                        Logger.DebugFormat("O:--FAILED--:--Get Contact Name from KKWebsite--:MainContent/{0}:Error Message/{1}", s, ex.Message);
                                        Logger.Error("Exception occur:\n", ex);
                                    }
                                }

                                // Clear value
                                mail.PlainText = null;
                            }

                            #endregion
                        }

                        allMessages.Add(mail);
                        Logger.Info(_logMsg.Clear().SetPrefixMsg("Prepared CommuPool Object").ToSuccessLogString());
                    }
                    catch (Exception ex)
                    {
                        Logger.Info(_logMsg.Clear().SetPrefixMsg("Prepared CommuPool Object").Add("Error Message", ex.Message).ToFailLogString());
                        Logger.Error("Exception occur:\n", ex);
                    }

                    k++;
                }
            })).Wait();

            // Now return the fetched messages
Outer:
            var orderedList = allMessages.OrderBy(x => x.RecvDateTime).ToList();
            return(orderedList);
        }
Beispiel #20
0
 public bool SaveCommPool(PoolEntity poolEntity, List <PoolBranchEntity> poolBranches)
 {
     _commPoolDataAccess = new CommPoolDataAccess(_context);
     return(_commPoolDataAccess.SaveCommPool(poolEntity, poolBranches));
 }
Beispiel #21
0
 public bool IsDuplicateCommPool(PoolEntity poolEntity)
 {
     _commPoolDataAccess = new CommPoolDataAccess(_context);
     return(_commPoolDataAccess.IsDuplicateCommPool(poolEntity));
 }
Beispiel #22
0
 public static void AddDestructible(this PoolEntity entity, int hp)
 {
     entity.AddDestructible(hp, hp);
 }
Beispiel #23
0
    public static void DamageDestructible(this PoolEntity entity)
    {
        var current = entity.destructible;

        entity.ReplaceDestructible(current.hp - 1, current.startingHP);
    }
Beispiel #24
0
 public static void AddAudioAttackSource(this PoolEntity entity,
                                         params Audio[] clips)
 {
     entity.AddAudioAttackSource(clips, clips.Length > 1);
 }