示例#1
0
文件: Host.cs 项目: VlaTo/EmpRe.NET
 /// <summary>
 /// 
 /// </summary>
 /// <param name="level"></param>
 /// <param name="message"></param>
 public static void CheckAspNetPermission(AspNetHostingPermissionLevel level, string message)
 {
     if (!HasAspNetPermission(level))
     {
         throw new HttpException(message);
     }
 }
示例#2
0
文件: CacheCas.cs 项目: nobled/mono
		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			if ((level != AspNetHostingPermissionLevel.None) && (action == SecurityAction.PermitOnly))
				return UnmanagedCreateControl (action, level);
			else
				return base.CreateControl (action, level);
		}
示例#3
0
		private object CreateControlStringCtor (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			// not public empty (default) ctor - at least not before 2.0
			ConstructorInfo ci = this.Type.GetConstructor (new Type[1] { typeof (string) });
			Assert.IsNotNull (ci, ".ctor(string)");
			return ci.Invoke (new object[1] { tempFile });
		}
		public AspNetHostingPermission (PermissionState state)
		{
			if (PermissionHelper.CheckPermissionState (state, true) == PermissionState.Unrestricted)
				_level = AspNetHostingPermissionLevel.Unrestricted;
			else
				_level = AspNetHostingPermissionLevel.None;
		}
示例#5
0
		// LinkDemand

		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			// static class 2.0 / no public ctor before (1.x)
			MethodInfo mi = this.Type.GetMethod ("EnumToString");
			Assert.IsNotNull (mi, "EnumToString");
			return mi.Invoke (null, new object[2] { typeof(SecurityAction), SecurityAction.Demand });
		}
		// LinkDemand

		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			ConstructorInfo ci = this.Type.GetConstructor (new Type[7] { typeof (string), typeof (string),
				typeof (int), typeof (string), typeof (string), typeof (string), typeof (BuildMethod) });
			Assert.IsNotNull (ci, ".ctor(2xstring,int,3xstring,BuildMethod)");
			return ci.Invoke (new object[7] { null, null, null, null, null, null, null });
		}
		/// <summary>
		/// Get the current trust level of the hosted application
		/// </summary>
		/// <returns></returns>
		public static AspNetHostingPermissionLevel GetCurrentTrustLevel()
		{
		    if (_knowTrustLevel) return _trustLevel;

			foreach (var trustLevel in new[] {
			                                 	AspNetHostingPermissionLevel.Unrestricted,
			                                 	AspNetHostingPermissionLevel.High,
			                                 	AspNetHostingPermissionLevel.Medium,
			                                 	AspNetHostingPermissionLevel.Low,
			                                 	AspNetHostingPermissionLevel.Minimal })
			{
				try
				{
					new AspNetHostingPermission(trustLevel).Demand();
				}
				catch (SecurityException)
				{
					continue;
				}

                _trustLevel = trustLevel;
			    _knowTrustLevel = true;
			    return _trustLevel;
			}

			_trustLevel = AspNetHostingPermissionLevel.None;
            _knowTrustLevel = true;
            return _trustLevel;
        }
示例#8
0
		// LinkDemand

		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			// no public ctor is available but we know the Count property isn't protected
			MethodInfo mi = this.Type.GetProperty ("Count").GetGetMethod ();
			Assert.IsNotNull (mi, "Count");
			return mi.Invoke (css, null);
		}
示例#9
0
		// LinkDemand

		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			// no public ctor is available but we know that it's properties don't have any restrictions
			MethodInfo mi = this.Type.GetProperty ("AcceptTypes").GetGetMethod ();
			Assert.IsNotNull (mi, "get_AcceptTypes");
			return mi.Invoke (response.Cache.VaryByHeaders, null);
		}
 public override void FromXml(SecurityElement securityElement)
 {
     if (securityElement == null)
     {
         throw new ArgumentNullException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "securityElement" }));
     }
     if (!securityElement.Tag.Equals("IPermission"))
     {
         throw new ArgumentException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "securityElement" }));
     }
     string str = securityElement.Attribute("class");
     if (str == null)
     {
         throw new ArgumentException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "securityElement" }));
     }
     if (str.IndexOf(base.GetType().FullName, StringComparison.Ordinal) < 0)
     {
         throw new ArgumentException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "securityElement" }));
     }
     if (string.Compare(securityElement.Attribute("version"), "1", StringComparison.OrdinalIgnoreCase) != 0)
     {
         throw new ArgumentException(SR.GetString("AspNetHostingPermissionBadXml", new object[] { "version" }));
     }
     string str3 = securityElement.Attribute("Level");
     if (str3 == null)
     {
         this._level = AspNetHostingPermissionLevel.None;
     }
     else
     {
         this._level = (AspNetHostingPermissionLevel) Enum.Parse(typeof(AspNetHostingPermissionLevel), str3);
     }
 }
