private void iInstallListsLookups(SPList list, XmlNode ndList, int parentMessageId) { if (ndList == null) { throw new ArgumentNullException(nameof(ndList)); } var ndParent = ndList.ParentNode; var ndLookups = ndList.SelectSingleNode("Lookups"); if (ndLookups != null) { parentMessageId = addMessage(0, bVerifyOnly ? "Checking Lookups" : "Fixing Lookups", string.Empty, parentMessageId); foreach (XmlNode ndLookup in ndLookups.SelectNodes("Lookup")) { var internalName = ApplicationInstallerHelpers.getAttribute(ndLookup, "InternalName"); try { ProcessNode(list, parentMessageId, ndParent, ndLookup, internalName); } catch (Exception ex) { addMessage(ErrorLevels.Error, internalName, "Error processing: " + ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } } } }
private void InstallListsViews(SPList list, int parentMessageId, XmlNode nodeView, string name) { if (list == null) { throw new ArgumentNullException(nameof(list)); } if (nodeView == null) { throw new ArgumentNullException(nameof(nodeView)); } var fields = new StringCollection(); fields.AddRange(nodeView.SelectSingleNode(Fields).InnerText.Split(SeparatorComma)); var query = ApplicationInstallerHelpers.getChildNodeText(nodeView, Query); var projectedFields = ApplicationInstallerHelpers.getChildNodeText(nodeView, ProjectedFields); var joins = ApplicationInstallerHelpers.getChildNodeText(nodeView, Joins); uint rowLimit; uint.TryParse(ApplicationInstallerHelpers.getAttribute(nodeView, RowLimit), out rowLimit); bool isDefault; bool.TryParse(ApplicationInstallerHelpers.getAttribute(nodeView, MakeDefault), out isDefault); list.Views.Add(name, fields, query, joins, projectedFields, rowLimit, false, isDefault, SPViewCollection.SPViewType.Html, false); addMessage(0, name, string.Empty, parentMessageId); }
private void iInstallListsWorkflowsInstall(SPList oList, string sName, string sDisplayName, SPList oTaskList, SPList oHistoryList, XmlNode ndWorkflow) { SPWorkflowAssociation assocation = null; var bAllowManual = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndWorkflow, "AllowManual"), out bAllowManual); var bStartOnCreate = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndWorkflow, "StartOnCreate"), out bStartOnCreate); var bStartOnChange = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndWorkflow, "StartOnChange"), out bStartOnChange); foreach (SPWorkflowTemplate template in oWeb.WorkflowTemplates) { if (template.Name == sName) { assocation = SPWorkflowAssociation.CreateListAssociation(template, sDisplayName, oTaskList, oHistoryList); break; } } if (assocation != null) { assocation.AllowManual = bAllowManual; assocation.AutoStartChange = bStartOnChange; assocation.AutoStartCreate = bStartOnCreate; oList.WorkflowAssociations.Add(assocation); } }
private void iInstallListsEvents(SPList list, XmlNode ndList, int ParentMessageId, bool added) { var ndEventHandlers = ndList.SelectSingleNode("EventHandlers"); if (ndEventHandlers != null) { if (bVerifyOnly) { ParentMessageId = addMessage(0, "Checking Event Handlers", string.Empty, ParentMessageId); } else { ParentMessageId = addMessage(0, "Installing Event Handlers", string.Empty, ParentMessageId); } var ndParent = ndList.ParentNode; foreach (XmlNode ndEventHandler in ndEventHandlers.SelectNodes("EventHandler")) { var sType = ApplicationInstallerHelpers.getAttribute(ndEventHandler, "Type"); var sAssembly = ApplicationInstallerHelpers.getAttribute(ndEventHandler, "Assembly"); var sClass = ApplicationInstallerHelpers.getAttribute(ndEventHandler, "Class"); var oType = CoreFunctions.iGetListEventType(sType); if (oType != SPEventReceiverType.InvalidReceiver) { if (bVerifyOnly) { addMessage(0, sType + "(" + sClass + ")", string.Empty, ParentMessageId); } else { var found = false; foreach (SPEventReceiverDefinition oRecDef in list.EventReceivers) { if (oRecDef.Type == oType && oRecDef.Assembly.ToLower() == sAssembly.ToLower() && oRecDef.Class.ToLower() == oRecDef.Class.ToLower()) { found = true; addMessage(ErrorLevels.Upgrade, sType + "(" + sClass + ")", "Event found, skipped", ParentMessageId); break; } } if (!found) { list.EventReceivers.Add(oType, sAssembly, sClass); addMessage(0, sType + "(" + sClass + ")", string.Empty, ParentMessageId); } } } else { addMessage(ErrorLevels.Error, sType + "(" + sClass + ")", "Invalid receiver type", ParentMessageId); } } } }
private void ProcessNode(SPList list, int parentMessageId, XmlNode ndParent, XmlNode ndLookup, string internalName) { if (list == null) { throw new ArgumentNullException(nameof(list)); } var listValue = ApplicationInstallerHelpers.getAttribute(ndLookup, "List"); var field = ApplicationInstallerHelpers.getAttribute(ndLookup, "Field"); var displayName = ApplicationInstallerHelpers.getAttribute(ndLookup, "DisplayName"); var advancedLookup = ApplicationInstallerHelpers.getAttribute(ndLookup, "AdvancedLookup"); bool overwrite; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndLookup, "Overwrite"), out overwrite); bool required; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndLookup, "Required"), out required); bool deleteIfNoList; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndLookup, "DeleteIfNoList"), out deleteIfNoList); var tList = oWeb.Lists.TryGetList(listValue); SPField spField = null; try { spField = list.Fields.GetFieldByInternalName(internalName); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } if (tList != null) { int messageId; if (spField == null) { messageId = AddField(list, parentMessageId, internalName, field, displayName, required, tList.ID); } else { messageId = FieldExist(parentMessageId, internalName, field, overwrite, tList.ID.ToString("B"), spField); } if (!string.IsNullOrEmpty(advancedLookup)) { SaveGridGantSettings(list, internalName, advancedLookup, messageId); } } else { ParentListIsNotFound(list, parentMessageId, ndParent, internalName, listValue, deleteIfNoList, spField); } }
private void InstallProperty( int parentMessageId, XmlNode propertyNode, string propertyName, string propertyValue, bool overWrite, bool isLockWeb) { if (oWeb.Properties.ContainsKey(propertyName)) { var separator = GetSeparator(propertyNode); var duplicateRegEx = ApplicationInstallerHelpers.getAttribute(propertyNode, "DuplicateRegEx"); var curProp = iInstallPropertiesGet(propertyName, isLockWeb); if (separator == '\r') { curProp = curProp.Replace("\r\n", "\r"); } var currentValues = curProp.Split(separator); if (string.IsNullOrWhiteSpace(duplicateRegEx)) { duplicateRegEx = propertyValue; } var found = GetFound(duplicateRegEx, currentValues); if (found) { InstallProperty( parentMessageId, propertyName, propertyValue, overWrite, isLockWeb, separator, duplicateRegEx, currentValues); } else { InstallProperty(parentMessageId, propertyName, propertyValue, isLockWeb, separator); } } else { if (!bVerifyOnly) { iInstallPropertiesSet(propertyName, propertyValue, isLockWeb); } addMessage(ErrorLevels.NoError, propertyName, string.Empty, parentMessageId); } }
private void InstallListsViews(SPList list, int parentMessageId, XmlNode nodeView, string name, SPView view) { if (list == null) { throw new ArgumentNullException(nameof(list)); } if (nodeView == null) { throw new ArgumentNullException(nameof(nodeView)); } if (view == null) { throw new ArgumentNullException(nameof(view)); } var fields = nodeView.SelectSingleNode(Fields).InnerText.Split(SeparatorComma); var query = ApplicationInstallerHelpers.getChildNodeText(nodeView, Query); var projectedFields = ApplicationInstallerHelpers.getChildNodeText(nodeView, ProjectedFields); var joins = ApplicationInstallerHelpers.getChildNodeText(nodeView, Joins); uint iRowLimit = 0; uint.TryParse(ApplicationInstallerHelpers.getAttribute(nodeView, RowLimit), out iRowLimit); var bDefault = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(nodeView, MakeDefault), out bDefault); view.ViewFields.DeleteAll(); foreach (var sField in fields) { SPField oField = null; try { oField = list.Fields.GetFieldByInternalName(sField); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } if (oField != null) { view.ViewFields.Add(oField); } } view.Query = query; view.ProjectedFields = projectedFields; view.Joins = joins; view.RowLimit = iRowLimit; view.DefaultView = bDefault; view.Update(); addMessage(ErrorLevels.Upgrade, name, "View exists and will overwrite", parentMessageId); }
private void InstallProperties() { var webNode = appDef.ApplicationXml.FirstChild.SelectSingleNode("Web"); if (webNode != null) { var propertyNodes = webNode.SelectSingleNode("Properties"); if (propertyNodes != null) { var parentMessageId = 0; parentMessageId = addMessage(0, bVerifyOnly ? "Checking Properties" : "Installing Properties", string.Empty, 0); var listProperties = propertyNodes.SelectNodes("Property"); float max = listProperties.Count; float counter = 0; foreach (XmlNode propertyNode in listProperties) { try { var propertyName = propertyNode.Attributes["Name"].Value; var propertyValue = propertyNode.Attributes["Value"].Value; bool append; bool overWrite; bool isLockWeb; bool.TryParse(ApplicationInstallerHelpers.getAttribute(propertyNode, "Append"), out append); bool.TryParse(ApplicationInstallerHelpers.getAttribute(propertyNode, "Overwrite"), out overWrite); bool.TryParse(ApplicationInstallerHelpers.getAttribute(propertyNode, "LockWebProperty"), out isLockWeb); if (append) { InstallProperty(parentMessageId, propertyNode, propertyName, propertyValue, overWrite, isLockWeb); } else { InstallProperty(parentMessageId, propertyName, propertyValue, overWrite, isLockWeb); } } catch (Exception ex) { addMessage(ErrorLevels.Error, propertyNode.Attributes["Name"].Value, ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } counter++; var percent = counter / max; updateLIPercent(percent); } } } }
private void InstallFeatures( int ParentMessageId, IDictionary <Guid, SPFeatureDefinition> ArrInstalledSiteFeatures14, IDictionary <Guid, SPFeatureDefinition> ArrInstalledFarmFeatures14, IDictionary <Guid, SPFeatureDefinition> ArrInstalledSiteFeatures15, IDictionary <Guid, SPFeatureDefinition> ArrInstalledFarmFeatures15, XmlNode ndFeature, string FeatureId, string sFeatureName) { var included = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndFeature, "IncludedInSolutions"), out included); var featureId = new Guid(FeatureId); if (ArrInstalledFarmFeatures15.ContainsKey(featureId)) { var def = ArrInstalledFarmFeatures15[featureId]; iInstallFeature(featureId, def, SPFeatureDefinitionScope.Farm, ParentMessageId); } else if (ArrInstalledFarmFeatures14.ContainsKey(featureId)) { var def = ArrInstalledFarmFeatures14[featureId]; iInstallFeature(featureId, def, SPFeatureDefinitionScope.Farm, ParentMessageId); } else if (ArrInstalledSiteFeatures15.ContainsKey(featureId)) { var def = ArrInstalledSiteFeatures15[featureId]; iInstallFeature(featureId, def, SPFeatureDefinitionScope.Site, ParentMessageId); } else if (ArrInstalledSiteFeatures14.ContainsKey(featureId)) { var def = ArrInstalledSiteFeatures14[featureId]; iInstallFeature(featureId, def, SPFeatureDefinitionScope.Site, ParentMessageId); } else { if (included && bVerifyOnly) { addMessage(ErrorLevels.NoError, sFeatureName == string.Empty ? FeatureId : sFeatureName, string.Empty, ParentMessageId); } else { addMessage(ErrorLevels.Error, sFeatureName == string.Empty ? FeatureId : sFeatureName, "Feature Not Installed on Farm", ParentMessageId); } } }
private void ProcessField(SPList list, int parentMessageId, XmlNode ndField) { if (list == null) { throw new ArgumentNullException(nameof(list)); } if (ndField == null) { throw new ArgumentNullException(nameof(ndField)); } var internalName = ApplicationInstallerHelpers.getAttribute(ndField, "InternalName"); var internalFieldXml = ndField.SelectSingleNode("Field"); var typeValue = ApplicationInstallerHelpers.getAttribute(internalFieldXml, "Type"); bool overwrite; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndField, "Overwrite"), out overwrite); var total = ApplicationInstallerHelpers.getAttribute(ndField, "Total"); SPField spField = null; try { spField = list.Fields.GetFieldByInternalName(internalName); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } if (spField == null) { FieldNewLetsAdd(list, parentMessageId, internalName, internalFieldXml, typeValue); } else { FieldExistsSoWeCanUpgrade( list, parentMessageId, internalName, internalFieldXml, typeValue, overwrite, spField); } if (!string.IsNullOrEmpty(total)) { SaveGridGanttSettings(list, internalName, total); } }
private void InstallFilesProcessFolder(int parentMessageId, float counter, float max, AppStore appCopy, bool overwrite, XmlNode ndLists, XmlNode ndChild, string sType, string fullFile, string fileName, string parentFolder) { if (sType == "1") { var spFolder = oWeb.GetFolder(fullFile); var id = parentMessageId; var bProcessFolder = false; if (!spFolder.Exists) { InstallFilesProcessFolder(parentMessageId, ndLists, fullFile, fileName, out id, out bProcessFolder); } else { InstallFilesProcessFolder(parentMessageId, ndChild, fileName, out id, out bProcessFolder); } var overwriteFolder = overwrite; try { overwriteFolder = bool.Parse(ApplicationInstallerHelpers.getAttribute(ndChild, "Overwrite")); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } if (bProcessFolder) { InstallFilesProcessFolder(id, counter, ndChild, max, appCopy, overwriteFolder); } } else { var overWriteFile = false; try { overWriteFile = bool.Parse(ApplicationInstallerHelpers.getAttribute(ndChild, "Overwrite")); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } InstallFile(parentMessageId, appCopy, overwrite, ndChild, fullFile, fileName, parentFolder, overWriteFile); } }
private void iInstallListsViewsWebparts(SPList oList, XmlNode ndList, int ParentMessageId, bool added) { var ndViews = ndList.SelectSingleNode("Views"); if (ndViews != null) { var storeurl = CoreFunctions.getFarmSetting("workenginestore"); ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; var copy = new AppStore(); copy.Credentials = CoreFunctions.GetStoreCreds(); copy.Url = storeurl + "_vti_bin/appstore.asmx"; if (bVerifyOnly) { ParentMessageId = addMessage(0, "Checking WebParts", string.Empty, ParentMessageId); } else { ParentMessageId = addMessage(0, "Updating WebParts", string.Empty, ParentMessageId); } var bInstallAll = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndViews, "InstallGridOnAllViews"), out bInstallAll); if (bInstallAll) { addMessage(0, "Grid on All Views", string.Empty, ParentMessageId); } if (oList != null) { foreach (SPView oView in oList.Views) { if (!oView.PersonalView) { var ndView = ndViews.SelectSingleNode("View[@Name='" + oView.Title + "']"); InstallListsViewsWebPartsInstall(oView, bInstallAll, copy, ParentMessageId); } } } } }
private void InstallFile(int parentMessageId, AppStore appCopy, bool overwrite, XmlNode ndChild, string fullFile, string fileName, string parentFolder, bool overWriteFile) { var spFille = oWeb.GetFile(ApplicationInstallerHelpers.getAttribute(ndChild, "FullFile")); if (spFille.Exists) { if (overwrite || overWriteFile) { try { if (!bVerifyOnly) { iInstallFile(fileName, parentFolder, fullFile, appCopy); } addMessage(ErrorLevels.NoError, "File: " + fileName, string.Empty, parentMessageId); } catch (Exception ex) { addMessage(ErrorLevels.Error, "File: " + fileName, "Error: " + ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } } else { addMessage(ErrorLevels.Warning, "File: " + fileName, "File exists and can't overwrite", parentMessageId); } } else { try { if (!bVerifyOnly) { iInstallFile(fileName, parentFolder, fullFile, appCopy); } addMessage(ErrorLevels.NoError, "File: " + fileName, string.Empty, parentMessageId); } catch (Exception ex) { addMessage(ErrorLevels.Error, "File: " + fileName, "Error: " + ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } } }
private SPList iInstallListsAddList(XmlNode ndList, out string error) { error = string.Empty; SPList list = null; try { var sFileName = ApplicationInstallerHelpers.getAttribute(ndList, "FileName"); var sTemplate = ApplicationInstallerHelpers.getAttribute(ndList, "Template"); var sListName = ApplicationInstallerHelpers.getAttribute(ndList, "Name"); var sDescription = ApplicationInstallerHelpers.getAttribute(ndList, "Description"); var lists = (SPDocumentLibrary)oWeb.Site.GetCatalog(SPListTemplateType.ListTemplateCatalog); if (sFileName != string.Empty) { foreach (SPListTemplate template in oWeb.Site.GetCustomListTemplates(oWeb)) { if (template.InternalName == sFileName) { var gList = oWeb.Lists.Add(sListName, sDescription, template); list = oWeb.Lists[gList]; break; } } } else if (sTemplate != string.Empty) { var gList = oWeb.Lists.Add(sListName, sDescription, ApplicationInstallerHelpers.GetTemplateType(sTemplate)); list = oWeb.Lists[gList]; } else { error = "List FileName or Template property not found"; } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); error = "Error: " + ex.Message; } return(list); }
private static char GetSeparator(XmlNode propertyNode) { var separator = ApplicationInstallerHelpers.getAttribute(propertyNode, Seperator)[0]; if (ApplicationInstallerHelpers.getAttribute(propertyNode, Seperator) == "\\n") { separator = '\n'; } if (ApplicationInstallerHelpers.getAttribute(propertyNode, Seperator) == "\\r") { separator = '\r'; } if (separator == '\0') { separator = ','; } return(separator); }
private void InstallFilesProcessFolder(int parentMessageId, float counter, XmlNode ndFolder, float max, AppStore appCopy, bool overwrite) { if (ndFolder == null) { throw new ArgumentNullException(nameof(ndFolder)); } var ndLists = appDef.ApplicationXml.FirstChild.SelectSingleNode("Lists"); foreach (XmlNode ndChild in ndFolder.ChildNodes) { var remoteName = ApplicationInstallerHelpers.getAttribute(ndChild, "RemoteFile"); var sType = ApplicationInstallerHelpers.getAttribute(ndChild, "Type"); var fullFile = remoteName.Replace(appDef.appurl + "/Files/", string.Empty); var fileName = ApplicationInstallerHelpers.getAttribute(ndChild, "Name"); var parentFolder = Path.GetDirectoryName(fullFile).Replace("\\", "/"); try { var bSkipReports = fileName == "Report Library" && oWeb.ID != oWeb.Site.RootWeb.ID; if (bSkipReports) { addMessage(ErrorLevels.NoError, "Folder: Report Library", "Report Library will not be processed at web level", parentMessageId); } else { InstallFilesProcessFolder(parentMessageId, counter, max, appCopy, overwrite, ndLists, ndChild, sType, fullFile, fileName, parentFolder); } } catch (Exception ex) { addMessage(ErrorLevels.Error, fileName, "Error: " + ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } counter++; var percent = counter / max; updateLIPercent(percent); } }
private void InstallListsViews(SPList list, XmlNode nodeList, int parentMessageId) { var nodeViews = nodeList.SelectSingleNode("Views"); if (nodeViews != null) { parentMessageId = addMessage(0, bVerifyOnly ? "Checking Views" : "Updating Views", string.Empty, parentMessageId); foreach (XmlNode nodeView in nodeViews.SelectNodes("View")) { var name = ApplicationInstallerHelpers.getAttribute(nodeView, "Name"); bool overWrite; bool.TryParse(ApplicationInstallerHelpers.getAttribute(nodeView, "Overwrite"), out overWrite); SPView view = null; try { view = list.Views[name]; } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } if (bVerifyOnly) { AddMessage(parentMessageId, name, overWrite, view); } else { InstallListsViews(list, parentMessageId, nodeView, name, overWrite, view); } } } }
private void InstallLists() { var ndLists = appDef.ApplicationXml.FirstChild.SelectSingleNode("Lists"); if (ndLists != null) { var parentMessageId = 0; if (bVerifyOnly) { parentMessageId = addMessage(0, "Checking Lists", string.Empty, 0); } else { parentMessageId = addMessage(0, "Installing Lists", string.Empty, 0); } var listNdLists = ndLists.SelectNodes("List"); float max = listNdLists.Count; float counter = 0; foreach (XmlNode ndList in listNdLists) { try { var sListName = ndList.Attributes["Name"].Value; var bCanUpgrade = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndList, "CanUpgrade"), out bCanUpgrade); var bAddReporting = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndList, "Reporting"), out bAddReporting); var bDoesListExist = DoesListExist(sListName); if (bDoesListExist) { var attrNoDelete = ndList.Attributes["NoDelete"]; if (attrNoDelete == null) { attrNoDelete = ndList.OwnerDocument.CreateAttribute("NoDelete"); attrNoDelete.Value = "True"; ndList.Attributes.Append(attrNoDelete); } else { attrNoDelete.Value = "True"; } } if (bDoesListExist && bCanUpgrade || !bDoesListExist) { InstallLists(parentMessageId, ndList, sListName, bCanUpgrade, bAddReporting, bDoesListExist); } else { addMessage(ErrorLevels.Error, sListName, "List exists and cannot upgrade", parentMessageId); } } catch (Exception ex) { addMessage(ErrorLevels.Error, ndList.Attributes["Name"].Value, "Error: " + ex.Message, parentMessageId); Trace.WriteLine(ex.ToString()); } counter++; var percent = counter / max; updateLIPercent(percent); } } }
private void InstallFeatures() { var ndFeatures = appDef.ApplicationXml.FirstChild.SelectSingleNode("Features"); if (ndFeatures != null) { var ParentMessageId = 0; if (bVerifyOnly) { ParentMessageId = addMessage(0, "Checking Features", string.Empty, 0); } else { ParentMessageId = addMessage(0, "Installing Features", string.Empty, 0); } float percent = 0; var ListNdFeatures = ndFeatures.SelectNodes("Feature"); float max = ListNdFeatures.Count; float counter = 0; var ArrInstalledSiteFeatures14 = new Dictionary <Guid, SPFeatureDefinition>(); var ArrInstalledFarmFeatures14 = new Dictionary <Guid, SPFeatureDefinition>(); var ArrInstalledSiteFeatures15 = new Dictionary <Guid, SPFeatureDefinition>(); var ArrInstalledFarmFeatures15 = new Dictionary <Guid, SPFeatureDefinition>(); SPSecurity.RunWithElevatedPrivileges(delegate { using (var site = new SPSite(oWeb.Site.ID)) { foreach (var def in site.WebApplication.Farm.FeatureDefinitions) { if (def.CompatibilityLevel == 14) { ArrInstalledFarmFeatures14.Add(def.Id, def); } else { ArrInstalledFarmFeatures15.Add(def.Id, def); } } foreach (var def in site.FeatureDefinitions) { if (def.CompatibilityLevel == 14) { ArrInstalledSiteFeatures14.Add(def.Id, def); } else { ArrInstalledSiteFeatures15.Add(def.Id, def); } } } }); foreach (XmlNode ndFeature in ListNdFeatures) { var FeatureId = ApplicationInstallerHelpers.getAttribute(ndFeature, "ID"); var sFeatureName = ApplicationInstallerHelpers.getAttribute(ndFeature, "Name"); if (FeatureId != string.Empty) { try { InstallFeatures(ParentMessageId, ArrInstalledSiteFeatures14, ArrInstalledFarmFeatures14, ArrInstalledSiteFeatures15, ArrInstalledFarmFeatures15, ndFeature, FeatureId, sFeatureName); } catch (Exception ex) { addMessage(ErrorLevels.Error, sFeatureName == string.Empty ? FeatureId : sFeatureName, "Error: " + ex.Message, ParentMessageId); } } counter++; percent = counter / max; updateLIPercent(percent); } } }
private void iInstallListsWorkflows(SPList list, XmlNode ndList, int ParentMessageId, bool added) { var ndWorkflows = ndList.SelectSingleNode("Workflows"); if (ndWorkflows != null) { if (bVerifyOnly) { ParentMessageId = addMessage(0, "Checking Workflows", string.Empty, ParentMessageId); } else { ParentMessageId = addMessage(0, "Updating Workflows", string.Empty, ParentMessageId); } var ndParent = ndList.ParentNode; foreach (XmlNode ndWorkflow in ndWorkflows.SelectNodes("Workflow")) { var sName = ApplicationInstallerHelpers.getAttribute(ndWorkflow, "Name"); var sDisplayName = ApplicationInstallerHelpers.getAttribute(ndWorkflow, "DisplayName"); if (sDisplayName == string.Empty) { sDisplayName = sName; } if (sName != string.Empty) { try { var sTaskList = ApplicationInstallerHelpers.getAttribute(ndWorkflow, "TaskList"); if (sTaskList == string.Empty) { sTaskList = "Workflow Tasks"; } var sHistoryList = ApplicationInstallerHelpers.getAttribute(ndWorkflow, "HistoryList"); if (sHistoryList == string.Empty) { sHistoryList = "Workflow History"; } var bOverwrite = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndWorkflow, "Overwrite"), out bOverwrite); var oTaskList = oWeb.Lists.TryGetList(sTaskList); var oHistoryList = oWeb.Lists.TryGetList(sHistoryList); if (oTaskList != null || (IsListInstalledWithApplication(sTaskList) && bVerifyOnly)) { if (oHistoryList != null || (IsListInstalledWithApplication(sHistoryList) && bVerifyOnly)) { if (bVerifyOnly) { var found = false; if (list != null) { foreach (SPWorkflowAssociation association in list.WorkflowAssociations) { if (association.BaseTemplate.Name == sName) { found = true; break; } } } if (found && !bOverwrite) { addMessage(ErrorLevels.Error, sName, "Workflow found and cannot overwrite", ParentMessageId); } else if (found) { addMessage(ErrorLevels.Upgrade, sName, "Workflow found and will upgrade", ParentMessageId); } else { addMessage(ErrorLevels.NoError, sName, string.Empty, ParentMessageId); } } else { SPWorkflowAssociation association = null; var found = false; foreach (SPWorkflowAssociation oassociation in list.WorkflowAssociations) { if (oassociation.BaseTemplate.Name == sName) { association = oassociation; found = true; break; } } if (found && bOverwrite) { found = false; list.WorkflowAssociations.Remove(association); iInstallListsWorkflowsInstall(list, sName, sDisplayName, oTaskList, oHistoryList, ndWorkflow); addMessage(ErrorLevels.Upgrade, sName, "Workflow found and was upgraded", ParentMessageId); } else if (found) { addMessage(ErrorLevels.Error, sName, "Workflow found and could not overwrite", ParentMessageId); } else { iInstallListsWorkflowsInstall(list, sName, sDisplayName, oTaskList, oHistoryList, ndWorkflow); addMessage(ErrorLevels.NoError, sName, string.Empty, ParentMessageId); } } } else { addMessage(ErrorLevels.Error, sName, "Workflow history list (" + sHistoryList + ") does not exist", ParentMessageId); } } else { addMessage(ErrorLevels.Error, sName, "Workflow task list (" + sTaskList + ") does not exist", ParentMessageId); } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); addMessage(ErrorLevels.Error, sName, "Error: " + ex.Message, ParentMessageId); } } } } }
private void iInstallListTemplate(XmlNode ndSolution, int ParentMessageId) { try { var solutions = (SPDocumentLibrary)oWeb.Site.GetCatalog(SPListTemplateType.ListTemplateCatalog); var FileName = ApplicationInstallerHelpers.getAttribute(ndSolution, "FileName"); var bOverwrite = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndSolution, "Overwrite"), out bOverwrite); if (bVerifyOnly) { var found = false; foreach (SPFile f in solutions.RootFolder.Files) { if (f.Name == FileName) { found = true; } } if (found) { if (bOverwrite) { addMessage(ErrorLevels.Upgrade, FileName, "List template exists but will upgrade", ParentMessageId); } else { addMessage(ErrorLevels.Error, FileName, "List template exists and cannot upgrade", ParentMessageId); } } else { addMessage(ErrorLevels.NoError, FileName, string.Empty, ParentMessageId); } } else { var found = false; SPFile foundFile = null; foreach (SPFile f in solutions.RootFolder.Files) { if (f.Name == FileName) { foundFile = f; found = true; } } if (found && bOverwrite) { foundFile.Delete(); } if (!found || bOverwrite) { using (var webClient = new WebClient()) { webClient.Headers.Add(FBAHeader, FBAValue); ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); }; webClient.Credentials = CoreFunctions.GetStoreCreds(); byte[] fileBytes = null; fileBytes = webClient.DownloadData(appDef.fullurl + "/Lists/" + FileName); solutions.RootFolder.Files.Add(FileName, fileBytes); } if (found) { addMessage(ErrorLevels.NoError, FileName, "List template upgraded", ParentMessageId); } else { addMessage(ErrorLevels.NoError, FileName, string.Empty, ParentMessageId); } } else { addMessage(ErrorLevels.Error, FileName, "List template exists and cannot upgrade", ParentMessageId); } } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); addMessage(ErrorLevels.Error, ndSolution.Attributes["FileName"].Value, "Error: " + ex.Message, ParentMessageId); } }
private float iInstallNavigationItem(SPNavigationNodeCollection navNode, XmlNodeList ndParentItems, int ParentMessageId, XmlNode docFiles, float counter, float max, string navField, SPListItem oParentListItem, ref ArrayList arrNavNodes) { var iArrNodes = new ArrayList(); foreach (XmlNode nd in ndParentItems) { var sParentName = ApplicationInstallerHelpers.getAttribute(nd, "Name"); var sParentUrl = GetCleanUrl(ApplicationInstallerHelpers.getAttribute(nd, "Url")); var bParentExternal = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(nd, "External"), out bParentExternal); var bAppend = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(nd, "Append"), out bAppend); if (bParentExternal || DoesLocationExist(sParentUrl, ApplicationInstallerHelpers.getAttribute(nd, "Url"), ApplicationInstallerHelpers.getAttribute(nd, "List"), docFiles)) { var ndChildItems = nd.SelectNodes("Item"); try { SPNavigationNode oNewNav = null; if (!bVerifyOnly) { oNewNav = ApplicationInstallerHelpers.GetNavNode(navNode, navField, sParentName, oParentListItem); } if (!bVerifyOnly && oNewNav == null) { oNewNav = new SPNavigationNode(sParentName, sParentUrl, bParentExternal); navNode.AddAsLast(oNewNav); iArrNodes.Add(oNewNav.Id.ToString()); arrNavNodes.Add(oNewNav.Id + (iCommunity != 0 ? ":" + appDef.Id : string.Empty)); } var ParentNavMessageId = addMessage(ErrorLevels.NoError, sParentName, string.Empty, ParentMessageId); foreach (XmlNode ndChild in nd.SelectNodes("Item")) { var sChildName = ApplicationInstallerHelpers.getAttribute(ndChild, "Name"); try { var sChildUrl = GetCleanUrl(ApplicationInstallerHelpers.getAttribute(ndChild, "Url")); var bChildExternal = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndChild, "External"), out bChildExternal); if (bChildExternal || DoesLocationExist(sChildUrl, ApplicationInstallerHelpers.getAttribute(ndChild, "Url"), ApplicationInstallerHelpers.getAttribute(ndChild, "List"), docFiles)) { if (oNewNav != null) { var oNewChildNav = new SPNavigationNode(sChildName, GetCleanUrl(sChildUrl), bChildExternal); oNewNav.Children.AddAsLast(oNewChildNav); arrNavNodes.Add(oNewChildNav.Id + (iCommunity != 0 ? ":" + appDef.Id : string.Empty)); iArrNodes.Add(oNewChildNav.Id.ToString()); } addMessage(ErrorLevels.NoError, sChildName, string.Empty, ParentNavMessageId); } else { addMessage(ErrorLevels.Warning, sChildName, "Url Doesn't Exist (" + sChildUrl + ")", ParentNavMessageId); } } catch (Exception ex2) { Trace.WriteLine(ex2.ToString()); addMessage(ErrorLevels.Warning, sChildName, "Error: " + ex2.Message, ParentNavMessageId); } } if (oNewNav != null) { oNewNav.Update(); } } catch (Exception ex1) { Trace.WriteLine(ex1.ToString()); addMessage(ErrorLevels.Warning, sParentName, "Error: " + ex1.Message, ParentMessageId); } } else { addMessage(ErrorLevels.Warning, sParentName, "Url Doesn't Exist (" + sParentUrl + ")", ParentMessageId); } counter++; var percent = counter / max; updateLIPercent(percent); } if (!bVerifyOnly && oParentListItem != null) { try { if (oParentListItem[navField].ToString() != string.Empty) { var Navs = oParentListItem[navField].ToString().Split(','); iArrNodes.AddRange(Navs); } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } oParentListItem[navField] = string.Join(",", (string[])iArrNodes.ToArray(typeof(string))); oParentListItem.Update(); } return(counter); }