예제 #1
0
        public IEnumerable <string> GetCPByIdentityFiles(WebAnalyticsProvider webAnalyticsProvider, IList <string> identities, string startDate, string endDate)
        {
            identities.Remove("ip address");
            APIManager apiCalls = new APIManager();

            foreach (string identity in identities)
            {
                string cpByIdentityUrl = "http://api.visistat.com/stats-api-v25.php?key=" + webAnalyticsProvider.APIKey
                                         + "&qt=cpbyid&d=json&sdate=" + startDate + "&edate=" + endDate + "&myid=" + identity;

                string cpByIdentityLocation = System.Configuration.ConfigurationManager.AppSettings["WEBANALYTICS_API_RESPONSE_PATH"] + "/Received"
                                              + "\\CPByIdentity " + endDate.Replace(":", "-") + "_AccID_" + webAnalyticsProvider.AccountID + "_Identity_" + identity.Replace(".", "~");
                Logger.Current.Informational("AccountId: " + webAnalyticsProvider.AccountID + ", cpByIdentityURL: " + cpByIdentityUrl);

                apiCalls.APICall(cpByIdentityUrl, cpByIdentityLocation);
                yield return(cpByIdentityLocation);
            }
        }
예제 #2
0
        public static void Trigger(Object stateInfo)
        {
            try
            {
                if (emailNotifierIsProcessing)
                {
                    return;
                }
                emailNotifierIsProcessing = true;
                Logger.Current.Verbose("WebVisitEmailNotifier triggered");


                Logger.Current.Verbose("Getting visits");

                GetCurrentWebVisitNotificationsResponse webVisitsToBeNotified = webAnalyticsService.GetCurrentWebVistNotifications(new GetCurrentWebVisitNotificationsRequest());
                Logger.Current.Informational("WebVisitsToBeNotified Count" + webVisitsToBeNotified.CurrentVisits.Count());

                var accounts = webVisitsToBeNotified.CurrentVisits.Select(c => c.AccountId).ToList().Distinct();

                var emailResults = new List <KeyValuePair <IEnumerable <string>, string> >();
                var failedEmails = new List <KeyValuePair <IEnumerable <string>, string> >();

                foreach (int accountId in accounts)
                {
                    var userIds = webVisitsToBeNotified.CurrentVisits
                                  .Where(c => c.AccountId == accountId)
                                  .Select(c => c.OwnerID).Distinct().ToList();
                    if (userIds.IsAny())
                    {
                        Dictionary <Guid, string> emailProvider   = accountService.GetTransactionalProviderDetails(accountId);
                        GetDropdownValueResponse  lifeCycleStages = dropdownService.GetDropdownValue(new GetDropdownValueRequest()
                        {
                            AccountId = accountId, DropdownID = (byte)DropdownFieldTypes.LifeCycle
                        });

                        IEnumerable <UserBasicInfo> optedUsers
                            = userService.GetUsersOptedInstantWebVisitEmail(new GetUsersOptedInstantWebVisitEmailRequest()
                        {
                            AccountId = accountId
                        }).Users;


                        List <UserBasicInfo> owners = userService.GetUsersByUserIDs(new GetUsersByUserIDsRequest()
                        {
                            UserIDs = userIds
                        }).Users.ToList();
                        //add empty owner
                        var eo = new UserBasicInfo()
                        {
                            UserID = 0,
                            Email  = defaultEmail
                        };
                        if (!owners.Any(f => f.Email == defaultEmail))
                        {
                            owners.Add(eo);
                        }



                        var account = accountRepository.GetAccountBasicDetails(accountId);
                        if (account.Status != (byte)AccountStatus.Suspend)
                        {
                            #region == Send email to each user ==
                            //is account subscribed
                            var providerResponse = accountService.GetAccountWebAnalyticsProviders(new GetWebAnalyticsProvidersRequest()
                            {
                                AccountId = accountId
                            });

                            WebAnalyticsProvider provider = providerResponse.WebAnalyticsProviders.FirstOrDefault();

                            foreach (var owner in owners)
                            {
                                IEnumerable <WebVisitReport> relatedVisits = null;
                                if (owner.Email == defaultEmail)
                                {
                                    relatedVisits   = webVisitsToBeNotified.CurrentVisits.Where(c => c.AccountId == accountId && c.OwnerID == null).OrderByDescending(c => c.VisitedOn).ToList();
                                    owner.FirstName = "Not";
                                    owner.LastName  = "Assigned";
                                    owner.TimeZone  = account.TimeZone;
                                }
                                else
                                {
                                    relatedVisits = webVisitsToBeNotified.CurrentVisits.Where(c => c.AccountId == accountId && c.OwnerID == owner.UserID).OrderByDescending(c => c.VisitedOn).ToList();
                                }

                                if (relatedVisits.IsAny())
                                {
                                    try
                                    {
                                        if (provider.NotificationStatus)
                                        {
                                            //when owner is default user or un assigned, email will not be sent to owner.
                                            NotifyByEmail(accountId, relatedVisits, owner, "SmartTouch Current Web Visit Alert", lifeCycleStages, emailProvider, owner.Email);
                                        }
                                        foreach (var optedUser in optedUsers)
                                        {
                                            try
                                            {
                                                NotifyByEmail(accountId, relatedVisits, owner, "SmartTouch Current Web Visit Alert (Admin)", lifeCycleStages, emailProvider, optedUser.Email);
                                            }
                                            catch (Exception ex)
                                            {
                                                ex.Data.Clear();
                                                ex.Data.Add("Copy User", optedUser.UserID);
                                                Logger.Current.Error("Unable to send web visit email to user: "******", email: " + optedUser.Email, ex);
                                            }
                                        }
                                        emailResults.Add(new KeyValuePair <IEnumerable <string>, string>(relatedVisits.Select(c => c.VisitReference).ToList(), "Success"));
                                    }
                                    catch (Exception ex)
                                    {
                                        ex.Data.Clear();
                                        ex.Data.Add("Copy User", owner.UserID);
                                        Logger.Current.Error("Unable to send web visit email to user: "******"Failed"));
                                    }
                                }
                            }
                            #endregion
                        }
                        emailResults.AddRange(failedEmails);
                    }
                }

                #region == Update Audits ==
                if (emailResults != null && emailResults.Any())
                {
                    webAnalyticsService.UpdateWebVisitNotifications(new UpdateWebVisitNotificationsRequest()
                    {
                        VisitReferences = emailResults
                    });
                }
                #endregion

                emailNotifierIsProcessing = false;
            }

            catch (Exception ex)
            {
                emailNotifierIsProcessing = false;
                Logger.Current.Error("Exception occured in Email Notifier.", ex);
            }

            finally
            {
                //emailNotifierIsProcessing = false;
            }
        }