Ejemplo n.º 1
0
        private void InitializeSettings()
        {
            m_CounterSettings = new SettingCollection();
            m_PaidSettings    = new SettingCollection();

            ConfigurationDataSet.SettingDataTable table = ConfigurationDataSet.Current.Setting;

            string filter = string.Format(CultureInfo.InvariantCulture, "{0} = {1}", table.SettingTypeIdColumn.ColumnName, (int)SettingType.Counter);

            foreach (ConfigurationDataSet.SettingRow row in table.Select(filter))
            {
                m_CounterSettings.Add(SettingProvider.CreateSetting(row));
            }

            filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName);
            foreach (ConfigurationDataSet.SettingRow row in table.Select(filter))
            {
                if ((row.ShortName == "PhoneSupport") || (row.ShortName == "Training1Hour") || (row.ShortName == "Training3Hours") || (row.ShortName == "Training8Hours"))
                {
                    continue;
                }

                m_PaidSettings.Add(SettingProvider.CreateSetting(row));
            }
        }
Ejemplo n.º 2
0
        public static SettingCollection GetCalculatedPaidSettings(Guid OrgId, Guid InstId)
        {
            string cnnString = GetSettingsValuesHistoryDbConnectionString();

            if (string.IsNullOrEmpty(cnnString))
            {
                return(SettingProvider.GetAllPricedSettings(OrgId, InstId));
            }

            DataTable dtLastValues = SelectSettingsLastValues(OrgId, InstId);

            if (dtLastValues.Rows.Count == 0)
            {
                return(SettingProvider.GetAllPricedSettings(OrgId, InstId));
            }

            dtLastValues.PrimaryKey = new DataColumn[] { dtLastValues.Columns["SettingId"] };

            SettingCollection resCol = new SettingCollection();

            ConfigurationDataSet.SettingDataTable table = ConfigurationDataSet.Current.Setting;
            string filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName);

            Micajah.Common.Bll.Handlers.SettingHandler handler = Micajah.Common.Bll.Handlers.SettingHandler.Current;

            foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter))
            {
                Setting s    = SettingProvider.CreateSetting(_srow);
                DataRow rowS = dtLastValues.Rows.Find(_srow[table.SettingIdColumn.ColumnName]);
                if (rowS != null)
                {
                    s.Value = rowS["SettingValue"].ToString();
                }
                else
                {
                    int settingVal = handler.GetUsedItemsCount(s, OrgId, InstId);
                    s.Value = settingVal.ToString(CultureInfo.InvariantCulture);
                }
                resCol.Add(s);
            }

            return(resCol);
        }
Ejemplo n.º 3
0
        public static SettingCollection GetLastModifiedPaidSettings(Guid OrgId, Guid InstId, DateTime?FromDate)
        {
            if (!FromDate.HasValue)
            {
                return(SettingProvider.GetAllPricedSettings(OrgId, InstId));
            }

            string cnnString = GetSettingsValuesHistoryDbConnectionString();

            if (string.IsNullOrEmpty(cnnString))
            {
                return(SettingProvider.GetAllPricedSettings(OrgId, InstId));
            }

            DataTable dtS = SelectLastModifiedSettings(OrgId, InstId, FromDate.Value);

            SettingCollection resCol = new SettingCollection();

            if (dtS.Rows.Count == 0)
            {
                return(resCol);
            }

            dtS.PrimaryKey = new DataColumn[] { dtS.Columns["SettingId"] };

            ConfigurationDataSet.SettingDataTable table = ConfigurationDataSet.Current.Setting;
            string filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName);

            foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter))
            {
                DataRow rowS = dtS.Rows.Find(_srow[table.SettingIdColumn.ColumnName]);
                if (rowS == null)
                {
                    continue;
                }
                Setting s = SettingProvider.CreateSetting(_srow);
                s.Value = rowS["SettingValue"].ToString();
                resCol.Add(s);
            }

            return(resCol);
        }