示例#11
0
		// LinkDemand

		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			// no public ctor but we know the properties aren't protected
			MethodInfo mi = this.Type.GetProperty ("Visible").GetGetMethod ();
			Assert.IsNotNull (mi, "Visible");
			return mi.Invoke (pager_style, null);
		}
示例#12
0
		// LinkDemand

		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			// there are no public ctor so we're taking a method that we know isn't protected
			// (by a Demand) and call it thru reflection so any linkdemand (on the class) will
			// be promoted to a Demand
			MethodInfo mi = this.Type.GetProperty ("AllKeys").GetGetMethod ();
			return mi.Invoke (appstate, null);
		}
示例#13
0
 public bool HasTrustLevel(AspNetHostingPermissionLevel level)
 {
     bool hasTrustLevel = true;
     try {
         new AspNetHostingPermission(level).Demand();
     }
     catch (SecurityException) {
         hasTrustLevel = false;
     }
     return hasTrustLevel;
 }
	public AspNetHostingPermission(PermissionState state)
			{
				if(state == PermissionState.Unrestricted)
				{
					this.level = AspNetHostingPermissionLevel.Unrestricted;
				}
				else
				{
					this.level = AspNetHostingPermissionLevel.None;
				}
			}
示例#15
0
		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			if ((level != AspNetHostingPermissionLevel.None) && (action == SecurityAction.PermitOnly)) {
				try {
					return FileIOPermissionCreateControl (action, level);
				}
				catch (TargetInvocationException tie) {
					throw tie;
				}
			} 
			else
				return CreateControlStringCtor (action, level);
		}
        public AspNetHostingPermission(PermissionState state)
        {
            switch (state)
            {
                case PermissionState.None:
                    this._level = AspNetHostingPermissionLevel.None;
                    return;

                case PermissionState.Unrestricted:
                    this._level = AspNetHostingPermissionLevel.Unrestricted;
                    return;
            }
            throw new ArgumentException(SR.GetString("InvalidArgument", new object[] { state.ToString(), "state" }));
        }
示例#17
0
		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			// the ctor NRE makes it more complex
			try {
				return base.CreateControl (action, level);
			}
			catch (TargetInvocationException tie) {
				// we really checking for security exceptions that occurs before a NRE can occurs
				if (tie.InnerException is NullReferenceException)
					return String.Empty;
				else
					return null;
			}
		}
        static internal void VerifyAspNetHostingPermissionLevel(AspNetHostingPermissionLevel level, string arg) {
            switch (level) {
            case AspNetHostingPermissionLevel.Unrestricted:
            case AspNetHostingPermissionLevel.High:
            case AspNetHostingPermissionLevel.Medium:
            case AspNetHostingPermissionLevel.Low:
            case AspNetHostingPermissionLevel.Minimal:
            case AspNetHostingPermissionLevel.None:
                break;

            default:
                throw new ArgumentException(arg);
            }
        }
示例#19
0
        private static string _shadowDirectory = "~/Plugins/loaded"; //this is set in web.config as probe path //used only for medium trust

        #endregion Fields

        #region Constructors

        static PluginEngine()
        {
            TrustLevel = ServerHelper.GetCurrentTrustLevel();
            if (TrustLevel == AspNetHostingPermissionLevel.Unrestricted)
            {
                _shadowDirectory = AppDomain.CurrentDomain.DynamicDirectory;
                ShadowDirectory = new DirectoryInfo(_shadowDirectory);
            }
            else
            {
                ShadowDirectory = new DirectoryInfo(HostingEnvironment.MapPath(_shadowDirectory));

            }

            PluginsDirectory = new DirectoryInfo(HostingEnvironment.MapPath(_pluginsDirectory));

            Plugins = new List<PluginInfo>();
        }
