Exemplo n.º 1
0
 internal void Handle(SendContactMessage input) {
    Log.Trace("Request send contact message");
    //test
    XmlDocument res = null;
    if (input.Contact.Type == ContactTypes.Email) {
       res = _sendMsg(_message.GetEmail(input.Contact.Value, input.Message));
    } else if (input.Contact.Type == ContactTypes.MobilePhone) {
       res = _sendMsg(_message.GetSms(input.Contact.Value, input.Message));
    } else {
       Log.Warn("Unsupported contact type: {0}", input.Contact.Type);
    }
    if (res != null && res.SelectNodes("/Resultsets").Count > 0 && res.SelectNodes("/Resultsets/UpdateCount").Count > 0) {
       var result = false;
       foreach (XmlNode node in res.SelectNodes("/Resultsets/UpdateCount")) {
          if (node.InnerText == "1") {
             result = true;
             break;
          }
       }
       Reply(result);
    } else {
       Throw(GeneralFailureCode.ServiceUnavailable);
    }
 }
Exemplo n.º 2
0
 internal void Handle(SendContactMessage input) {
    Forward(input, r => Reply(r), e => Throw(e.Error));
 }
Exemplo n.º 3
0
 private void _validateContact(LoginContact contact, Uri callbackUri, string pin, string token, Action<bool> onResult) {
    if (contact == null) {
       Log.Warn("Unable to validate empty contact");
       onResult(false);
    } else {
       var message = new SendContactMessage { Contact = contact.CreateContact() };
       if (contact.LoginKind == LoginKind.Email) {
          var builder = new UriBuilder(callbackUri);
          builder.Query = builder.Query.Append("&pin={0}&token={1}".Substitute(pin, token));
          //TODO: Localize this;
          message.Message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Please follow {0}.".Substitute(builder.Uri.AbsoluteUri);
       } else if (message.Contact.Type == ContactTypes.MobilePhone) {
          //TODO: Localize this;
          message.Message = "Validation code: ".Append(pin);
       } else {
          Log.Warn("Driver registration: Unable to validate contact information since contact is neither email nor mobile phone.");
          onResult(false);
       }
       if (message.Message.NotEmpty()) {
          Services.Invoke(message, o => onResult(o), e => {
             Log.Error("Driver registration: Unable to send a message due to {0}", e.Error);
             onResult(false);
          });
       }
    }
 }