// Called for each non-switch command-line argument (filespecs) protected override SwitchStatus OnNonSwitch(String switchValue) { SwitchStatus ss = SwitchStatus.NoError; // Add command-line argument to array of pathnames. // Convert switchValue to set of pathnames, add each pathname to the pathnames ArrayList. try { String d = Path.GetDirectoryName(switchValue); DirectoryInfo dir = new DirectoryInfo((d.Length == 0) ? "." : d); foreach (FileInfo f in dir.GetFiles(Path.GetFileName(switchValue))) { pathnames.Add(f.FullName); } } catch (System.Security.SecurityException SecEx) { throw (SecEx); } catch { ss = SwitchStatus.Error; } if (pathnames.Count == 0) { Console.WriteLine("None of the specified files exists."); ss = SwitchStatus.Error; } return(ss); }
/// <summary> /// Isolates the checking for the path parameter. /// </summary> /// <param name="pathToTest"> /// The path value to test. /// </param> /// <returns> /// A valid <see cref="SwitchStatus"/> value. /// </returns> private SwitchStatus TestPath(String pathToTest) { // Assume good. SwitchStatus ss = SwitchStatus.NoError; if (false == String.IsNullOrEmpty(this.Path)) { this.errorMessage = Constants.PathMultipleSwitches; ss = SwitchStatus.Error; } else { if (Directory.Exists(pathToTest)) { this.Path = pathToTest; } else { this.errorMessage = Constants.PathNotExist; ss = SwitchStatus.Error; } } return(ss); }
// Called for each non-switch command-line argument (filespecs) protected override SwitchStatus OnNonSwitch(String switchValue) { SwitchStatus ss = SwitchStatus.NoError; // Add command-line argument to array of pathnames. // Convert switchValue to set of pathnames, add each pathname to the pathnames ArrayList. try { String d = Path.GetDirectoryName(switchValue); DirectoryInfo dir = new DirectoryInfo((d.Length == 0) ? "." : d); foreach (FileInfo f in dir.GetFiles(Path.GetFileName(switchValue))) { pathnames.Add(f.FullName); } } catch (System.Security.SecurityException) { Console.WriteLine("This sample has failed to run due to a security limitation!\n" + "Try running the sample from a local drive or using CasPol.exe to turn off security."); ss = SwitchStatus.Error; } catch { ss = SwitchStatus.Error; } if (pathnames.Count == 0) { Console.WriteLine("None of the specified files exists."); ss = SwitchStatus.Error; } return(ss); }
/// <summary> /// Handles processing the -groupname switch. /// </summary> /// <param name="switchValue"> /// The value of the -groupname switch. /// </param> /// <returns> /// One of the <see cref="ArgParser.SwitchStatus"/> values. /// </returns> private SwitchStatus ProcessGroupName(string switchValue) { SwitchStatus ss = SwitchStatus.NoError; if (false == String.IsNullOrEmpty(this.GroupName)) { this.errorMessage = Constants.GroupNameMultipleSwitches; ss = SwitchStatus.Error; } else if (String.IsNullOrEmpty(switchValue)) { this.errorMessage = Constants.GroupNameCannotBeEmpty; ss = SwitchStatus.Error; } else if (switchValue.Length >= 65) { this.errorMessage = Constants.GroupNameTooLong; ss = SwitchStatus.Error; } else { this.GroupName = switchValue; } return(ss); }
private static SwitchStatus Switch(SwitchStatus status, SwitchOperation operation) { switch (operation) { case SwitchOperation.On: return(SwitchStatus.On); case SwitchOperation.Off: return(SwitchStatus.Off); case SwitchOperation.Switch: switch (status) { case SwitchStatus.On: return(SwitchStatus.Off); case SwitchStatus.Off: return(SwitchStatus.On); case SwitchStatus.Switched: return(SwitchStatus.Default); case SwitchStatus.Default: return(SwitchStatus.Switched); } break; } throw new ArgumentException($"Invalid combination of switch status: {status} and switch operation {operation}"); }
private SwitchStatus ProcessProxySwitch(string switchValue) { SwitchStatus ss = SwitchStatus.NoError; if (!String.IsNullOrEmpty(switchValue)) { Match proxyMatch = m_processproxySwitch.Match(switchValue); if (proxyMatch.Success) { this.proxyMatch = proxyMatch; ss = SwitchStatus.NoError; } else { errorMessage = Constants.Proxy; ss = SwitchStatus.Error; } } else { errorMessage = Constants.Proxy; ss = SwitchStatus.Error; } return(ss); }
private void switchStatusChanged(int index, int ooff) { SwitchStatus ss = AllSwitchStatus.FirstOrDefault(s => s.Index == index); if (ss != null) { ss.IsSwitchOn = ooff == 0 ? false : true; } }
private void doSwitchClickCmd(object obj) { SwitchStatus ss = obj as SwitchStatus; if (ss != null && ss.Index >= 0) { var onOff = ss.IsSwitchOn ? "AuxOff" : "AuxOn"; CameraControlRemoteCall.Instance.CameraControl(VideoId, onOff, ss.Index); } }
protected override SwitchStatus OnDoneParse() { SwitchStatus ss = SwitchStatus.NoError; // The output file can never be null. if (true == string.IsNullOrEmpty(FileName)) { errorMessage = Constants.OutputCannotBeEmpty; ss = SwitchStatus.Error; errorInOnDoneParse = true; } else if (false == Update) { // Check that I at least have a directory and prefix. Everything // else is optional when updating files. if (true == String.IsNullOrEmpty(StartDirectory)) { errorMessage = Constants.DirectoryCannotBeEmpty; ss = SwitchStatus.Error; errorInOnDoneParse = true; } else if (false == Directory.Exists(StartDirectory)) { errorMessage = Constants.DirectoryDoesNotExist; ss = SwitchStatus.Error; errorInOnDoneParse = true; } else if (true == String.IsNullOrEmpty(CustomValue)) { errorMessage = Constants.UniqueCannotBeEmpty; ss = SwitchStatus.Error; errorInOnDoneParse = true; } } else { // The user is asking to update. // Check that they didn't also specify creation options. if ((false == String.IsNullOrEmpty(StartDirectory) || (false == String.IsNullOrEmpty(CustomValue)))) { errorMessage = Constants.MutuallyExclusiveOptions; ss = SwitchStatus.Error; errorInOnDoneParse = true; } // Check to at least see if the file exists. if (false == File.Exists(FileName)) { errorMessage = Constants.UpdateFileMustExist; ss = SwitchStatus.Error; errorInOnDoneParse = true; } } return(ss); }
internal byte[] GetRaiseSwitchData(SwitchStatus switchStatus) { var list = new List <byte>(); list.AddRange("CC".HexStrToBytes(" ").ToList()); list.AddRange("EE".HexStrToBytes(" ").ToList()); list.Add(DeviceNumber.ToByte()); list.Add(_switchNumber.ToByte()); list.Add(switchStatus.ToInt32().ToByte()); list.AddRange("3A".HexStrToBytes(" ").ToList()); return(list.ToArray()); }
/// <summary> /// Called when parsing is finished so final sanity checking can be /// performed. /// </summary> /// <returns> /// One of the <see cref="ArgParser.SwitchStatus"/> values. /// </returns> protected override SwitchStatus OnDoneParse() { SwitchStatus ss = SwitchStatus.NoError; if (String.IsNullOrEmpty(this.Path)) { this.Path = Directory.GetCurrentDirectory(); } // The only error we can have is no patterns. if (this.rawPatterns.Count == 0) { this.errorMessage = Constants.NoPatternsSpecified; ss = SwitchStatus.Error; } else { // Convert all the raw patterns into regular expressions. for (Int32 i = 0; i < this.rawPatterns.Count; i++) { String thePattern = this.rawPatterns[i]; if (false == this.useRegEx) { thePattern = "^" + Regex.Escape(this.rawPatterns[i]).Replace("\\*", ".*").Replace("\\?", ".") + "$"; } try { Regex r = new Regex(thePattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); this.Patterns.Add(r); } catch (ArgumentException e) { // There was an error converting the command line // parameter into a regular expression. This happens // when the user specified the -regex switch and they // used a DOS wildcard pattern like *.. StringBuilder sb = new StringBuilder(); sb.AppendFormat(CultureInfo.CurrentCulture, Constants.InvalidRegExFmt, thePattern, e.Message); this.errorMessage = sb.ToString(); ss = SwitchStatus.Error; break; } } } return(ss); }
public void Switch(SwitchStatus switchStatus) { if (switchStatus == SwitchStatus.On) { SwitchStatus = SwitchStatus.On; } else { SwitchStatus = SwitchStatus.Off; SetValue = 0.00; PowerConsumptionValue = 0.00; } }
// Start is called before the first frame update IEnumerator Start() { SwitchStatus ss = null; while (ss == null) { yield return(null); ss = FindObjectOfType <SwitchStatus>(); } ss.EventOnSet += SwitchAnimator_EventOnSet; Animator.SetBool("On", ss.isOn); }
public void Open() { switchStatus = SwitchStatus.Open; sr.sprite = statusSprites[(int)switchStatus]; transform.GetComponent <BoxCollider2D>().enabled = false; animator.enabled = true; AudioClip ac = Resources.Load <AudioClip>("SoundEffects/heal"); if (ac == null) { return; } audioSound.PlayOneShot(ac); }
// Called when all command-line arguments have been parsed protected override SwitchStatus OnDoneParse() { SwitchStatus ss = SwitchStatus.NoError; if (pathnames.Count == 0) { // No pathnames were specified ss = SwitchStatus.Error; } else { // Sort all the pathnames in the list pathnames.Sort(0, pathnames.Count, null); } return(ss); }
protected override void OnClick(EventArgs e) { base.OnClick(e); if (this.slideing) { this.animationTimer.Stop(); } this.slideing = true; this.status = this.Status == SwitchStatus.OFF ? SwitchStatus.ON : SwitchStatus.OFF; this.switchSlide.slide_prepare = this.switchSlide.slide_current; this.animationTimer.Options.Data = new SwitchData() { slide = this.switchSlide, target_status = this.status }; this.animationTimer.AT = AnimationType.EaseOut; this.animationTimer.Start(true, 0); }
public void SetTiming(SwitchStatus switchStatus, int outNo) { try { if (controllerMode == ControllerMode.GenMode) { SetCommunicationMode(); } int sw = (int)switchStatus; string command = "TS," + sw.ToString() + "," + outNo.ToString("d2"); Write(command, 100); } catch (Exception) { throw; } }
private SwitchStatus ProcessFileSwitch(string file) { SwitchStatus retValue = SwitchStatus.NoError; // The file has to exists. if (false == File.Exists(file)) { retValue = SwitchStatus.Error; errorMessage = String.Format(CultureInfo.CurrentCulture, Constants.ErrorFileDoesNotExist, file); } else { Files.Add(file); } return(retValue); }
/// <summary> /// Called when a switch is parsed out. /// </summary> /// <param name="switchSymbol"> /// The switch value parsed out. /// </param> /// <param name="switchValue"> /// The value of the switch. For flag switches this is null/Nothing. /// </param> /// <returns> /// One of the <see cref="ArgParser.SwitchStatus"/> values. /// </returns> protected override SwitchStatus OnSwitch(String switchSymbol, String switchValue) { SwitchStatus ss = SwitchStatus.NoError; switch (switchSymbol) { case PathFlag: case PathFlagShort: ss = TestPath(switchValue); break; case RegExFlag: case RegExFlagShort: this.useRegEx = true; break; case IncludeDirectoryName: case IncludeDirectoryNameShort: this.IncludeDirectories = true; break; case NoStats: case NoStatsShort: this.NoStatistics = true; break; case HelpFlag: case HelpFlagShort: ss = SwitchStatus.ShowUsage; break; case NoRecurseFlag: case NoRecurseFlagShort: this.NoRecurse = true; break; default: ss = SwitchStatus.Error; this.errorMessage = Constants.UnknownCommandLineOption; break; } return(ss); }
/// <summary> /// Called when a non-switch value is parsed out. /// </summary> /// <param name="value"> /// The value parsed out. /// </param> /// <returns> /// One of the <see cref="ArgParser.SwitchStatus"/> values. /// </returns> protected override SwitchStatus OnNonSwitch(string value) { SwitchStatus ss = SwitchStatus.NoError; if (false == String.IsNullOrEmpty(this.FileName)) { this.errorMessage = Constants.OutputAlreadySpecified; ss = SwitchStatus.Error; } else if (String.IsNullOrEmpty(value)) { this.errorMessage = Constants.OutputCannotBeEmpty; ss = SwitchStatus.Error; } else { this.FileName = value; } // There are no non switches allowed. this.errorMessage = Constants.UnknownCommandLineOption; return(ss); }
private SwitchStatus ProcessDirectorySwitch(string directory) { SwitchStatus retValue = SwitchStatus.NoError; if (false == Directory.Exists(directory)) { retValue = SwitchStatus.Error; errorMessage = String.Format(CultureInfo.CurrentCulture, Constants.ErrorDirectoryDoesNotExist, directory); } else { SearchOption so = AppSettings.ProcessInputDirRecursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; // Get all the DLLs and EXEs. String [] dirFiles = Directory.GetFiles(directory, "*.DLL", so); Files.AddRange(dirFiles); dirFiles = Directory.GetFiles(directory, "*.EXE", so); Files.AddRange(dirFiles); } return(retValue); }
// Called for each switch command-line argument protected override SwitchStatus OnSwitch(String switchSymbol, String switchValue) { // NOTE: For case-insensitive switches, // switchSymbol will contain all lower-case characters SwitchStatus ss = SwitchStatus.NoError; switch (switchSymbol) { case "?": // User wants to see Usage ss = SwitchStatus.ShowUsage; break; case "a": // User wants to see all words sorted alphabetically showAlphabeticalWordUsage = true; break; case "o": // User wants to see all words sorted by occurrence showOccurrenceWordUsage = true; break; case "f": // User wants output redirected to a specified file if (switchValue.Length < 1) { Console.WriteLine("No output file specified."); ss = SwitchStatus.Error; } else { outputFile = switchValue.Substring(1, switchValue.Length - 1); } break; case "c": // User wants a specific codepage to be used to open the file if (switchValue.Length < 1) { Console.WriteLine("No codepage specified."); ss = SwitchStatus.Error; } else { try { int codePage = System.Int32.Parse(switchValue); fileEncoding = System.Text.Encoding.GetEncoding(codePage); } catch { Console.WriteLine("No valid codepage specified."); ss = SwitchStatus.Error; } } break; default: Console.WriteLine("Invalid switch: \"" + switchSymbol + "\".\n"); ss = SwitchStatus.Error; break; } return(ss); }
/// <summary> /// Called when parsing is finished so final sanity checking can be /// performed. /// </summary> /// <returns> /// One of the <see cref="ArgParser.SwitchStatus"/> values. /// </returns> protected override SwitchStatus OnDoneParse() { SwitchStatus ss = SwitchStatus.NoError; // The output file can never be null. if (string.IsNullOrEmpty(this.FileName)) { this.errorMessage = Constants.OutputCannotBeEmpty; ss = SwitchStatus.Error; this.errorInOnDoneParse = true; } if ((false == this.Update) && (false == this.PatchUpdate) && (false == this.PatchCreateFiles)) { // Check that I at least have a directory and prefix. Everything // else is optional when creating files. if (String.IsNullOrEmpty(this.StartDirectory)) { this.errorMessage = Constants.DirectoryCannotBeEmpty; ss = SwitchStatus.Error; this.errorInOnDoneParse = true; } else if (false == Directory.Exists(this.StartDirectory)) { this.errorMessage = Constants.DirectoryDoesNotExist; ss = SwitchStatus.Error; this.errorInOnDoneParse = true; } else if (String.IsNullOrEmpty(this.GroupName)) { this.errorMessage = Constants.GroupNameCannotBeEmpty; ss = SwitchStatus.Error; this.errorInOnDoneParse = true; } else if (this.PatchCreateFiles || this.PatchUpdate) { this.errorMessage = Constants.NoPatchWhenCreating; ss = SwitchStatus.Error; this.errorInOnDoneParse = true; } // If no directory ref was specified, set it to the default. if (String.IsNullOrEmpty(this.DirectoryRef)) { this.DirectoryRef = DEFAULTDIRREF; } } else if (this.Update) { // The user is asking to update. // Check that they didn't also specify creation options. if (false == String.IsNullOrEmpty(this.StartDirectory) || (false == String.IsNullOrEmpty(this.GroupName))) { this.errorMessage = Constants.MutuallyExclusiveOptions; ss = SwitchStatus.Error; this.errorInOnDoneParse = true; } // Check to see if the user asked for patch updating, too. if (this.PatchUpdate) { this.errorMessage = Constants.MutuallyExclusiveOptions; ss = SwitchStatus.Error; this.errorInOnDoneParse = true; } } else if (this.PatchUpdate) { // Check that they didn't also specify creation options. if (false == String.IsNullOrEmpty(this.StartDirectory) || (false == String.IsNullOrEmpty(this.GroupName))) { this.errorMessage = Constants.MutuallyExclusiveOptions; ss = SwitchStatus.Error; this.errorInOnDoneParse = true; } // Check to at least see if the file exists. if (false == File.Exists(this.FileName)) { this.errorMessage = Constants.UpdateFileMustExist; ss = SwitchStatus.Error; this.errorInOnDoneParse = true; } } return(ss); }
protected override SwitchStatus OnSwitch(string switchSymbol, string switchValue) { SwitchStatus ss = SwitchStatus.NoError; switch (switchSymbol) { case ALIASSHORT: case ALIAS: if (false == String.IsNullOrEmpty(this.Alias)) { this.errorMessage = Constants.AliasMultipleSwitches; ss = SwitchStatus.Error; } else { // If the alias does not end with a \, add one to // help the user out. if (false == switchValue.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { switchValue += "\\"; } this.Alias = switchValue; } break; case DIRSHORT: case DIR: if (false == String.IsNullOrEmpty(this.StartDirectory)) { this.errorMessage = Constants.DirectoryMultipleSwitches; ss = SwitchStatus.Error; } else { // If the directory does not end with a \, add one. if (false == switchValue.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { switchValue += "\\"; } this.StartDirectory = switchValue; } break; case DIREXCLUDESHORT: case DIREXCLUDE: this.DirectoryExcludeList.Add(switchValue); break; case DIRREFSHORT: case DIRREF: if (false == String.IsNullOrEmpty(this.DirectoryRef)) { this.errorMessage = Constants.DirectoryRefMultipleSwitches; ss = SwitchStatus.Error; } else { this.DirectoryRef = switchValue; } break; case DISKID: case DISKIDSHORT: { // Only integer values are acceptable. Int32 outVal; if (false == Int32.TryParse(switchValue, out outVal)) { this.errorMessage = Constants.DiskIdMustBeInteger; ss = SwitchStatus.Error; } else { this.DiskId = outVal; } } break; case EXTSHORT: case EXT: { // Does it start with a period? If not, add one to help // the user out. if ('.' != switchValue[0]) { switchValue = "." + switchValue; } // You can have as many -ext switches as you want. this.ExtensionList.Add(switchValue.ToUpperInvariant(), true); } break; case GROUPNAMESHORT: case GROUPNAME: ss = this.ProcessGroupName(switchValue); break; case HELPQUESTION: case HELPSHORT: case HELP: ss = SwitchStatus.ShowUsage; break; case INCFILE: case INCFILESHORT: this.IncludeFiles.Add(switchValue); break; case NORECURSESHORT: case NORECURSE: this.NoRecursion = true; break; case NOROOTDIRECTORY: case NOROOTDIRECTORYSHORT: this.NoRootDirectoryState = true; this.NoRootDirectory = true; break; case PATCHUPDATE: case PATCHUPDATESHORT: this.PatchUpdate = true; break; case PATCHCREATEFILES: case PATCHCREATEFILESSHORT: this.PatchCreateFiles = true; break; case REGEXEXCLUDE: case REGEXEXCLUDESHORT: { // Do the regular expression conversion here so any // errors are reported before I start parsing. try { Regex newRegex = new Regex(switchValue, RegexOptions.IgnoreCase); this.RegExExcludes.Add(newRegex); } catch (ArgumentException ex) { // There's a problem with the regular expression. ss = SwitchStatus.Error; this.errorMessage = ex.Message; } } break; case REPORTIFDIFFERENT: case REPORTIFDIFFERENTSHORT: this.ReportIfDifferent = true; break; case UPDATESHORT: case UPDATE: this.Update = true; break; case VERBOSESHORT: case VERBOSE: this.Verbose = true; break; case WIN64VAR: if (false == String.IsNullOrEmpty(this.Win64)) { this.errorMessage = Constants.Win64VarMultipleSwitches; ss = SwitchStatus.Error; } else { this.Win64 = switchValue; } break; case PERMANENT: this.Permanent = true; break; default: { this.errorMessage = Constants.UnknownCommandLineOption; ss = SwitchStatus.Error; } break; } return(ss); }
public async Task <BaseResponse> SetSceneAsync(int sceneId, SwitchStatus status) { return(await GetAndParseActionAsync <BaseResponse>(action : String.Format("/gp/{0}/{1}", sceneId, status.ToString().ToLower())).ConfigureAwait(false)); }
protected override SwitchStatus OnSwitch(string switchSymbol, string switchValue) { SwitchStatus ss = SwitchStatus.NoError; switch (switchSymbol) { case k_HELP_QUESTION: case k_HELP_SHORT: case k_HELP: ss = SwitchStatus.ShowUsage; break; case k_GUIDS_SHORT: case k_GUIDS: GenerateGuids = true; break; case k_GENERATE_ROOT: case k_GENERATE_ROOT_SHORT: GenerateRootDir = true; break; case k_MULTIPLE_SHORT: case k_MULTIPLE: MultipleFilesPerComponent = true; break; case k_NORECURSE_SHORT: case k_NORECURSE: NoDirectoryRecursion = true; break; case k_UPDATE_SHORT: case k_UPDATE: Update = true; break; case k_WIN64: Win64 = true; break; case k_ALIAS_SHORT: case k_ALIAS: if (false == String.IsNullOrEmpty(Alias)) { errorMessage = Constants.AliasMultipleSwitches; ss = SwitchStatus.Error; } else { // If the alias does not end with a \, add one to help // the user out. if (false == switchValue.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { switchValue += "\\"; } Alias = switchValue; } break; case k_DIRREF_SHORT: case k_DIRREF: if (!String.IsNullOrEmpty(DirectoryRef)) { errorMessage = Constants.DirectoryRefMultipleSwitches; ss = SwitchStatus.Error; } else { DirectoryRef = switchValue; } break; case k_COMPONENT_GROUP: case k_COMPONENT_GROUP_SHORT: if (!String.IsNullOrEmpty(ComponentGroup)) { errorMessage = Constants.CompGroupMultipleSwitches; ss = SwitchStatus.Error; } else { ComponentGroup = switchValue; } break; case k_DISKID: if (!String.IsNullOrEmpty(DiskId)) { errorMessage = Constants.DiskIdMultipleSwitches; ss = SwitchStatus.Error; } else { DiskId = switchValue; } break; case k_DIR_SHORT: case k_DIR: if (false == String.IsNullOrEmpty(StartDirectory)) { errorMessage = Constants.DirectoryMultipleSwitches; ss = SwitchStatus.Error; } else if (true == String.IsNullOrEmpty(switchValue)) { errorMessage = Constants.DirectoryCannotBeEmpty; ss = SwitchStatus.Error; } else { // If the directory does not end with a \, add one. if (false == switchValue.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { switchValue += "\\"; } StartDirectory = switchValue; } break; case k_CUSTOM_SHORT: case k_CUSTOM: if (false == String.IsNullOrEmpty(CustomValue)) { errorMessage = Constants.UniqueMultipleSwitches; ss = SwitchStatus.Error; } else if (true == String.IsNullOrEmpty(switchValue)) { errorMessage = Constants.UniqueCannotBeEmpty; ss = SwitchStatus.Error; } else if (switchValue.Length >= 65) { errorMessage = Constants.UniqueTooLong; ss = SwitchStatus.Error; } else { CustomValue = switchValue; } break; case k_EXT_SHORT: case k_EXT: if (true == String.IsNullOrEmpty(switchValue)) { errorMessage = Constants.ExtensionCannotBeEmpty; ss = SwitchStatus.Error; } else { // Does it start with a period? If not, add one to help // the user out. if ('.' != switchValue[0]) { switchValue = "." + switchValue; } // You can have as many -ext switches as you want. ExtensionList.Add(switchValue.ToUpperInvariant(), true); } break; case k_INC_SHORT: case k_INC: if (true == seenIncrementSwitch) { errorMessage = Constants.IncrementMultipleSwitches; ss = SwitchStatus.Error; } else { Int32 level = 0; if (false == Int32.TryParse(switchValue, out level)) { errorMessage = Constants.IncrementNoParse; ss = SwitchStatus.Error; } else if (level <= 0) { errorMessage = Constants.IncrementNotZero; ss = SwitchStatus.Error; } else { IncrementValue = level; seenIncrementSwitch = true; } } break; case k_DIREXCLUDE_SHORT: case k_DIREXCLUDE: DirectoryExcludeList.Add(switchValue); break; default: { errorMessage = Constants.UnknownCommandLineOption; ss = SwitchStatus.Error; } break; } return(ss); }
public Boolean Parse(String [] args) { Debug.Assert(null != args, "null != args"); // Avoid side effects in debug builds. if (null == args) { throw new ArgumentException(Constants.InvalidParameter); } // If there are no arguments, leave now. if (args.Length == 0) { return(false); } // Assume parsing is successful. SwitchStatus ss = SwitchStatus.NoError; int errorArg = -1; int currArg; for (currArg = 0; (ss == SwitchStatus.NoError) && (currArg < args.Length); currArg++) { errorArg = currArg; // Determine if this argument starts with a valid switch // character Boolean isSwitch = StartsWithSwitchChar(args [currArg]); if (true == isSwitch) { // Indicates the symbol is a data symbol. Boolean useDataSymbols = false; // Get the argument itself. String processedArg = args [currArg].Substring(1); // The index into the symbol array. int n; // First check the flags array. n = IsSwitchInArray(flagSymbols, processedArg); // If it's not in the flags array, try the data array if that // array is not null. if ((-1 == n) && (null != dataSymbols)) { n = IsSwitchInArray(dataSymbols, processedArg); useDataSymbols = true; } if (-1 != n) { String theSwitch = null; String dataValue = null; // If it's a flag switch. if (false == useDataSymbols) { // This is a legal switch, notified the derived // class of this switch and its value. theSwitch = flagSymbols [n]; if (caseSensitiveSwitches) { theSwitch = flagSymbols [n]. ToLowerInvariant( ); } } else { theSwitch = dataSymbols [n]; // Look at the next parameter if it's there. if (currArg + 1 < args.Length) { currArg++; dataValue = args [currArg]; // Take a look at dataValue to see if it starts // with a switch character. If it does, that // means this data argument is empty. if (true == StartsWithSwitchChar( dataValue)) { ss = SwitchStatus.Error; break; } } else { ss = SwitchStatus.Error; break; } } ss = OnSwitch(theSwitch, dataValue); } else { ss = SwitchStatus.Error; break; } } else { // This is not a switch, notified the derived class of this // "non-switch value" ss = OnNonSwitch(args [currArg]); } } // Finished parsing arguments if (ss == SwitchStatus.NoError) { // No error occurred while parsing, let derived class perform a // sanity check and return an appropriate status ss = OnDoneParse( ); } if (ss == SwitchStatus.ShowUsage) { // Status indicates that usage should be shown, show it OnUsage(null); } if (ss == SwitchStatus.Error) { String errorValue = null; if ((errorArg != -1) && (errorArg != args.Length)) { errorValue = args [errorArg]; } // Status indicates that an error occurred, show it and the // proper usage OnUsage(errorValue); } // Return whether all parsing was successful. return(ss == SwitchStatus.NoError); }
public Task <bool> RaiseDigitalSwitchStatus(int deviceNumber, int itemCount, int switchNumber, SwitchStatus swtichStatus) { throw new NotImplementedException(); }
// This Parse method parses an arbitrary set of arguments public Boolean Parse(String[] args) { SwitchStatus ss = SwitchStatus.NoError; // Assume parsing is sucessful. int ArgNum; for (ArgNum = 0; (ss == SwitchStatus.NoError) && (ArgNum < args.Length); ArgNum++) { // Determine if this argument starts with a valid switch character Boolean fIsSwitch = false; for (int n = 0; !fIsSwitch && (n < switchChars.Length); n++) { fIsSwitch = (0 == String.CompareOrdinal(args[ArgNum], 0, switchChars[n], 0, 1)); } if (fIsSwitch) { // Does the switch begin with a legal switch symbol? Boolean fLegalSwitchSymbol = false; int n; for (n = 0; !fLegalSwitchSymbol && (n < switchSymbols.Length); n++) { if (caseSensitiveSwitches) { fLegalSwitchSymbol = (0 == String.CompareOrdinal(args[ArgNum], 1, switchSymbols[n], 0, switchSymbols[n].Length)); } else { fLegalSwitchSymbol = (0 == String.CompareOrdinal(args[ArgNum].ToUpper(), 1, switchSymbols[n].ToUpper(), 0, switchSymbols[n].Length)); } if (fLegalSwitchSymbol) { break; } } if (!fLegalSwitchSymbol) { // User specified an unrecognized switch, exit ss = SwitchStatus.Error; break; } else { // This is a legal switch, notified the derived class of this switch and its value ss = OnSwitch( caseSensitiveSwitches ? switchSymbols[n] : switchSymbols[n].ToLower(), args[ArgNum].Substring(1 + switchSymbols[n].Length)); } } else { // This is not a switch, notified the derived class of this "non-switch value" ss = OnNonSwitch(args[ArgNum]); } } // Finished parsing arguments if (ss == SwitchStatus.NoError) { // No error occurred while parsing, let derived class perform a // sanity check and return an appropraite status ss = OnDoneParse(); } if (ss == SwitchStatus.ShowUsage) { // Status indicates that usage should be shown, show it OnUsage(null); } if (ss == SwitchStatus.Error) { // Status indicates that an error occurred, show it and the proper usage OnUsage((ArgNum == args.Length) ? null : args[ArgNum]); } // Return whether all parsing was sucessful. return(ss == SwitchStatus.NoError); }
public SwitchItem(int switchNumber, SwitchStatus switchStatus) { SwitchNumber = switchNumber; SwitchStatus = switchStatus; }