protected void Page_Load(object sender, EventArgs e) { if (Request["delete"] != "") { EPMLiveCore.CoreFunctions.deleteKey(Request["delete"]); } MenuTemplate propertyNameListMenu = new MenuTemplate(); propertyNameListMenu.ID = "PropertyNameListMenu"; MenuItemTemplate testMenu = new MenuItemTemplate( "Delete Key", "/_layouts/images/delete.gif"); testMenu.ClientOnClickNavigateUrl = "features.aspx?delete=%NAME%"; propertyNameListMenu.Controls.Add(testMenu); this.Controls.Add(propertyNameListMenu); DataTable dt = new DataTable(); dt.Columns.Add("feature"); dt.Columns.Add("company"); dt.Columns.Add("features"); dt.Columns.Add("users"); dt.Columns.Add("servers"); dt.Columns.Add("dtcreated"); dt.Columns.Add("expiration"); int servercount = 0; string[] features = EPMLiveCore.CoreFunctions.featureList(); foreach (string feature in features) { string[] featureData = EPMLiveCore.CoreFunctions.Decrypt(feature, "jLHKJH5416FL>1dcv3#I").Split('\n'); if (featureData[2] == "0") { featureData[2] = "Unlimited"; } string[] featureNames = featureData[1].Split(','); string featureRealName = ""; string servers = ""; try { servers = featureData[5]; servercount += int.Parse(servers); }catch {} foreach (string featureName in featureNames) { featureRealName += CoreFunctions.getFeatureName(featureName); } if (featureRealName.Length > 0) { featureRealName = featureRealName.Substring(4); } if (featureData[0][0] == '*') { dt.Rows.Add(new string[] { HttpUtility.UrlEncode(feature), featureData[2], featureRealName, featureData[2], servers, DateTime.Parse(featureData[1]).ToShortDateString(), featureData[4] }); } else { dt.Rows.Add(new string[] { HttpUtility.UrlEncode(feature), featureData[0], featureRealName, featureData[2], servers, featureData[3], featureData[4] }); } } GvItems.DataSource = dt; GvItems.DataBind(); DataTable dt2 = new DataTable(); dt2.Columns.Add("featureid"); dt2.Columns.Add("feature"); dt2.Columns.Add("quantity"); dt2.Columns.Add("active"); SortedList acts = Act.GetAllAvailableLevels(out actType); ArrayList arrUsers = new ArrayList(); if (actType == 3) { MenuTemplate propertyNameListMenu2 = new MenuTemplate(); propertyNameListMenu2.ID = "PropertyNameListMenu2"; MenuItemTemplate testMenu2 = new MenuItemTemplate( "Manage Users", ""); testMenu2.ClientOnClickScript = "managelicv2('%NAME%');"; propertyNameListMenu2.Controls.Add(testMenu2); this.Controls.Add(propertyNameListMenu2); arrUsers = CoreFunctions.getFeatureUsers(1000); if (arrUsers.Count == 1 && arrUsers[0].ToString() == "") { arrUsers = new ArrayList(); } } else { MenuTemplate propertyNameListMenu2 = new MenuTemplate(); propertyNameListMenu2.ID = "PropertyNameListMenu2"; MenuItemTemplate testMenu2 = new MenuItemTemplate( "Manage Users", ""); //testMenu2.ClientOnClickNavigateUrl = "users.aspx?feature=%NAME%"; testMenu2.ClientOnClickScript = "managelic('%NAME%');"; propertyNameListMenu2.Controls.Add(testMenu2); this.Controls.Add(propertyNameListMenu2); } foreach (DictionaryEntry de in acts) { if (actType == 3) { int counter = 0; foreach (string user in arrUsers) { string[] sUserInfo = user.Split(':'); try { if (sUserInfo[1] == de.Key.ToString()) { counter++; } } catch { } } string count = de.Value.ToString(); if (count == "0") { count = "Unlimited"; } dt2.Rows.Add(new string[] { de.Key.ToString(), Act.GetFeatureNameV2(de.Key.ToString()), count, counter.ToString() }); } else { CoreFunctions.getFeatureLicenseUserCount(int.Parse(de.Key.ToString())); string count = de.Value.ToString(); if (count == "0") { count = "Unlimited"; } dt2.Rows.Add(new string[] { de.Key.ToString(), Act.GetFeatureName(de.Key.ToString()), count, CoreFunctions.getFeatureUsers(int.Parse(de.Key.ToString())).Count.ToString() }); } } gvFeatures.DataSource = dt2; gvFeatures.DataBind(); lblFarmId.Text = SPFarm.Local.Id.ToString(); string epmliveservers = ""; try { epmliveservers = SPFarm.Local.Properties["EPMLiveServers"].ToString(); } catch { } SPSecurity.RunWithElevatedPrivileges(delegate() { SPServerCollection servers = SPFarm.Local.Servers; int farmservercount = 0; foreach (SPServer server in servers) { if (server.Role == SPServerRole.WebFrontEnd || server.Role == SPServerRole.Application) { farmservercount++; } } if (farmservercount > servercount && servercount != 0 && epmliveservers != "") { lblWarning.Text = "<b>Warning:</b> It appears you have may have more servers in your farm than your key allows. To select specific servers go to the <a href=\"servers.aspx\">EPM Live Servers</a> page."; } }); }
private static int UpdateUserFeature1000(string username, int featureId, SPFarm farm) { var retVal = -1; var _chrono = farm.GetChild <UserManager>("UserManager" + featureId); if (_chrono == null) { _chrono = new UserManager("UserManager" + featureId, farm, Guid.NewGuid()); _chrono.Update(); farm.Update(); } var lstUsers = _chrono.UserList; if (lstUsers.Count == 1 && lstUsers[0].ToString() == string.Empty) { lstUsers = new ArrayList(); } var actType = 0; var availableLevels = Act.GetAllAvailableLevels(out actType); LoggingService.WriteTrace( LoggingService.Area.EPMLiveCore, LoggingService.Categories.EPMLiveCore.Event, TraceSeverity.Medium, $"Before normalization of username: {username}"); var normalizedUsername = NormalizeUsername(username); LoggingService.WriteTrace( LoggingService.Area.EPMLiveCore, LoggingService.Categories.EPMLiveCore.Event, TraceSeverity.Medium, $"After normalization of username: {normalizedUsername}"); var userInfos = normalizedUsername.Split(':'); var newFeatureId = int.Parse(userInfos[1]); if (availableLevels.Contains(newFeatureId) || newFeatureId == 0) { int max; int.TryParse(Convert.ToString(availableLevels[newFeatureId]), out max); if (max != 0 || newFeatureId == 0) { var counter = 0; var newUsers = new ArrayList(); var already = false; ProcessUsers( normalizedUsername, lstUsers, newFeatureId, ref counter, userInfos, newUsers, ref already); retVal = UpdateFarm( normalizedUsername, farm, counter, max, newFeatureId, already, newUsers, _chrono); } } else { retVal = 2; } return(retVal); }
public override void Execute(Guid contentDbId) { // get a reference to the current site collection's content database SPWebApplication webApplication = this.Parent as SPWebApplication; string[] arrUsers = new string[20]; string LevelUsers = ""; bool mustprocess = false; int actType = 0; SortedList LevelList = Act.GetAllAvailableLevels(out actType); if (actType == 3) { mustprocess = true; } else { for (int i = 0; i < 20; i++) { string scount = ""; try { scount = CoreFunctions.getFeatureLicenseUserCount(i); if (scount != "Unlimited" && scount != "0") { mustprocess = true; } } catch { } arrUsers[i] = ""; } } if (!mustprocess) { return; } foreach (SPSite site in webApplication.Sites) { if (actType == 3) { string sLevelUsers = ""; try { sLevelUsers = site.RootWeb.Properties["workengineusers1000"].ToString(); } catch { } if (sLevelUsers != "") { site.RootWeb.Properties["workengineusers1000"] = ""; site.RootWeb.Properties.Update(); LevelUsers = LevelUsers + "," + sLevelUsers; } } else { for (int i = 0; i < 20; i++) { string sUsers = ""; try { sUsers = site.RootWeb.Properties["workengineusers" + i].ToString(); } catch { } if (sUsers != "") { site.RootWeb.Properties["workengineusers" + i] = ""; site.RootWeb.Properties.Update(); arrUsers[i] = arrUsers[i] + "," + sUsers; } } } site.Dispose(); } SPFarm farm = webApplication.Farm; if (actType == 3) { ProcessV3Users(farm, LevelUsers, LevelList); } else { for (int i = 0; i < 20; i++) { ProcessUsers(farm, arrUsers[i], i); } } }