public bool Contains(string key)
        {
            Validation.ArgumentNotNullOrEmpty(key, "key");

            var args = new ContainsKeyDataArgs();
            args.Key = key;
            args.SiteId = this.siteId;

            args.Level = (int) ConfigLevel.CurrentSPWebApplication;

            var result = SPUtility.ExecuteRegisteredProxyOperation(
                                    ContainsKeyDataArgs.OperationAssemblyName,
                                     ContainsKeyDataArgs.OperationTypeName,
                                     args);


            if (result != null && result.GetType().IsSubclassOf(typeof(System.Exception)))
            {
                var ex = new ConfigurationException(string.Format(CultureInfo.CurrentCulture,
                    Resources.UnexpectedExceptionFromSandbox, ConfigLevel.CurrentSPWebApplication.ToString()), (Exception)result);
                throw ex;
            }

            return (bool)result;
        }
        private string Serializer(Type type, object value)
        {
             if (value == null)
                return null;

            string retVal = null;

            //Try to simplify serialization for simple types first without using xmlserializer.
            if (typeof(string) == type)
                retVal = value as string;
            else if (typeof(Type) == type)
                retVal = ((Type)value).AssemblyQualifiedName;
            else if (type.IsEnum)
                retVal = value.ToString();
            else
                retVal = TrySerializePrimitive(type, value);

            if (retVal == null)
            {
                using (var writer = new StringWriter(CultureInfo.InvariantCulture))
                {
                    try
                    {
                        XmlSerializer xmlserializer = XmlSerializerCache.GetSerializer(type);
                        xmlserializer.Serialize(writer, value);
                        retVal = writer.ToString();
                    }
                    catch (Exception ex)
                    {
                        var configEx = new ConfigurationException("Error on serializing configuration data", ex);
                        throw configEx;
                    }
                }
            }
            return retVal;
        }
        private object Deserializer(Type type, string value)
        {
            object retVal = null;

            // First try to deserialize using simple types first, then use xml serializer
            if (value == null)
                return null;
            else if (typeof(string) == type)
                retVal = value;
            else if (typeof(Type) == type)
               retVal= Type.GetType(value);
            else if (type.IsEnum)
                retVal = Enum.Parse(type, value);

            if (retVal == null)
                retVal = TryParsePrimitive(type, value);

            if (retVal == null)
            {
                using (var reader = new StringReader(value))
                {
                    try
                    {
                        XmlSerializer xmlserializer = XmlSerializerCache.GetSerializer(type);
                        retVal = xmlserializer.Deserialize(reader);
                    }
                    catch (Exception ex)
                    {
                        var configEx = new ConfigurationException("Error on deserializing configuration data", ex);
                        throw configEx;
                    }
                }
            }

            return retVal;
        }
Example #4
0
 internal static void ThrowSandboxConfigurationException(Exception exception, ConfigLevel configLevel)
 {
     var ex = new ConfigurationException(string.Format(CultureInfo.CurrentCulture,
     Resources.UnexpectedExceptionFromSandbox, configLevel.ToString()), exception);
     throw ex;
 }
Example #5
0
        private static SPContentType EnsureContentType(SPSite site)
        {
            SPWeb web = site.RootWeb;
            SPContentType configContentType = web.AvailableContentTypes[ConfigurationContentTypeId];

            if (configContentType == null)
            {
                try
                {
                    EnsureSiteColumns(web);
                    configContentType = new SPContentType(ConfigurationContentTypeId, web.ContentTypes, ConfigContentTypeName);

                    web.ContentTypes.Add(configContentType);
                    configContentType.Group = PNPContentTypeGroup;
                    configContentType.FieldLinks.Add(new SPFieldLink(web.AvailableFields[SettingWebIdFieldId]));
                    configContentType.FieldLinks.Add(new SPFieldLink(web.AvailableFields[SettingKeyFieldId]));
                    configContentType.FieldLinks.Add(new SPFieldLink(web.AvailableFields[SettingValueFieldId]));
                    configContentType.Update();
                }
                catch (Exception ex)
                {
                    //try to cleanup
                    configContentType = web.AvailableContentTypes[ConfigurationContentTypeId];

                    if (configContentType != null)
                        web.ContentTypes.Delete(ConfigurationContentTypeId);

                    ConfigurationException configEx = new ConfigurationException(Resources.CreateConfigContentTypeFailed, ex);
                    throw (configEx);
                }
            }

            return configContentType;
        }