AbstractHandler.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Abstract Handler
  2. //
  3. // Douglas Thrift
  4. //
  5. // AbstractHandler.cs
  6. /* Copyright 2013 Douglas Thrift
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. using System;
  21. using System.IO;
  22. public abstract class AbstractHandler
  23. {
  24. protected string FindInPath(string program)
  25. {
  26. foreach (string location in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator))
  27. {
  28. string path = Path.Combine(location, program);
  29. if (File.Exists(path))
  30. return path;
  31. }
  32. return null;
  33. }
  34. protected void SetYesNoValue(string input, out AutoYesNoOption option, out string value)
  35. {
  36. value = null;
  37. switch (input.ToLowerInvariant())
  38. {
  39. case "yes":
  40. option = AutoYesNoOption.Yes;
  41. break;
  42. case "no":
  43. option = AutoYesNoOption.No;
  44. break;
  45. default:
  46. value = input;
  47. goto case "yes";
  48. }
  49. }
  50. }