private void WaitForPoolStatusResolve(ApplicationPool pool)
        {
            // Delay to get proper status of newly created pool
            int n = 10;

            for (int i = 0; i < n; i++)
            {
                try {
                    StatusExtensions.FromObjectState(pool.State);
                    break;
                }
                catch (COMException) {
                    if (i < n - 1)
                    {
                        Thread.Sleep(10 / n);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void WaitForSiteStatusResolve(Site site)
        {
            // Delay to get proper status of newly created site
            int n = 10;

            for (int i = 0; i < n; i++)
            {
                try {
                    StatusExtensions.FromObjectState(site.State);
                    break;
                }
                catch (COMException) {
                    if (i < n - 1)
                    {
                        Thread.Sleep(10 / n);
                    }
                }
            }
        }
Exemplo n.º 3
0
        internal static object ToJsonModel(Site site, Fields fields = null, bool full = true)
        {
            if (site == null)
            {
                return(null);
            }

            if (fields == null)
            {
                fields = Fields.All;
            }

            dynamic obj    = new ExpandoObject();
            var     siteId = new SiteId(site.Id);

            //
            // name
            if (fields.Exists("name"))
            {
                obj.name = site.Name;
            }

            //
            // id
            obj.id = siteId.Uuid;

            //
            // physical_path
            if (fields.Exists("physical_path"))
            {
                string      physicalPath = string.Empty;
                Application rootApp      = site.Applications["/"];

                if (rootApp != null && rootApp.VirtualDirectories["/"] != null)
                {
                    physicalPath = rootApp.VirtualDirectories["/"].PhysicalPath;
                }

                obj.physical_path = physicalPath;
            }

            //
            // key
            if (fields.Exists("key"))
            {
                obj.key = siteId.Id;
            }

            //
            // status
            if (fields.Exists("status"))
            {
                // Prepare state
                Status state = Status.Unknown;
                try {
                    state = StatusExtensions.FromObjectState(site.State);
                }
                catch (COMException) {
                    // Problem getting state of site. Possible reasons:
                    // 1. Site's application pool was deleted.
                    // 2. Site was just created and the status is not accessible yet.
                }
                obj.status = Enum.GetName(typeof(Status), state).ToLower();
            }

            //
            // server_auto_start
            if (fields.Exists("server_auto_start"))
            {
                obj.server_auto_start = site.ServerAutoStart;
            }

            //
            // enabled_protocols
            if (fields.Exists("enabled_protocols"))
            {
                Application rootApp = site.Applications["/"];
                obj.enabled_protocols = rootApp == null ? string.Empty : rootApp.EnabledProtocols;
            }

            //
            // limits
            if (fields.Exists("limits"))
            {
                dynamic limits = new ExpandoObject();

                limits.connection_timeout = site.Limits.ConnectionTimeout.TotalSeconds;
                limits.max_bandwidth      = site.Limits.MaxBandwidth;
                limits.max_connections    = site.Limits.MaxConnections;

                if (site.Limits.Schema.HasAttribute(MaxUrlSegmentsAttribute))
                {
                    limits.max_url_segments = site.Limits.MaxUrlSegments;
                }

                obj.limits = limits;
            }

            //
            // bindings
            if (fields.Exists("bindings"))
            {
                obj.bindings = site.Bindings.Select(b => ToJsonModel(b));
            }

            //
            // application_pool
            if (fields.Exists("application_pool"))
            {
                Application rootApp = site.Applications["/"];
                var         pool    = rootApp != null?AppPoolHelper.GetAppPool(rootApp.ApplicationPoolName) : null;

                obj.application_pool = (pool == null) ? null : AppPoolHelper.ToJsonModelRef(pool, fields.Filter("application_pool"));
            }

            return(Core.Environment.Hal.Apply(Defines.Resource.Guid, obj, full));
        }
Exemplo n.º 4
0
        internal static object ToJsonModel(ApplicationPool pool, Fields fields = null, bool full = true)
        {
            if (pool == null)
            {
                return(null);
            }

            if (fields == null)
            {
                fields = Fields.All;
            }

            dynamic obj = new ExpandoObject();

            //
            // name
            if (fields.Exists("name"))
            {
                obj.name = pool.Name;
            }

            //
            // id
            obj.id = AppPoolId.CreateFromName(pool.Name).Uuid;

            //
            // status
            if (fields.Exists("status"))
            {
                // Prepare state
                Status state = Status.Unknown;
                try {
                    state = StatusExtensions.FromObjectState(pool.State);
                }
                catch (COMException) {
                    // Problem getting state of app pool. Possible reasons:
                    // 1. App pool's application pool was deleted.
                    // 2. App pool was just created and the status is not accessible yet.
                }
                obj.status = Enum.GetName(typeof(Status), state).ToLower();
            }

            //
            // auto_start
            if (fields.Exists("auto_start"))
            {
                obj.auto_start = pool.AutoStart;
            }

            //
            // pipeline_mode
            if (fields.Exists("pipeline_mode"))
            {
                obj.pipeline_mode = Enum.GetName(typeof(ManagedPipelineMode), pool.ManagedPipelineMode).ToLower();
            }

            //
            // managed_runtime_version
            if (fields.Exists("managed_runtime_version"))
            {
                obj.managed_runtime_version = pool.ManagedRuntimeVersion;
            }

            //
            // enable_32bit_win64
            if (fields.Exists("enable_32bit_win64"))
            {
                obj.enable_32bit_win64 = pool.Enable32BitAppOnWin64;
            }

            //
            // queue_length
            if (fields.Exists("queue_length"))
            {
                obj.queue_length = pool.QueueLength;
            }

            //
            // cpu
            if (fields.Exists("cpu"))
            {
                obj.cpu = new {
                    limit                      = pool.Cpu.Limit,
                    limit_interval             = pool.Cpu.ResetInterval.TotalMinutes,
                    action                     = Enum.GetName(typeof(ProcessorAction), pool.Cpu.Action),
                    processor_affinity_enabled = pool.Cpu.SmpAffinitized,
                    processor_affinity_mask32  = "0x" + pool.Cpu.SmpProcessorAffinityMask.ToString("X"),
                    processor_affinity_mask64  = "0x" + pool.Cpu.SmpProcessorAffinityMask2.ToString("X")
                };
            }


            //
            // process_model
            if (fields.Exists("process_model"))
            {
                dynamic processModel = new ExpandoObject();

                processModel.idle_timeout        = pool.ProcessModel.IdleTimeout.TotalMinutes;
                processModel.max_processes       = pool.ProcessModel.MaxProcesses;
                processModel.pinging_enabled     = pool.ProcessModel.PingingEnabled;
                processModel.ping_interval       = pool.ProcessModel.PingInterval.TotalSeconds;
                processModel.ping_response_time  = pool.ProcessModel.PingResponseTime.TotalSeconds;
                processModel.shutdown_time_limit = pool.ProcessModel.ShutdownTimeLimit.TotalSeconds;
                processModel.startup_time_limit  = pool.ProcessModel.StartupTimeLimit.TotalSeconds;

                if (pool.ProcessModel.Schema.HasAttribute(IdleTimeoutActionAttribute))
                {
                    processModel.idle_timeout_action = Enum.GetName(typeof(IdleTimeoutAction), pool.ProcessModel.IdleTimeoutAction);
                }

                obj.process_model = processModel;
            }

            //
            // identity
            if (fields.Exists("identity"))
            {
                obj.identity = new {
                    // Not changing the casing or adding '_' on the identity type enum because they represent identities and therefore spelling and casing are important
                    identity_type     = Enum.GetName(typeof(ProcessModelIdentityType), pool.ProcessModel.IdentityType),
                    username          = pool.ProcessModel.UserName,
                    load_user_profile = pool.ProcessModel.LoadUserProfile
                };
            }

            //
            // recycling
            if (fields.Exists("recycling"))
            {
                RecyclingLogEventOnRecycle logEvent = pool.Recycling.LogEventOnRecycle;

                Dictionary <string, bool> logEvents = new Dictionary <string, bool>();
                logEvents.Add("time", logEvent.HasFlag(RecyclingLogEventOnRecycle.Time));
                logEvents.Add("requests", logEvent.HasFlag(RecyclingLogEventOnRecycle.Requests));
                logEvents.Add("schedule", logEvent.HasFlag(RecyclingLogEventOnRecycle.Schedule));
                logEvents.Add("memory", logEvent.HasFlag(RecyclingLogEventOnRecycle.Memory));
                logEvents.Add("isapi_unhealthy", logEvent.HasFlag(RecyclingLogEventOnRecycle.IsapiUnhealthy));
                logEvents.Add("on_demand", logEvent.HasFlag(RecyclingLogEventOnRecycle.OnDemand));
                logEvents.Add("config_change", logEvent.HasFlag(RecyclingLogEventOnRecycle.ConfigChange));
                logEvents.Add("private_memory", logEvent.HasFlag(RecyclingLogEventOnRecycle.PrivateMemory));

                obj.recycling = new {
                    disable_overlapped_recycle       = pool.Recycling.DisallowOverlappingRotation,
                    disable_recycle_on_config_change = pool.Recycling.DisallowRotationOnConfigChange,
                    log_events       = logEvents,
                    periodic_restart = new {
                        time_interval  = pool.Recycling.PeriodicRestart.Time.TotalMinutes,
                        private_memory = pool.Recycling.PeriodicRestart.PrivateMemory,
                        request_limit  = pool.Recycling.PeriodicRestart.Requests,
                        virtual_memory = pool.Recycling.PeriodicRestart.Memory,
                        schedule       = pool.Recycling.PeriodicRestart.Schedule.Select(s => s.Time.ToString(@"hh\:mm"))
                    }
                };
            }

            //
            // rapid_fail_protection
            if (fields.Exists("rapid_fail_protection"))
            {
                obj.rapid_fail_protection = new {
                    enabled = pool.Failure.RapidFailProtection,
                    load_balancer_capabilities = Enum.GetName(typeof(LoadBalancerCapabilities), pool.Failure.LoadBalancerCapabilities),
                    interval             = pool.Failure.RapidFailProtectionInterval.TotalMinutes,
                    max_crashes          = pool.Failure.RapidFailProtectionMaxCrashes,
                    auto_shutdown_exe    = pool.Failure.AutoShutdownExe,
                    auto_shutdown_params = pool.Failure.AutoShutdownParams
                };
            }

            //
            // process_orphaning
            if (fields.Exists("process_orphaning"))
            {
                obj.process_orphaning = new {
                    enabled              = pool.Failure.OrphanWorkerProcess,
                    orphan_action_exe    = pool.Failure.OrphanActionExe,
                    orphan_action_params = pool.Failure.OrphanActionParams,
                };
            }

            return(Core.Environment.Hal.Apply(Defines.Resource.Guid, obj, full));
        }