示例#20
0
文件: Host.cs 项目: VlaTo/EmpRe.NET
        /// <summary>
        /// 
        /// </summary>
        /// <param name="level"></param>
        /// <returns></returns>
        public static bool HasAspNetPermission(AspNetHostingPermissionLevel level)
        {
            var set = HttpRuntime.GetNamedPermissionSet();

            if (set == null)
            {
                return true;
            }

            var permission = (AspNetHostingPermission)set.GetPermission(typeof(AspNetHostingPermission));

            if (null == permission)
            {
                return false;
            }

            return permission.Level >= level;
        }
示例#21
0
		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			if ((level != AspNetHostingPermissionLevel.None) && (action == SecurityAction.PermitOnly)) {
				try {
					return FileIOPermissionCreateControl (action, level);
				}
				catch (TargetInvocationException tie) {
#if ONLY_1_1
					// hide this error (occurs with ms 1.x)
					if ((tie.InnerException is NullReferenceException) &&
						(level == AspNetHostingPermissionLevel.Unrestricted)) {
						return String.Empty;
					}
#endif
					throw tie;
				}
			} 
			else
				return CreateControlStringCtor (action, level);
		}
示例#22
0
		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			// in this case testing with a (private) ctor isn't very conveniant
			// and the LinkDemand promotion (to Demand) will still occurs on other stuff
			// and (finally) we know that the CreateApplicationHost method is only 
			// protected for unmanaged code (which we can assert)
			try {
				MethodInfo mi = this.Type.GetMethod ("CreateApplicationHost");
				Assert.IsNotNull (mi, "method");
				return mi.Invoke (null, new object[3] { null, null, null });
			}
			catch (TargetInvocationException e) {
				// so we hit the same exception as we did for the ctor
				if (e.InnerException is NullReferenceException)
					return String.Empty; // MS
				else if (e.InnerException is NotImplementedException)
					return String.Empty; // Mono
				else
					return null;
			}
		}
示例#23
0
        public override object CreateControl(SecurityAction action, AspNetHostingPermissionLevel level)
        {
            try
            {
                // static class 2.0 / no public ctor before (1.x)
                MethodInfo mi = this.Type.GetMethod("ParseTemplate");
                Assert.IsNotNull(mi, "ParseTemplate");
                return(mi.Invoke(null, new object[1] {
                    dtpd
                }));
            }
            catch (TargetInvocationException tie)
            {
#if ONLY_1_1
                if (tie.InnerException is NullReferenceException)
                {
                    return(String.Empty);
                }
#endif
                throw tie;
            }
        }
        public void DontUseMutex(AspNetHostingPermissionLevel level)
        {
            string testDir = Guid.NewGuid().ToString();

            var trustLevel = new Mock<ITrustLevel>();
            trustLevel.SetupGet(tl => tl.CurrentTrustLevel).Returns(level);

            //just want to be sure nothing is called on this
            var filePathMutextProvider = new Mock<IFilePathMutexProvider>(MockBehavior.Strict);

            using(new TrustLevelScope(trustLevel.Object))
            using(new FilePathMutexProviderScope(filePathMutextProvider.Object))
            {
                using(new CriticalRenderingSection(testDir))
                {
                    //do something
                }
            }

            trustLevel.VerifyAll();
            filePathMutextProvider.VerifyAll();
        }
        public void UseMutex(AspNetHostingPermissionLevel level)
        {
            string testDir = Guid.NewGuid().ToString();

            var trustLevel = new Mock<ITrustLevel>();
            trustLevel.SetupGet(tl => tl.CurrentTrustLevel).Returns(level);

            var filePathMutextProvider = new Mock<IFilePathMutexProvider>();
            filePathMutextProvider.Setup(mp => mp.GetMutexForPath(testDir)).Returns(new Mutex());

            using(new TrustLevelScope(trustLevel.Object))
            using(new FilePathMutexProviderScope(filePathMutextProvider.Object))
            {
                using(new CriticalRenderingSection(testDir))
                {
                    //do something
                }
            }

            trustLevel.VerifyAll();
            filePathMutextProvider.VerifyAll();
        }
