コード例 #1
0
 private UserAdminUtilities()
 {
     Users = new UsersCollection();
     Roles = new RolesCollection();
     Rights = new RightsCollection();
     UserPatterns = new UserPatternCollection();
     organizations = new OrganizationCollection();
     groups = new GroupCollection();
     Desearilize();
 }
コード例 #2
0
        public void Desearilize()
        {
            try
            {
                Users = UsersCollection.Desearilize();
                Rights = RightsCollection.Desearilize();
                Roles = RolesCollection.Desearilize();
                UserPatterns = UserPatternCollection.Desearilize();
                organizations = OrganizationCollection.Desearilize();
                groups = GroupCollection.Desearilize();
            }
            catch
            {

            }
        }
コード例 #3
0
        public void ReplicateAllOrganizations()
        {
            if (!FrameworkConfiguration.Current.WebApplication.Integration.Ldap.Enabled)
            {
                throw new InvalidOperationException("Ldap integration is not enabled in the application configuration file.");
            }
            int replicated = 0;
            int errors     = 0;
            int count      = 0;

            using (OrganizationsLdapGroupsTableAdapter adapter = new OrganizationsLdapGroupsTableAdapter())
            {
                OrganizationCollection organizationCollection = OrganizationProvider.GetOrganizations(false, false);

                DateTime startDate = DateTime.UtcNow;
                LdapInfoProvider.InsertLdapLog(null, false, Resources.LdapProcessLog_ReplicationAllStarted);

                foreach (Organization org in organizationCollection)
                {
                    if (String.IsNullOrEmpty(org.LdapServerAddress) == true || String.IsNullOrEmpty(org.LdapServerPort) == true || String.IsNullOrEmpty(org.LdapUserName) == true || String.IsNullOrEmpty(org.LdapPassword) == true || String.IsNullOrEmpty(org.LdapDomain) == true || !org.Beta)
                    {
                        continue;
                    }

                    //Get All Groups
                    DataView dvDomains = LdapInfoProvider.GetDomains(org.OrganizationId);
                    if (dvDomains.Table.Rows.Count > 0)
                    {
                        for (int i = 0; i < dvDomains.Table.Rows.Count; i++)
                        {
                            DataRow  drDomain = dvDomains.Table.Rows[i];
                            DataView dvGroups = LdapInfoProvider.GetGroupsByDomainDistinguishedName(org.OrganizationId, drDomain["DistinguishedName"].ToString());
                            if (dvGroups.Table.Rows.Count > 0)
                            {
                                adapter.Delete(org.OrganizationId, drDomain["DomainName"].ToString());
                                for (int j = 0; j < dvGroups.Table.Rows.Count; j++)
                                {
                                    DataRow drGroup = dvGroups.Table.Rows[j];
                                    adapter.Insert(Guid.NewGuid(), org.OrganizationId, (Guid)drDomain["Id"], drDomain["DomainName"].ToString(), (Guid)drGroup["Id"], drGroup["GroupName"].ToString(), drGroup["DistinguishedName"].ToString(), DateTime.UtcNow);
                                }
                            }
                        }
                    }
                    count++;
                    RunADReplication(org.OrganizationId, true);

                    Bll.LdapProcess ldapProcess = LdapInfoProvider.LdapProcesses.Find(x => x.ProcessId == string.Format(CultureInfo.InvariantCulture, "RealADReplication_{0}", org.OrganizationId));
                    if (ldapProcess != null)
                    {
                        if (ldapProcess.ThreadStateType == ThreadStateType.Failed)
                        {
                            replicated++;
                        }
                        else
                        {
                            errors++;
                        }
                    }
                }
                LdapInfoProvider.InsertLdapLog(null, false, string.Format(Resources.LdapProcessLog_ReplicationAllFinished, Math.Round((DateTime.UtcNow - startDate).TotalMinutes, 1), count, replicated, errors));
            }
        }
コード例 #4
0
ファイル: LogOnControl.cs プロジェクト: jy4618272/Common
        /// <summary>
        /// Occurs when the login button is clicked.
        /// </summary>
        /// <param name="sender">The sourceRow of the event.</param>
        /// <param name="e">An EventArgs that contains no event data.</param>
        protected void LogOnButton_Click(object sender, EventArgs e)
        {
            string loginName = LoginTextBox.Text;

            try
            {
                if (LoginProvider.Current.Authenticate(loginName, PasswordTextBox.Text, true, true, this.OrganizationId, this.InstanceId))
                {
                    if (!string.IsNullOrEmpty(m_EmailToLink))
                    {
                        if (!EmailProvider.IsEmailExists(m_EmailToLink))
                        {
                            LinkEmailLabel.Text = string.Format(CultureInfo.InvariantCulture, Resources.LogOnControl_LinkEmailLabel_Text, loginName, m_EmailToLink);

                            LinkEmailPanel.Visible = true;
                            FormTable.Visible      = false;
                            if (LogoImagePanel != null)
                            {
                                LogoImagePanel.Visible = false;
                            }

                            m_MainContainerHeight = 150;
                        }
                        else
                        {
                            this.RedirectAfterLogOn();
                        }
                    }
                    else
                    {
                        this.RedirectAfterLogOn();
                    }
                }
            }
            catch (AuthenticationException ex)
            {
                string message = ex.Message;

                if (FrameworkConfiguration.Current.WebApplication.Integration.Google.Enabled)
                {
                    IList domains = null;

                    if (string.Compare(ex.Message, FrameworkConfiguration.Current.WebApplication.Login.FailureText, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        Organization org = OrganizationProvider.GetOrganization(this.OrganizationId);

                        if (org == null)
                        {
                            OrganizationCollection orgs = LoginProvider.Current.GetOrganizationsByLoginName(loginName);
                            if ((orgs != null) && (orgs.Count > 0))
                            {
                                org = orgs[0];
                            }
                        }

                        if (org != null)
                        {
                            if (SettingProvider.OrganizationProviderIsGoogle(org.OrganizationId))
                            {
                                domains = EmailSuffixProvider.GetEmailSuffixesList(org.OrganizationId);
                            }
                        }
                    }

                    if (domains == null)
                    {
                        domains = FrameworkConfiguration.Current.WebApplication.Integration.Google.MailDomains;
                    }

                    if (domains != null)
                    {
                        foreach (string domain in domains)
                        {
                            if (loginName.IndexOf(domain, StringComparison.OrdinalIgnoreCase) != -1)
                            {
                                message = Resources.LoginElement_GoogleFailureText;
                                break;
                            }
                        }
                    }
                }

                this.ShowErrorMessage(message);
            }
        }
コード例 #5
0
ファイル: ChargifyHandler.cs プロジェクト: jy4618272/Common
        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);
        }
コード例 #6
0
        /// <summary>
        /// Occurs when the page is being loaded.
        /// </summary>
        /// <param name="sender">The sourceRow of the event.</param>
        /// <param name="e">An EventArgs that contains no event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            Micajah.Common.Pages.MasterPage.CreatePageHeader(this.Page, false, false);

            if (!IsPostBack)
            {
                UserContext user = UserContext.Current;

                if (user.OrganizationId == null)
                {
                    Response.Redirect(ResourceProvider.GetActiveOrganizationUrl(Request.Url.PathAndQuery));
                }

                Micajah.Common.Pages.MasterPage.SetPageTitle(this.Page, ActionProvider.GlobalNavigationLinks.FindByActionId(ActionProvider.LogOffGlobalNavigationLinkActionId));

                OrganizationArea.Visible = false;
                InstanceArea.Visible     = false;

                InstanceCollection     instances = LoginProvider.Current.GetLoginInstances(user.UserId, user.OrganizationId);
                OrganizationCollection orgs      = LoginProvider.Current.GetOrganizationsByLoginId(user.UserId);
                int instCount = instances.Count;
                int orgsCount = 0;
                if (orgs != null)
                {
                    orgsCount = orgs.Count;
                    if (orgsCount > 1)
                    {
                        orgs      = orgs.FindAllVisible();
                        orgsCount = orgs.Count;
                        if (orgsCount == 1)
                        {
                            if (orgs[0].OrganizationId != user.OrganizationId)
                            {
                                orgsCount = 2;
                            }
                        }
                    }
                }

                if (user.InstanceId == Guid.Empty)
                {
                    instCount = 0;
                }
                else
                {
                    if (instCount > 1)
                    {
                        InstanceDescriptionLabel.Text = Resources.LogOffControl_InstanceDescriptionLabel_Text;

                        InstanceList.DataSource = instances;
                        InstanceList.DataBind();

                        InstanceArea.Visible = true;
                    }
                }

                if (orgsCount > 1)
                {
                    OrganizationLabel.Text = Resources.LogOffControl_OrganizationLabel_Text;

                    orgs.SortByExpiration();

                    OrganizationList.DataSource = orgs;
                    OrganizationList.DataBind();

                    OrganizationArea.Visible = true;
                }
                else if (!InstanceArea.Visible)
                {
                    LoginProvider.Current.SignOut();

                    return;
                }

                TitleLabel.Text = Resources.LogOffControl_TitleLabel_Text;
                LogOffLink.Text = Resources.LogoffControl_LogoffLink_Text;
            }

            if (FrameworkConfiguration.Current.WebApplication.MasterPage.Theme == Pages.MasterPageTheme.Modern)
            {
                this.Page.Header.Controls.Add(Support.CreateStyleSheetLink(ResourceProvider.GetResourceUrl(ResourceProvider.LogOnModernStyleSheet, true)));
            }
            else
            {
                this.Page.Header.Controls.Add(Support.CreateStyleSheetLink(ResourceProvider.GetResourceUrl(ResourceProvider.LogOnStyleSheet, true)));
            }
        }
