internal LogSearchRuleData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, string kind, string etag, string createdWithApiVersion, bool?isLegacyLogAnalyticsRule, string description, string displayName, bool?autoMitigate, Enabled?enabled, DateTimeOffset?lastUpdatedOn, ProvisioningState?provisioningState, MonitorSource source, MonitorSchedule schedule, MonitorAction action) : base(id, name, resourceType, systemData, tags, location, kind, etag)
 {
     CreatedWithApiVersion    = createdWithApiVersion;
     IsLegacyLogAnalyticsRule = isLegacyLogAnalyticsRule;
     Description       = description;
     DisplayName       = displayName;
     AutoMitigate      = autoMitigate;
     Enabled           = enabled;
     LastUpdatedOn     = lastUpdatedOn;
     ProvisioningState = provisioningState;
     Source            = source;
     Schedule          = schedule;
     Action            = action;
 }
        public LogSearchRuleData(AzureLocation location, MonitorSource source, MonitorAction action) : base(location)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            Source = source;
            Action = action;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="AutoSwitchConfigViewModel" /> class.
        /// </summary>
        /// <param name="autoSwitchConfig">The automatic switch configuration.</param>
        /// <param name="environment"></param>
        public AutoSwitchConfigViewModel(AutoSwitchConfig autoSwitchConfig, IKvmSwitchEnvironment environment)
        {
            this.environment = environment;
            this.Name        = autoSwitchConfig.Name;
            this.Active      = autoSwitchConfig.Active;
            this.ExecuteOnUsbDeviceConnected    = autoSwitchConfig.ExecuteOnUsbDeviceConnected;
            this.ExecuteOnUsbDeviceDisconnected = autoSwitchConfig.ExecuteOnUsbDeviceDisconnected;

            this.InitUsbDevices(autoSwitchConfig);

            // Displays
            var supportedMonitorSources = environment.DisplayDataChannel.GetSupportedSourcesOfMonitors();

            this.MonitorInfos = new List <MonitorInfo>();

            for (var monitorIndex = 0; monitorIndex < supportedMonitorSources.Count; ++monitorIndex)
            {
                var monitorInfo = new MonitorInfo
                {
                    MonitorIndex   = monitorIndex,
                    MonitorSources = supportedMonitorSources[monitorIndex]
                };

                var existingMonitorConfig =
                    autoSwitchConfig.MonitorConfigs?.FirstOrDefault(x => x.Name == monitorInfo.Name);


                MonitorSource monitorSource = null;

                if (existingMonitorConfig != null)
                {
                    monitorSource =
                        monitorInfo.MonitorSources.FirstOrDefault(x => x.Name == existingMonitorConfig.Input);
                    monitorInfo.UseInProfile = true;
                }


                if (monitorSource == null)
                {
                    monitorSource = monitorInfo.MonitorSources.FirstOrDefault();
                }

                monitorInfo.SelectedMonitorSource = monitorSource;
                this.MonitorInfos.Add(monitorInfo);
            }
        }
