コード例 #1
0
ファイル: FormatProcessor.cs プロジェクト: jagrem/Pash
 public void ProcessPayload(FormatData data)
 {
     if (data is FormatStartData)
     {
         VerifyState(FormattingState.FormatEnd, data);
         ProcessFormatStart((FormatStartData)data);
         _state = FormattingState.FormatStart;
     }
     else if (data is GroupStartData)
     {
         var groupData = (GroupStartData)data;
         VerifyState(FormattingState.FormatStart | FormattingState.GroupEnd, data);
         ProcessGroupStart(groupData);
         _state = FormattingState.GroupStart;
     }
     else if (data is SimpleFormatEntryData)
     {
         // may occur in any state
         ProcessFormatEntry((SimpleFormatEntryData)data);
     }
     else if (data is ErrorFormatEntryData)
     {
         // may occur in any state
         ProcessFormatEntry((ErrorFormatEntryData)data);
     }
     else if (data is FormatEntryData)
     {
         VerifyState(FormattingState.GroupStart, data);
         ProcessFormatEntry((FormatEntryData)data);
     }
     else if (data is GroupEndData)
     {
         VerifyState(FormattingState.GroupStart, data);
         ProcessGroupEnd((GroupEndData)data);
         _state = FormattingState.GroupEnd;
     }
     else if (data is FormatEndData)
     {
         VerifyState(FormattingState.GroupEnd, data);
         ProcessFormatEnd((FormatEndData)data);
         _state = FormattingState.GroupEnd;
     }
     else
     {
         var msg = String.Format("The format data of type {0} is unknown and cannot be processed",
                                 data.GetType().Name);
         throw new InvalidOperationException(msg);
     }
 }
コード例 #2
0
ファイル: FormatProcessor.cs プロジェクト: jagrem/Pash
 private void VerifyState(FormattingState allowedStates, FormatData currentData)
 {
     if (!allowedStates.HasFlag(_state))
     {
         var msg = String.Format("The format data is invalid. Did you modify the output of an Format-* command?",
                                 currentData.GetType().Name, _state);
         throw new InvalidOperationException(msg);
     }
 }