Beispiel #1
0
        private int CheckOnlineFeatureLicense(ActFeature feature, string username, SPSite site)
        {
            var assemblyInstance = Assembly.Load(EPMLiveAccountManagementAssembly);
            var thisClass        = assemblyInstance.GetType("EPMLiveAccountManagement.AccountManagement", true, true);

            var methodInfo = thisClass.GetMethod("GetActivationInfo");
            var dsInfo     = (DataSet)methodInfo.Invoke(
                null,
                new object[]
            {
                _web.Site.ID,
                CoreFunctions.GetRealUserName(username, site)
            });

            if (dsInfo.Tables.Count == 0 || dsInfo.Tables[0].Rows.Count == 0 || dsInfo.Tables[0].Columns.Count == 0)
            {
                throw new InvalidOperationException("dsInfo.Tables[0].Rows[0][0] should not be null.");
            }

            int activationType;

            if (!int.TryParse(dsInfo.Tables[0].Rows[0][0]?.ToString(), out activationType))
            {
                activationType = 0;
            }

            switch (activationType)
            {
            case AccessLicense:
                return(7);

            case OldPurchaseMethod:
                return(CheckOldPurchaseMethod(feature, username, dsInfo));

            case Trial:
                return(HasAccess(username, dsInfo)
                        ? AccessLicense
                        : PurchasedLicense);

            case NewPurchaseMethod:
                return(CheckNewPurchaseMethod(feature, username, dsInfo));

            default:
                Trace.WriteLine("Unexpected activationType: " + activationType);
                break;
            }

            return(-1);
        }
Beispiel #2
0
        private static int CheckOldPurchaseMethod(ActFeature feature, string username, DataSet dsInfo)
        {
            if (dsInfo.Tables.Count < 2 || dsInfo.Tables[1].Rows.Count == 0 || !dsInfo.Tables[1].Columns.Contains(LevelColumn))
            {
                throw new InvalidOperationException($"dsInfo.Tables[1].Rows[0][{LevelColumn}] should not be null");
            }

            int contractlevel;

            if (!int.TryParse(dsInfo.Tables[1].Rows[0][LevelColumn]?.ToString(), out contractlevel))
            {
                contractlevel = 2;
            }

            var userLevels = new UserLevels();
            var userLevel  = userLevels.GetById(1);

            if (contractlevel == 2)
            {
                userLevel = userLevels.GetById(2);
            }
            else if (contractlevel == 4)
            {
                userLevel = userLevels.GetById(3);
            }

            if (userLevel == null || userLevel.levels == null)
            {
                throw new InvalidOperationException("userLevel.levels should not be null.");
            }
            if (userLevel.levels.Contains((int)feature))
            {
                if (HasAccess(username, dsInfo))
                {
                    return(AccessLicense);
                }
                return(6);
            }

            return(5);
        }
Beispiel #3
0
        public int CheckFeatureLicense(ActFeature feature)
        {
            int act = -1;

            string user = CoreFunctions.GetRealUserName(_web.CurrentUser.LoginName, _web.Site);

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(_web.Site.ID))
                {
                    if (IsOnline)
                    {
                        act = CheckOnlineFeatureLicense(feature, user, site);
                    }
                    else
                    {
                        act = CheckOnsiteFeatureLicense(feature, user, site);
                    }
                }
            });
            return(act);
        }
Beispiel #4
0
        private int CheckOnsiteFeatureLicense(ActFeature feature, string username, SPSite site)
        {
            int ActivationType = 0;

            SortedList slAvailable = GetAllAvailableLevels(out ActivationType);

            switch (ActivationType)
            {
            case 1:
            case 2:
                if (slAvailable.ContainsKey((int)feature))
                {
                    if ((int)slAvailable[(int)feature] == 0)
                    {
                        return(0);
                    }
                    else
                    {
                        if (username.ToLower() == "sharepoint\\system")
                        {
                            return(0);
                        }
                        else
                        {
                            return(SetUserActivation((int)feature, username, site));
                        }
                    }
                }
                else
                {
                    return(5);
                }

            case 3:
                bool HasPurchased = false;
                bool HasAccess    = false;

                UserLevels uls = new UserLevels();

                foreach (System.Collections.Generic.KeyValuePair <int, UserLevel> ul in uls)
                {
                    UserLevel oUl = (UserLevel)ul.Value;

                    if (slAvailable.Contains(oUl.id))
                    {
                        if (oUl.levels.Contains((int)feature))
                        {
                            if (username.ToLower() == "sharepoint\\system")
                            {
                                return(0);
                            }

                            HasPurchased = true;

                            ArrayList arrUsers = GetFeatureUsers(1000);

                            bool userAlreadyIn = false;

                            int featureUserCount = 0;

                            foreach (string sUser in arrUsers)
                            {
                                try
                                {
                                    string[] sUserInfo = sUser.Split(':');

                                    if (sUserInfo[1] == oUl.id.ToString())
                                    {
                                        featureUserCount++;
                                    }

                                    if (sUserInfo[0] == username && sUserInfo[1] == oUl.id.ToString() && oUl.levels.Contains((int)feature))
                                    {
                                        userAlreadyIn = true;
                                    }
                                }
                                catch { }
                            }

                            if (userAlreadyIn)
                            {
                                if (featureUserCount > (int)slAvailable[oUl.id])
                                {
                                    return(2);
                                }
                                HasAccess = true;
                            }
                        }
                    }
                }

                if (HasAccess)
                {
                    return(0);
                }
                else if (HasPurchased)
                {
                    return(6);
                }
                else
                {
                    return(5);
                }
            }

            return(1);
        }
Beispiel #5
0
        private int CheckNewPurchaseMethod(ActFeature feature, string username, DataSet dsInfo)
        {
            if (dsInfo.Tables.Count < 3)
            {
                throw new ArgumentException("dsInfo.Tables should have at least 3 tables.", nameof(dsInfo));
            }
            var hasPurchased = false;
            var hasAccess    = false;
            var userLevel    = 0;

            foreach (DataRow dataRow in dsInfo.Tables[1].Rows)
            {
                var arrFeatures = new ArrayList(dataRow[FeaturesColumn]?.ToString().Split(','));
                if (arrFeatures.Contains(((int)feature).ToString()))
                {
                    hasPurchased = true;
                    if (SharepointSystemUser.Equals(username, StringComparison.OrdinalIgnoreCase))
                    {
                        return(AccessLicense);
                    }
                    break;
                }
            }

            if (!int.TryParse(dsInfo.Tables[2].Rows[0][0].ToString(), out userLevel))
            {
                Trace.WriteLine("Unable to parse dsInfo.Tables[2].Rows[0][0]");
            }

            if (userLevel == 9999)
            {
                return(AccessLicense);
            }
            else
            {
                var dataRows = dsInfo.Tables[1].Select($"ResLevel='{userLevel}'");
                if (dataRows.Any())
                {
                    int usercount;
                    int maxusers;
                    if (!int.TryParse(dataRows[0][UserCountColumn]?.ToString(), out usercount))
                    {
                        usercount = 0;
                    }
                    if (!int.TryParse(dataRows[0][QuantityColumn]?.ToString(), out maxusers))
                    {
                        maxusers = 0;
                    }

                    if (maxusers >= usercount)
                    {
                        var arrFeatures = new ArrayList(dataRows[0][FeaturesColumn]?.ToString().Split(','));
                        if (arrFeatures.Contains(((int)feature).ToString()))
                        {
                            hasAccess = true;
                        }
                    }
                    else
                    {
                        return(Trial);
                    }
                }
            }

            return(GetLicenseValue(hasPurchased, hasAccess));
        }