示例#26
0
        public void DontUseMutex(AspNetHostingPermissionLevel level)
        {
            string testDir = Guid.NewGuid().ToString();

            var trustLevel = new Mock <ITrustLevel>();

            trustLevel.SetupGet(tl => tl.CurrentTrustLevel).Returns(level);

            //just want to be sure nothing is called on this
            var filePathMutextProvider = new Mock <IFilePathMutexProvider>(MockBehavior.Strict);

            using (new TrustLevelScope(trustLevel.Object))
                using (new FilePathMutexProviderScope(filePathMutextProvider.Object))
                {
                    using (new CriticalRenderingSection(testDir))
                    {
                        //do something
                    }
                }

            trustLevel.VerifyAll();
            filePathMutextProvider.VerifyAll();
        }
示例#27
0
        public override object CreateControl(SecurityAction action, AspNetHostingPermissionLevel level)
        {
            if ((level != AspNetHostingPermissionLevel.None) && (action == SecurityAction.PermitOnly))
            {
                try {
                    return(FileIOPermissionCreateControl(action, level));
                }
                catch (TargetInvocationException tie) {
#if ONLY_1_1
                    // hide this error (occurs with ms 1.x)
                    if ((tie.InnerException is NullReferenceException) &&
                        (level == AspNetHostingPermissionLevel.Unrestricted))
                    {
                        return(String.Empty);
                    }
#endif
                    throw tie;
                }
            }
            else
            {
                return(CreateControlStringCtor(action, level));
            }
        }
示例#28
0
 static TrustHelper()
 {
     foreach (AspNetHostingPermissionLevel trustLevel in
              new AspNetHostingPermissionLevel[] {
         AspNetHostingPermissionLevel.Unrestricted,
         AspNetHostingPermissionLevel.High,
         AspNetHostingPermissionLevel.Medium,
         AspNetHostingPermissionLevel.Low,
         AspNetHostingPermissionLevel.Minimal,
         AspNetHostingPermissionLevel.None
     })
     {
         try
         {
             new AspNetHostingPermission(trustLevel).Demand();
         }
         catch (System.Security.SecurityException)
         {
             continue;
         }
         _trustLevel = trustLevel;
         break;
     }
 }
示例#29
0
        public void UseMutex(AspNetHostingPermissionLevel level)
        {
            string testDir = Guid.NewGuid().ToString();

            var trustLevel = new Mock <ITrustLevel>();

            trustLevel.SetupGet(tl => tl.CurrentTrustLevel).Returns(level);

            var filePathMutextProvider = new Mock <IFilePathMutexProvider>();

            filePathMutextProvider.Setup(mp => mp.GetMutexForPath(testDir)).Returns(new Mutex());

            using (new TrustLevelScope(trustLevel.Object))
                using (new FilePathMutexProviderScope(filePathMutextProvider.Object))
                {
                    using (new CriticalRenderingSection(testDir))
                    {
                        //do something
                    }
                }

            trustLevel.VerifyAll();
            filePathMutextProvider.VerifyAll();
        }
示例#30
0
 public override object CreateControl(SecurityAction action, AspNetHostingPermissionLevel level)
 {
     return(base.CreateControl(action, level));
 }
示例#31
0
 public void AspNetHostingPermissionLevels_Bad()
 {
     AspNetHostingPermissionLevel ppl  = (AspNetHostingPermissionLevel)Int32.MinValue;
     AspNetHostingPermission      anhp = new AspNetHostingPermission(ppl);
 }
 private object FileIOPermissionCreateControl(SecurityAction action, AspNetHostingPermissionLevel level)
 {
     return(CreateControlStringCtor(action, level));
 }
示例#33
0
 public AspNetHostingPermission(AspNetHostingPermissionLevel level)
 {
 }
示例#34
0
		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			ConstructorInfo ci = this.Type.GetConstructor (VoidType);
			Assert.IsNotNull (ci, "default .ctor");
			return ci.Invoke (null);
		}
		// LinkDemand

		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			ConstructorInfo ci = this.Type.GetConstructor (new Type[2] { typeof (int), typeof (int) });
			Assert.IsNotNull (ci, ".ctor(int,int)");
			return ci.Invoke (new object[2] { 1, 1 });
		}
示例#36
0
		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			try {
				return base.CreateControl (action, level);
			}
			catch (TypeInitializationException) {
				// ctor can't be called more than once (else it throws TIE)
				return String.Empty;
			}
		}
 public AspNetHostingPermission(AspNetHostingPermissionLevel level)
 {
     VerifyAspNetHostingPermissionLevel(level, "level");
     _level = level;
 }
 public AspNetHostingPermission(AspNetHostingPermissionLevel level)
 {
     return(default(AspNetHostingPermission));
 }
