示例#1
0
 public GeneralFailure(MsgGeneralFailure failure, AppInstance instance)
 {
     this.Failure = failure;
     this.Instance = instance;
     if (instance != null)
         instance.Issue(this);
 }
示例#2
0
 /// <summary>
 /// Serialize this to exception to json as defined in Mycroft.Msg.MsgGeneralFailure.Serialize
 /// </summary>
 /// <returns>The JSON</returns>
 public string Serialize()
 {
     var msgFail = new Msg.MsgGeneralFailure();
     msgFail.Message = Message;
     msgFail.Received = Received;
     return msgFail.Serialize();
 }
 public void TestMsgGeneralFailureSerialization()
 {
     string target = "{\"received\":\"APP_MANFST {}\",\"message\":\"this is a message\"}";
     var msg = new MsgGeneralFailure();
     msg.Received = "APP_MANFST {}";
     msg.Message = "this is a message";
     string json = msg.Serialize();
     Assert.AreEqual(target, json);
 }
示例#4
0
 public GeneralFailure(ParseException ex, AppInstance instance)
 {
     this.Failure = new MsgGeneralFailure();
     this.Failure.Received = ex.Received;
     this.Failure.Message = ex.Message;
     this.Instance = instance;
     if (instance != null)
         instance.Issue(this);
 }
示例#5
0
 /// <summary>
 /// Check if this guid is already in the message archive
 /// If the GUID given already exists in the archive the app instance
 /// is notified and HasValidGuid is set to false
 /// </summary>
 /// <param name="messageArchive">The archive to visit</param>
 public override void VisitMessageArchive(MessageArchive messageArchive)
 {
     if (messageArchive[this.guid] != null)
     {
         HasValidGuid = false;
         var genFail = new MsgGeneralFailure();
         genFail.Received = "";
         genFail.Message = "The guid " + this.guid + " was already taken";
         var msg = "MSG_GENERAL_FAILURE " + genFail.Serialize();
         FromInstance.Send(msg);
     }
     else
         HasValidGuid = true;
 }
示例#6
0
        public override void VisitMessageArchive(MessageArchive messageArchive)
        {
            if (!messageArchive.TryPostMessage(this))
            {
                Debug.WriteLine("failed because message currently exists");
                var fail = new MsgGeneralFailure();
                fail.Message = "Message key '" + guid + "' currently exists in message archive, can't override";
                fail.FromInstanceId = FromInstance.InstanceId;
                fail.Received = "";

                FromInstance.Send("MSG_GENERAL_FAILURE " + fail.Serialize());

            }
        }
示例#7
0
 public static new DataPacket Deserialize(string json)
 {
     try
     {
         var ret = new MsgGeneralFailure();
         var obj = Json.Decode(json);
         ret.Message = obj["message"];
         ret.Received = obj["received"];
         return ret;
     }
     catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException)
     {
         throw new ParseException(json, "General binding exception");
     }
     catch (ArgumentException)
     {
         throw new ParseException(json, "Invalid JSON");
     }
 }