static bool isSupported(string scope, out string[] items, out string unsupportedScope) { if (Supported is null) { items = new string[0]; unsupportedScope = scope; return(false); } var test = scope.Trim(); if (!test.Contains(Separator)) { unsupportedScope = string.Empty; if (test.Length == 0) { items = new string[0]; return(true); } if (Supported.Any(i => i.Equals(test, StringComparison.InvariantCultureIgnoreCase))) { items = new[] { test }; return(true); } unsupportedScope = test; items = new string[0]; return(false); } if (!tryParse(ref test, out items)) { throw invalidFormatError(scope); } var unsupported = new StringBuilder(); for (var i = 0; i < items.Length; i++) { if (IsScopeSupported(items[i], out _)) { continue; } unsupported.Append(items[i]); unsupported.Append(Separator); } if (unsupported.Length != 0) { unsupportedScope = unsupported.ToString().TrimEnd(); items = new string[0]; return(false); } unsupportedScope = string.Empty; return(true); }
public static bool IsSupportedNativelyOrByComposition(this MethodInfo methodInfo) { if (methodInfo.IsGenericMethod) { methodInfo = methodInfo.GetGenericMethodDefinition(); } return(methodInfo.IsSupportedByComposition() || Supported.Contains(methodInfo)); }
public Boolean IsSupportCulture(CultureInfo info) { if (info is null) { throw new ArgumentNullException(nameof(info)); } if (info.LCID == CultureUtils.Default || info.LCID == Default.LCID) { return(true); } return(Supported.ContainsKey(info)); }
public Boolean AddSupportedCulture([NotNull] CultureInfo info, [CanBeNull] ISubLocalization config) { if (info is null) { throw new ArgumentNullException(nameof(info)); } if (!Supported.TryAdd(info, config)) { return(false); } SupportedLanguagesChanged?.Invoke(); return(true); }
public Languages(String path) { Dictionary = new Dictionary <String, Language>(); foreach (XElement lang in XElement.Load(path).Elements("language")) { Language language = new Language(); language.Culture = new CultureInfo((String)lang.Attribute("culture")); language.IsDefault = (Boolean?)lang.Attribute("default") == true; language.Abbreviation = (String)lang.Attribute("abbreviation"); language.Name = (String)lang.Attribute("name"); Dictionary.Add(language.Abbreviation, language); } Supported = Dictionary.Select(language => language.Value).ToArray(); Default = Supported.Single(language => language.IsDefault); }
public LogLevel(string Label, int Criticality, string ChibiLabel = null, ConsoleColor Color = ConsoleColor.Gray) { this.Name = Label; this.ChibiName = ChibiLabel ?? Label.Substring(0, 4); this.Criticality = Criticality; this.Color = Color; if (Supported.Any(p => string.Equals(p.Name, Label, StringComparison.OrdinalIgnoreCase))) { throw new InvalidLogLevelException($"Value entered for {nameof(Label)} ({Label}) is already in use."); } if (Supported.Any(p => string.Equals(p.ChibiName, ChibiLabel, StringComparison.OrdinalIgnoreCase))) { throw new InvalidLogLevelException($"Value entered for {nameof(ChibiLabel)} ({ChibiLabel}) is already in use."); } Supported.Add(this); gotPadding = false; }
public Boolean RemoveSupportedCulture([NotNull] CultureInfo info) { if (info is null) { throw new ArgumentNullException(nameof(info)); } if (info.LCID == CultureUtils.Default || info.LCID == Default.LCID) { return(false); } if (!Supported.Remove(info)) { return(false); } SupportedLanguagesChanged?.Invoke(); return(true); }
/// <summary> /// Validates the <paramref name="selection"/> against what is <see cref="Supported"/> to ensure validity. /// </summary> /// <param name="selection">The <see cref="WildcardSelection"/> to validate.</param> /// <returns><c>true</c> indicates that the selection is valid; otherwise, <c>false</c> for invalid.</returns> public bool Validate(WildcardSelection selection) { if ((selection.HasFlag(WildcardSelection.None) && !Supported.HasFlag(WildcardSelection.None)) || (selection.HasFlag(WildcardSelection.Equal) && !Supported.HasFlag(WildcardSelection.Equal)) || (selection.HasFlag(WildcardSelection.Single) && !Supported.HasFlag(WildcardSelection.Single)) || (selection.HasFlag(WildcardSelection.StartsWith) && !Supported.HasFlag(WildcardSelection.StartsWith)) || (selection.HasFlag(WildcardSelection.EndsWith) && !Supported.HasFlag(WildcardSelection.EndsWith)) || (selection.HasFlag(WildcardSelection.Contains) && !Supported.HasFlag(WildcardSelection.Contains)) || (selection.HasFlag(WildcardSelection.Embedded) && !Supported.HasFlag(WildcardSelection.Embedded)) || (selection.HasFlag(WildcardSelection.MultiWildcard) && !Supported.HasFlag(WildcardSelection.MultiWildcard)) || (selection.HasFlag(WildcardSelection.SingleWildcard) && !Supported.HasFlag(WildcardSelection.SingleWildcard)) || (selection.HasFlag(WildcardSelection.AdjacentWildcards) && !Supported.HasFlag(WildcardSelection.AdjacentWildcards)) || (selection.HasFlag(WildcardSelection.InvalidCharacter))) { return(false); } else { return(true); } }
public Languages(IConfiguration config) { String path = Path.Combine(config["Application:Path"], config["Languages:Path"]); IEnumerable <XElement> languages = XElement.Load(path).Elements("language"); Dictionary = new Dictionary <String, Language>(); foreach (XElement lang in languages) { Language language = new Language(); language.Culture = new CultureInfo((String)lang.Attribute("culture")); language.IsDefault = (Boolean?)lang.Attribute("default") == true; language.Abbreviation = (String)lang.Attribute("abbreviation"); language.Name = (String)lang.Attribute("name"); Dictionary.Add(language.Abbreviation, language); } Supported = Dictionary.Select(language => language.Value).ToArray(); Default = Supported.Single(language => language.IsDefault); }
public Boolean Update(CultureInfo info) { info ??= Default; if (info.IsCultureEquals(Culture)) { return(false); } if (!Supported.ContainsKey(info)) { return(false); } Culture = info; if (ChangeUIThreadLanguage) { SetUILanguage(); } LanguageChanged?.Invoke(Culture); return(true); }
/// <summary> /// Parses the wildcard text to ensure validitity returning a <see cref="WildcardResult"/>. /// </summary> /// <param name="text">The wildcard text.</param> /// <returns>The corresponding <see cref="WildcardResult"/>.</returns> public WildcardResult Parse(string?text) { text = Cleaner.Clean(text, StringTrim.Both, Transform); if (string.IsNullOrEmpty(text)) { return new WildcardResult(this) { Selection = WildcardSelection.None, Text = text } } ; var sb = new StringBuilder(); var wr = new WildcardResult(this) { Selection = WildcardSelection.Undetermined }; if (CharactersNotAllowed != null && CharactersNotAllowed.Count > 0 && text.IndexOfAny(CharactersNotAllowed.ToArray()) >= 0) { wr.Selection |= WildcardSelection.InvalidCharacter; } var hasMulti = SpaceTreatment == WildcardSpaceTreatment.MultiWildcardWhenOthers && Supported.HasFlag(WildcardSelection.MultiWildcard) && text.IndexOf(MultiWildcardCharacter, StringComparison.InvariantCulture) >= 0; var hasTxt = false; for (int i = 0; i < text.Length; i++) { var c = text[i]; var isMulti = c == MultiWildcard; var isSingle = c == SingleWildcard; if (isMulti) { wr.Selection |= WildcardSelection.MultiWildcard; // Skip adjacent multi's as they are redundant. for (int j = i + 1; j < text.Length; j++) { if (text[j] == MultiWildcard) { i = j; continue; } break; } } if (isSingle) { wr.Selection |= WildcardSelection.SingleWildcard; } if (isMulti || isSingle) { if (text.Length == 1) { wr.Selection |= WildcardSelection.Single; } else if (i == 0) { wr.Selection |= WildcardSelection.EndsWith; } else if (i == text.Length - 1) { wr.Selection |= WildcardSelection.StartsWith; } else { if (hasTxt || isSingle) { wr.Selection |= WildcardSelection.Embedded; } else { wr.Selection |= WildcardSelection.EndsWith; } } if (i < text.Length - 1 && (text[i + 1] == MultiWildcard || text[i + 1] == SingleWildcard)) { wr.Selection |= WildcardSelection.AdjacentWildcards; } } else { hasTxt = true; if (c == SpaceCharacter && (SpaceTreatment == WildcardSpaceTreatment.Compress || SpaceTreatment == WildcardSpaceTreatment.MultiWildcardAlways || SpaceTreatment == WildcardSpaceTreatment.MultiWildcardWhenOthers)) { // Compress adjacent spaces. bool skipChar = SpaceTreatment != WildcardSpaceTreatment.Compress && text[i - 1] == MultiWildcardCharacter; for (int j = i + 1; j < text.Length; j++) { if (text[j] == SpaceCharacter) { i = j; continue; } break; } if (skipChar || (SpaceTreatment != WildcardSpaceTreatment.Compress && text[i + 1] == MultiWildcardCharacter)) { continue; } if (SpaceTreatment == WildcardSpaceTreatment.MultiWildcardAlways || (SpaceTreatment == WildcardSpaceTreatment.MultiWildcardWhenOthers && hasMulti)) { c = MultiWildcardCharacter; wr.Selection |= WildcardSelection.MultiWildcard; wr.Selection |= WildcardSelection.Embedded; } } } sb.Append(c); } if (!hasTxt && wr.Selection == (WildcardSelection.StartsWith | WildcardSelection.MultiWildcard)) { wr.Selection |= WildcardSelection.Single; wr.Selection ^= WildcardSelection.StartsWith; } if (hasTxt && wr.Selection.HasFlag(WildcardSelection.StartsWith) && wr.Selection.HasFlag(WildcardSelection.EndsWith) && !wr.Selection.HasFlag(WildcardSelection.Embedded)) { wr.Selection |= WildcardSelection.Contains; wr.Selection ^= WildcardSelection.StartsWith; wr.Selection ^= WildcardSelection.EndsWith; } if (wr.Selection == WildcardSelection.Undetermined) { wr.Selection |= WildcardSelection.Equal; } wr.Text = sb.Length == 0 ? null : sb.ToString(); return(wr); } }
/// <summary> /// Changes the screen size to the bounds specified for the enum value /// </summary> public void ResizeScreen(ScreenType screenType) { var screenSize = Supported.GetScreenSize(screenType); CurrentDriver.Manage().Window.Size = new Size(screenSize.Width, screenSize.Height); }
/// <summary> /// Check to see if a Machine passes the filters /// </summary> /// <param name="machine">Machine to check</param> /// <returns>True if the machine passed the filter, false otherwise</returns> public bool PassesFilters(Machine machine) { if (machine == null) { return(false); } #region Common // Machine_Name bool passes = PassStringFilter(Name, machine.Name); if (IncludeOfInGame) { passes |= PassStringFilter(Name, machine.CloneOf); passes |= PassStringFilter(Name, machine.RomOf); } if (!passes) { return(false); } // Machine_Comment if (!PassStringFilter(Comment, machine.Comment)) { return(false); } // Machine_Description if (!PassStringFilter(Description, machine.Description)) { return(false); } // Machine_Year if (!PassStringFilter(Year, machine.Year)) { return(false); } // Machine_Manufacturer if (!PassStringFilter(Manufacturer, machine.Manufacturer)) { return(false); } // Machine_Publisher if (!PassStringFilter(Publisher, machine.Publisher)) { return(false); } // Machine_Category if (!PassStringFilter(Category, machine.Category)) { return(false); } // Machine_RomOf if (!PassStringFilter(RomOf, machine.RomOf)) { return(false); } // Machine_CloneOf if (!PassStringFilter(CloneOf, machine.CloneOf)) { return(false); } // Machine_SampleOf if (!PassStringFilter(SampleOf, machine.SampleOf)) { return(false); } // Machine_Type if (Type.MatchesPositive(0x0, machine.MachineType) == false) { return(false); } if (Type.MatchesNegative(0x0, machine.MachineType) == true) { return(false); } #endregion #region AttractMode // Machine_Players if (!PassStringFilter(Players, machine.Players)) { return(false); } // Machine_Rotation if (!PassStringFilter(Rotation, machine.Rotation)) { return(false); } // Machine_Control if (!PassStringFilter(Control, machine.Control)) { return(false); } // Machine_Status if (!PassStringFilter(Status, machine.Status)) { return(false); } // Machine_DisplayCount if (!PassStringFilter(DisplayCount, machine.DisplayCount)) { return(false); } // Machine_DisplayType if (!PassStringFilter(DisplayType, machine.DisplayType)) { return(false); } // Machine_Buttons if (!PassStringFilter(Buttons, machine.Buttons)) { return(false); } #endregion #region ListXML // Machine_History if (!PassStringFilter(History, machine.History)) { return(false); } // Machine_SourceFile if (!PassStringFilter(SourceFile, machine.SourceFile)) { return(false); } // Machine_Runnable if (Runnable.MatchesPositive(Core.Runnable.NULL, machine.Runnable) == false) { return(false); } if (Runnable.MatchesNegative(Core.Runnable.NULL, machine.Runnable) == true) { return(false); } #endregion #region Logiqx // Machine_Board if (!PassStringFilter(Board, machine.Board)) { return(false); } // Machine_RebuildTo if (!PassStringFilter(RebuildTo, machine.RebuildTo)) { return(false); } #endregion #region Logiqx EmuArc // Machine_TitleID if (!PassStringFilter(TitleID, machine.TitleID)) { return(false); } // Machine_Developer if (!PassStringFilter(Developer, machine.Developer)) { return(false); } // Machine_Genre if (!PassStringFilter(Genre, machine.Genre)) { return(false); } // Machine_Subgenre if (!PassStringFilter(Subgenre, machine.Subgenre)) { return(false); } // Machine_Ratings if (!PassStringFilter(Ratings, machine.Ratings)) { return(false); } // Machine_Score if (!PassStringFilter(Score, machine.Score)) { return(false); } // Machine_Enabled if (!PassStringFilter(Enabled, machine.Enabled)) { return(false); } // Machine_CRC if (!PassBoolFilter(CRC, machine.Crc)) { return(false); } // Machine_RelatedTo if (!PassStringFilter(RelatedTo, machine.RelatedTo)) { return(false); } #endregion #region OpenMSX // Machine_GenMSXID if (!PassStringFilter(GenMSXID, machine.GenMSXID)) { return(false); } // Machine_System if (!PassStringFilter(System, machine.System)) { return(false); } // Machine_Country if (!PassStringFilter(Country, machine.Country)) { return(false); } #endregion #region SoftwareList // Machine_Supported if (Supported.MatchesPositive(Core.Supported.NULL, machine.Supported) == false) { return(false); } if (Supported.MatchesNegative(Core.Supported.NULL, machine.Supported) == true) { return(false); } #endregion // SoftwareList return(true); }
public object FunctionHandler(object input, ILambdaContext context) { // Get request object Request request = JsonConvert.DeserializeObject <Request>(input.ToString()); string requestType = request.Directive.Header.Name; LambdaLogger.Log("Request type: " + requestType + Environment.NewLine); if (requestType == "Discover") { // Create response object Response response = new Response { Event = new Event() }; response.Event.Header = new Header(); LambdaLogger.Log("DISCOVER: " + input.ToString()); response.Event.Payload = new Payload { Endpoints = new List <Endpoint>() }; LambdaLogger.Log("Discovering devices" + Environment.NewLine); // Set header properties response.Event.Header.Namespace = "Alexa.Discovery"; response.Event.Header.Name = "Discover.Response"; response.Event.Header.PayloadVersion = "3"; response.Event.Header.MessageId = request.Directive.Header.MessageId; // Create endpoint Endpoint ep1 = new Endpoint { EndpointId = "endpoint-001", ManufacturerName = "Ryan Malencia", FriendlyName = "Apple Jacks", Description = "This is a switch!", DisplayCategories = new List <string>() { "SMARTPLUG" } }; ep1.Capabilities = new List <Capability>(); // Create capabilities Capability cap1 = new Capability { Type = "AlexaInterface", Interface = "Alexa", Version = "3" }; Capability cap2 = new Capability { Type = "AlexaInterface", Interface = "Alexa.PowerController", Version = "3" }; // Create properties Properties p1 = new Properties(); Supported s1 = new Supported { Name = "powerState" }; p1.Supported = new List <Supported>(); p1.Supported.Add(s1); //p1.ProactivelyReported = true; //p1.Retrievable = true; cap2.Properties = p1; // Set capabilities ep1.Capabilities.Add(cap1); ep1.Capabilities.Add(cap2); // Add endpoint to response response.Event.Payload.Endpoints.Add(ep1); return(response); } else if (requestType == "TurnOff") { PowerRequest powerRequest = JsonConvert.DeserializeObject <PowerRequest>(input.ToString()); PowerResponse powerResponse = new PowerResponse { Context = new Context { Properties = new List <Property>() } }; Property p1 = new Property { Namespace = "Alexa.PowerController", Name = "powerState", Value = "OFF", TimeOfSample = DateTime.Now, UncertaintyInMilliseconds = 200 }; Property p2 = new Property { Namespace = "Alexa.EndpointHealth", Name = "connectivity", Value = "OK", TimeOfSample = DateTime.Now, UncertaintyInMilliseconds = 200 }; powerResponse.Context.Properties.Add(p1); powerResponse.Context.Properties.Add(p2); powerResponse.Event = new SmartPLugHandlerLambda.Response.Event { Header = new SmartPLugHandlerLambda.Response.Header { Namespace = "Alexa", Name = "Response", PayloadVersion = "3", MessageId = powerRequest.Directive.Header.MessageId, CorrelationToken = powerRequest.Directive.Header.CorrelationToken }, Endpoint = new SmartPLugHandlerLambda.Response.Endpoint { Scope = new SmartPLugHandlerLambda.Response.Scope { Type = powerRequest.Directive.Endpoint.Scope.Type, Token = powerRequest.Directive.Endpoint.Scope.Token }, EndpointId = powerRequest.Directive.Endpoint.EndpointId, }, Payload = new SmartPLugHandlerLambda.Response.Payload() }; LambdaLogger.Log("OFF: " + input.ToString()); const string queueUrl = "https://sqs.us-east-1.amazonaws.com/320502343338/SmartPlugQueue"; var config = new AmazonSQSConfig { ServiceURL = "http://sqs.us-east-1.amazonaws.com" }; var client = new AmazonSQSClient(config); var sendMessage = client.SendMessageAsync(queueUrl, "OFF", new System.Threading.CancellationToken()); while (!sendMessage.IsCompleted) { } return(powerResponse); } else if (requestType == "TurnOn") { PowerRequest powerRequest = JsonConvert.DeserializeObject <PowerRequest>(input.ToString()); PowerResponse powerResponse = new PowerResponse { Context = new Context { Properties = new List <Property>() } }; Property p1 = new Property { Namespace = "Alexa.PowerController", Name = "powerState", Value = "ON", TimeOfSample = DateTime.Now, UncertaintyInMilliseconds = 200 }; Property p2 = new Property { Namespace = "Alexa.EndpointHealth", Name = "connectivity", Value = "OK", TimeOfSample = DateTime.Now, UncertaintyInMilliseconds = 200 }; powerResponse.Context.Properties.Add(p1); powerResponse.Context.Properties.Add(p2); powerResponse.Event = new SmartPLugHandlerLambda.Response.Event { Header = new SmartPLugHandlerLambda.Response.Header { Namespace = "Alexa", Name = "Response", PayloadVersion = "3", MessageId = powerRequest.Directive.Header.MessageId, CorrelationToken = powerRequest.Directive.Header.CorrelationToken }, Endpoint = new SmartPLugHandlerLambda.Response.Endpoint { Scope = new SmartPLugHandlerLambda.Response.Scope { Type = powerRequest.Directive.Endpoint.Scope.Type, Token = powerRequest.Directive.Endpoint.Scope.Token }, EndpointId = powerRequest.Directive.Endpoint.EndpointId, }, Payload = new SmartPLugHandlerLambda.Response.Payload() }; LambdaLogger.Log("ON: " + input.ToString()); const string queueUrl = "https://sqs.us-east-1.amazonaws.com/320502343338/SmartPlugQueue"; var config = new AmazonSQSConfig { ServiceURL = "http://sqs.us-east-1.amazonaws.com" }; var client = new AmazonSQSClient(config); var sendMessage = client.SendMessageAsync(queueUrl, "ON", new System.Threading.CancellationToken()); while (!sendMessage.IsCompleted) { } return(powerResponse); } return(new Response()); }