コード例 #7
0
ファイル: GoogleProvider.cs プロジェクト: jy4618272/Common
        public static void ReplicateAllOrganizations()
        {
            int failed  = 0;
            int success = 0;

            DateTime startDate = DateTime.UtcNow;

            WriteResponseLog(string.Format("GoogleReplicator started replication process at {0}.", startDate));

            try
            {
                OrganizationCollection organizationCollection = OrganizationProvider.GetOrganizations(false, false);

                foreach (Organization org in organizationCollection)
                {
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(org.GoogleAdminAuthToken))
                        {
                            var domains = EmailSuffixProvider.GetEmailSuffixesList(org.OrganizationId);

                            if (domains != null)
                            {
                                WriteResponseLog(string.Format("Organization '{0}' is setup for Google Replication and has {1} Google domains.", org.Name, domains.Count));

                                foreach (string domain in domains)
                                {
                                    bool isSuccess = false;

                                    try
                                    {
                                        WriteResponseLog(string.Format("Receiving users of Organization '{0}' from Google domain '{1}'.", org.Name, domain));

                                        AppsService service  = new AppsService(domain, org.GoogleAdminAuthToken);
                                        UserFeed    userFeed = service.RetrieveAllUsers();

                                        if (userFeed != null && userFeed.Entries != null)
                                        {
                                            int      totalUsers  = userFeed.Entries.Count;
                                            int      failedUsers = 0;
                                            DateTime start       = DateTime.UtcNow;
                                            WriteResponseLog(string.Format("Received {0} users from Google.", totalUsers));
                                            WriteResponseLog(string.Format("Replication for Organization '{0}' is started at {1}.", org.Name, start));

                                            totalUsers = userFeed.Entries.Count;
                                            for (int i = 0; i < totalUsers; i++)
                                            {
                                                UserEntry userEntry = userFeed.Entries[i] as UserEntry;
                                                try
                                                {
                                                    GoogleProvider.ImportUser(userEntry, org.OrganizationId, service.Domain);
                                                }
                                                catch (Exception ex)
                                                {
                                                    failedUsers++;
                                                    WriteResponseLog(string.Format("Replication failed for Organization: {0}; Google domain: {1}; UserName: {2}. Error message: {3}.", org.Name, domain, userEntry.Login.UserName, ex.Message));
                                                    WriteResponseLog(string.Format("Full error: {0}.", ex.ToString()));
                                                }
                                            }

                                            DateTime end = DateTime.UtcNow;
                                            WriteResponseLog(string.Format("Replication for Organization '{0}' is finished at {1}. Replication takes {2} minutes.", org.Name, end, Math.Round((end - start).TotalMinutes, TIME_ROUND_DIGITS)));
                                            WriteResponseLog(string.Format("Number of successfully replicated users: {0}.", totalUsers - failedUsers));
                                            WriteResponseLog(string.Format("Number of not successfully replicated users: {0}.", failedUsers));
                                            isSuccess = true;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        WriteResponseLog(string.Format("GoogleReplicator replication process is failed for Organization '{0}' for Google domain '{1}'. Error message: {2}.", org.Name, domain, ex.Message));
                                        WriteResponseLog(string.Format("Full error: {0}.", ex.ToString()));
                                    }

                                    if (!isSuccess)
                                    {
                                        failed++;
                                    }
                                    else
                                    {
                                        success++;
                                    }
                                }
                            }
                            else
                            {
                                WriteResponseLog(string.Format("Organization '{0}' is not configured for Google replication. Google domain is missing.", org.Name));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        failed++;
                        WriteResponseLog(string.Format("GoogleReplicator replication process failed for Organization '{0}'. Error: {1}.", org.Name, ex.ToString()));
                    }
                }
            }
            catch (Exception ex)
            {
                WriteResponseLog(string.Format("GoogleReplicator error: {0}.", ex.ToString()));
            }

            DateTime endDate = DateTime.UtcNow;

            WriteResponseLog(string.Format("GoogleReplicator finished replication process at {0}. Process was run for {1} minutes.", endDate, Math.Round((endDate - startDate).TotalMinutes, TIME_ROUND_DIGITS)));
            WriteResponseLog(string.Format("Number of successful replications: {0}.", success));
            WriteResponseLog(string.Format("Number of failed replications: {0}.", failed));
        }
コード例 #8
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();
                }
            }
        }