Advertisement
Guest User

ConsoleCommand

a guest
Feb 18th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.13 KB | None | 0 0
  1. public class ConsoleCommand : NotifyPropertyChanged, INotifyPropertyChanged
  2.     {
  3.         public ConsoleCommand(string ID)
  4.         {
  5.             this.ID = ID;
  6.             CreationTime = HelpFunction.GetTimeNowPath();
  7.             MessageList = new ObservableCollection<IConsoleMessage>();
  8.         }
  9.         public ConsoleCommand(string ID, eImage ImageType)
  10.         {
  11.             this.ID = ID;
  12.             this.ImageType = ImageType;
  13.             CreationTime = HelpFunction.GetTimeNowPath();
  14.             MessageList = new ObservableCollection<IConsoleMessage>();
  15.         }
  16.         public ConsoleCommand(string ID, eImage ImageType, IConsoleMessage Message)
  17.         {
  18.             this.ID = ID;
  19.             this.ImageType = ImageType;
  20.             CreationTime = HelpFunction.GetTimeNowPath();
  21.             MessageList = new ObservableCollection<IConsoleMessage>();
  22.             MessageList.Add(Message);
  23.         }
  24.         public ConsoleCommand(string ID, eImage ImageType, IConsoleMessage[] Messages)
  25.         {
  26.             this.ID = ID;
  27.             this.ImageType = ImageType;
  28.             CreationTime = HelpFunction.GetTimeNowPath();
  29.             MessageList = new ObservableCollection<IConsoleMessage>();
  30.             if (Messages != null)
  31.                 foreach (IConsoleMessage m in Messages)
  32.                     MessageList.Add(m);
  33.         }
  34.  
  35.         public string ID { get; set; }
  36.  
  37.         private eImage imageType;
  38.         public eImage ImageType
  39.         {
  40.             get
  41.             {
  42.                 return imageType;
  43.             }
  44.             set
  45.             {
  46.                 imageType = value;
  47.                 OnPropertyChanged("ImageType");
  48.             }
  49.         }
  50.  
  51.         private string creationTime;
  52.         public string CreationTime
  53.         {
  54.             get
  55.             {
  56.                 return creationTime;
  57.             }
  58.             set
  59.             {
  60.                 creationTime = value;
  61.                 OnPropertyChanged("CreationTime");
  62.             }
  63.         }
  64.  
  65.         private IList<IConsoleMessage> messageList;
  66.         public IList<IConsoleMessage> MessageList
  67.         {
  68.             get
  69.             {
  70.                 return messageList;
  71.             }
  72.             private set
  73.             {
  74.                 messageList = value;
  75.                 OnPropertyChanged("MessageList");
  76.             }
  77.         }
  78.        
  79.         public IConsoleMessage Add(IConsoleMessage Message)
  80.         {
  81.             if (Message == null)
  82.                 return null;
  83.             MessageList.Add(Message);
  84.             return Message;
  85.         }
  86.         public IConsoleMessage Add(string Message, Brush Foreground)
  87.         {
  88.             IConsoleMessage msg = new ConsoleMessage(new CombinedText(
  89.                     new InformationText(Message, Foreground)
  90.                 ));
  91.             MessageList.Add(msg);
  92.             return msg;
  93.         }
  94.         public void Add(IConsoleMessage[] Messages)
  95.         {
  96.             if (Messages == null)
  97.                 return;
  98.             foreach(IConsoleMessage m in Messages)
  99.             {
  100.                 MessageList.Add(m);
  101.             }
  102.         }
  103.         public IConsoleMessage Add(CombinedText Message)
  104.         {
  105.             if (Message == null)
  106.                 return null;
  107.             IConsoleMessage m = new ConsoleMessage(Message);
  108.             MessageList.Add(m);
  109.             return m;
  110.         }
  111.         public IConsoleMessage AddCommandInformation(CommandValue Command)
  112.         {
  113.             if (Command == null)
  114.             {
  115.                 ConsoleMessage ErrorMessage = new ConsoleMessage(false, false, new CombinedText(new InformationText("Polecenie nieprawidłowe", InvalidForeground)));
  116.                 MessageList.Add(ErrorMessage);
  117.                 return ErrorMessage;
  118.             }
  119.             CombinedText Header = new CombinedText(new InformationText(((Command.Direction == eCommandDirection.Send) ? "Informacje o wysyłanym poleceniu:" : "Informacje o przychodzącym poleceniu:"), DefaultForeground, Command.ToString()));
  120.             IConsoleMessage Message = new ConsoleMessage(true, false, Header);
  121.  
  122.             Message.Add(
  123.                 new ConsoleMessage(false, false, new CombinedText(new InformationText("Nazwa polecenia: "),
  124.                 new InformationText(Command.BaseCommand.Name, ((Command.IsValidate) ? ValidForeground : InvalidForeground), Command.BaseCommand.Description)))
  125.                 );
  126.             if (Command.Arguments.Count() > 0)
  127.             {
  128.                 Message.Add(
  129.                     new ConsoleMessage(true, false, new CombinedText(
  130.                         new InformationText("Argumenty: ")))
  131.                     );
  132.                 foreach (ArgumentValue a in Command.Arguments)
  133.                 {
  134.                     CombinedText Argument = new CombinedText();
  135.                     Argument.Add("   > ");
  136.                     Argument.Add(a.BaseArgument.Name, HeaderForeground, a.BaseArgument.Description);
  137.                     if (a.HasValue)
  138.                     {
  139.                         Argument.Add(" = ");
  140.                         Argument.Add(a.Value, (a.Validate) ? ValidForeground : InvalidForeground);
  141.                     }
  142.                     Message.Add(Argument);
  143.                 }
  144.             }
  145.             MessageList.Add(Message);
  146.             return Message;
  147.         }
  148.         public IConsoleMessage AddInputCommand(CommandValue Command)
  149.         {
  150.             if (Command == null)
  151.                 return null;
  152.             IConsoleMessage Message = new ConsoleMessage(new CombinedText(
  153.                     new InformationText("Wprowadzono: ", HeaderForeground),
  154.                     new InformationText(Command.ToString(), DefaultForeground)
  155.                 ));
  156.             MessageList.Add(Message);
  157.             return Message;
  158.         }
  159.         public ConsoleCommand Copy()
  160.         {
  161.             ConsoleCommand cmd = new ConsoleCommand(ID);
  162.             cmd.CreationTime = CreationTime;
  163.             cmd.ImageType = ImageType;
  164.             cmd.ID = ID;
  165.             foreach(IConsoleMessage m in MessageList)
  166.             {
  167.                 cmd.Add(m.Copy());
  168.             }
  169.             return cmd;
  170.         }
  171.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement