public SPListTemplate GetListTemplate(SPListTemplateCollection listTemplates, string templateName) { listTemplates.RequireNotNull("listTemplates"); templateName.RequireNotNullOrEmpty("templateName"); try { return listTemplates[templateName]; } catch (Exception exception) { LogUtility logUtility = new LogUtility(); logUtility.TraceDebugException("Can't find list template", GetType(), exception); return null; } }
/// <summary> /// The Byte array is the SLAM Configuration file /// </summary> /// <param name="webApplication"></param> /// <param name="connectionString"></param> /// <returns></returns> public Byte[] WriteSlamConfig(SPWebApplication webApplication, string connectionString) { webApplication.RequireNotNull("webApplication"); connectionString.RequireNotNullOrEmpty("connectionString"); Byte[] SLAMConfigData = null; LogUtility logUtlity = new LogUtility(); try { logUtlity.TraceDebugInformation("Writing SLAM Configuration now.", GetType()); SLAMConfigData = WriteSlamConfigImpl(webApplication, connectionString); } catch (Exception exception) { logUtlity.TraceDebugException("Error while writing SLAM configuration!", GetType(), exception); } finally { logUtlity.TraceDebugInformation("Finished writing SLAM Configuration now.", GetType()); } return SLAMConfigData; }
private byte[] WriteSlamConfigImpl(SPWebApplication webApplication, string connectionString) { LogUtility logUtlity = new LogUtility(); XDocument configurationFile = new XDocument(); XElement configuration = new XElement("Configuration"); configurationFile.Add(configuration); XElement connectionStrings = new XElement("ConnectionStrings"); configuration.Add(connectionStrings); XAttribute defaultAttribute = new XAttribute("Default", "SLAM"); connectionStrings.Add(defaultAttribute); connectionStrings.Add(new XElement("add", new XAttribute("Name", "SLAM"), new XAttribute("ConnectionString", connectionString) )); XElement dataMapping = new XElement("DataMapping", new XAttribute("DataSchema", "SLAM")); configuration.Add(dataMapping); SPWebApplication app = webApplication; if (null != app) { foreach (SPSite site in app.Sites) { try { AddConfigInfo(dataMapping, site); } catch (Exception exception) { logUtlity.TraceDebugException("Error trying to write Config information", GetType(), exception); } finally { site.Dispose(); } } Byte[] slamConfigData = null; using (MemoryStream stream = new MemoryStream()) { XmlWriter xmlWriter = XmlWriter.Create(stream); configurationFile.WriteTo(xmlWriter); xmlWriter.Close(); slamConfigData = stream.ToArray(); } logUtlity.TraceDebugInformation(string.Format("Writing {0} bytes of SLAM configuration data", slamConfigData.Length), GetType()); return slamConfigData; } else { logUtlity.TraceDebugInformation("Cannot find Web Application at http://localhost!", GetType()); } return null; }
private void SetFieldElements(XElement dataMapping, SPSite site, IEnumerable<SPField> fields, XElement contentTypeElement) { LogUtility logUtility = new LogUtility(); foreach (SPField field in fields) { XElement fieldElement = new XElement("Field", new XAttribute("Name", field.Title), new XAttribute("Required", field.Required) ); switch (field.Type) { case SPFieldType.Recurrence: fieldElement.Add(new XAttribute("SqlType", "bit"), new XAttribute("SPType", "Recurrence")); contentTypeElement.Add(fieldElement); break; case SPFieldType.AllDayEvent: fieldElement.Add(new XAttribute("SqlType", "bit"), new XAttribute("SPType", "AllDayEvent")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Boolean: fieldElement.Add(new XAttribute("SqlType", "bit"), new XAttribute("SPType", "Boolean")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Calculated: fieldElement.Add(new XAttribute("SqlType", "decimal"), new XAttribute("SPType", "Calculated")); contentTypeElement.Add(fieldElement); break; case SPFieldType.DateTime: fieldElement.Add(new XAttribute("SqlType", "datetime"), new XAttribute("SPType", "DateTime")); contentTypeElement.Add(fieldElement); break; case SPFieldType.MultiChoice: fieldElement.Add(new XAttribute("SqlType", "nvarchar(255)"), new XAttribute("SPType", "MultiChoice")); contentTypeElement.Add(fieldElement); break; case SPFieldType.GridChoice: fieldElement.Add(new XAttribute("SqlType", "nvarchar(255)"), new XAttribute("SPType", "GridChoice")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Choice: fieldElement.Add(new XAttribute("SqlType", "nvarchar(255)"), new XAttribute("SPType", "Choice")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Integer: fieldElement.Add(new XAttribute("SqlType", "int"), new XAttribute("SPType", "Integer")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Lookup: SPFieldLookup lookupField = field as SPFieldLookup; if (null != lookupField) { Guid webID = lookupField.LookupWebId; try { ProcessLookupLists(dataMapping, site, logUtility, fieldElement, lookupField, webID, contentTypeElement); } catch (Exception exception) { logUtility.TraceDebugException(string.Format("Caught exception trying to parse {0} field", field.Title), GetType(), exception); } } break; case SPFieldType.ModStat: fieldElement.Add(new XAttribute("SqlType", "int"), new XAttribute("SPType", "ModStat")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Currency: fieldElement.Add(new XAttribute("SqlType", "float"), new XAttribute("SPType", "Currency")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Number: fieldElement.Add(new XAttribute("SqlType", "float"), new XAttribute("SPType", "Number")); contentTypeElement.Add(fieldElement); break; case SPFieldType.URL: fieldElement.Add(new XAttribute("SqlType", "nvarchar(255)"), new XAttribute("SPType", "Url")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Note: fieldElement.Add(new XAttribute("SqlType", "nvarchar(512)"), new XAttribute("SPType", "Note")); contentTypeElement.Add(fieldElement); break; case SPFieldType.User: fieldElement.Add(new XAttribute("SqlType", "nvarchar(255)"), new XAttribute("SPType", "User")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Computed: fieldElement.Add(new XAttribute("SqlType", "nvarchar(255)"), new XAttribute("SPType", "Computed")); contentTypeElement.Add(fieldElement); break; case SPFieldType.Text: fieldElement.Add(new XAttribute("SqlType", "nvarchar(255)"), new XAttribute("SPType", "Text")); contentTypeElement.Add(fieldElement); break; case SPFieldType.WorkflowStatus: fieldElement.Add(new XAttribute("SqlType", "nvarchar(255)"), new XAttribute("SPType", "WorkflowStatus")); contentTypeElement.Add(fieldElement); break; default: break; } } }
private void ProcessLookupLists(XElement dataMapping, SPSite site, LogUtility logUtility, XElement fieldElement, SPFieldLookup lookupField, Guid webID, XElement contentType) { Guid listID = Guid.Empty; try { listID = new Guid(lookupField.LookupList); } catch (FormatException formatException) { logUtility.TraceDebugException(string.Format("Caught format Exception for field with id: {0} and title: {1}", lookupField.LookupField, lookupField.Title), GetType(), formatException); } if (!ListIDs.Contains(listID)) { ListIDs.Add(listID); LookUpListProcess(dataMapping, site, logUtility, fieldElement, webID, listID, contentType); } }
private static void UnregisterTypes(SPSite site) { site.RequireNotNull("site"); LogUtility logUtility = new LogUtility(); try { logUtility.TraceDebugInformation("Deactivating Local utilities", typeof(ServiceLocationRegistration)); IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(); IServiceLocatorConfig typeMappings = serviceLocator.GetInstance<IServiceLocatorConfig>(); typeMappings.Site = site; unregisterTypeMappings(typeMappings); logUtility.TraceDebugInformation("Successfully deactivated Local utilities", typeof(ServiceLocationRegistration)); } catch (Exception exception) { logUtility.TraceDebugException("Error while deactivating Local utilities", typeof(ServiceLocationRegistration), exception); } finally { logUtility.TraceDebugInformation("Finished deactivating Local utilities", typeof(ServiceLocationRegistration)); } }
private static void UnregisterTypes(SPWeb web) { LogUtility logUtility = new LogUtility(); try { logUtility.TraceDebugInformation("Deactivating Local utilities", typeof(ServiceLocationRegistration)); IServiceLocator serviceLocator = new SPWebServiceLocator(web); IServiceLocatorConfig typeMappings = serviceLocator.GetInstance<IServiceLocatorConfig>(); unregisterTypeMappings(typeMappings); logUtility.TraceDebugInformation("Successfully deactivated Local utilities", typeof(ServiceLocationRegistration)); } catch (Exception exception) { logUtility.TraceDebugException("Error while deactivating Local utilities", typeof(ServiceLocationRegistration), exception); } finally { logUtility.TraceDebugInformation("Finished deactivating Local utilities", typeof(ServiceLocationRegistration)); } }
private static void RegisterTypes(SPSite site) { site.RequireNotNull("site"); LogUtility logger = new LogUtility(); try { logger.TraceDebugInformation("Registering types for use across farms", typeof(ServiceLocationRegistration)); IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(); IServiceLocatorConfig typeMappings = serviceLocator.GetInstance<IServiceLocatorConfig>(); typeMappings.Site = site; registerTypeMappings(typeMappings); } catch (Exception exception) { logger.TraceDebugException("Exception while registering types!", typeof(ServiceLocationRegistration), exception); } finally { logger.TraceDebugInformation("Finished registering types for use across farms", typeof(ServiceLocationRegistration)); } }
private static void RegisterTypes(SPWeb web) { web.RequireNotNull("web"); LogUtility logger = new LogUtility(); try { logger.TraceDebugInformation("Registering types for use across farms", typeof(ServiceLocationRegistration)); IServiceLocator serviceLocator = new SPWebServiceLocator(web); IServiceLocatorConfig typeMappings = serviceLocator.GetInstance<IServiceLocatorConfig>(); registerTypeMappings(typeMappings); } catch (Exception exception) { logger.TraceDebugException("Exception while registering types!", typeof(ServiceLocationRegistration), exception); } finally { logger.TraceDebugInformation("Finished registering types for use across farms", typeof(ServiceLocationRegistration)); } }