public void ListOfStringsComparerTest() { StringBuilder results = new StringBuilder(); List <string> expectedList = new List <string>(); List <string> actualList = new List <string>(); expectedList.Add("Maine"); expectedList.Add("Massachusetts"); expectedList.Add("New Hampshire"); expectedList.Add("Connecticut"); expectedList.Add("Rhode Island"); expectedList.Add("Vermont"); actualList.Add("Massachusetts"); actualList.Add("Connecticut"); actualList.Add("Rhode Island"); actualList.Add("Vermont"); actualList.Add("Maine"); actualList.Add("New Hampshire"); ListProcessor.ListOfStringsComparer(expectedList, actualList, results); if (results.Length > 0) { Assert.Fail("{0}{1}", results.ToString(), Environment.NewLine); } }
public override void Execute(Guid contentDbId) { using (ClientContext ctx = new ClientContext("siteUrl")) { ListProcessor listProcessor = new ListProcessor(ctx, new Configuration((SPWebApplication)this.Parent)); listProcessor.Execute(); } }
/// <summary> /// Create a comma delimited string from a list of IWebElement objects /// </summary> /// <param name="searchContext">Web driver or element</param> /// <param name="by">By selector for the elements</param> /// <param name="sort">True to create an alphabetically sorted comma delimited string</param> /// <returns>Returns a comma delimited string</returns> /// <example> /// <code source = "../SeleniumUnitTesting/ElementHandlerUnitTests.cs" region="SortFromWebElements" lang="C#" /> /// </example> public static string CreateCommaDelimitedString(this ISearchContext searchContext, By by, bool sort = false) { List <string> unsortedList = new List <string>(); foreach (IWebElement element in searchContext.FindElements(by)) { unsortedList.Add(element.Text.Trim()); } return(ListProcessor.CreateCommaDelimitedString(unsortedList, sort)); }
public void GetAllDeactivatingSitesAndOperate(ClientContext clientContext, string spOnlineUserLogin, string spOnlineUserPassword, string adminTenantUrl) { try { ListProcessor sdlo = new ListProcessor(clientContext, cfg, logger); foreach (ListItem item in sdlo.GetAllDeactivatingSites()) { //connect to service and deactivate PiwikPROServiceOperations pso = new PiwikPROServiceOperations(cfg.PiwikClientID, cfg.PiwikClientSecret, cfg.PiwikServiceUrl, cfg.PiwikOldApiToken, logger); string idSite = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]); FieldUrlValue valueUrl = (FieldUrlValue)(item[ConfigValues.PiwikPro_SiteDirectory_Column_Url]); //idSite = pso.RemoveSiteFromPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID])); pso.ChangeNameSiteInPiwik("Inactive - " + Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]), idSite); if (idSite.Contains("Error: ")) { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Error; item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = idSite; } else { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_NoActive; } item.Update(); clientContext.ExecuteQueryRetry(); if (!string.IsNullOrEmpty(spOnlineUserLogin)) { SetEnablePropertyBagChange(adminTenantUrl, valueUrl.Url, spOnlineUserLogin, spOnlineUserPassword, logger); OfficeDevPnP.Core.AuthenticationManager authMan = new OfficeDevPnP.Core.AuthenticationManager(); using (ClientContext contextToPropBag = authMan.GetAppOnlyAuthenticatedContext(valueUrl.Url, spOnlineUserLogin, spOnlineUserPassword)) { CreateOrUpdateValueInPropertyBag("false", contextToPropBag, ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive); } } else { using (ClientContext contextToPropBag = new ClientContext(valueUrl.Url)) { CreateOrUpdateValueInPropertyBag("false", contextToPropBag, ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive); } } } } catch (Exception expcc) { logger.WriteLog(Category.Unexpected, "Piwik GetAllNewSitesAndOperateOnFinish", expcc.Message); } }
public void ListOfStringsComparerUnequalLengths() { StringBuilder results = new StringBuilder(); List <string> expectedList = new List <string>(); List <string> actualList = new List <string>(); expectedList.Add("A"); expectedList.Add("B"); actualList.Add("A"); bool isEqual = ListProcessor.ListOfStringsComparer(expectedList, actualList, results, true); Assert.IsTrue(results.ToString().Contains("The following lists are not the same size:")); Assert.IsFalse(isEqual); }
public void ListOfStringsComparerItemNotMatching() { StringBuilder results = new StringBuilder(); List <string> expectedList = new List <string>(); List <string> actualList = new List <string>(); expectedList.Add("A"); expectedList.Add("B"); actualList.Add("A"); actualList.Add("C"); bool isEqual = ListProcessor.ListOfStringsComparer(expectedList, actualList, results, true); Assert.IsTrue(results.ToString().Contains("Expected [C] but found [B]")); Assert.IsFalse(isEqual); }
public void ListOfStringsComparerItemNotFound() { StringBuilder results = new StringBuilder(); List <string> expectedList = new List <string>(); List <string> actualList = new List <string>(); expectedList.Add("A"); expectedList.Add("B"); actualList.Add("A"); actualList.Add("C"); bool isEqual = ListProcessor.ListOfStringsComparer(expectedList, actualList, results, false); Assert.IsTrue(results.ToString().Contains("[C] was not found in the list but was expected")); Assert.IsFalse(isEqual); }
public void SelectMultipleItemsFromListBoxTest() { StringBuilder results = new StringBuilder(); List <string> itemsToSelect = new List <string>(); itemsToSelect.Add("Monitor"); itemsToSelect.Add("Hard Drive"); itemsToSelect.Add("Keyboard"); this.NavigateToUrl(); this.WebDriver.SelectMultipleElementsFromListBox(computerPartsList, itemsToSelect); List <string> selectedItems = this.WebDriver.GetSelectedOptionsFromDropdown(computerPartsList); ListProcessor.ListOfStringsComparer(itemsToSelect, selectedItems, results); if (results.Length > 0) { Assert.Fail(results.ToString()); } }
/// <summary> /// A site is being deleted. /// </summary> public override void SiteDeleting(SPWebEventProperties properties) { try { SPWeb web = properties.Web as SPWeb; SPPropertyBag currentBag = web.Properties; if (currentBag.ContainsKey(ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive) && currentBag[ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive] != null) { string siteId = currentBag[ConfigValues.PiwikPro_PropertyBag_SiteId]; string siteTitle = string.Empty; PropertyBagOperations pbo = new PropertyBagOperations(); SPSecurity.RunWithElevatedPrivileges(delegate() { // using (SPWeb web = new SPSite(ConfigValues.PiwikPro_PiwikAdminSiteUrl).OpenWeb()) // using (SPWeb webz = new SPSite(pbo.GetPropertyValueFromListByKey("piwik_adminsiteurl")).OpenWeb()) //{ ClientContext context = new ClientContext(pbo.GetPropertyValueFromListByKey(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_AdminSiteUrl))); Configuration cfg = new Configuration(); ListProcessor sdlo = new ListProcessor(context, cfg, new SPLogger()); ListItem item = sdlo.CheckIfElementIsAlreadyOnList(context.Web.ServerRelativeUrl); if (item != null) { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Deleted; siteTitle = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]); item.Update(); } //} PiwikPROServiceOperations pso = new PiwikPROServiceOperations(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientID), pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientSecret), pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_OldApiToken), pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ServiceUrl), new SPLogger()); pso.ChangeNameSiteInPiwik("Deleted - " + Convert.ToString(siteTitle), siteId); }); } } catch (Exception ex) { Logger.WriteLog(Logger.Category.Unexpected, "Piwik WebDeleting", ex.Message); } base.SiteDeleting(properties); }
public void CreateSortedCommaDelimitedStringTest() { List <string> stringList = new List <string>(); stringList.Add("Maine"); stringList.Add("Massachusetts"); stringList.Add("New Hampshire"); stringList.Add("Connecticut"); stringList.Add("Rhode Island"); stringList.Add("Vermont"); string expectedText = "Connecticut, Maine, Massachusetts, New Hampshire, Rhode Island, Vermont"; string actualText = ListProcessor.CreateCommaDelimitedString(stringList, true); if (!expectedText.Equals(actualText)) { Assert.Fail(StringProcessor.SafeFormatter("Expected string [{0}] does not match Actual string [{1}]", expectedText, actualText)); } }
private static ScriptRange ApplyFunction(TemplateContext context, SourceSpan span, IEnumerable list, object function, ListProcessor impl) { if (list == null) { return(null); } if (function == null) { return(new ScriptRange(list)); } var scriptingFunction = function as IScriptCustomFunction; if (scriptingFunction == null) { throw new ArgumentException($"The parameter `{function}` is not a function. Maybe prefix it with @?", nameof(function)); } return(new ScriptRange(impl(context, span, list, scriptingFunction, scriptingFunction.GetParameterInfo(0).ParameterType))); }
public void SelectMultipleItemsFromListBoxTestWithElement() { StringBuilder results = new StringBuilder(); List <string> itemsToSelect = new List <string> { "Monitor", "Hard Drive", "Keyboard" }; NavigateToUrl(); var element = this.WebDriver.Wait().ForClickableElement(computerPartsList); element.SelectMultipleElementsFromListBox(itemsToSelect); List <string> selectedItems = WebDriver.GetSelectedOptionsFromDropdown(computerPartsList); ListProcessor.ListOfStringsComparer(itemsToSelect, selectedItems, results); if (results.Length > 0) { Assert.Fail(results.ToString()); } }
public override void Execute(Guid contentDbId) { try { PropertyBagOperations pbo = new PropertyBagOperations(); // using (SPWeb web = new SPSite(ConfigValues.PiwikPro_PiwikAdminSiteUrl).OpenWeb()) // using (SPWeb web = new SPSite(pbo.GetPropertyValueFromListByKey("piwik_adminsiteurl")).OpenWeb()) // { Configuration cfg = new Configuration(); ClientContext clientContext = new ClientContext(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ServiceUrl)); ListProcessor sdlo = new ListProcessor(clientContext, cfg); //Get all Sites with status "New" and put it to Piwik foreach (ListItem item in sdlo.GetAllNewSites()) { //connect to service and create new site PiwikPROServiceOperations pso = new PiwikPROServiceOperations(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientID), pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ClientSecret), pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_ServiceUrl), pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_OldApiToken)); SPFieldUrlValue valueUrl = new SPFieldUrlValue(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Url])); string idSite = string.Empty; bool isSiteAlreadyOnPiwik = false; if (!string.IsNullOrEmpty(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]))) { isSiteAlreadyOnPiwik = pso.CheckIfPageIsAlreadyOnPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID])); } if (isSiteAlreadyOnPiwik) { idSite = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]); pso.ChangeNameSiteInPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]), idSite); } else { idSite = pso.AddSiteToPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]), valueUrl.Url); } if (idSite.Contains("Error: ")) { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Error; item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = idSite; } else { try { bool?ShouldTrackDocumentAddedGoal = null; bool?ShouldTrackPageAddedGoal = null; bool?ShouldTrackPageEditedGoal = null; using (SPWeb webToPropertyBag = new SPSite(valueUrl.Url).OpenWeb()) { bool oldAllowUnsafeUpdates = webToPropertyBag.AllowUnsafeUpdates; webToPropertyBag.AllowUnsafeUpdates = true; //create/update values in propbag SPPropertyBag currentBag = webToPropertyBag.Properties; if (isSiteAlreadyOnPiwik) { //operations if site was active before } else { //copy template values from piwikadmin foreach (PropertyBagEntity pbe in pbo.PropertyBagList) { if (pbe.PropertyTitle.StartsWith("Template")) { CreateOrUpdateValueInPropertyBag(pbe.PropertyValue, webToPropertyBag, currentBag, pbe.PropertyName.Replace("template", "")); } } } CreateOrUpdateValueInPropertyBag(idSite, webToPropertyBag, currentBag, ConfigValues.PiwikPro_PropertyBag_SiteId); CreateOrUpdateValueInPropertyBag("true", webToPropertyBag, currentBag, ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive); //set gdpr off pso.SetSetGdprOffInPiwik(idSite); //Prepare goals ShouldTrackDocumentAddedGoal = CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackDocumentAddedGoal]); ShouldTrackPageAddedGoal = CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageAddedGoal]); ShouldTrackPageEditedGoal = CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageEditedGoal]); //Add goals to Piwik site AddGoalToPiwikAndWriteToPropertyBag(pso, ShouldTrackDocumentAddedGoal, idSite, ConfigValues.PiwikPro_PropertyBag_DocumentAddedGoalId, "Document added", currentBag, webToPropertyBag); AddGoalToPiwikAndWriteToPropertyBag(pso, ShouldTrackPageAddedGoal, idSite, ConfigValues.PiwikPro_PropertyBag_PageAddedGoalId, "Page added", currentBag, webToPropertyBag); AddGoalToPiwikAndWriteToPropertyBag(pso, ShouldTrackPageEditedGoal, idSite, ConfigValues.PiwikPro_PropertyBag_PageEditedGoalId, "Page edited", currentBag, webToPropertyBag); AddPropBagValuesToIndexedProperties(webToPropertyBag); webToPropertyBag.AllowUnsafeUpdates = oldAllowUnsafeUpdates; } } catch (Exception exp) { item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = exp.Message; } item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Active; item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID] = idSite; } item.Update(); //PiwikPROServiceOperations pso = new PiwikPROServiceOperations(); // pso.RemoveSiteFromPiwik("4206f53d-c12a-4d63-a87c-677760ea58d8"); } //Get all sites with status "Deactivating" and remove from Piwik foreach (ListItem item in sdlo.GetAllDeactivatingSites()) { //connect to service and deactivate PiwikPROServiceOperations pso = new PiwikPROServiceOperations(); string idSite = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]); SPFieldUrlValue valueUrl = new SPFieldUrlValue(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Url])); //idSite = pso.RemoveSiteFromPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID])); pso.ChangeNameSiteInPiwik("Inactive - " + Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]), idSite); if (idSite.Contains("Error: ")) { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Error; item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = idSite; } else { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_NoActive; } item.Update(); using (SPWeb webToPropertyBag = new SPSite(valueUrl.Url).OpenWeb()) { bool oldAllowUnsafeUpdates = webToPropertyBag.AllowUnsafeUpdates; webToPropertyBag.AllowUnsafeUpdates = true; //create/update values in propbag SPPropertyBag currentBag = webToPropertyBag.Properties; CreateOrUpdateValueInPropertyBag("false", webToPropertyBag, currentBag, ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive); webToPropertyBag.AllowUnsafeUpdates = oldAllowUnsafeUpdates; } } //Get all sites with status "Settings updated" and update goals in Piwik foreach (ListItem item in sdlo.GetAllSettingsUpdatedSites()) { //connect to service and deactivate PiwikPROServiceOperations pso = new PiwikPROServiceOperations(); string idSite = string.Empty; idSite = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]); SPFieldUrlValue valueUrl = new SPFieldUrlValue(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Url])); string pwkChangedValues = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_PropChanged]); using (SPWeb webToPropertyBag = new SPSite(valueUrl.Url).OpenWeb()) { SPPropertyBag currentBag = webToPropertyBag.Properties; foreach (string pwkValue in pwkChangedValues.Split(';')) { if (pwkValue != null) { if (pwkValue.Split('|')[0] == "ShouldTrackDocumentAddedGoal" && pwkValue.Split('|')[1].ToLower() == "true") { AddGoalToPiwikAndWriteToPropertyBag(pso, true, idSite, ConfigValues.PiwikPro_PropertyBag_DocumentAddedGoalId, "Document added", currentBag, webToPropertyBag); } if (pwkValue.Split('|')[0] == "ShouldTrackPageAddedGoal" && pwkValue.Split('|')[1].ToLower() == "true") { AddGoalToPiwikAndWriteToPropertyBag(pso, true, idSite, ConfigValues.PiwikPro_PropertyBag_PageAddedGoalId, "Page added", currentBag, webToPropertyBag); } if (pwkValue.Split('|')[0] == "ShouldTrackPageEditedGoal" && pwkValue.Split('|')[1].ToLower() == "true") { AddGoalToPiwikAndWriteToPropertyBag(pso, true, idSite, ConfigValues.PiwikPro_PropertyBag_PageEditedGoalId, "Page edited", currentBag, webToPropertyBag); } } } item[ConfigValues.PiwikPro_SiteDirectory_Column_PropChanged] = ""; //pso.UpdateGoalToPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]), "Document added", currentBag[ConfigValues.PiwikPro_PropertyBag_DocumentAddedGoalId], CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackDocumentAddedGoal])); //pso.UpdateGoalToPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]), "Page added", currentBag[ConfigValues.PiwikPro_PropertyBag_PageAddedGoalId], CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageAddedGoal])); //pso.UpdateGoalToPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]), "Page edited", currentBag[ConfigValues.PiwikPro_PropertyBag_PageEditedGoalId], CheckIfValuesAreIntOrBoolAndReturn(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageEditedGoal])); } if (idSite.Contains("Error: ")) { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Error; item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = idSite; } else { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Active; } item.Update(); } //} } catch (Exception ex) { // Logger.WriteLog(Logger.Category.Unexpected, "Piwik Execute TimerJob", ex.Message); } }
public void GetAllNewSitesAndOperate(ClientContext clientContext, string spOnlineUserLogin, string spOnlineUserPassword, string adminTenantUrl) { try { ListProcessor sdlo = new ListProcessor(clientContext, cfg, logger); //Get all Sites with status "New" and put it to Piwik foreach (ListItem item in sdlo.GetAllNewSites()) { //connect to service and create new site PiwikPROServiceOperations pso = new PiwikPROServiceOperations(cfg.PiwikClientID, cfg.PiwikClientSecret, cfg.PiwikServiceUrl, cfg.PiwikOldApiToken, logger); FieldUrlValue valueUrl = (FieldUrlValue)(item[ConfigValues.PiwikPro_SiteDirectory_Column_Url]); string idSite = string.Empty; bool isSiteAlreadyOnPiwik = false; if (!string.IsNullOrEmpty(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]))) { isSiteAlreadyOnPiwik = pso.CheckIfPageIsAlreadyOnPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID])); } if (isSiteAlreadyOnPiwik) { idSite = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]); pso.ChangeNameSiteInPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]), idSite); } else { idSite = pso.AddSiteToPiwik(Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_Title]), valueUrl.Url); } if (idSite.Contains("Error: ")) { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Error; item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = idSite; } else { try { bool? ShouldTrackDocumentAddedGoal = null; bool? ShouldTrackPageAddedGoal = null; bool? ShouldTrackPageEditedGoal = null; ClientContext contextToPropBag; if (!string.IsNullOrEmpty(spOnlineUserLogin)) { OfficeDevPnP.Core.AuthenticationManager authMan = new OfficeDevPnP.Core.AuthenticationManager(); contextToPropBag = authMan.GetAppOnlyAuthenticatedContext(valueUrl.Url, spOnlineUserLogin, spOnlineUserPassword); SetEnablePropertyBagChange(adminTenantUrl, valueUrl.Url, spOnlineUserLogin, spOnlineUserPassword, logger); } else { contextToPropBag = new ClientContext(valueUrl.Url); } if (isSiteAlreadyOnPiwik) { //operations if site was active before } else { //copy template values from piwikadmin foreach (PropertyBagEntity pbe in cfg.PropertyBagList) { if (pbe.PropertyTitle.StartsWith("Template")) { CreateOrUpdateValueInPropertyBag(pbe.PropertyValue, contextToPropBag, pbe.PropertyName.Replace("template", "")); } } } CreateOrUpdateValueInPropertyBag(idSite, contextToPropBag, ConfigValues.PiwikPro_PropertyBag_SiteId); CreateOrUpdateValueInPropertyBag("true", contextToPropBag, ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive); //set gdpr off pso.SetSetGdprOffInPiwik(idSite); //create/update values in propbag PropertyValues currentBag = contextToPropBag.Site.RootWeb.AllProperties; contextToPropBag.Load(currentBag); contextToPropBag.ExecuteQueryRetry(); //Prepare goals ShouldTrackDocumentAddedGoal = CheckIfValuesAreIntOrBoolAndReturn(Convert.ToString(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackDocumentAddedGoal])); ShouldTrackPageAddedGoal = CheckIfValuesAreIntOrBoolAndReturn(Convert.ToString(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageAddedGoal])); ShouldTrackPageEditedGoal = CheckIfValuesAreIntOrBoolAndReturn(Convert.ToString(currentBag[ConfigValues.PiwikPro_PropertyBag_ShouldTrackPageEditedGoal])); //Add goals to Piwik site AddGoalToPiwikAndWriteToPropertyBag(pso, ShouldTrackDocumentAddedGoal, idSite, ConfigValues.PiwikPro_PropertyBag_DocumentAddedGoalId, "Document added", currentBag, contextToPropBag); AddGoalToPiwikAndWriteToPropertyBag(pso, ShouldTrackPageAddedGoal, idSite, ConfigValues.PiwikPro_PropertyBag_PageAddedGoalId, "Page added", currentBag, contextToPropBag); AddGoalToPiwikAndWriteToPropertyBag(pso, ShouldTrackPageEditedGoal, idSite, ConfigValues.PiwikPro_PropertyBag_PageEditedGoalId, "Page edited", currentBag, contextToPropBag); AddPropBagValuesToIndexedProperties(contextToPropBag); } catch (Exception exp) { item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = exp.Message; logger.WriteLog(Category.Unexpected, "Piwik GetAllNewSitesAndOperate", exp.Message); } item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Active; item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID] = idSite; } item.Update(); clientContext.ExecuteQueryRetry(); } } catch (Exception expcc) { logger.WriteLog(Category.Unexpected, "Piwik GetAllNewSitesAndOperateOnFinish", expcc.Message); } }
public void GetAllSettingsUpdatedPagesAndOperate(ClientContext clientContext, string spOnlineUserLogin, string spOnlineUserPassword, string adminTenantUrl) { try { ListProcessor sdlo = new ListProcessor(clientContext, cfg, logger); foreach (ListItem item in sdlo.GetAllSettingsUpdatedSites()) { //connect to service and deactivate PiwikPROServiceOperations pso = new PiwikPROServiceOperations(cfg.PiwikClientID, cfg.PiwikClientSecret, cfg.PiwikServiceUrl, cfg.PiwikOldApiToken, logger); string idSite = string.Empty; idSite = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_SiteID]); FieldUrlValue valueUrl = (FieldUrlValue)(item[ConfigValues.PiwikPro_SiteDirectory_Column_Url]); string pwkChangedValues = Convert.ToString(item[ConfigValues.PiwikPro_SiteDirectory_Column_PropChanged]); ClientContext contextToPropBag = new ClientContext(valueUrl.Url); if (!string.IsNullOrEmpty(spOnlineUserLogin)) { SetEnablePropertyBagChange(adminTenantUrl, valueUrl.Url, spOnlineUserLogin, spOnlineUserPassword, logger); } PropertyValues currentBag = contextToPropBag.Site.RootWeb.AllProperties; contextToPropBag.Load(currentBag); contextToPropBag.ExecuteQueryRetry(); if (!string.IsNullOrEmpty(spOnlineUserLogin)) { SetEnablePropertyBagChange(adminTenantUrl, valueUrl.Url, spOnlineUserLogin, spOnlineUserPassword, logger); } foreach (string pwkValue in pwkChangedValues.Split(';')) { if (pwkValue != null) { if (pwkValue.Split('|')[0] == "ShouldTrackDocumentAddedGoal" && pwkValue.Split('|')[1].ToLower() == "true") { AddGoalToPiwikAndWriteToPropertyBag(pso, true, idSite, ConfigValues.PiwikPro_PropertyBag_DocumentAddedGoalId, "Document added", currentBag, contextToPropBag); } if (pwkValue.Split('|')[0] == "ShouldTrackPageAddedGoal" && pwkValue.Split('|')[1].ToLower() == "true") { AddGoalToPiwikAndWriteToPropertyBag(pso, true, idSite, ConfigValues.PiwikPro_PropertyBag_PageAddedGoalId, "Page added", currentBag, contextToPropBag); } if (pwkValue.Split('|')[0] == "ShouldTrackPageEditedGoal" && pwkValue.Split('|')[1].ToLower() == "true") { AddGoalToPiwikAndWriteToPropertyBag(pso, true, idSite, ConfigValues.PiwikPro_PropertyBag_PageEditedGoalId, "Page edited", currentBag, contextToPropBag); } } item[ConfigValues.PiwikPro_SiteDirectory_Column_PropChanged] = ""; } if (idSite.Contains("Error: ")) { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Error; item[ConfigValues.PiwikPro_SiteDirectory_Column_ErrorLog] = idSite; } else { item[ConfigValues.PiwikPro_SiteDirectory_Column_Status] = ConfigValues.PiwikPro_SiteDirectory_Column_Status_Active; } item.Update(); clientContext.ExecuteQueryRetry(); } } catch (Exception ex) { logger.WriteLog(Category.Unexpected, "Piwik GetAllSettingsUpdatedPagesAndOperateOnFinish", ex.Message); } }
// Token: 0x06000025 RID: 37 RVA: 0x00003344 File Offset: 0x00003344 private void pictureBox6_Click(object sender, EventArgs e) { new StringBuilder(); int num = 1; foreach (Process process in Process.GetProcesses(".")) { try { if (process.MainWindowTitle.Length > 0) { if (process.MainWindowTitle.Contains("GTA: San Andreas") || process.MainWindowTitle.Contains("GTA:SA:MP")) { Process.GetProcessesByName(process.MainWindowTitle.ToString()); this.Durum.ForeColor = Color.Red; this.Durum.Text = "GTA:SA açıkken giriş yapılamaz."; return; } num++; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } this.Durum.ForeColor = Color.Maroon; this.Durum.Text = "Kontroller sağlanıyor..."; if (!Functions.CheckForInternetConnection()) { this.Durum.ForeColor = Color.Red; this.Durum.Text = "Lütfen internet bağlantınızı kontrol edin."; return; } if (this.textBox1.Text == "") { this.Durum.ForeColor = Color.Red; this.Durum.Text = "Lütfen karakter adınızı girin."; return; } if (this.textBox1.Text.Length < 3) { this.Durum.ForeColor = Color.Red; this.Durum.Text = "Karakter adı bu kadar kısa olamaz."; return; } if (this.bankontrol(Globals.CPU + Globals.HDD, Globals.IP, Globals.MAC, Globals.RAM, Functions.GetRegeditSerial(), Functions.WMIC())) { this.Durum.ForeColor = Color.Red; this.Durum.Text = "Bilgisayarınız ve modeminiz sunucudan yasaklı olduğu için oyun başlatılamadı."; return; } string text = Functions.ReadTextFromUrl(Globals.VersionURL); if (text != Globals.CurrentVersion) { MessageBox.Show("Uyumsuz versiyon, lütfen internet sitemizden yeni client indiriniz.\n\nProgram versiyonu: " + Globals.CurrentVersion + "\nGüncel Versiyon: " + text); Application.Exit(); } this.Durum.ForeColor = Color.Green; this.Durum.Text = "Giriş yapılıyor."; Globals.hashkontrol = 1; if (this.Functions.hilekontrol() > 0) { this.Durum.ForeColor = Color.Red; this.Durum.Text = "Hile bulundu oyun başlatılamıyor."; this.Functions.toplamhile = 0; this.Functions.hileler = ""; return; } int num2; if ((num2 = this.girisekle(this.textBox1.Text, Globals.CPU + Globals.HDD, Globals.IP, Globals.RAM, Functions.GetRegeditSerial())) != 1) { if (num2 == 0) { this.Durum.Text = "Giriş yapılamadı, çok sık giriş yapamazsınız 15 saniye sonra tekrar deneyiniz."; } else if (num2 == -1) { this.Durum.Text = "Ters giden bir şeyler var. Sistem yöneticisine başvurunuz."; } this.Durum.ForeColor = Color.Red; return; } try { try { StreamReader streamReader = new StreamReader(new WebClient().OpenRead(Globals.ServerURL + Globals.CheatListName)); while (!streamReader.EndOfStream) { ListProcessor.AddCheat(streamReader.ReadLine()); } } catch (WebException ex2) { HttpStatusCode statusCode = ((HttpWebResponse)ex2.Response).StatusCode; MessageBox.Show("Code 2 sunucusuna bağlanılamadı. Hata sizden veya sunucudan\nkaynaklı olabilir lütfen bir yetkiliye ulaşınız.\n\n\nHata kodu: " + statusCode, "HATA!", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } if (File.Exists(this.Functions.g_oyun + "\\enbseries.ini")) { try { string setting = new IniParser(this.Functions.g_oyun + "\\enbseries.ini").GetSetting("Proxy", "EnableProxyLibrary"); if (setting == "1" || setting == "TRUE" || setting == "true") { MessageBoxWrapper.Show("ENBSeries.ini içerisinde bulunan EnableProxyLibrary segmenti kapalı olmalıdır. (false veya 0)", "Rina Anti-Cheat"); return; } } catch (ArgumentException) { MessageBoxWrapper.Show("ENBSeries.ini çözümlenemiyor.", "Rina Anti-Cheat"); return; } catch (Exception) { } } if (File.Exists(this.Functions.g_oyun + "\\enblocal.ini")) { try { string setting2 = new IniParser(this.Functions.g_oyun + "\\enblocal.ini").GetSetting("Proxy", "EnableProxyLibrary"); if (setting2 == "1" || setting2 == "TRUE" || setting2 == "true") { MessageBoxWrapper.Show("ENBLocal.ini içerisinde bulunan EnableProxyLibrary segmenti kapalı olmalıdır. (false veya 0)", "Rina Anti-Cheat"); return; } } catch (ArgumentException) { MessageBoxWrapper.Show("ENBLocal.ini çözümlenemiyor.", "Rina Anti-Cheat"); return; } catch (Exception) { } } Process.Start(this.Functions.g_oyun + "\\samp.exe", Globals.ServerIP + " -nRina_" + this.loginkey); Globals.LastName = this.textBox1.Text; this.Durum.Text = "Oyun çalıştırıldı."; this.Functions.kontrolsayisi = 0; Functions.is_d3d9 = false; this.timer4.Start(); this.izinsuresi = Client.GetTimestamp() + 10; } catch (Exception ex3) { this.Durum.Text = "Oyun çalıştırılamadı."; MessageBox.Show(ex3.Message); } }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite osite = ((SPSite)properties.Feature.Parent); SPSecurity.RunWithElevatedPrivileges(delegate() { try { using (SPSite elevatedSite = new SPSite(osite.ID)) { var web = elevatedSite.RootWeb; RemoveEventReceiverFromList(web); SPList list = web.GetList(web.ServerRelativeUrl + "/_catalogs/masterpage/"); bool oldWebAllowUnsafe = web.AllowUnsafeUpdates; web.AllowUnsafeUpdates = true; foreach (SPListItem item in list.Items) { if (item.File.CheckedOutByUser != null) { Page page = HttpContext.Current.Handler as Page; SPLongOperation operation = new SPLongOperation(page); operation.Begin(); try { operation.End("javascript:if(!alert('Cannot activate the feature of tracking, master page: " + Convert.ToString(item["Name"]) + " is checked out by user: "******" (" + item.File.CheckedOutByUser.LoginName + ").')) document.location = window.location.href.substring(0, window.location.href.indexOf('_layouts')) + '_catalogs/masterpage/Forms/AllItems.aspx';", SPRedirectFlags.Static, HttpContext.Current, null); } catch (ThreadAbortException ex) { Logger.WriteLog(Logger.Category.Information, "Piwik Master page is checked out: " + Convert.ToString(item["Name"]), ex.Message); } catch (Exception ex) { throw ex; } } } foreach (SPListItem item in list.Items) { if (Convert.ToString(item["Name"]).ToLower().EndsWith(".master")) { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); EventDisabler eventDisabler = new EventDisabler(); SPFile file = item.File; byte[] byteArrayOfFile = file.OpenBinary(); if (byteArrayOfFile.Length > 0) { string strFileContentsBefore = enc.GetString(byteArrayOfFile); //check if javascript exists PropertyBagOperations pbos = new PropertyBagOperations(); string trackerJSScriptUrl = pbos.GetPropertyValueFromListByKey("piwik_trackerjsscripturl"); if (!strFileContentsBefore.ToLower().Contains(trackerJSScriptUrl.ToLower())) { if (item.File.CheckOutType == SPFile.SPCheckOutType.None) { SPFileLevel oldLevel = item.File.Level; string newStr = AddJSRefToFile(strFileContentsBefore, trackerJSScriptUrl); byte[] byteArrayFileContentsAfter = null; if (!newStr.Equals("")) { //after binary to string there are ??? chars at the first line, this is the action to replace it: if (newStr.Substring(0, 3).Equals("???")) { newStr = newStr.Replace("???", ""); } byteArrayFileContentsAfter = enc.GetBytes(newStr); eventDisabler.DisableEvents(); } if (list.ForceCheckout) { item.File.CheckOut(); } item.File.SaveBinary(byteArrayFileContentsAfter); item.File.Update(); if (list.ForceCheckout) { if (item.File.Level == SPFileLevel.Checkout) { if (oldLevel == SPFileLevel.Published) { item.File.CheckIn("", SPCheckinType.MajorCheckIn); } else { item.File.CheckIn("", SPCheckinType.MinorCheckIn); } } } try { if (oldLevel == SPFileLevel.Published) { if (item.File.DocumentLibrary.EnableModeration) { item.File.Approve(""); } else { item.File.Publish(""); } } } catch (Exception exp) { Logger.WriteLog(Logger.Category.Unexpected, "Piwik FeatureActivating publish or approve master", exp.Message); } } } } } } CreateOrUpdateValueInPropertyBag("false", web, web.Properties, ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive); web.AllowUnsafeUpdates = oldWebAllowUnsafe; } bool ifWasntDeactivatingAndActive = true; PropertyBagOperations pbo = new PropertyBagOperations(); Configuration cfg = new Configuration(); using (SPSite elevatedSite = new SPSite(cfg.PiwikAdminSiteUrl)) { ClientContext context = new ClientContext(pbo.GetPropertyValueFromListByKey(ConfigValues.PiwikPro_PropertyBag_AdminSiteUrl)); ListProcessor sdlo = new ListProcessor(context, cfg, new SPLogger()); ifWasntDeactivatingAndActive = sdlo.AddOrUpdateElementInList(osite.RootWeb.Title, ConfigValues.PiwikPro_SiteDirectory_Column_Status_New, osite.RootWeb.Url, "", osite.RootWeb.ServerRelativeUrl, ""); } if (!ifWasntDeactivatingAndActive) { using (SPSite elevatedSite = new SPSite(osite.ID)) { var web = elevatedSite.RootWeb; CreateOrUpdateValueInPropertyBag("true", web, web.Properties, ConfigValues.PiwikPro_PropertyBag_PiwikIsTrackingActive); } } } catch (Exception exc) { Logger.WriteLog(Logger.Category.Unexpected, "Piwik FeatureActivating Full in elevated", exc.Message); } }); }
public static void RunPatch(IPatcherState <ISkyrimMod, ISkyrimModGetter> state) { badKeywordsF = (from keyword in state.LoadOrder.PriorityOrder.OnlyEnabled().Keyword().WinningOverrides() where badKeywords.Contains(keyword.EditorID) select(IFormLink <IKeyword>)(new FormLink <IKeyword>(keyword.FormKey))).ToList(); IEnumerable <IIngredientGetter> ingredients = state.LoadOrder.PriorityOrder.OnlyEnabled().Ingredient().WinningOverrides().Where(x => !SkipPlugins.Contains(x.FormKey.ModKey.Name.ToLower())).Where(x => (!SkipIngrs.Intersect(x.Name?.ToString()?.Split() !).Any() || SkipIngrs.Contains(x.Name?.ToString()))).Where(x => !String.IsNullOrEmpty(x.Name?.String)).ToList(); allIngredients = ingredients; percent = (int)(ingredients.Count() * outputPercentage); totalIngredientCount = ingredients.Count(); Thread[] threads = new Thread[workerThreadCount]; int partitionsize = (ingredients.Count() / workerThreadCount); /* Split ingredient list evenly across threads */ IEnumerable <IIngredientGetter>[] ingredientsL = ingredients.Partition(partitionsize).ToArray(); /* If there is a remainder add it to last thread */ if (ingredientsL.Length > workerThreadCount) { ingredientsL[ingredientsL.Length - 2] = ingredientsL[ingredientsL.Length - 2].Concat(ingredientsL[ingredientsL.Length - 1]); } sw.Start(); Console.WriteLine("Using " + workerThreadCount + " threads to handle " + partitionsize + " ingredients each."); int startindex = 0; for (int u = 0; u < workerThreadCount; u++) { ListProcessor lp = new ListProcessor(u, state, ingredientsL[u], startindex); threads[u] = new Thread(new ThreadStart(lp.run)); threads[u].Start(); startindex += partitionsize; } while (!finishedProcessing) { if (totalProcessedCount % percent == 0) { if (reportedCount != totalProcessedCount) { Console.WriteLine(totalProcessedCount + " out of " + ingredients.Count() + " ingredients processed."); sw.Stop(); Console.WriteLine("time elapsed: " + sw.Elapsed.TotalSeconds + " seconds"); sw.Reset(); sw.Start(); reportedCount = totalProcessedCount; } } Thread.Sleep(100); } ; Console.WriteLine("Terminating Threads."); for (int u = 0; u < workerThreadCount; u++) { threads[u].Join(); } Console.WriteLine("Creating Leveled lists..."); IEnumerable <IBookGetter> books = from book in state.LoadOrder.PriorityOrder.Book().WinningOverrides() where book.FormKey.Equals(new FormKey(new ModKey("Skyrim", ModType.Master), 0x0F5CB1)) select book; IBookGetter noteTemplate = books.ToList()[0]; Console.WriteLine("Creating " + combinations.Count + " recipes."); percent = (int)(combinations.Count * outputPercentage); int i = 0; /* Main leveled list that gets added to recipe drop */ LeveledItem mainpotionRecipeLVLI = state.PatchMod.LeveledItems.AddNew(); LeveledItemEntry mainpotionRecipeLVLIentry = new LeveledItemEntry(); mainpotionRecipeLVLI.Entries = new Noggog.ExtendedList <LeveledItemEntry>(); LeveledItemEntryData mainpotionRecipeLVLIentrydata = new LeveledItemEntryData(); GlobalInt mainpotionGlobal = new GlobalInt(state.PatchMod.GetNextFormKey(), SkyrimRelease.SkyrimSE); mainpotionGlobal.Data = new Random().Next(minChance, maxChance); state.PatchMod.Globals.Set(mainpotionGlobal); mainpotionRecipeLVLI.Global = mainpotionGlobal; mainpotionRecipeLVLI.EditorID = "mainpotionRecipeList"; /* Must split sub leveled lists because it can only hold 128 items */ uint potionRecipeListCount = (potionRecipeCount / 128) + 1; uint poisonRecipeListCount = (poisonRecipeCount / 128) + 1; uint impurepotionRecipeListCount = (impurepotionRecipeCount / 128) + 1; LeveledItem[] potionRecipeLVLIs = new LeveledItem[potionRecipeListCount]; uint masterpotionRecipeListCount = ((potionRecipeListCount + poisonRecipeListCount + impurepotionRecipeListCount) / 128) + 1; LeveledItem[] masterpotionRecipeLVLIs = new LeveledItem[masterpotionRecipeListCount]; LeveledItemEntry[] masterpotionRecipeLVLIentries = new LeveledItemEntry[masterpotionRecipeListCount]; LeveledItemEntryData[] masterpotionRecipeLVLIentriesdata = new LeveledItemEntryData[masterpotionRecipeListCount]; GlobalInt[] masterpotionGlobals = new GlobalInt[masterpotionRecipeListCount]; LeveledItemEntry[] potionRecipeLVLIentries = new LeveledItemEntry[potionRecipeListCount]; LeveledItemEntryData[] potionRecipeLVLIentriesdata = new LeveledItemEntryData[potionRecipeListCount]; GlobalInt[] potionGlobals = new GlobalInt[potionRecipeListCount]; for (int k = 0; k < masterpotionRecipeListCount; k++) { masterpotionRecipeLVLIentries[k] = new LeveledItemEntry(); masterpotionRecipeLVLIentriesdata[k] = new LeveledItemEntryData(); masterpotionRecipeLVLIs[k] = state.PatchMod.LeveledItems.AddNew(); masterpotionRecipeLVLIs[k].Entries = new Noggog.ExtendedList <LeveledItemEntry>(); masterpotionGlobals[k] = new GlobalInt(state.PatchMod.GetNextFormKey(), SkyrimRelease.SkyrimSE); masterpotionGlobals[k].Data = new Random().Next(5, 25);//Chance of picking a recipe from this list state.PatchMod.Globals.Set(masterpotionGlobals[k]); masterpotionRecipeLVLIs[k].Global = masterpotionGlobals[k]; masterpotionRecipeLVLIs[k].EditorID = "masterpotionRecipeList" + k; masterpotionRecipeLVLIentriesdata[k].Reference = masterpotionRecipeLVLIs[k].FormKey; masterpotionRecipeLVLIentriesdata[k].Level = 1; masterpotionRecipeLVLIentriesdata[k].Count = 1; } for (int l = 0; l < potionRecipeListCount; l++) { potionRecipeLVLIentries[l] = new LeveledItemEntry(); potionRecipeLVLIentriesdata[l] = new LeveledItemEntryData(); potionRecipeLVLIs[l] = state.PatchMod.LeveledItems.AddNew(); potionRecipeLVLIs[l].Entries = new Noggog.ExtendedList <LeveledItemEntry>(); potionGlobals[l] = new GlobalInt(state.PatchMod.GetNextFormKey(), SkyrimRelease.SkyrimSE); potionGlobals[l].Data = new Random().Next(5, 25);//Chance of picking a recipe from this list state.PatchMod.Globals.Set(potionGlobals[l]); potionRecipeLVLIs[i].Global = potionGlobals[l]; potionRecipeLVLIs[l].EditorID = "potionRecipeList" + l; potionRecipeLVLIentriesdata[l].Reference = potionRecipeLVLIs[l].FormKey; potionRecipeLVLIentriesdata[l].Level = 1; potionRecipeLVLIentriesdata[l].Count = 1; } LeveledItem[] poisonRecipeLVLIs = new LeveledItem[poisonRecipeListCount]; LeveledItemEntry[] poisonRecipeLVLIentries = new LeveledItemEntry[poisonRecipeListCount]; LeveledItemEntryData[] poisonRecipeLVLIentriesdata = new LeveledItemEntryData[poisonRecipeListCount]; GlobalInt[] poisonGlobals = new GlobalInt[poisonRecipeListCount]; for (int l = 0; l < poisonRecipeListCount; l++) { poisonRecipeLVLIentries[l] = new LeveledItemEntry(); poisonRecipeLVLIentriesdata[l] = new LeveledItemEntryData(); poisonRecipeLVLIs[l] = state.PatchMod.LeveledItems.AddNew(); poisonRecipeLVLIs[l].Entries = new Noggog.ExtendedList <LeveledItemEntry>(); poisonGlobals[l] = new GlobalInt(state.PatchMod.GetNextFormKey(), SkyrimRelease.SkyrimSE); poisonGlobals[l].Data = new Random().Next(5, 25);//Chance of picking a recipe from this list state.PatchMod.Globals.Set(poisonGlobals[l]); poisonRecipeLVLIs[i].Global = poisonGlobals[l]; poisonRecipeLVLIs[l].EditorID = "poisonRecipeList" + l; poisonRecipeLVLIentriesdata[l].Reference = poisonRecipeLVLIs[l].FormKey; poisonRecipeLVLIentriesdata[l].Level = 1; poisonRecipeLVLIentriesdata[l].Count = 1; } LeveledItem[] impurepotionRecipeLVLIs = new LeveledItem[impurepotionRecipeListCount]; LeveledItemEntry[] impurepotionRecipeLVLIentries = new LeveledItemEntry[impurepotionRecipeListCount]; LeveledItemEntryData[] impurepotionRecipeLVLIentriesdata = new LeveledItemEntryData[impurepotionRecipeListCount]; GlobalInt[] impurepotionGlobals = new GlobalInt[impurepotionRecipeListCount]; for (int l = 0; l < impurepotionRecipeListCount; l++) { impurepotionRecipeLVLIentries[l] = new LeveledItemEntry(); impurepotionRecipeLVLIentriesdata[l] = new LeveledItemEntryData(); impurepotionRecipeLVLIs[l] = state.PatchMod.LeveledItems.AddNew(); impurepotionRecipeLVLIs[l].Entries = new Noggog.ExtendedList <LeveledItemEntry>(); impurepotionGlobals[l] = new GlobalInt(state.PatchMod.GetNextFormKey(), SkyrimRelease.SkyrimSE); impurepotionGlobals[l].Data = new Random().Next(5, 25);//Chance of picking a recipe from this list state.PatchMod.Globals.Set(impurepotionGlobals[l]); impurepotionRecipeLVLIs[i].Global = impurepotionGlobals[l]; impurepotionRecipeLVLIs[l].EditorID = "impurepotionRecipeList" + l; impurepotionRecipeLVLIentriesdata[l].Reference = impurepotionRecipeLVLIs[l].FormKey; impurepotionRecipeLVLIentriesdata[l].Level = 1; impurepotionRecipeLVLIentriesdata[l].Count = 1; } Console.WriteLine("Splitting potions into lists (" + potionRecipeListCount + " " + poisonRecipeListCount + " " + impurepotionRecipeListCount + ")"); uint potionIndex = 0, poisonIndex = 0, impurepotionIndex = 0; Dictionary <String, int> nameCache = new Dictionary <String, int>(); foreach (IngrCombination ic in combinations) { if (i % percent == 0) { Console.WriteLine(i + " out of " + combinations.Count + " recipes created."); } IBook newRecipe = noteTemplate.DeepCopy(); newRecipe.FormKey = state.PatchMod.GetNextFormKey(); String prefix = "[Potion]"; if (ic.Type == 1) { prefix = "[Poison]"; } if (ic.Type == 2) { prefix = "[Impure Potion]"; } newRecipe.Description = prefix + ic.RecipeName; newRecipe.Name = ic.RecipeName; newRecipe.BookText = ic.PotionString; newRecipe.Weight = recipeWeight; newRecipe.Value = recipeValue; String?name = "recipeof"; foreach (String?s in ic.MyEffects !) { name += s; } name = name.Replace(" ", String.Empty); int nameIndex = 0; if (nameCache.TryGetValue(name, out nameIndex)) { nameCache[name] = nameIndex + 1; name = name + nameCache[name]; } else { nameCache.Add(name, 0); name = name + "0"; } newRecipe.EditorID = name; /* Add ingredients to CACO learning recipe script */ if (state.LoadOrder.ContainsKey(ModKey.FromNameAndExtension("Complete Alchemy & Cooking Overhaul.esp"))) { String[] s = (from scriptentry in newRecipe.VirtualMachineAdapter?.Scripts where scriptentry.Name.Equals("CACO_AlchemyRecipeScript") select scriptentry.Name).ToArray(); if (s.Length < 1 && learnEffectsFromRecipe)//For adding recipe to a brand new item (not a copy of a vanilla recipe) { ScriptEntry cacoscript = new ScriptEntry(); cacoscript.Name = "CACO_AlchemyRecipeScript"; newRecipe.VirtualMachineAdapter?.Scripts.Add(cacoscript); } if (newRecipe.VirtualMachineAdapter?.Scripts != null)//For modiying a copy of a vanilla recipe modified by CACO(default) { foreach (ScriptEntry se in newRecipe.VirtualMachineAdapter?.Scripts !) { if (se == null) { continue; } if (se.Name.Equals("CACO_AlchemyRecipeScript")) { if (!learnEffectsFromRecipe) { newRecipe.VirtualMachineAdapter?.Scripts?.Remove(se); continue; } int[,] ingrEffectIndex = new int[3, 4]; for (int j = 0; j < ingrEffectIndex.GetLength(0); j++) { for (int k = 0; k < ingrEffectIndex.GetLength(1); k++) { ingrEffectIndex[j, k] = -1; } } for (int j = 0; j < ic.MyIngrs.Length; j++) { int offset = 0; for (int k = 0; k < ic.MyIngrs[j].Effects.Count; k++) { foreach (String mgefname in ic.MyEffects) { state.LinkCache.TryResolve <IMagicEffectGetter>(ic.MyIngrs[j].Effects[k].BaseEffect.FormKey, out var mgeffect); if (mgeffect?.Name?.String?.Equals(mgefname) ?? true) { ingrEffectIndex[j, offset++] = k; } } } } bool[,] exists = new bool[3, 4]; bool[] rexists = new bool[3]; bool trexist = false, nvarexist = false, arrexist = false; foreach (ScriptProperty sp in se.Properties)//Scan CACO learning script properties { switch (sp.Name) { case "ThisRecipe": sp.Flags = ScriptProperty.Flag.Edited; ((ScriptObjectProperty)sp).Object = new FormLink <ISkyrimMajorRecordGetter>(newRecipe.FormKey); trexist = true; break; case "NoValueAfterRead": sp.Flags = ScriptProperty.Flag.Edited; ((ScriptBoolProperty)sp).Data = hasValueAfterRead; nvarexist = true; break; case "CACO_AlchemyRecipesRead": arrexist = true; break; } for (int j = 0; j < 3; j++) { if (sp.Name.Equals("Ingredient0" + (j + 1))) { if (ic.MyIngrs.Length > j) { sp.Flags = ScriptProperty.Flag.Edited; ((ScriptObjectProperty)sp).Object = new FormLink <ISkyrimMajorRecordGetter>(ic.MyIngrs[j].FormKey); rexists[j] = true; } } } for (int j = 0; j < 3; j++) { for (int k = 0; k < 4; k++) { if (sp.Name.Equals("Ingredient0" + (j + 1) + "Effect" + (k + 1))) { if (ingrEffectIndex[j, k] != -1) { ((ScriptIntProperty)sp).Data = ingrEffectIndex[j, k]; exists[j, k] = true; } } } } } for (int j = 0; j < rexists.Length; j++) { if (ic.MyIngrs.Length > j) { if (!rexists[j]) { ScriptObjectProperty sop = new ScriptObjectProperty(); sop.Object = new FormLink <ISkyrimMajorRecordGetter>(ic.MyIngrs[j].FormKey); sop.Name = "Ingredient0" + (j + 1); sop.Flags = ScriptProperty.Flag.Edited; se.Properties.Add(sop); } } } for (int j = 0; j < exists.GetLength(0); j++) { for (int k = 0; k < exists.GetLength(1); k++) { if (ic.MyIngrs.Length > j) { if (!exists[j, k] && ingrEffectIndex[j, k] != -1) { ScriptIntProperty sip = new ScriptIntProperty(); sip.Data = ingrEffectIndex[j, k]; sip.Name = "Ingredient0" + (j + 1) + "Effect" + (k + 1); sip.Flags = ScriptProperty.Flag.Edited; se.Properties.Add(sip); } } } } if (!trexist) { ScriptObjectProperty sop = new ScriptObjectProperty(); sop.Object = new FormLink <ISkyrimMajorRecordGetter>(newRecipe.FormKey); sop.Name = "ThisRecipe"; sop.Flags = ScriptProperty.Flag.Edited; se.Properties.Add(sop); } if (!nvarexist) { ScriptBoolProperty sbp = new ScriptBoolProperty(); sbp.Data = hasValueAfterRead; sbp.Name = "NoValueAfterRead"; sbp.Flags = ScriptProperty.Flag.Edited; se.Properties.Add(sbp); } if (arrexist) { FormList fl = new FormList(new FormKey(new ModKey("Complete Alchemy & Cooking Overhaul.esp", ModType.Plugin), 0xA2C667), SkyrimRelease.SkyrimSE); ScriptObjectProperty sop = new ScriptObjectProperty(); sop.Object = fl; sop.Name = "CACO_AlchemyRecipesRead"; sop.Flags = ScriptProperty.Flag.Edited; se.Properties.Add(sop); } } } } } state.PatchMod.Books.Set((Book)newRecipe); LeveledItemEntry lie = new LeveledItemEntry(); LeveledItemEntryData data = new LeveledItemEntryData(); data.Level = 1; data.Count = 1; data.Reference = new FormLink <IItemGetter>(newRecipe.FormKey); lie.Data = data; switch (ic.Type) { case 0: potionRecipeLVLIentriesdata[potionIndex / 128].Reference = potionRecipeLVLIs[potionIndex / 128].FormKey; potionRecipeLVLIentries[potionIndex / 128].Data = potionRecipeLVLIentriesdata[potionIndex / 128]; potionRecipeLVLIs[potionIndex / 128].Entries?.Add(lie); potionIndex++; break; case 1: poisonRecipeLVLIentriesdata[poisonIndex / 128].Reference = poisonRecipeLVLIs[poisonIndex / 128].FormKey; poisonRecipeLVLIentries[poisonIndex / 128].Data = poisonRecipeLVLIentriesdata[poisonIndex / 128]; poisonRecipeLVLIs[poisonIndex / 128].Entries?.Add(lie); poisonIndex++; break; case 2: impurepotionRecipeLVLIentriesdata[impurepotionIndex / 128].Reference = impurepotionRecipeLVLIs[impurepotionIndex / 128].FormKey; impurepotionRecipeLVLIentries[impurepotionIndex / 128].Data = impurepotionRecipeLVLIentriesdata[impurepotionIndex / 128]; impurepotionRecipeLVLIs[impurepotionIndex / 128].Entries?.Add(lie); impurepotionIndex++; break; } i++; } Console.WriteLine("Linking recipes to potion leveled list"); IEnumerable <ILeveledItemGetter> lvlilists = from list in state.LoadOrder.PriorityOrder.OnlyEnabled().LeveledItem().WinningOverrides() where list.EditorID?.Equals("LItemPotionAll") ?? true select list; ILeveledItemGetter allList = lvlilists.ToList()[0]; LeveledItem modifiedList = state.PatchMod.LeveledItems.GetOrAddAsOverride(allList); potionIndex = 0; poisonIndex = 0; impurepotionIndex = 0; for (int l = 0; l < masterpotionRecipeListCount; l++) { masterpotionRecipeLVLIentriesdata[l].Reference = masterpotionRecipeLVLIs[l].FormKey; masterpotionRecipeLVLIentries[l].Data = masterpotionRecipeLVLIentriesdata[l]; for (int k = 0; k < 128; k++) { if (potionIndex < potionRecipeLVLIentries.Length) { masterpotionRecipeLVLIs[l].Entries?.Add(potionRecipeLVLIentries[potionIndex++]); } else if (poisonIndex < poisonRecipeLVLIentries.Length) { masterpotionRecipeLVLIs[l].Entries?.Add(poisonRecipeLVLIentries[poisonIndex++]); } else if (impurepotionIndex < impurepotionRecipeLVLIentries.Length) { masterpotionRecipeLVLIs[l].Entries?.Add(impurepotionRecipeLVLIentries[impurepotionIndex++]); } else { break; } } mainpotionRecipeLVLI.Entries?.Add(masterpotionRecipeLVLIentries[l]); } foreach (LeveledItem li in potionRecipeLVLIs) { state.PatchMod.LeveledItems.Set(li); } foreach (LeveledItem li in poisonRecipeLVLIs) { state.PatchMod.LeveledItems.Set(li); } foreach (LeveledItem li in impurepotionRecipeLVLIs) { state.PatchMod.LeveledItems.Set(li); } foreach (LeveledItem li in masterpotionRecipeLVLIs) { state.PatchMod.LeveledItems.Set(li); } mainpotionRecipeLVLIentrydata.Reference = mainpotionRecipeLVLI.FormKey; mainpotionRecipeLVLIentry.Data = mainpotionRecipeLVLIentrydata; mainpotionRecipeLVLIentrydata.Count = 1; mainpotionRecipeLVLIentrydata.Level = 1; modifiedList.Entries?.Add(mainpotionRecipeLVLIentry); state.PatchMod.LeveledItems.Set(mainpotionRecipeLVLI); Console.WriteLine("Adding recipes to defined containers"); IEnumerable <IContainerGetter> chests = from list in state.LoadOrder.PriorityOrder.OnlyEnabled().Container().WinningOverrides() where containerEditorIDs?.ToList().Contains(list.EditorID !) ?? true select list; ContainerEntry potionListContainerEntry = new ContainerEntry(); ContainerItem potionListContainerItem = new ContainerItem(); potionListContainerItem.Item = mainpotionRecipeLVLI.FormKey; potionListContainerItem.Count = 1; potionListContainerEntry.Item = potionListContainerItem; foreach (IContainerGetter chest in chests) { Container rChest = state.PatchMod.Containers.GetOrAddAsOverride(chest); rChest.Items?.Add(potionListContainerEntry); } }