示例#39
0
        private IEnumerable <KeyValuePair <string, string> > GetMetricData()
        {
            string stringData = null;
            IEnumerable <KeyValuePair <string, string> > tupleData = null;

            // Gather data for each row, return special message if data is null
            switch (MetricCodeName)
            {
            // Categories
            case MetricDataEnum.support_metrics:
            case MetricDataEnum.support_metrics_system:
            case MetricDataEnum.support_metrics_environment:
            case MetricDataEnum.support_metrics_counters:
            case MetricDataEnum.support_metrics_ecommerce:
            case MetricDataEnum.support_metrics_tasks:
            case MetricDataEnum.support_metrics_eventlog:
                return(null);

                #region System

            case MetricDataEnum.support_metrics_system_version:
                stringData = CMSVersion.GetVersion(true, true, true, true);
                break;

            case MetricDataEnum.support_metrics_system_appname:
                stringData = SettingsHelper.AppSettings["CMSApplicationName"];
                break;

            case MetricDataEnum.support_metrics_system_instancename:
                stringData = SystemContext.InstanceName;
                break;

            case MetricDataEnum.support_metrics_system_physicalpath:
                stringData = SystemContext.WebApplicationPhysicalPath;
                break;

            case MetricDataEnum.support_metrics_system_apppath:
                stringData = SystemContext.ApplicationPath;
                break;

            case MetricDataEnum.support_metrics_system_uiculture:
                stringData = LocalizationContext.CurrentUICulture.CultureName;
                break;

            case MetricDataEnum.support_metrics_system_installtype:
                stringData = SystemContext.IsWebApplicationProject ? "Web App" : "Web site";
                break;

            case MetricDataEnum.support_metrics_system_portaltemplatepage:
                stringData = URLHelper.PortalTemplatePage;
                break;

            case MetricDataEnum.support_metrics_system_timesinceapprestart:
                stringData = (DateTime.Now - CMSApplication.ApplicationStart).ToString(@"dd\:hh\:mm\:ss");
                break;

            case MetricDataEnum.support_metrics_system_discoveredassemblies:
                tupleData = AssemblyDiscoveryHelper.GetAssemblies(true).Select((a, i) => GetKeyValuePair(i, a.FullName));
                break;

            case MetricDataEnum.support_metrics_system_targetframework:
                HttpRuntimeSection httpRuntime = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
                stringData = httpRuntime.TargetFramework;
                break;

            case MetricDataEnum.support_metrics_system_authmode:
                AuthenticationSection Authentication = ConfigurationManager.GetSection("system.web/authentication") as AuthenticationSection;
                stringData = Authentication?.Mode.ToString();
                break;

            case MetricDataEnum.support_metrics_system_sessionmode:
                SessionStateSection SessionState = ConfigurationManager.GetSection("system.web/sessionState") as SessionStateSection;
                stringData = SessionState?.Mode.ToString();
                break;

            case MetricDataEnum.support_metrics_system_debugmode:
                CompilationSection Compilation = ConfigurationManager.GetSection("system.web/compilation") as CompilationSection;
                stringData = Compilation?.Debug.ToString();
                break;

            case MetricDataEnum.support_metrics_system_runallmanagedmodules:
                var xmlDoc = new System.Xml.XmlDocument();
                xmlDoc.Load(URLHelper.GetPhysicalPath("~/Web.config"));
                stringData = xmlDoc.SelectSingleNode("/configuration/system.webServer/modules").Attributes["runAllManagedModulesForAllRequests"]?.Value;
                break;

                #endregion System

                #region Environment

            case MetricDataEnum.support_metrics_environment_trustlevel:

                AspNetHostingPermissionLevel trustLevel = AspNetHostingPermissionLevel.None;

                if (!SystemContext.IsWebSite)
                {
                    trustLevel = AspNetHostingPermissionLevel.Unrestricted;
                }

                // Check the trust level by evaluation of levels
                foreach (AspNetHostingPermissionLevel permissionLevel in new[] {
                    AspNetHostingPermissionLevel.Unrestricted,
                    AspNetHostingPermissionLevel.High,
                    AspNetHostingPermissionLevel.Medium,
                    AspNetHostingPermissionLevel.Low,
                    AspNetHostingPermissionLevel.Minimal
                })
                {
                    try
                    {
                        new AspNetHostingPermission(permissionLevel).Demand();
                    }
                    catch (SecurityException)
                    {
                        continue;
                    }

                    trustLevel = permissionLevel;
                    break;
                }

                stringData = trustLevel.ToString();
                break;

            case MetricDataEnum.support_metrics_environment_iisversion:
                stringData = MetricServerVariables["SERVER_SOFTWARE"];
                break;

            case MetricDataEnum.support_metrics_environment_https:
                stringData = MetricServerVariables["HTTPS"];
                break;

            case MetricDataEnum.support_metrics_environment_windowsversion:
                using (RegistryKey versionKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"))
                {
                    var productName  = versionKey?.GetValue("ProductName");
                    var currentBuild = versionKey?.GetValue("CurrentBuild");
                    var releaseId    = versionKey?.GetValue("ReleaseId");

                    stringData = String.Format("{0}, build {1}, release {2}", productName.ToString(), currentBuild.ToString(), releaseId.ToString());
                }
                break;

            case MetricDataEnum.support_metrics_environment_netversion:
                using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"))
                {
                    var keyValue = ndpKey?.GetValue("Release");
                    if (keyValue != null)
                    {
                        var releaseKey = (int)keyValue;
                        if (releaseKey >= 461808)
                        {
                            stringData = "4.7.2 or later";
                        }
                        else
                        if (releaseKey >= 461308)
                        {
                            stringData = "4.7.1";
                        }
                        else
                        if (releaseKey >= 460798)
                        {
                            stringData = "4.7";
                        }
                        else
                        if (releaseKey >= 394802)
                        {
                            stringData = "4.6.2";
                        }
                        else
                        if (releaseKey >= 394254)
                        {
                            stringData = "4.6.1";
                        }
                        else
                        if (releaseKey >= 393295)
                        {
                            stringData = "4.6";
                        }
                        else
                        if (releaseKey >= 379893)
                        {
                            stringData = "4.5.2";
                        }
                        else
                        if (releaseKey >= 378675)
                        {
                            stringData = "4.5.1";
                        }
                        else
                        if (releaseKey >= 378389)
                        {
                            stringData = "4.5";
                        }
                    }
                }
                break;

            case MetricDataEnum.support_metrics_environment_sqlserverversion:
                var dtm = new TableManager(null);
                stringData = dtm.DatabaseServerVersion;
                break;

            case MetricDataEnum.support_metrics_environment_azure:
                var azureStats = new Dictionary <string, string>(4)
                {
                    { "Is a Cloud Service", (SettingsHelper.AppSettings["CMSAzureProject"] == "true").ToString("false") },
                    { "Is file system on Azure", (SettingsHelper.AppSettings["CMSExternalStorageName"] == "azure").ToString("false") },
                    { "Azure storage account", SettingsHelper.AppSettings["CMSAzureAccountName"] ?? String.Empty },
                    { "Azure CDN endpoint", SettingsHelper.AppSettings["CMSAzureCDNEndpoint"] ?? String.Empty }
                };

                tupleData = azureStats.Select(s => GetKeyValuePair(s.Key, s.Value));
                break;

            case MetricDataEnum.support_metrics_environment_amazon:
                var amazonStats = new Dictionary <string, string>(3)
                {
                    { "Is file system on Amazon", (SettingsHelper.AppSettings["CMSExternalStorageName"] == "amazon").ToString() },
                    { "Amazon bucket name", SettingsHelper.AppSettings["CMSAmazonBucketName"] ?? String.Empty },
                    { "Amazon public access", SettingsHelper.AppSettings["CMSAmazonPublicAccess"] ?? String.Empty },
                };

                tupleData = amazonStats.Select(s => GetKeyValuePair(s.Key, s.Value));
                break;

            case MetricDataEnum.support_metrics_environment_services:
                tupleData = ServiceManager.GetServices().Select(s => GetKeyValuePair(s.ServiceName, s.Status));
                break;

                #endregion Environment

                #region Counters

            case MetricDataEnum.support_metrics_counters_webfarmservers:
                stringData = CoreServices.WebFarm.GetEnabledServerNames().Count().ToString();
                break;

            case MetricDataEnum.support_metrics_counters_stagingservers:
                stringData = ServerInfoProvider.GetServers().GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_counters_pagemostchildren:
                CMS.DocumentEngine.TreeProvider tree = new CMS.DocumentEngine.TreeProvider();

                var pageWithMostChildren = tree.SelectNodes().OnCurrentSite().Published()
                                           .ToDictionary(n => n, n => n.Children.Count)
                                           .Aggregate((l, r) => l.Value > r.Value ? l : r);

                tupleData = new[] { GetKeyValuePair(URLHelper.GetAbsoluteUrl("~" + pageWithMostChildren.Key.NodeAliasPath), pageWithMostChildren.Value) };
                break;

            case MetricDataEnum.support_metrics_counters_modules:
                stringData = ResourceInfoProvider.GetResources().GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_counters_medialibraries:
                stringData = MediaLibraryInfoProvider.GetMediaLibraries().WhereNull("LibraryGroupID").GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_counters_activities:
                stringData = ActivityInfoProvider.GetActivities().GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_counters_contacts:
                stringData = ContactInfoProvider.GetContacts().GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_counters_contactgroups:
                stringData = ContactGroupInfoProvider.GetContactGroups().GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_counters_omrules:
                stringData = RuleInfoProvider.GetRules().GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_counters_products:
                stringData = SKUInfoProvider.GetSKUs(SiteContext.CurrentSiteID).WhereNull("SKUOptionCategoryID").GetCount().ToString();
                break;

                #endregion Counters

                #region Tasks

            case MetricDataEnum.support_metrics_tasks_webfarm:
                stringData = WebFarmTaskInfoProvider.GetWebFarmTasks()
                             .WhereLessThan("TaskCreated", DateTime.Now.AddDays(-1))
                             .GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_tasks_staging:
                stringData = StagingTaskInfoProvider.GetTasks()
                             .WhereLessThan("TaskTime", DateTime.Now.AddDays(-1))
                             .GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_tasks_integration:
                stringData = IntegrationTaskInfoProvider.GetIntegrationTasks()
                             .WhereLessThan("TaskTime", DateTime.Now.AddDays(-1))
                             .GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_tasks_scheduled:
                stringData = TaskInfoProvider.GetTasks()
                             .WhereTrue("TaskDeleteAfterLastRun")
                             .WhereLessThan("TaskNextRunTime", DateTime.Now.AddDays(-1))
                             .GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_tasks_search:
                stringData = SearchTaskInfoProvider.GetSearchTasks()
                             .WhereLessThan("SearchTaskCreated", DateTime.Now.AddDays(-1))
                             .GetCount().ToString();
                break;

            case MetricDataEnum.support_metrics_tasks_email:
                stringData = EmailInfoProvider.GetEmailCount("EmailStatus = 1 AND EmailLastSendResult IS NOT NULL").ToString();
                break;

                #endregion Tasks

                #region Event log

            case MetricDataEnum.support_metrics_eventlog_macroerrors:
                var macroErrors = EventLogProvider.GetEvents()
                                  .WhereEquals("Source", "MacroResolver")
                                  .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7)))
                                  .OrderByDescending("EventTime")
                                  .TopN(10);

                tupleData = macroErrors.Select(e =>
                                               GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName),
                                                               e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription)
                                               );
                break;

            case MetricDataEnum.support_metrics_eventlog_stagingerrors:
                var stagingErrors = EventLogProvider.GetEvents()
                                    .WhereEquals("Source", "staging")
                                    .WhereIn("EventType", new[] { "E", "W" })
                                    .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7)))
                                    .OrderByDescending("EventTime")
                                    .TopN(10);

                tupleData = stagingErrors.Select(e =>
                                                 GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName),
                                                                 e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription)
                                                 );
                break;

            case MetricDataEnum.support_metrics_eventlog_searcherrors:
                var searchErrors = EventLogProvider.GetEvents()
                                   .WhereEquals("Source", "search")
                                   .WhereIn("EventType", new[] { "E", "W" })
                                   .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7)))
                                   .OrderByDescending("EventTime")
                                   .TopN(10);

                tupleData = searchErrors.Select(e =>
                                                GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName),
                                                                e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription)
                                                );
                break;

            case MetricDataEnum.support_metrics_eventlog_contenterrors:
                var contentErrors = EventLogProvider.GetEvents()
                                    .WhereEquals("Source", "content")
                                    .WhereIn("EventType", new[] { "E", "W" })
                                    .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7)))
                                    .OrderByDescending("EventTime")
                                    .TopN(10);

                tupleData = contentErrors.Select(e =>
                                                 GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName),
                                                                 e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription)
                                                 );
                break;

            case MetricDataEnum.support_metrics_eventlog_exceptions:
                var exceptions = EventLogProvider.GetEvents()
                                 .WhereEquals("EventCode", "exception")
                                 .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7)))
                                 .OrderByDescending("EventTime")
                                 .TopN(10);

                tupleData = exceptions.Select(e =>
                                              GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName),
                                                              e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription)
                                              );
                break;

            case MetricDataEnum.support_metrics_eventlog_upgrade:

                EventLogInfo upgrade = EventLogProvider.GetEvents().WhereLike("Source", "upgrade%").FirstOrDefault();
                var          version = upgrade?.Source.Split(' ')[2];

                if (!String.IsNullOrEmpty(version))
                {
                    var parameters = new QueryDataParameters
                    {
                        { "@versionnumber", version }
                    };

                    var events = ConnectionHelper.ExecuteQuery("SupportHelper.CustomMetric.checkupgrade", parameters);

                    tupleData = (from DataRow row in events.Tables[0]?.Rows select row)
                                .Select(r => new EventLogInfo(r)).Select(e =>
                                                                         GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName),
                                                                                         e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription)
                                                                         );
                }
                break;

                #endregion Event log
            }

            if (tupleData?.Count() > 0)
            {
                return(tupleData);
            }

            if (stringData != null)
            {
                return(new[] { GetKeyValuePair(0, stringData) });
            }

            return(new[] { GetKeyValuePair(0, ResHelper.GetStringFormat("support.metrics.invalid", MetricDisplayName, MetricCodeName)) });
        }
