示例#1
0
        public ServiceConfigurationEntry GetConfiguration(Data.Country country, Data.MobileOperator mobileOperator)
        {
            ServiceConfigurationEntry sce = null;

            if (mobileOperator == null)
            {
                if (this._countryConfigurationEntryMap.ContainsKey(country.ID))
                {
                    return(this._countryConfigurationEntryMap[country.ID]);
                }

                sce = ServiceConfigurationEntry.CreateManager().Load(this._serviceData, country);
                if (sce != null)
                {
                    this._countryConfigurationEntryMap.Add(country.ID, sce);
                }

                return(sce);
            }
            else
            {
                return(ServiceConfigurationEntry.CreateManager().Load(this._serviceData, country, mobileOperator));
            }
        }
        // SUMMARY: Here we are receiving message that customer sent to us

        /*
         *  - Check if we can parse shortcode
         *  - Check if we can find ServiceConfigurationEntry
         *  - Check if we have Customer, if not, create one
         *  - We create ShorMessage
         *    -ShortMessage.Guid '{0}' proccessed!
         */

        protected override void ProcessReceiveShortMessageNotification(ReceiveShortMessageNotification notification)
        {
            base.ProcessReceiveShortMessageNotification(notification);

            try
            {
                ActionContext actionContext = null;
                MobiChat.Data.MobileOperator mobileOperator = null;
                MobiChat.Data.Service        service        = null;
                MobiChat.Data.Customer       customer       = null;
                Country country = null;

                Log.Info(string.Format("ShortMessage.ExternalGuid '{0}' arrived!", notification.ShortMessage.ShortMessageID.Value));

                if (notification.ShortMessage.Operator.HasValue)
                {
                    mobileOperator = MobiChat.Data.MobileOperator.CreateManager().Load(notification.ShortMessage.Operator.Value, IDType.External);
                }
                country = mobileOperator != null ? mobileOperator.Country : null;

                int shortcode = -1;
                if (!Int32.TryParse(notification.ShortMessage.Shortcode, out shortcode))
                {
                    Log.Error(string.Format("Shortcode could not be parsed (Shortcode={0})", notification.ShortMessage.Shortcode));
                    return;
                }

                ServiceConfigurationEntry sce = ServiceConfigurationEntry.CreateManager().Load(notification.ShortMessage.Keyword, shortcode, country);
                if (sce == null)
                {
                    Log.Error(string.Format("ServiceConfigurationEntry could not be loaded. ( keyword={0}, shortcode={1}, country={2} )",
                                            notification.ShortMessage.Keyword,
                                            shortcode,
                                            country != null ? country.TwoLetterIsoCode : "NULL"));

                    return;
                }

                service = MobiChat.Data.Service.CreateManager().Load(sce.ServiceConfiguration);
                if (service == null)
                {
                    Log.Error(string.Format("Service could not be loaded by ServiceConfiguration={0}", sce.ServiceConfiguration.ID));
                    return;
                }

                Guid   externalCustomerGuid     = Guid.Empty;
                string notificationCustomerGuid = (from ms in notification.Arguments where ms.Key.Equals("customer") select ms.Value).FirstOrDefault().ToString();
                if (!Guid.TryParse(notificationCustomerGuid, out externalCustomerGuid))
                {
                    Log.Error(string.Format("ExternalCustomerGuid could not be parsed. ExternalCustomerGuid={0}",
                                            (from ms in notification.Arguments where ms.Key.Equals("customer") select ms.Key).ToString()));
                    return;
                }

                country  = service.FallbackCountry;
                customer = this.GetCustomer(externalCustomerGuid, service, country, mobileOperator, notification.ShortMessage.Msisdn);

                if (!notification.ShortMessage.ShortMessageID.HasValue)
                {
                    Log.Error(string.Format("Notification does not contain ShortMessageID"));
                    return;
                }

                MobiChat.Data.ShortMessage shortMessage = MobiChat.Data.ShortMessage.CreateManager().Load(notification.ShortMessage.ShortMessageID.Value);
                if (shortMessage != null)
                {
                    Log.Error(string.Format("ShortMessage with guid:'{0}' allready exists", notification.ShortMessage.ShortMessageID.Value));
                    return;
                }

                shortMessage = new MobiChat.Data.ShortMessage(-1,
                                                              notification.ShortMessage.ShortMessageID.Value,
                                                              actionContext,
                                                              service,
                                                              mobileOperator,
                                                              customer,
                                                              ShortMessageDirection.Incoming,
                                                              ShortMessageStatus.Received,
                                                              notification.ShortMessage.Text,
                                                              shortcode,
                                                              notification.ShortMessage.Keyword,
                                                              DateTime.Now, DateTime.Now);
                shortMessage.Insert();

                Log.Info(string.Format("ShortMessage.Guid '{0}' proccessed!", shortMessage.Guid));

                List <CallbackReport> reports = CallbackReport.CreateManager().Load(CallbackNotificationType.ReceiveShortMessageNotification);
                foreach (CallbackReport report in reports)
                {
                    Code.Report.Call(report.Url.Replace("{data}", shortMessage.Guid.ToString()));
                }
                Code.Report.Call(string.Format("http://{0}/notification/received/{1}", service.Name, shortMessage.Guid.ToString()));
            }
            catch (Exception e)
            {
                Log.Fatal(string.Format("ProcessReceiveShortMessageNotification FATAL!"), e);
            }
        }