Ejemplo n.º 4
0
        public static void CalculateCounterSettingsValues()
        {
            string cnnString = GetSettingsValuesHistoryDbConnectionString();

            if (string.IsNullOrEmpty(cnnString))
            {
                return;
            }

            ConfigurationDataSet.SettingDataTable table = ConfigurationDataSet.Current.Setting;
            string            filter          = string.Format(CultureInfo.InvariantCulture, "{0} = " + ((int)SettingType.Counter).ToString(), table.SettingTypeIdColumn.ColumnName);
            SettingCollection counterSettings = new SettingCollection();

            foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter))
            {
                counterSettings.Add(SettingProvider.CreateSetting(_srow));
            }

            filter = string.Format(CultureInfo.InvariantCulture, "{0} > 0", table.PriceColumn.ColumnName);
            SettingCollection paidSettings = new SettingCollection();

            foreach (ConfigurationDataSet.SettingRow _srow in table.Select(filter))
            {
                paidSettings.Add(SettingProvider.CreateSetting(_srow));
            }

            if (counterSettings.Count == 0 && paidSettings.Count == 0)
            {
                return;
            }

            OrganizationCollection orgs = OrganizationProvider.GetOrganizations(false, false);

            DataTable dtModifiedSettings = new DataTable();

            dtModifiedSettings.Columns.Add(new DataColumn("OrganizationId", typeof(Guid)));
            dtModifiedSettings.Columns.Add(new DataColumn("InstanceId", typeof(Guid)));
            dtModifiedSettings.Columns.Add(new DataColumn("SettingId", typeof(Guid)));
            dtModifiedSettings.Columns.Add(new DataColumn("SettingValue", typeof(string)));

            Micajah.Common.Bll.Handlers.SettingHandler handler = Micajah.Common.Bll.Handlers.SettingHandler.Current;

            foreach (Organization org in orgs)
            {
                InstanceCollection insts = InstanceProvider.GetInstances(org.OrganizationId, false);
                if (insts.Count == 0)
                {
                    continue;
                }

                foreach (Instance inst in insts)
                {
                    DataTable dtLastValues = SelectSettingsLastValues(org.OrganizationId, inst.InstanceId);
                    dtLastValues.PrimaryKey = new DataColumn[] { dtLastValues.Columns["SettingId"] };

                    foreach (Setting setting in counterSettings)
                    {
                        int     settingVal = handler.GetUsedItemsCount(setting, org.OrganizationId, inst.InstanceId);
                        DataRow rowLastVal = dtLastValues.Rows.Find(setting.SettingId);
                        if (rowLastVal == null || rowLastVal["SettingValue"].ToString() != settingVal.ToString())
                        {
                            DataRow rowNewVal = dtModifiedSettings.NewRow();
                            rowNewVal["OrganizationId"] = org.OrganizationId;
                            rowNewVal["InstanceId"]     = inst.InstanceId;
                            rowNewVal["SettingId"]      = setting.SettingId;
                            rowNewVal["SettingValue"]   = settingVal.ToString(CultureInfo.InvariantCulture);
                            dtModifiedSettings.Rows.Add(rowNewVal);
                        }
                    }

                    SettingCollection settings = SettingProvider.GetAllPricedSettings(org.OrganizationId, inst.InstanceId);
                    foreach (Setting setting in settings)
                    {
                        string settingVal = string.Empty;
                        if (setting.Paid)
                        {
                            if (string.IsNullOrEmpty(setting.Value))
                            {
                                settingVal = setting.DefaultValue;
                            }
                            else
                            {
                                settingVal = setting.Value;
                            }
                        }
                        else
                        {
                            settingVal = handler.GetUsedItemsCount(setting, org.OrganizationId, inst.InstanceId).ToString();
                        }

                        DataRow rowLastVal = dtLastValues.Rows.Find(setting.SettingId);

                        if (rowLastVal == null || rowLastVal["SettingValue"].ToString() != settingVal)
                        {
                            DataRow rowNewVal = dtModifiedSettings.NewRow();
                            rowNewVal["OrganizationId"] = org.OrganizationId;
                            rowNewVal["InstanceId"]     = inst.InstanceId;
                            rowNewVal["SettingId"]      = setting.SettingId;
                            rowNewVal["SettingValue"]   = settingVal.ToString(CultureInfo.InvariantCulture);
                            dtModifiedSettings.Rows.Add(rowNewVal);
                        }
                    }
                }
            }

            if (dtModifiedSettings.Rows.Count == 0)
            {
                return;
            }

            using (SqlConnection connection = new SqlConnection(cnnString))
            {
                using (var cmd = GetInsertHistoryRecordCommand(connection))
                {
                    SqlParameter pOrgId        = cmd.Parameters["@OrganizationId"];
                    SqlParameter pInstId       = cmd.Parameters["@InstanceId"];
                    SqlParameter pSettingId    = cmd.Parameters["@SettingId"];
                    SqlParameter pSettingValue = cmd.Parameters["@SettingValue"];
                    cmd.Connection.Open();
                    foreach (DataRow rowS in dtModifiedSettings.Rows)
                    {
                        pOrgId.Value        = rowS["OrganizationId"];
                        pInstId.Value       = rowS["InstanceId"];
                        pSettingId.Value    = rowS["SettingId"];
                        pSettingValue.Value = rowS["SettingValue"];
                        cmd.ExecuteNonQuery();
                    }
                    pOrgId.Value        = Guid.Empty;
                    pInstId.Value       = Guid.Empty;
                    pSettingId.Value    = Guid.Empty;
                    pSettingValue.Value = DBNull.Value;
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                }
            }
        }