示例#40
0
		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			return base.CreateControl (action, level);
		}
 public AspNetHostingPermission(AspNetHostingPermissionLevel level)
 {
     throw new NotImplementedException();
 }
        public AspNetHostingPermission (AspNetHostingPermissionLevel level) {

          return default(AspNetHostingPermission);
        }
 public override object CreateControl(SecurityAction action, AspNetHostingPermissionLevel level)
 {
     // don't let UnmanagedCode mess up the results
     return(base.CreateControl(action, level));
 }
示例#44
0
 public AspNetHostingPermission(AspNetHostingPermissionLevel level)
 {
     // use the property to get the enum validation
     Level = level;
 }
示例#45
0
 private object UnmanagedCreateControl(SecurityAction action, AspNetHostingPermissionLevel level)
 {
     return(base.CreateControl(action, level));
 }
 public AspNetHostingPermissionAttribute(SecurityAction action) : base(action)
 {
     _level = AspNetHostingPermissionLevel.None;
 }
示例#47
0
 public AspNetHostingPermissionAttribute(SecurityAction action)
     : base(action)
 {
     // LAMESPEC: seems to initialize to None
     _level = AspNetHostingPermissionLevel.None;
 }
示例#48
0
		// LinkDemand

		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			// there are no public ctor so we're taking a method that we know isn't protected
			// (by a Demand) and call it thru reflection so any linkdemand (on the class) will
			// be promoted to a Demand
			MethodInfo mi = this.Type.GetMethod ("HtmlDecode", new Type[1] { typeof (string) } );
			return mi.Invoke (hsu, new object[1] { String.Empty });
		}
示例#49
0
 public static void AspNetHostingPermissionAttributeCallMethods()
 {
     var apa = new AspNetHostingPermissionAttribute(new SecurityAction());
     AspNetHostingPermissionLevel level = apa.Level;
     IPermission ip = apa.CreatePermission();
 }
		// LinkDemand

		public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
		{
			ConstructorInfo ci = this.Type.GetConstructor (new Type[1] { typeof (string) });
			Assert.IsNotNull (ci, ".ctor(string)");
			return ci.Invoke (new object[1] { String.Empty });
		}
示例#51
0
 // Constructors.
 public AspNetHostingPermission(AspNetHostingPermissionLevel level)
 {
     this.level = level;
 }