/// <summary> /// Parses all passed arguments and fills PassedSwitches with switches and their values /// </summary> /// <param name="args">Arguments array (string)</param> /// <returns>Indicates whether or not parse was successful</returns> private bool ParseArgs(string[] args) { Switch sw = null; foreach (string arg in args) { switch (arg.Substring(0, 1)) { case "/": case "-": // Check for subvalues Regex re = new Regex(":|="); string[] arrArg = re.Split(arg.Substring(1).ToLower()); sw = PassedSwitches[arrArg[0]]; if (sw == null) { // Check if help screen is called // or switch is in PossibleSwitches if (arrArg[0] == "?" || arrArg[0] == "help" || !SwitchOk(arrArg[0])) { PassedSwitches.Clear(); return(false); } sw = new Switch(arrArg[0]); PassedSwitches.Add(sw); } // Add values for (int i = 1; i < arrArg.Length; i++) { sw.SwitchValues.Add(arrArg[i]); } break; default: // Value of switch when seperated by space if (sw != null) { sw.SwitchValues.Add(arg); break; } else { // Switch-less value sw = PassedSwitches[""]; if (sw == null) { sw = new Switch(""); PassedSwitches.Add(sw); } sw.SwitchValues.Add(arg); break; } } } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="SwitchExcludeArchiveFilenameCollection"/> class. /// </summary> /// <param name="initial">The initial.</param> /// <param name="additional">The additional.</param> public SwitchExcludeArchiveFilenameCollection( SwitchExcludeArchiveFilename initial, params SwitchExcludeArchiveFilename[] additional) { Switches.Add(initial); Switches.AddRange(additional); }
/// <summary> /// Initializes a new instance of the <see cref="ZipatoDevices"/> class. /// The list of UUIDs from the SettingsData is used to create the device instances. /// </summary> /// <param name="zipato"></param> public ZipatoDevices(IZipato zipato) { _zipato = zipato; foreach (var uuid in zipato.DevicesInfo.Switches) { Switches.Add(new Switch(zipato, uuid)); } foreach (var uuid in zipato.DevicesInfo.OnOffSwitches) { OnOffSwitches.Add(new OnOff(zipato, uuid)); } foreach (var uuid in zipato.DevicesInfo.Wallplugs) { Wallplugs.Add(new Plug(zipato, uuid)); } foreach (var uuid in zipato.DevicesInfo.Dimmers) { Dimmers.Add(new Dimmer(zipato, uuid)); } foreach (var uuid in zipato.DevicesInfo.RGBControls) { RGBControls.Add(new RGBControl(zipato, uuid)); } Status = _zipato?.Data?.Status ?? Uncertain; }
public RegexLiteral(string name) : base(name) { Switches.Add('i', RegexOptions.IgnoreCase); Switches.Add('g', RegexOptions.None); //not sure what to do with this flag? anybody, any advice? Switches.Add('m', RegexOptions.Multiline); SetFlag(TermFlags.IsLiteral); }
private void LoadSwitches() { Switches.Add( new SwitchProperty <bool>( "--no-data", "--no-data=true (true|false)", "Don't display packet data", bool.TryParse, (result => NoData = result) ) ); Switches.Add( new SwitchProperty <int>( "--max-packet-size", "--max-packet-size=64 (integer)", "Don't display packet data", int.TryParse, (result => MaxPacketSize = result) ) ); Switches.Add( new SwitchProperty <int>( "--log-level", "--log-level=20 (integer) [Debug=10, Info=20, Error=30]", "Only display logs of the same level or above", int.TryParse, (result => MinLogLevel = result) ) ); Switches.Add( new SwitchProperty <object>( "--clear", "--clear", "Resets all switches to default", SwitchProperty <object> .NoOp, result => Reset() ) ); Switches.Add( new SwitchProperty <List <Tuple <ServerType?, ushort> > >( "--b-list", "--b-list=1:1000,2000,3:0xAA (ServerType:PacketId[0xA|10] | PacketId[0xA|10]) [Auth=1, Msg=2, Area=3]", "A blacklist that does not logs packets specified", TryParsePacketIdList, results => { AssinPacketIdList(results, BlacklistPacket, BlacklistPacket); } ) ); Switches.Add( new SwitchProperty <List <Tuple <ServerType?, ushort> > >( "--w-list", "--w-list=1:1000,2000,3:0xAA (ServerType:PacketId[0xA|10] | PacketId[0xA|10]) [Auth=1, Msg=2, Area=3]", "A whitelist that only logs packets specified", TryParsePacketIdList, results => { AssinPacketIdList(results, WhitelistPacket, WhitelistPacket); } ) ); }
public static ErrorCode Parse(string[] args, string[] expectedSwitches, string[] expectedSwitchesWithValues) { if (args.Length == 0) { return(ErrorCode.NoArgument); } string lastSwitch = null; for (int i = 0; i < args.Length; i++) { string arg = args[i].ToLowerInvariant(); if (string.IsNullOrWhiteSpace(arg)) { return(ErrorCode.WhiteSpace); } if (arg.StartsWith("-", StringComparison.InvariantCulture)) { if (lastSwitch != null) { return(ErrorCode.InvalidValueForSwitch); } if (expectedSwitches.Contains(arg)) { Switches.Add(arg); } else if (expectedSwitchesWithValues.Contains(arg)) { lastSwitch = arg; } else { return(ErrorCode.InvalidSwitch); } } else if (lastSwitch != null) { SwitchesWithValues[lastSwitch] = arg; lastSwitch = null; } else { OrdinaryArguments.Add(arg); } } if (lastSwitch != null) { return(ErrorCode.MissingValueForSwitch); } return(ErrorCode.Success); }
public override void AddReference(ModelCode referenceId, long globalId) { switch (referenceId) { case ModelCode.SWITCH_SWITCHINGOPERATION: Switches.Add(globalId); break; default: base.AddReference(referenceId, globalId); break; } }
public CommandLine() : base() { Switches.Add(ShowUsageSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.TrueFalse)); Switches.Add(VerboseSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.TrueFalse)); Switches.Add(MinimumLengthSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.ValueSwitch)); Switches.Add(MaximumLengthSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.ValueSwitch)); Switches.Add(IncludeUppercaseSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.TrueFalse)); Switches.Add(IncludeLowercaseSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.TrueFalse)); Switches.Add(IncludeNumbersSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.TrueFalse)); Switches.Add(IncludeSymbolsSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.TrueFalse)); Switches.Add(IncludeSimpleSymbolsSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.TrueFalse)); Switches.Add(ExcludeAmbiguousSwitch.ToUpper(), new SwitchDescription(SwitchDescription.SwitchTypeOption.TrueFalse)); AvailableCharacters = new List <string>(); }
private void CreateSwitch() { var sw = new Switch() { IsON = true, IsNew = true }; Switches.Add(sw); SelectedObject = sw; }
private void LoadSwitch(XmlElement element, StationElements allDevices) { string strSwitch = element.GetAttribute("InSwitches").TrimEnd(); string strPosition = element.GetAttribute("Positions").TrimEnd(); if (!string.IsNullOrEmpty(strSwitch)) { string[] names = strSwitch.Split(' '); string[] positions = strPosition.Split(' '); for (int i = 0; i < names.Length; i++) { Switches.Add(new RouteSwitch( FindDevice(names[i], allDevices) as RailSwitch, (RailSwitch.SwitchPosition)Enum.Parse(typeof(RailSwitch.SwitchPosition), positions[i]))); } } }
protected void AddCheck(GumpCheck entry, Action <GumpCheck, bool> handler) { if (entry == null) { return; } if (!Switches.ContainsKey(entry)) { Switches.Add(entry, handler); } else { Switches[entry] = handler; } Add(entry); }
private void ParseCommandLineArguments(string[] args) { foreach (var arg in args) { if (arg.Contains('=')) { var arr = arg.Split('='); Parameters.Add(arr[0], arr[1]); } else if (arg.StartsWith("-")) { Switches.Add(arg.Substring(1)); } else { OtherParameters.Add(arg); } } }
public AzureLoggerSettings(IConfigurationSection section) { var thresholdAsString = section["OverflowThreshold"]; int thresholdAsInt; if (!string.IsNullOrEmpty(thresholdAsString) && int.TryParse(thresholdAsString, out thresholdAsInt)) { this.OverflowThreshold = thresholdAsInt; } this.OverflowContainer = section["OverflowContainer"]; this.ConnectionString = section["ConnectionString"]; this.Table = section["Table"]; foreach (var switchConfig in section.GetSection("LogLevel").GetChildren()) { Switches.Add(switchConfig.Key, (LogLevel)Enum.Parse(typeof(LogLevel), switchConfig.Value)); } }
public bool TryDivide(string fullCmd) { CommandName = fullCmd.Split(' ')[0].Trim(); ArgString = fullCmd.IndexOf(" ", StringComparison.Ordinal) == -1 ? "" : fullCmd.Substring(fullCmd.IndexOf(" ", StringComparison.Ordinal) + 1, fullCmd.Length - CommandName.Length - 1).Trim(); List <string> splitedParam = new List <string>(); SimpleArgs = ArgString.Split(' ').ToList(); if (ArgString == "") { return(false); } try { splitedParam.AddRange(ArgString.Split(' ')); foreach (var item in splitedParam) { if (Quote.Any(q => ContainsChar(q, item))) { throw new ArgumentException(); } } bool combined = true; foreach (var item in Quote) { for (int i = 0; i < splitedParam.Count - 1; i++) { string cur = splitedParam[i], next = splitedParam[i + 1]; if (cur.StartsWith(item) && !cur.EndsWith(item)) { combined = false; splitedParam[i] = cur + " " + next; splitedParam.Remove(next); if (splitedParam[i].EndsWith(item)) { combined = true; } i--; } } if (!combined) { throw new ArgumentException("Expect '" + item + "'."); } } string tmpKey = null, tmpValue; bool isLastKeyOrValue = false; splitedParam.Add("-"); foreach (var item in splitedParam) { tmpValue = null; if (item.StartsWith('-')) { if (tmpKey != null) { Switches.Add(tmpKey, tmpKey); } tmpKey = item.Remove(0, 1); isLastKeyOrValue = true; } else { foreach (var q in Quote) { tmpValue = tmpValue == null?item.Trim(q) : tmpValue.Trim(q); } if (!isLastKeyOrValue) { FreeArgs.Add(tmpValue); //throw new ArgumentException("Expect key."); } else { Args.Add(tmpKey, tmpValue); tmpKey = null; tmpValue = null; isLastKeyOrValue = false; } } } } catch (Exception ex) { Logger.Debug(ex.Message); return(false); } return(true); }
private void GenerateFields() { WaterField TempWaterField2 = null; FieldArray[0, 0] = new EndWaterField { Game = this }; for (int i = 1; i < 12; i++) { WaterField TempWaterField = new WaterField { Game = this }; FieldArray[i, 0] = TempWaterField; if (i == 9) { TempWaterField2 = TempWaterField; } if (i == 11) { TempWaterField.MoveAble = this.Ship; Ship.CurrentField = TempWaterField; ShipField = TempWaterField; } } FieldArray[0, 1] = new EndField(); for (int i = 1; i < 12; i++) { FieldArray[i, 1] = new Field(); if (i == 9) { Quay TempQuay = new Quay { Game = this }; FieldArray[i, 1] = TempQuay; TempWaterField2.LowerField = TempQuay; } } FieldArray[11, 2] = new Field(); Warehouse TempHouse = new Warehouse { Game = this }; FieldArray[0, 3] = TempHouse; Warehouses.Add(TempHouse); for (int i = 1; i < 12; i++) { if (i != 4 && i != 10) { FieldArray[i, 3] = new Field(); } } FieldArray[3, 5] = new Field(); FieldArray[4, 4] = new Field(); FieldArray[10, 4] = new Field(); FieldArray[11, 4] = new Field(); TempHouse = new Warehouse { Game = this }; FieldArray[0, 5] = TempHouse; Warehouses.Add(TempHouse); FieldArray[1, 5] = new Field(); FieldArray[2, 5] = new Field(); FieldArray[5, 5] = new Field(); FieldArray[9, 5] = new Field(); FieldArray[6, 6] = new Field(); FieldArray[8, 6] = new Field(); FieldArray[7, 7] = new Field(); TempHouse = new Warehouse { Game = this }; FieldArray[0, 8] = TempHouse; Warehouses.Add(TempHouse); for (int i = 1; i < 12; i++) { if (i != 7) { FieldArray[i, 8] = new Field(); } } FieldArray[1, 9] = new ManeuveringField(); FieldArray[0, 9] = new EndManeuveringField(); for (int i = 2; i < 12; i++) { FieldArray[i, 9] = new ManeuveringField(); if (i == 9 || i == 10 || i == 11) { FieldArray[i, 9] = new Field(); } } Switch TempSwitch = new Switch { UpperField = FieldArray[5, 3], LowerField = FieldArray[5, 5], MayChangeNextField = true }; FieldArray[5, 4] = TempSwitch; Switches.Add(TempSwitch); TempSwitch = new Switch { UpperField = FieldArray[9, 3], LowerField = FieldArray[9, 5] }; FieldArray[9, 4] = TempSwitch; Switches.Add(TempSwitch); TempSwitch = new Switch { UpperField = FieldArray[8, 6], LowerField = FieldArray[8, 8], MayChangeNextField = true }; FieldArray[8, 7] = TempSwitch; Switches.Add(TempSwitch); TempSwitch = new Switch { UpperField = FieldArray[6, 6], LowerField = FieldArray[6, 8] }; FieldArray[6, 7] = TempSwitch; Switches.Add(TempSwitch); TempSwitch = new Switch { UpperField = FieldArray[3, 3], LowerField = FieldArray[3, 5] }; FieldArray[3, 4] = TempSwitch; Switches.Add(TempSwitch); }
/// <summary> /// Parses a switch. /// </summary> private void ParseSwitch(string SwitchID, ref int CmdLinePtr, ref int TemplPtr, bool xlatStrings) { string MethodName = "CommandLine.ParseSwitch"; LogWrite(MethodName + ": SwitchID = " + SwitchID); char SwitchType; int i = Template.ToUpper().IndexOf(SwitchID.ToUpper()); if (i > -1) { // The switch is expected. Set the template // pointer to point to the switch's type: TemplPtr = i + 2; // Determine the type of switch: if (TemplPtr < Template.Length) { // Not yet to end-of-template. if ((Template[TemplPtr] == 'n') || (Template[TemplPtr] == 's')) { SwitchType = Template[TemplPtr]; } else { SwitchType = 'b'; } } else { // Reached the end of the template. SwitchType = 'b'; } // Parse the switch's setting: } LogWrite(MethodName + ": SwitchType = \"" + SwitchType + "\""); switch (SwitchType) { case 'n': if ((CmdLinePtr < this.Text.Length) && ("0123456789-+".IndexOf(this.Text[CmdLinePtr]) != -1)) { // The first character is part of an integer. Parse it: string Token = ""; while ((CmdLinePtr < this.Text.Length) && (this.Text[CmdLinePtr] != ' ') && (this.Text[CmdLinePtr] != '\t')) { Token += this.Text[CmdLinePtr]; CmdLinePtr++; } try { // Convert the token to an integer value: int Value = Convert.ToInt32(Token); Switch TheSwitch = new Switch(SwitchID, Value, CmdLinePtr); LogWrite(MethodName + ": IntSwitch value = " + Value.ToString()); Switches.Add(TheSwitch); } catch (Exception) { PipeWrenchCompileException ex = new PipeWrenchCompileException("Integer value is invalid"); ex.Data.Add("CharPos", CmdLinePtr); ex.Data.Add("CmdLine", this.Text); throw ex; } } else { // The first character is not part of an integer. PipeWrenchCompileException ex = new PipeWrenchCompileException("Expected an integer immediately following this switch."); ex.Data.Add("CharPos", CmdLinePtr); ex.Data.Add("CmdLine", this.Text); throw ex; } break; case 's': if ((CmdLinePtr < this.Text.Length) && (this.Text[CmdLinePtr] == '\'')) { // The first character is a quote. Parse the string: string Value; if (xlatStrings) { string tempStr = GetString(this.Text, ref CmdLinePtr, '\'', true); try { Value = XlatEscapes(tempStr); } catch (PipeWrenchCompileException ex) { ex.Data.Add("CmdLine", this.Text); ex.Data["CharPos"] = CmdLinePtr - tempStr.Length + (int)ex.Data["Offset"]; throw ex; } } else { Value = GetString(this.Text, ref CmdLinePtr, '\'', false); } Switch TheSwitch = new Switch(SwitchID, Value, CmdLinePtr); LogWrite(MethodName + ": StrSwitch value = " + Value); Switches.Add(TheSwitch); } else { // The first character is not a quote. PipeWrenchCompileException ex = new PipeWrenchCompileException("Expected a string immediately following this switch."); ex.Data.Add("CharPos", CmdLinePtr); ex.Data.Add("CmdLine", this.Text); throw ex; } break; case 'b': bool SwitchIsValid = (CmdLinePtr == this.Text.Length) || (this.Text[CmdLinePtr] == ' ') || (this.Text[CmdLinePtr] == '\t'); if (SwitchIsValid) { Switch TheSwitch = new Switch(SwitchID, null, CmdLinePtr); LogWrite(MethodName + ": BoolSwitch value = true"); Switches.Add(TheSwitch); } else { // Switch is invalid. PipeWrenchCompileException ex = new PipeWrenchCompileException("Boolean switch is invalid."); ex.Data.Add("CharPos", CmdLinePtr); ex.Data.Add("CmdLine", this.Text); throw ex; } break; } } else { // The switch was not expected. PipeWrenchCompileException ex = new PipeWrenchCompileException("Switch is unexpected."); ex.Data.Add("CharPos", CmdLinePtr); ex.Data.Add("CmdLine", this.Text); throw ex; } }
/// <summary> /// Initializes a new instance of the <see cref="SwitchSetHashFunctionCollection"/> class. /// </summary> /// <param name="initial">The initial.</param> /// <param name="additional">The additional.</param> public SwitchSetHashFunctionCollection(SwitchSetHashFunction initial, params SwitchSetHashFunction[] additional) { Switches.Add(initial); Switches.AddRange(additional); }
private List <Error> ReadDeviceDefinitionsFromDirectory( string deviceDefinitionsDirectory) { var errors = new List <Error>(); var deviceDefinitionFiles = new List <string>(); if (Directory.Exists(deviceDefinitionsDirectory)) { deviceDefinitionFiles = Directory.EnumerateFiles( deviceDefinitionsDirectory ) .Where(x => x.Contains(DeviceFileExtension)) .ToList(); } else { errors.Add( Error.DirectoryNotFoundError(deviceDefinitionsDirectory) ); } foreach (var file in deviceDefinitionFiles) { var fileContents = File.ReadAllText(file); var jDoc = JsonDocument.Parse(fileContents); foreach (var item in jDoc.RootElement.EnumerateObject()) { try { switch (item.Name.ToLower()) { case "clients": AddNetworkNodes <Client>(item.Value); break; case "contentservers": AddNetworkNodes <ContentServer>(item.Value); break; case "dnsservers": AddNetworkNodes <DnsServer>(item.Value); break; case "switches": AddNetworkNodes <Switch>(item.Value); break; default: break; } ; } catch (Exception ex) { errors.Add( Error.GeneralException(ex) ); } } } return(errors); void AddNetworkNodes <T>( JsonElement array) { var settings = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }; foreach (var item in array.EnumerateArray()) { switch (typeof(T)) { case var x when x == typeof(Client): Clients.Add( JsonSerializer.Deserialize <Client>( item.GetRawText(), settings ) ); break; case var x when x == typeof(ContentServer): ContentServers.Add( JsonSerializer.Deserialize <ContentServer>( item.GetRawText(), settings ) ); break; case var x when x == typeof(DnsServer): DnsServers.Add( JsonSerializer.Deserialize <DnsServer>( item.GetRawText(), settings ) ); break; case var x when x == typeof(Switch): Switches.Add( JsonSerializer.Deserialize <Switch>( item.GetRawText(), settings ) ); break; default: break; } } } }
public void LoadTracks(string path) { string[] lines = File.ReadAllLines(path); string[] meta = lines[0].Split(" "); int nodeCount = int.Parse(meta[0]); int segmentCount = int.Parse(meta[1]); Nodes = new TrackNode[nodeCount]; for (int i = 1; i <= nodeCount; i++) { string[] nodeData = lines[i].Split(" "); int switchType = int.Parse(nodeData[3]); if (switchType > 0) { Nodes[i - 1] = new TrackSwitch(i - 1, new Vector3(float.Parse(nodeData[0]), float.Parse(nodeData[1]), float.Parse(nodeData[2])), (Direction)(switchType) - 1); } else { Nodes[i - 1] = new TrackNode(i - 1, new Vector3(float.Parse(nodeData[0]), float.Parse(nodeData[1]), float.Parse(nodeData[2]))); } } for (int i = nodeCount + 1; i <= nodeCount + segmentCount; i++) { string[] segment = lines[i].Split(" "); TrackSegment trackSegment = new TrackSegment(Segments.Count); for (int j = 0; j < segment.Length - 1; j++) { TrackNode n1 = Nodes[int.Parse(segment[j]) - 1]; TrackNode n2 = Nodes[int.Parse(segment[j + 1]) - 1]; trackSegment.Nodes.Add(n1); if (n1 is TrackSwitch) { TrackSwitch s1 = (TrackSwitch)n1; if (s1.SwitchDirection == Direction.Forward) { if (!Switches.Contains(s1)) { Switches.Add(s1); } s1.SwitchNodes.Add(n2); if (s1.ToNode == null) { s1.ToNode = n2; } } else { s1.ToNode = n2; } } else { n1.ToNode = n2; } if (n2 is TrackSwitch) { TrackSwitch s2 = (TrackSwitch)n2; if (s2.SwitchDirection == Direction.Backward) { Switches.Add(s2); s2.SwitchNodes.Add(n1); if (s2.FromNode == null) { s2.FromNode = n1; } } else { s2.FromNode = n1; } } else { n2.FromNode = n1; } n1.Segment = trackSegment; } Segments.Add(trackSegment); } }
public bool TryDivide(string fullCmd) { CommandName = fullCmd.Split(' ')[0].Trim(); ArgString = fullCmd.IndexOf(" ", StringComparison.Ordinal) == -1 ? "" : fullCmd.Substring(fullCmd.IndexOf(" ", StringComparison.Ordinal) + 1, fullCmd.Length - CommandName.Length - 1).Trim(); char quoteFlag = '\0'; bool isKeyOrValue = true; int startP = -1, endP = -1; string tmpKey = "", tmpValue = ""; string param = ArgString + " "; try { for (var i = 0; i < param.Length; i++) { var item = param[i]; if (quoteFlag == '\0') { switch (item) { case '\'': case '\"': quoteFlag = item; break; case '-': if (startP != -1 && isKeyOrValue) { throw new ArgumentException(); //Parameters.GetOrAdd(tmpKey, value: null); //Switches.GetOrAdd(tmpKey, tmpKey); } startP = i; isKeyOrValue = true; break; case ' ': endP = i; if (isKeyOrValue) { tmpKey = param.Substring(startP, endP - startP).Trim().TrimStart('-'); Switches.Add(tmpKey, tmpKey); isKeyOrValue = false; } else { tmpValue = param.Substring(startP, endP - startP).Trim().Trim('\"'); Args.Add(tmpKey, tmpValue); Switches.Remove(tmpKey, out _); } startP = i; break; } } else { if (item == quoteFlag) { quoteFlag = '\0'; } } } } catch { return(false); } return(true); }
public Block[,] GetMap() { Block[,] map = new Rails[8, 12]; // De map wordt vanaf links boven gemaakt // Bovenste rij for (int i = 0; i < 12; i++) { if (i == 9) { var w = new Wharf(RailType.HORIZONTAL); map[0, i] = w; Wharf = w; } else { if (i == 11) { map[0, i] = new Rails(RailType.BOTTOMLEFT); } else { map[0, i] = new Rails(RailType.HORIZONTAL); } } } //Rechts boven for (int i = 1; i < 4; i++) { if (i == 3) { map[i, 11] = new Rails(RailType.TOPLEFT); } else { map[i, 11] = new Rails(RailType.VERTICAL); } } map[3, 10] = new Rails(RailType.HORIZONTAL); var s1 = new Switch(RailType.TOPRIGHT, 3); map[3, 9] = s1; Switches.Add(s1); for (int i = 5; i < 10; i++) { if (i == 9) { map[2, i] = new Rails(RailType.BOTTOMLEFT); } else if (i == 5) { map[2, i] = new Rails(RailType.BOTTOMRIGHT); } else { map[2, i] = new Rails(RailType.HORIZONTAL); } } var s2 = new Switch(RailType.TOPLEFT, 2); map[3, 5] = s2; Switches.Add(s2); map[3, 4] = new Rails(RailType.HORIZONTAL); var s3 = new Switch(RailType.TOPRIGHT, 1); map[3, 3] = s3; Switches.Add(s3); for (int i = 1; i < 4; i++) { if (i == 3) { map[2, i] = new Rails(RailType.BOTTOMLEFT); } else { map[2, i] = new Rails(RailType.HORIZONTAL); } } for (int i = 1; i < 4; i++) { if (i == 3) { map[4, i] = new Rails(RailType.TOPLEFT); } else { map[4, i] = new Rails(RailType.HORIZONTAL); } } map[4, 5] = new Rails(RailType.TOPRIGHT); map[4, 6] = new Rails(RailType.BOTTOMLEFT); map[4, 8] = new Rails(RailType.BOTTOMRIGHT); map[4, 9] = new Rails(RailType.TOPLEFT); var s4 = new Switch(RailType.TOPRIGHT, 4); map[5, 6] = s4; Switches.Add(s4); map[5, 7] = new Rails(RailType.HORIZONTAL); var s5 = new Switch(RailType.TOPLEFT, 5); map[5, 8] = s5; Switches.Add(s5); for (int i = 1; i < 7; i++) { if (i == 6) { map[6, i] = new Rails(RailType.TOPLEFT); } else { map[6, i] = new Rails(RailType.HORIZONTAL); } } for (int i = 8; i < 12; i++) { if (i == 8) { map[6, i] = new Rails(RailType.TOPRIGHT); } else if (i == 11) { map[6, i] = new Rails(RailType.BOTTOMLEFT); } else { map[6, i] = new Rails(RailType.HORIZONTAL); } } for (int i = 1; i < 9; i++) { map[7, i] = new Parking(RailType.HORIZONTAL); } for (int i = 8; i < 12; i++) { if (i == 11) { map[7, i] = new Rails(RailType.TOPLEFT); } else { map[7, i] = new Rails(RailType.HORIZONTAL); } } // Warehouses var w1 = new Warehouse(RailType.HORIZONTAL, 'A'); var w2 = new Warehouse(RailType.HORIZONTAL, 'B'); var w3 = new Warehouse(RailType.HORIZONTAL, 'C'); Warehouses.Add(w1); Warehouses.Add(w2); Warehouses.Add(w3); map[2, 0] = w1; map[4, 0] = w2; map[6, 0] = w3; map = LinkMap(map); return(map); }
/// <summary> /// Initializes a new instance of the <see cref="SwitchVolumeCollection"/> class. /// </summary> /// <param name="initial">The initial.</param> /// <param name="additional">The additional.</param> public SwitchVolumeCollection(SwitchVolume initial, params SwitchVolume[] additional) { Switches.Add(initial); Switches.AddRange(additional); }
protected override void OnAppearing() { base.OnAppearing(); if (IsInitialized) { return; } AddButton($"Collapse", (b) => { ToggleExpand(); if (IsExpanded) { b.Label = $"Collapse"; } else { b.Label = $"Expand"; } }); //AddSwitch("Collapse", (b) => //{ // if (b) // { // ButtonsColumn.Width = new GridLength(0.4, GridUnitType.Star); // } // else // { // ButtonsColumn.Width = new GridLength(1, GridUnitType.Star); // } //}); AddAction($"SaveLog", () => { string toSave = ""; string filename = $"log{DateTime.Now:yyyyMMdd_HHmmss}.txt"; foreach (var item in InfoLayout.Children) { if (item is Label l) { toSave += $"{l.Text}\n"; } } //FileHelper.EnsureWritePersonal(filename, toSave); WriteString($"Saved log to file: {filename}"); }); AddAction($"Clear", () => { InfoLayout.Children.Clear(); WriteString($"Экран очищен"); }); foreach (var item in Objects) { switch (item.UIType) { case UIDynType.Button: Button b = new Button { Text = item.Name, //BackgroundColor = Colors.White, //BorderColor = Colors.Blue, BorderWidth = 1, //TextColor = Colors.Gray }; //if (item.Name.Length == 1) //{ // b.FontSize = 24; // b.FontFamily = Fonts.FabricIcons; // b.CornerRadius = 16; //} b.Clicked += (sender, e) => { try { WriteString($"Выполнение: {item.Name}"); item.Action?.Invoke(); } catch (Exception ex) { WriteString($" '{item.Name}' thrown an exception: ", ex); } }; ButtonsLayout.Children.Add(b); break; case UIDynType.Label: Label temp = new Label() { Margin = 10, Text = $"{item.Name}", FontFamily = MonoFont, }; ButtonsLayout.Children.Add(temp); break; case UIDynType.View: ButtonsLayout.Children.Add(item.View); break; case UIDynType.Switch: StackLayout stackLayout = new StackLayout() { Orientation = StackOrientation.Vertical }; if (!string.IsNullOrWhiteSpace(item.Name)) { Label temp2 = new Label() { VerticalOptions = LayoutOptions.CenterAndExpand, Margin = 5, Text = $"{item.Name}", FontFamily = MonoFont, }; //if (item.Name.Length == 1) //{ // temp2.FontSize = 24; // temp2.FontFamily = Fonts.FabricIcons; //} stackLayout.Children.Add(temp2); //ButtonsLayout.Children.Add(temp2); } Frame f = new Frame(); //f.BorderColor = Colors.Blue; f.CornerRadius = 16; f.HasShadow = false; f.Padding = new Thickness(0); //f.Content = Switch sw = new Switch() { AutomationId = item.Name, }; Switches.Add(item.Name, sw); sw.Toggled += (sender, e) => { Flags[item.Name] = e.Value; item.SwitchAction?.Invoke(e.Value); }; stackLayout.Children.Add(sw); f.Content = stackLayout; ButtonsLayout.Children.Add(f); break; case UIDynType.Picker: StackLayout stackLayout2 = new StackLayout() { Orientation = StackOrientation.Vertical }; Frame f2 = new Frame(); //f2.BorderColor = Colors.Blue; f2.CornerRadius = 16; f2.HasShadow = false; f2.Padding = new Thickness(0); if (!item.Name.StartsWith('-')) { Label temp3 = new Label() { Margin = new Thickness(5, 5, 5, 0), Text = $"{item.Name.TrimStart('-')}", FontFamily = MonoFont, }; stackLayout2.Children.Add(temp3); //ButtonsLayout.Children.Add(temp3); } Picker picker = new Picker() { Margin = new Thickness(5, 0, 5, 5), Title = item.Name.TrimStart('-'), FontFamily = MonoFont, }; stackLayout2.Children.Add(picker); foreach (var item2 in item.PickerVariants) { picker.Items.Add(item2); } picker.SelectedIndexChanged += (sender, e) => { item.PickerAction?.Invoke((string)picker.SelectedItem); }; if (item.PickerSelected != null) { picker.SelectedItem = item.PickerSelected; } f2.Content = stackLayout2; ButtonsLayout.Children.Add(f2); break; default: break; } } IsInitialized = true; }