Beispiel #1
0
        protected override void EditFormInitialize()
        {
            base.EditFormInitialize();

            EditForm.Fields[6].Visible        = m_UserContext.IsFrameworkAdministrator && FrameworkConfiguration.Current.WebApplication.Integration.Chargify.Enabled;
            EditForm.AutoGenerateDeleteButton = (InstanceProvider.GetInstances(m_UserContext.OrganizationId, false).Count > 1);

            EditForm.ItemDeleted += new DetailsViewDeletedEventHandler(EditForm_ItemDeleted);
            EditForm.DataBound   += new EventHandler(EditForm_DataBound);
        }
Beispiel #2
0
        public static void CreateOrganizationAndInstanceContainers(Guid organizationId)
        {
            CreateContainer(organizationId, true);

            ClientDataSet.InstanceDataTable table = InstanceProvider.GetInstances(organizationId);

            foreach (ClientDataSet.InstanceRow row in table)
            {
                CreateInstanceContainers(row.InstanceId);
            }
        }
Beispiel #3
0
        protected override void OnLoad(EventArgs e)
        {
            if (!IsPostBack)
            {
                if (InstanceProvider.GetInstances(UserContext.Current.OrganizationId, true).Count == 0)
                {
                    MasterPage.Message            = Resources.GroupsControl_NoInstanceError_Message;
                    MasterPage.MessageDescription = string.Format(CultureInfo.CurrentCulture, Resources.GroupsControl_NoInstanceError_Description, CustomUrlProvider.CreateApplicationAbsoluteUrl(ResourceProvider.InstancePageVirtualPath));
                    List.Visible = false;
                }
            }

            base.OnLoad(e);
        }
Beispiel #4
0
        public static int UpdateChargifyAllocations()
        {
            if (!Micajah.Common.Configuration.FrameworkConfiguration.Current.WebApplication.Integration.Chargify.Enabled)
            {
                throw new InvalidOperationException("Chargify integration is not enabled in the application configuration file.");
            }

            ChargifyConnect _chargify = ChargifyProvider.CreateChargify();

            if (_chargify == null)
            {
                throw new InvalidOperationException("No Chargify configuration settings found.");
            }

            DateTime?lastUpdatedAt = CounterSettingProvider.GetDateTimeMark(1);

            int updatedCount             = 0;
            OrganizationCollection _orgs = OrganizationProvider.GetOrganizations(false, false);

            foreach (Organization _org in _orgs)
            {
                InstanceCollection _insts = InstanceProvider.GetInstances(_org.OrganizationId, false);

                foreach (Instance _inst in _insts)
                {
                    if (_inst.BillingPlan == BillingPlan.Custom)
                    {
                        continue;
                    }

                    SettingCollection modifiedSettings = CounterSettingProvider.GetLastModifiedPaidSettings(_org.OrganizationId, _inst.InstanceId, lastUpdatedAt);
                    if (modifiedSettings.Count == 0)
                    {
                        continue;
                    }

                    SettingCollection paidSettings = lastUpdatedAt.HasValue ? CounterSettingProvider.GetCalculatedPaidSettings(_org.OrganizationId, _inst.InstanceId) : modifiedSettings;

                    ISubscription _custSubscr = ChargifyProvider.GetCustomerSubscription(_chargify, _org.OrganizationId, _inst.InstanceId);
                    ChargifyProvider.UpdateSubscriptionAllocations(_chargify, _custSubscr != null ? _custSubscr.SubscriptionID : 0, _inst, modifiedSettings, paidSettings);

                    if (_custSubscr != null)
                    {
                        updatedCount++;
                    }
                    if (_custSubscr == null && _inst.CreditCardStatus != CreditCardStatus.NotRegistered)
                    {
                        InstanceProvider.UpdateInstance(_inst, CreditCardStatus.NotRegistered);
                    }
                    else if (_custSubscr != null && _custSubscr.State == SubscriptionState.Expired && _inst.CreditCardStatus != CreditCardStatus.Expired)
                    {
                        InstanceProvider.UpdateInstance(_inst, CreditCardStatus.Expired);
                    }
                    else if (_custSubscr != null && _custSubscr.State == SubscriptionState.Active && _inst.CreditCardStatus != CreditCardStatus.Registered)
                    {
                        InstanceProvider.UpdateInstance(_inst, CreditCardStatus.Registered);
                    }
                    else if (_custSubscr != null && _custSubscr.State != SubscriptionState.Active && _custSubscr.State != SubscriptionState.Expired && _inst.CreditCardStatus != CreditCardStatus.Declined)
                    {
                        InstanceProvider.UpdateInstance(_inst, CreditCardStatus.Declined);
                    }
                }
            }

            CounterSettingProvider.SetDateTimeMark(1);

            return(updatedCount);
        }
Beispiel #5
0
        protected override void EditFormReset()
        {
            base.EditFormReset();

            EditForm.AutoGenerateDeleteButton = (InstanceProvider.GetInstances(m_UserContext.OrganizationId, false).Count > 1);
        }
Beispiel #6
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();
                }
            }
        }