Example #1
0
        /// <summary>
        /// Determines if a full trust proxy is installed to the farm.
        /// </summary>
        /// <param name="args">Provides the arguments defining the full trust proxy to check for installation, must be of type <see cref="ProxyInstalledArgs"/></param>
        /// <returns>true if the proxy is installed in the farm, false if not installed, or an exception representing an error if an error occurred</returns>
        public override object Execute(SPProxyOperationArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            var proxyInstalledArgs = args as ProxyInstalledArgs;

            if (proxyInstalledArgs == null)
            {
                string message = string.Format(CultureInfo.CurrentCulture, Resources.InvalidProxyArgumentType,
                                               typeof(ProxyInstalledArgs).FullName, args.GetType().FullName);
                var ex = new ConfigurationException(message);
                return(ex);
            }
            else if (proxyInstalledArgs.TypeName == null)
            {
                return(new ArgumentNullException("ProxyInstalledArgs.TypeName"));
            }
            else if (proxyInstalledArgs.AssemblyName == null)
            {
                return(new ArgumentNullException("ProxyInstalledArgs.AssemblyName"));
            }


            try
            {
                return(GetProxyInstalled(proxyInstalledArgs.AssemblyName, proxyInstalledArgs.TypeName));
            }
            catch (Exception excpt)
            {
                return(excpt);
            }
        }
        /// <summary>
        /// Implements the full trust proxy for tracing information to the ULS from the sandbox.
        /// </summary>
        /// <param name="args">The arguments for the operation, must be of type <see cref="TracingOperationArgs"/></param>
        /// <returns>null if successful, or an exception representing an error if an error occurred</returns>
        public override object Execute(SPProxyOperationArgs args)
        {
            Validation.ArgumentNotNull(args, "args");

            try
            {
                var proxyArgs = args as TracingOperationArgs;

                if (proxyArgs == null)
                {
                    return(new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidProxyArgProvided,
                                                               args.GetType().AssemblyQualifiedName, typeof(LoggingOperationArgs).AssemblyQualifiedName)));
                }

                if (proxyArgs.Message == null)
                {
                    return(new ArgumentNullException("proxyArgs.Message"));
                }

                ILogger logger = SharePointServiceLocator.GetCurrent().GetInstance <ILogger>();

                string sandboxMessage = null;

                if (proxyArgs.SiteID != null)
                {
                    using (SPSite site = new SPSite((Guid)proxyArgs.SiteID))
                    {
                        sandboxMessage = string.Format(CultureInfo.CurrentCulture, Resources.SandboxTraceMessage, site.ID, site.RootWeb.Name, proxyArgs.Message);
                    }
                }
                else
                {
                    sandboxMessage = string.Format(CultureInfo.CurrentCulture, Resources.NoSiteContextTraceMessage, proxyArgs.Message);
                }

                if (proxyArgs.Severity == null)
                {
                    logger.TraceToDeveloper(sandboxMessage, proxyArgs.EventId, proxyArgs.Category);
                }
                else
                {
                    var severity = (SandboxTraceSeverity)proxyArgs.Severity;
                    logger.TraceToDeveloper(sandboxMessage, proxyArgs.EventId, severity, proxyArgs.Category);
                }

                return(null);
            }
            catch (Exception exception)
            {
                return(exception);
            }
        }
        /// <summary>
        /// Implements the operation for determining if a key exists in a web application
        /// </summary>
        /// <param name="args">The arguments for the contains key operation.  This must be an instance of ContainsKeyDataArgs.</param>
        /// <returns>true if the key found, false if the key is not found, or an exception representing an error if an error occurred</returns>
        public override object Execute(SPProxyOperationArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            var containsKeyArgs = args as ContainsKeyDataArgs;

            if (containsKeyArgs == null)
            {
                string message = string.Format(CultureInfo.CurrentCulture, Resources.InvalidProxyArgumentType,
                                               typeof(ContainsKeyDataArgs).FullName, args.GetType().FullName);
                var ex = new ConfigurationException(message);
                return(ex);
            }
            else if (containsKeyArgs.Key == null)
            {
                return(new ArgumentNullException("ContainsKeyDataArgs.Key"));
            }

            try
            {
                ConfigLevel level = (ConfigLevel)containsKeyArgs.Level;

                if (containsKeyArgs.Key.StartsWith(ConfigManager.PnPKeyNamespace) == false)
                {
                    string message            = string.Format(CultureInfo.CurrentCulture, Resources.InvalidKeyName, containsKeyArgs.Key);
                    ConfigurationException ex = new ConfigurationException(message);
                    return(ex);
                }
                else
                {
                    bool contains = false;

                    if (level == ConfigLevel.CurrentSPWebApplication)
                    {
                        if (containsKeyArgs.SiteId == Guid.Empty)
                        {
                            return(new ConfigurationException(Resources.EmptySiteGuid));
                        }
                        using (SPSite site = new SPSite(containsKeyArgs.SiteId))
                        {
                            SPWebAppPropertyBag bag = new SPWebAppPropertyBag(site.WebApplication);
                            contains = bag.Contains(containsKeyArgs.Key);
                        }
                    }
                    else if (level == ConfigLevel.CurrentSPFarm)
                    {
                        var bag = new SPFarmPropertyBag(SPFarm.Local);
                        contains = bag.Contains(containsKeyArgs.Key);
                    }
                    else
                    {
                        string message            = string.Format(CultureInfo.CurrentCulture, Resources.InvalidConfigLevel, level.ToString());
                        ConfigurationException ex = new ConfigurationException(message);
                        return(ex);
                    }
                    return(contains);
                }
            }
            catch (Exception excpt)
            {
                return(excpt);
            }
        }