Exemple #4
0
        private static MonitorSource[] GetMonitorSupportedSources(IntPtr hMonitor)
        {
            int[] values = new int[0];

            uint strSize;
            GetCapabilitiesStringLength(hMonitor, out strSize);

            StringBuilder capabilities = new StringBuilder((int)strSize);
            CapabilitiesRequestAndCapabilitiesReply(hMonitor, capabilities, strSize);
            string capabilitiesStr = capabilities.ToString();

            // Parse source codes.
            Match match = vcp60ValuesRegex.Match(capabilitiesStr);
            if (match.Success)
            {
                string valuesStr = match.Groups[1].Value.Trim();
                string[] valueArray = valuesStr.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);

                values = Array.ConvertAll(valueArray, s =>
                    int.Parse(s, System.Globalization.NumberStyles.HexNumber));
            }

            // Parse MCCS version.
            string[] sourceNames = new string[0];
            match = mccsVersionRegex.Match(capabilitiesStr);
            if (match.Success)
            {
                string versionStr = match.Groups[1].Value.Trim();
                string[] versionArray = versionStr.Split(new char[]{'.'}, StringSplitOptions.RemoveEmptyEntries);
                int majorVersion = int.Parse(versionArray[0]);

                if (majorVersion < 3)
                    sourceNames = sourceNamesMccsV2;
                else
                    sourceNames = sourceNamesMccsV3;
            }

            // Prepare output.
            MonitorSource[] sources = new MonitorSource[values.Length];
            for (int i = 0; i < values.Length; ++i)
            {
                sources[i].code = values[i];
                if (0 <= values[i] && values[i] < sourceNames.Length)
                    sources[i].name = sourceNames[values[i]];
                else
                    sources[i].name = "**Unrecognized**";
            }

            return sources;
        }
        public virtual IVitalsSystem ApplyVitalsSource(Object srcObj)
        {
            GameObject vitalsSrcGO;
            Component  vitalsSrcComp;

            if (monitor == MonitorSource.Auto)
            {
                if (srcObj == null)
                {
                    srcObj  = (Object)GetComponentInParent <IVitalsSystem>();
                    monitor = MonitorSource.Self;
                }

                if (srcObj == null)
                {
                    srcObj  = (Object)OwnedIVitals.LastItem;
                    monitor = MonitorSource.Owned;
                }
            }

            /// Override the value if it doesn't conform to the type being monitored.
            if (monitor == MonitorSource.Owned)
            {
                var ownedVitals = OwnedIVitals.LastItem;
                vitalsSrcComp = ownedVitals as Component;
                vitalsSrcGO   = null;
            }
            else if (monitor == MonitorSource.Self)
            {
                vitalsSrcGO   = gameObject;
                vitalsSrcComp = null;
            }
            // Auto - try self first - if no vitals found fall back to owned
            else
            {
                vitalsSource  = srcObj;
                vitalsSrcGO   = srcObj as GameObject;
                vitalsSrcComp = srcObj as Component;
            }

            IVitalsSystem vs;

            /// Get the actual value we want
            if (vitalsSrcGO)
            {
                vs = FindIVitalComponentOnGameObj(vitalsSrcGO);

                if (vs != null)
                {
                    vitalsSource = (vs as Component).gameObject;
                }
            }
            else if (vitalsSrcComp)
            {
                vs = vitalsSrcComp as IVitalsSystem;

                if (monitor == MonitorSource.GameObject)
                {
                    vitalsSource = vitalsSrcComp.gameObject;
                }
            }
            else
            {
                vs           = null;
                vitalsSource = null;
            }

            return(vs);
        }
Exemple #6
0
        internal static LogSearchRuleData DeserializeLogSearchRuleData(JsonElement element)
        {
            Optional <string>            kind                     = default;
            Optional <string>            etag                     = default;
            IDictionary <string, string> tags                     = default;
            AzureLocation                location                 = default;
            ResourceIdentifier           id                       = default;
            string                       name                     = default;
            ResourceType                 type                     = default;
            SystemData                   systemData               = default;
            Optional <string>            createdWithApiVersion    = default;
            Optional <bool>              isLegacyLogAnalyticsRule = default;
            Optional <string>            description              = default;
            Optional <string>            displayName              = default;
            Optional <bool>              autoMitigate             = default;
            Optional <Enabled>           enabled                  = default;
            Optional <DateTimeOffset>    lastUpdatedTime          = default;
            Optional <ProvisioningState> provisioningState        = default;
            MonitorSource                source                   = default;
            Optional <MonitorSchedule>   schedule                 = default;
            MonitorAction                action                   = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("kind"))
                {
                    kind = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("etag"))
                {
                    etag = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = new AzureLocation(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("createdWithApiVersion"))
                        {
                            createdWithApiVersion = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("isLegacyLogAnalyticsRule"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isLegacyLogAnalyticsRule = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("description"))
                        {
                            description = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("displayName"))
                        {
                            displayName = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("autoMitigate"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            autoMitigate = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("enabled"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enabled = new Enabled(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("lastUpdatedTime"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            lastUpdatedTime = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = new ProvisioningState(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("source"))
                        {
                            source = MonitorSource.DeserializeMonitorSource(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("schedule"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            schedule = MonitorSchedule.DeserializeMonitorSchedule(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("action"))
                        {
                            action = MonitorAction.DeserializeMonitorAction(property0.Value);
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new LogSearchRuleData(id, name, type, systemData, tags, location, kind.Value, etag.Value, createdWithApiVersion.Value, Optional.ToNullable(isLegacyLogAnalyticsRule), description.Value, displayName.Value, Optional.ToNullable(autoMitigate), Optional.ToNullable(enabled), Optional.ToNullable(lastUpdatedTime), Optional.ToNullable(provisioningState), source, schedule.Value, action));
        }