Example #1
0
        private void InitializePage()
        {
            btnSave.Text          = Language.GetString(btnSave.Text);
            btnCancel.Text        = Language.GetString(btnCancel.Text);
            dtpStartDateTime.Date = DateManager.GetSolarDate(DateTime.Now);
            dtpStartDateTime.Time = DateTime.Now.TimeOfDay.ToString();
            dtpEndDateTime.Date   = DateManager.GetSolarDate(DateTime.Now);
            dtpEndDateTime.Time   = DateTime.Now.TimeOfDay.ToString();

            #region GetSenderNumber
            drpSenderNumber.DataSource     = Facade.PrivateNumber.GetUserPrivateNumbersForSend(UserGuid);
            drpSenderNumber.DataTextField  = "Number";
            drpSenderNumber.DataValueField = "Guid";
            drpSenderNumber.DataBind();
            #endregion


            #region Type
            foreach (RegularContentType type in System.Enum.GetValues(typeof(RegularContentType)))
            {
                drpType.Items.Add(new ListItem(Language.GetString(type.ToString()), ((int)type).ToString()));
            }
            drpType.Items.Insert(0, new ListItem(string.Empty, string.Empty));
            #endregion

            #region GetPeriodType
            foreach (SmsSentPeriodType periodType in System.Enum.GetValues(typeof(SmsSentPeriodType)))
            {
                drpPeriodType.Items.Add(new ListItem(Language.GetString(periodType.ToString()), ((int)periodType).ToString()));
            }
            drpPeriodType.Items.Insert(0, new ListItem(string.Empty, string.Empty));
            #endregion

            #region WarningType
            foreach (WarningType warning in System.Enum.GetValues(typeof(WarningType)))
            {
                drpWatningType.Items.Add(new ListItem(Language.GetString(warning.ToString()), ((int)warning).ToString()));
            }
            #endregion

            if (ActionType == "edit")
            {
                Common.RegularContent regularContent = Facade.RegularContent.Load(RegularContentGuid);

                txtTitle.Text                 = regularContent.Title;
                drpType.SelectedValue         = regularContent.Type.ToString();
                drpPeriodType.SelectedValue   = regularContent.PeriodType.ToString();
                txtPeriod.Text                = regularContent.Period.ToString();
                drpWatningType.SelectedValue  = regularContent.WarningType.ToString();
                dtpStartDateTime.Date         = DateManager.GetSolarDate(regularContent.StartDateTime);
                dtpStartDateTime.Time         = regularContent.StartDateTime.TimeOfDay.ToString();
                dtpEndDateTime.Date           = DateManager.GetSolarDate(regularContent.EndDateTime);
                dtpEndDateTime.Time           = regularContent.EndDateTime.TimeOfDay.ToString();
                chbIsActive.Checked           = regularContent.IsActive;
                drpSenderNumber.SelectedValue = regularContent.PrivateNumberGuid.ToString();
                Business.RegularContentSerialization regularContentSerialization = new Business.RegularContentSerialization();
                regularContentSerialization = (Business.RegularContentSerialization)GeneralLibrary.SerializationTools.DeserializeXml(regularContent.Config, typeof(Business.RegularContentSerialization));

                switch (regularContent.Type)
                {
                case (int)RegularContentType.URL:
                    txtUrl.Text = regularContentSerialization.URL;
                    break;

                case (int)RegularContentType.DB:
                    txtConnectionString.Text = regularContentSerialization.ConnectionString;
                    txtQuery.Text            = regularContentSerialization.Query;
                    txtField.Text            = regularContentSerialization.Field;
                    break;
                }
            }
        }
        private void ProcessRegularContent(Guid regularContentGuid, Guid privateNumberGuid, Business.RegularContentType type,
                                           string config, Business.WarningType warningType, Guid userGuid, Business.SmsSentPeriodType periodType,
                                           int period, DateTime effectiveDateTime)
        {
            try
            {
                string response = string.Empty;
                Business.RegularContentSerialization regularContentSerialization = (Business.RegularContentSerialization)GeneralLibrary.SerializationTools.DeserializeXml(config, typeof(Business.RegularContentSerialization));

                switch (type)
                {
                case Business.RegularContentType.URL:
                    try
                    {
                        using (var wb = new WebClient())
                        {
                            response = wb.DownloadString(regularContentSerialization.URL);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n-------------------------------------------------------------------------"));

                        LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n RegularContentType.URL URL: {0}", regularContentSerialization.URL));

                        LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n RegularContentType.URL Response: {0}", response));

                        LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n RegularContentType.URL DownloadString: {0}", ex.Message));

                        LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n-------------------------------------------------------------------------"));

                        switch (warningType)
                        {
                        case Business.WarningType.Sms:
                            //Facade.ScheduledSms.InsertSms()
                            break;
                        }

                        throw ex;
                    }

                    if (!string.IsNullOrEmpty(response))
                    {
                        Facade.RegularContent.SendURLContentToReceiver(regularContentGuid, privateNumberGuid, userGuid, response, periodType, period, effectiveDateTime);
                    }

                    break;

                case Business.RegularContentType.DB:
                    try
                    {
                        DataTable dataTable = new DataTable();
                        dataAdapter = new SqlDataAdapter();
                        command     = new SqlCommand();
                        connection  = new SqlConnection(regularContentSerialization.ConnectionString);

                        command.CommandType    = CommandType.Text;
                        command.CommandText    = regularContentSerialization.Query;
                        command.Connection     = connection;
                        command.CommandTimeout = 60;

                        dataAdapter.SelectCommand = command;

                        connection.Open();
                        dataAdapter.Fill(dataTable);

                        if (dataTable.Rows.Count > 0)
                        {
                            response = dataTable.Rows[0][regularContentSerialization.Field].ToString();
                        }
                    }
                    catch (Exception ex)
                    {
                        LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n-------------------------------------------------------------------------"));

                        LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n RegularContentType.DB Guid: {0}", regularContentGuid));

                        LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n RegularContentType.DB Error: {0}", ex.Message));

                        LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n-------------------------------------------------------------------------"));

                        switch (warningType)
                        {
                        case Business.WarningType.Sms:
                            //Facade.ScheduledSms.InsertSms()
                            break;
                        }

                        throw ex;
                    }

                    if (!string.IsNullOrEmpty(response))
                    {
                        Facade.RegularContent.SendDBContentToReceiver(regularContentGuid, privateNumberGuid, userGuid, response, periodType, period, effectiveDateTime);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n-------------------------------------------------------------------------"));

                LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n ProcessRegularContent : {0}", ex.Message));

                LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n ProcessRegularContent : {0}", ex.StackTrace));

                LogController <ServiceLogs> .LogInFile(ServiceLogs.RegularContent, string.Format("\r\n-------------------------------------------------------------------------"));
            }
        }