Advertisement
Guest User

ConsoleMessage

a guest
Feb 18th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.07 KB | None | 0 0
  1. public class ConsoleMessage : NotifyPropertyChanged, INotifyPropertyChanged, IConsoleMessage
  2.     {
  3.         public ConsoleMessage()
  4.         {
  5.             IsExpanded = false;
  6.             IsExpandedEnable = false;
  7.  
  8.             MessageList = new ObservableCollection<IConsoleMessage>();
  9.             Information = null;
  10.         }
  11.         public ConsoleMessage(string Message, Brush Foreground)
  12.         {
  13.             IsExpanded = false;
  14.             IsExpandedEnable = false;
  15.  
  16.             MessageList = new ObservableCollection<IConsoleMessage>();
  17.             Information = null;
  18.             Add(Message, Foreground);
  19.         }
  20.         public ConsoleMessage(CombinedText Message)
  21.         {
  22.             this.IsExpanded = false;
  23.             this.IsExpandedEnable = false;
  24.  
  25.             MessageList = new ObservableCollection<IConsoleMessage>();
  26.             Information = Message;
  27.         }      
  28.         public ConsoleMessage(bool IsExpandedEnable)
  29.         {
  30.             this.IsExpanded = false;
  31.             this.IsExpandedEnable = IsExpandedEnable;
  32.  
  33.             MessageList = new ObservableCollection<IConsoleMessage>();
  34.             Information = null;
  35.         }
  36.         public ConsoleMessage(bool IsExpandedEnable, bool IsExpanded)
  37.         {
  38.             this.IsExpanded = IsExpanded;
  39.             this.IsExpandedEnable = IsExpandedEnable;
  40.  
  41.             MessageList = new ObservableCollection<IConsoleMessage>();
  42.             Information = null;
  43.         }
  44.         public ConsoleMessage(bool IsExpandedEnable, bool IsExpanded, CombinedText Header)
  45.         {
  46.             this.IsExpanded = IsExpanded;
  47.             this.IsExpandedEnable = IsExpandedEnable;
  48.  
  49.             MessageList = new ObservableCollection<IConsoleMessage>();
  50.             Information = Header;
  51.         }
  52.         public ConsoleMessage(bool IsExpandedEnable, bool IsExpanded, CombinedText Header, IConsoleMessage[] MessageList)
  53.         {
  54.             this.IsExpanded = IsExpanded;
  55.             this.IsExpandedEnable = IsExpandedEnable;
  56.             this.MessageList = new ObservableCollection<IConsoleMessage>();
  57.             if(MessageList != null)
  58.                 foreach (IConsoleMessage m in MessageList)
  59.                     Add(m);
  60.             Information = Header;
  61.         }
  62.  
  63.         private bool isExpanded;
  64.         public bool IsExpanded
  65.         {
  66.             get
  67.             {
  68.                 return isExpanded;
  69.             }
  70.             set
  71.             {
  72.                 isExpanded = value;
  73.                 OnPropertyChanged("IsExpanded");
  74.             }
  75.         }
  76.  
  77.         private bool isExpandedEnable;
  78.         public bool IsExpandedEnable
  79.         {
  80.             get
  81.             {
  82.                 return isExpandedEnable;
  83.             }
  84.             private set
  85.             {
  86.                 isExpandedEnable = value;
  87.                 OnPropertyChanged("IsExpandedEnable");
  88.             }
  89.         }
  90.  
  91.         private CombinedText information;
  92.         public CombinedText Information
  93.         {
  94.             get
  95.             {
  96.                 return information;
  97.             }
  98.             set
  99.             {
  100.                 information = value;
  101.                 OnPropertyChanged("Information");
  102.             }
  103.         }
  104.  
  105.         private IList<IConsoleMessage> messageList;
  106.         public IList<IConsoleMessage> MessageList
  107.         {
  108.             get
  109.             {
  110.                 return messageList;
  111.             }
  112.             private set
  113.             {
  114.                 messageList = value;
  115.                 OnPropertyChanged("MessageList");
  116.             }
  117.         }
  118.  
  119.         public void SetHeader(CombinedText combinedText)
  120.         {
  121.             Information = combinedText;
  122.         }
  123.         public IConsoleMessage Add(IConsoleMessage Message)
  124.         {
  125.             if (Message == null)
  126.                 return null;
  127.             MessageList.Add(Message);
  128.             return Message;
  129.         }
  130.         public IConsoleMessage Add(string Message, Brush Foreground)
  131.         {
  132.             IConsoleMessage msg = new ConsoleMessage(new CombinedText(
  133.                     new InformationText(Message, Foreground)
  134.                 ));
  135.             MessageList.Add(msg);
  136.             return msg;
  137.         }
  138.         public void Add(IConsoleMessage[] Messages)
  139.         {
  140.             if (Messages == null)
  141.                 return;
  142.             foreach (IConsoleMessage m in Messages)
  143.             {
  144.                 MessageList.Add(m);
  145.             }
  146.         }
  147.         public IConsoleMessage Add(CombinedText Message)
  148.         {
  149.             if (Message == null)
  150.                 return null;
  151.             IConsoleMessage m = new ConsoleMessage(Message);
  152.             MessageList.Add(m);
  153.             return m;
  154.         }
  155.         public IConsoleMessage AddCommandInformation(CommandValue Command)
  156.         {
  157.             if (Command == null)
  158.                 return null;
  159.             CombinedText Header = new CombinedText(new InformationText(((Command.Direction == eCommandDirection.Send) ? "Informacje o wysyłanym poleceniu:" : "Informacje o przychodzącym poleceniu:"), HeaderForeground, Command.ToString()));
  160.             IConsoleMessage Message = new ConsoleMessage(true, false, Header);
  161.  
  162.             Message.Add(
  163.                 new ConsoleMessage(false, false, new CombinedText(new InformationText("Nazwa polecenia: "),
  164.                 new InformationText(Command.BaseCommand.Name, ((Command.IsValidate) ? ValidForeground : InvalidForeground), Command.BaseCommand.Description)))
  165.                 );
  166.             if(Command.Arguments.Count() > 0)
  167.             {
  168.                 Message.Add(
  169.                 new ConsoleMessage(true, false, new CombinedText(new InformationText("Argumenty: "),
  170.                 new InformationText(Command.BaseCommand.Name, HeaderForeground, Command.BaseCommand.Description)))
  171.                 );
  172.                 foreach (ArgumentValue a in Command.Arguments)
  173.                 {
  174.                     CombinedText Argument = new CombinedText();
  175.                     Argument.Add("   > ");
  176.                     Argument.Add(a.BaseArgument.Name, ValidForeground, a.BaseArgument.Description);
  177.                     if(a.HasValue)
  178.                     {
  179.                         Argument.Add(" = ");
  180.                         Argument.Add(a.Value, (a.Validate) ? ValidForeground : InvalidForeground);
  181.                     }
  182.                     Message.Add(Argument);
  183.                 }
  184.             }
  185.             return Message;
  186.         }
  187.         public IConsoleMessage AddInputCommand(CommandValue Command)
  188.         {
  189.             if (Command == null)
  190.                 return null;
  191.             IConsoleMessage Message = new ConsoleMessage(new CombinedText(
  192.                     new InformationText("Wprowadzono: ", HeaderForeground),
  193.                     new InformationText(Command.ToString(), DefaultForeground)
  194.                 ));
  195.             MessageList.Add(Message);
  196.             return Message;
  197.         }
  198.         public IConsoleMessage Copy()
  199.         {
  200.             IConsoleMessage msg = new ConsoleMessage(IsExpandedEnable, IsExpanded, Information);
  201.             foreach (IConsoleMessage m in MessageList)
  202.             {
  203.                 IConsoleMessage newM = m.Copy();
  204.                 msg.Add(m.Copy());
  205.             }
  206.             return msg;
  207.         }
  208.  
  209.         public static IConsoleMessage GenerateCommandInformation(CommandValue Command)
  210.         {
  211.             if (Command == null)
  212.             {
  213.                 ConsoleMessage ErrorMessage = new ConsoleMessage(false, false, new CombinedText(new InformationText("Polecenie nieprawidłowe", InvalidForeground)));
  214.                 return ErrorMessage;
  215.             }
  216.             CombinedText Header = new CombinedText(new InformationText(((Command.Direction == eCommandDirection.Send) ? "Informacje o wysyłanym poleceniu:" : "Informacje o przychodzącym poleceniu:"), DefaultForeground, Command.ToString()));
  217.             IConsoleMessage Message = new ConsoleMessage(true, false, Header);
  218.  
  219.             Message.Add(
  220.                 new ConsoleMessage(false, false, new CombinedText(new InformationText("Nazwa polecenia: "),
  221.                 new InformationText(Command.BaseCommand.Name, ((Command.IsValidate) ? ValidForeground : InvalidForeground), Command.BaseCommand.Description)))
  222.                 );
  223.             if (Command.Arguments.Count() > 0)
  224.             {
  225.                 Message.Add(
  226.                     new ConsoleMessage(true, false, new CombinedText(
  227.                         new InformationText("Argumenty: ")))
  228.                     );
  229.                 foreach (ArgumentValue a in Command.Arguments)
  230.                 {
  231.                     CombinedText Argument = new CombinedText();
  232.                     Argument.Add("   > ");
  233.                     Argument.Add(a.BaseArgument.Name, HeaderForeground, a.BaseArgument.Description);
  234.                     if (a.HasValue)
  235.                     {
  236.                         Argument.Add(" = ");
  237.                         Argument.Add(a.Value, (a.Validate) ? ValidForeground : InvalidForeground);
  238.                     }
  239.                     Message.Add(Argument);
  240.                 }
  241.             }
  242.             return Message;
  243.         }
  244.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement