/// <summary> /// Initializes a new instance of the Error class. /// </summary> /// <param name="type">The type of the error.</param> /// <param name="condition">The condition of the error.</param> /// <param name="data">The content of the error element.</param> public XmppError(ErrorType type, ErrorCondition condition, params XmlElement[] data) : this(type, condition, null, data) { }
private static void ErrorPresence(Presence presence, ErrorCondition condition) { presence.SwitchDirection(); presence.RemoveAllChildNodes(); presence.AddChild(new Muc()); presence.Type = PresenceType.error; presence.Error = new Error(condition); }
private void ErrorPresence(Presence presence, ErrorCondition condition, int code) { presence.Type = PresenceType.error; presence.RemoveAllChildNodes(); presence.Error = new Error(condition); if (code != -1) { presence.Error.Code = (ErrorCode)code; } presence.SwitchDirection(); presence.From = Jid; }
public Error(ErrorCondition condition) : this() { Condition = condition; }
/// <summary> /// Creates an error Element according the the condition The type attrib as added automatically as decribed in the XMPP specs This is the prefered way to create error Elements /// </summary> /// <param name="condition"> </param> public Error(ErrorCondition condition) : this() { Condition = condition; }
public static void SubmitChangePassForm(string username, IQ formdata) { ErrorCondition Error = ErrorCondition.NotAllowed; Register reg = formdata.Query as Register; if (formdata.Type == IqType.set) { if (reg.HasTag("x")) { if (reg.Data.Type == XDataFormType.submit) { Field oldpass = reg.Data.GetField("oldpassword"); Field pass = reg.Data.GetField("password"); if (oldpass != null && pass != null) { if (!string.IsNullOrEmpty(oldpass.Value) && !string.IsNullOrEmpty(pass.Value)) { NetTalk.BLL.Users api = new NetTalk.BLL.Users(); NetTalk.BLL.BLLResult result = api.ChangePassword(username, oldpass.Value, pass.Value); if (!result.IsSuccess) { Error = ErrorCondition.NotAcceptable; } } else { Error = ErrorCondition.NotAcceptable; } } else { Error = ErrorCondition.Forbidden; } } else { Error = ErrorCondition.Forbidden; } } else { Error = ErrorCondition.Forbidden; } } else { Error = ErrorCondition.FeatureNotImplemented; } int cindex; if (ThreadTools.Users.Online.IsAuthenticated(username, out cindex)) { switch (Error) { case ErrorCondition.NotAcceptable: IQ eiq = new IQ(); if (formdata.HasAttribute("id")) { eiq.Id = formdata.Id; } eiq.Type = IqType.error; eiq.Error = new agsXMPP.protocol.client.Error(); eiq.Error.Type = ErrorType.modify; eiq.Error.Condition = ErrorCondition.NotAcceptable; eiq.Error.Code = ErrorCode.NotAcceptable; ThreadTools.Users.Online[cindex].Send(eiq); break; case ErrorCondition.Forbidden: ThreadTools.Users.Online[cindex].Send(SendChangePassForm(username, formdata.Id)); break; case ErrorCondition.FeatureNotImplemented: IQ eiq2 = new IQ(); if (formdata.HasAttribute("id")) { eiq2.Id = formdata.Id; } eiq2.Type = IqType.error; eiq2.Error = new agsXMPP.protocol.client.Error(); eiq2.Error.Type = ErrorType.modify; eiq2.Error.Condition = ErrorCondition.FeatureNotImplemented; eiq2.Error.Code = ErrorCode.NotImplemented; ThreadTools.Users.Online[cindex].Send(eiq2); break; default: IQ success = new IQ(); if (formdata.HasAttribute("id")) { success.Id = formdata.Id; } success.Type = IqType.result; ThreadTools.Users.Online[cindex].Send(success); break; } } }
/// <summary> /// Creates an error Element according the the condition The type attrib as added automatically as decribed in the XMPP specs This is the prefered way to create error Elements /// </summary> /// <param name="condition"> </param> public Error(ErrorCondition condition) : base(condition) { Namespace = Uri.ACCEPT; }
public static string GetErrorString(ErrorCondition @enum) { return(ErrorStrings[@enum]); }
public static ValidationResult Custom( ErrorCondition errorCondition, string errorMessage ) { var result = new ValidationResult { errorCondition = errorCondition, errorMessage = errorMessage }; return result; }
public Error(ErrorCondition condition, string text) : this(condition) { ErrorText = text; }
private static void errorWriter( Validator validator, ErrorCondition validationResult ) { Console.WriteLine( "\nThe following validation resulted in an error: " + validationResult ); }
protected XmppHandlerResult Error(XmppSession session, ErrorCondition error, Stanza stanza, string message) { return(Error(session, new JabberStanzaException(error, stanza, message))); }
protected XmppHandlerResult Error(XmppSession session, ErrorCondition error, Stanza stanza) { return(Error(session, error, stanza, null)); }
public static IQ ToError(this IQ iq, ErrorType type = ErrorType.cancel, ErrorCondition condition = ErrorCondition.FeatureNotImplemented, string text = "Custom query error.") { iq.SwitchDirection(); iq.Type = IqType.error; var tag = ""; switch (condition) { case ErrorCondition.BadRequest: tag = "bad-request"; break; case ErrorCondition.Conflict: tag = "conflict"; break; case ErrorCondition.FeatureNotImplemented: tag = "feature-not-implemented"; break; case ErrorCondition.Forbidden: tag = "forbidden"; break; case ErrorCondition.Gone: tag = "gone"; break; case ErrorCondition.InternalServerError: tag = "internal-server-error"; break; case ErrorCondition.ItemNotFound: tag = "item-not-found"; break; case ErrorCondition.JidMalformed: tag = "jid-malformed"; break; case ErrorCondition.NotAcceptable: tag = "not-acceptable"; break; case ErrorCondition.NotAllowed: tag = "not-allowed"; break; case ErrorCondition.NotAuthorized: tag = "not-authorized"; break; case ErrorCondition.NotModified: tag = "not-modified"; break; case ErrorCondition.PaymentRequired: tag = "payment-required"; break; case ErrorCondition.RecipientUnavailable: tag = "recipient-unavailable"; break; case ErrorCondition.Redirect: tag = "redirect"; break; case ErrorCondition.RegistrationRequired: tag = "registration-required"; break; case ErrorCondition.RemoteServerNotFound: tag = "remote-server-not-found"; break; case ErrorCondition.RemoteServerTimeout: tag = "remote-server-timeout"; break; case ErrorCondition.ResourceConstraint: tag = "resource-constraint"; break; case ErrorCondition.ServiceUnavailable: tag = "service-unavailable"; break; case ErrorCondition.SubscriptionRequired: tag = "subscription-required"; break; case ErrorCondition.UndefinedCondition: tag = "undefined-condition"; break; case ErrorCondition.UnexpectedRequest: tag = "unexpected-request"; break; default: tag = "undefined-condition"; break; } iq.C("error") .A("type", type.ToString()) .C(tag, ns: Namespaces.STANZAS); return(iq); }
/// <summary> /// Initializes a new Error instance from the specified XML element. /// </summary> /// <param name="error">The 'error' XML element to initialize this /// instance with.</param> /// <exception cref="ArgumentNullException">The error parameter is null.</exception> /// <exception cref="ArgumentException">The error parameter contains /// invalid XML data.</exception> internal XmppError(XmlElement error) { error.ThrowIfNull("error"); // Verify mandatory error type attribute. ErrorType type = (ErrorType)Enum.Parse(typeof(ErrorType), error.GetAttribute("type"), true); // Look for mandatory error condition element. ErrorCondition? condition = null; foreach (var v in Enum.GetValues(typeof(ErrorCondition))) { string s = ErrorConditionToTagName((ErrorCondition)v); if (error[s] != null) condition = (ErrorCondition)v; } if (!condition.HasValue) throw new ArgumentException("The error XML element does not contain a " + "valid XMPP error condition element."); Data = error; Type = type; Condition = condition.Value; }
public BadReadStream(ErrorCondition condition) { _condition = condition; }
/// <summary> /// Returns the XMPP element name of the specified error condition. /// </summary> /// <param name="condition">A value from the ErrorCondition enumeration /// to convert into an element name.</param> /// <returns>The XML element name of the specified error condition.</returns> private string ErrorConditionToTagName(ErrorCondition condition) { StringBuilder b = new StringBuilder(); string s = condition.ToString(); for (int i = 0; i < s.Length; i++) { if (char.IsUpper(s, i) && i > 0) b.Append('-'); b.Append(char.ToLower(s[i])); } return b.ToString(); }
/// <summary> /// Start listening for an authentication response, and return the redirect URL that the web browser /// will be pointed to. /// </summary> /// <returns>The redirect URL for the remote web browser.</returns> public Uri BeginAuthentication() { NonblockingListener(); Uri url = openid.CreateRequest(false, false); if (url == null) { _ErrorState = openid.ErrorState; CancelAuthentication(); } else { AuthenticationTimer at = new AuthenticationTimer(WaitForResponse); at.BeginInvoke(null, null); } return url; }
/// <summary> /// Intended to be called asynchronously. Check every second to see if the user's authentication /// response has been received. If timeout occurs, automatically close HTTP server. /// </summary> /// <returns>True if a response has been received, false if timed out.</returns> bool WaitForResponse() { while (true) { if (responsereceived) { break; } if (DateTime.Now > startTime.AddSeconds(_Timeout)) { _ErrorState = ErrorCondition.SessionTimeout; authSuccessful = false; CancelAuthentication(); if (AuthenticationResponseTimedOut != null) { AuthenticationResponseTimedOut.Invoke(this, new EventArgs()); } break; } Thread.Sleep(1000); } return authSuccessful; }
public Error(ErrorType type, ErrorCondition condition) : this(type) { Condition = condition; }
/// <summary> /// Callback method for when OpenIdClient invokes its <see cref="ClientCore.ReceivedCancel"/> event. /// </summary> /// <param name="sender">The OpenIdClient object invoking the event.</param> /// <param name="e">Event arguments.</param> void openid_ReceivedCancel(object sender, EventArgs e) { _ErrorState = ErrorCondition.RequestCanceled; if (AuthenticationCanceled != null) { AuthenticationCanceled.Invoke(this, new EventArgs()); } }
public Error(ErrorCondition condition, ErrorType type) : this(condition) { Type = type; }
protected XmppHandlerResult Error(XmppSession session, ErrorCondition error, Stanza stanza) { return(new XmppErrorResult(session, new JabberStanzaException(error, stanza))); }
private static void errorWriter(Validator validator, ErrorCondition validationResult) { Console.WriteLine("\nThe following validation resulted in an error: " + validationResult); }
private void ErrorPresence(Presence presence, ErrorCondition condition) { ErrorPresence(presence, condition, -1); }
private static Stanza ToErrorStanzaWithError(Stanza stanza, ErrorType type, ErrorCondition condition) { return(ToErrorStanza(stanza, new Error(type, condition))); }
/// <summary> /// Initializes a new instance of the Error class. /// </summary> /// <param name="type">The type of the error.</param> /// <param name="condition">The condition of the error.</param> /// <param name="text">A more-detailed textual description of the error.</param> /// <param name="data">The content of the error element.</param> internal XmppError(ErrorType type, ErrorCondition condition, string text = null, params XmlElement[] data) { Data = Xml.Element("error"); Type = type; Condition = condition; Text = text; if (data != null) { foreach (var e in data) { if (e != null) Data.Child(e); } } }
/// <summary> /// Sets the error condition of the XMPP error to the specified value. /// </summary> /// <param name="condition">A value from the ErrorCondition enumeration.</param> private void SetCondition(ErrorCondition condition) { ISet<XmlElement> set = new HashSet<XmlElement>(); // Remove old condition, if any. foreach (var v in Enum.GetValues(typeof(ErrorCondition))) { string s = ErrorConditionToTagName((ErrorCondition)v); if (Data[s] != null) set.Add(Data[s]); } foreach (var e in set) Data.RemoveChild(e); // Add new condition element. string tag = ErrorConditionToTagName(condition); Data.Child(Xml.Element(tag, "urn:ietf:params:xml:ns:xmpp-stanzas")); this.condition = condition; }
/// <summary> /// This region allows outlining of the Kinect setup stuff /// </summary> #region Kinect discovery + setup //Kinect enabled apps should customize each message and replace the technique of displaying the message. private void ShowStatus(ErrorCondition errorCondition) { string statusMessage; switch (errorCondition) { case ErrorCondition.None: statusMessage = null; break; case ErrorCondition.NoKinect: statusMessage = Properties.Resources.NoKinectError; break; case ErrorCondition.NoPower: statusMessage = Properties.Resources.NoPowerError; break; case ErrorCondition.NoSpeech: statusMessage = Properties.Resources.NoSpeechError; break; case ErrorCondition.NotReady: statusMessage = Properties.Resources.NotReady; break; case ErrorCondition.KinectAppConflict: statusMessage = Properties.Resources.KinectAppConflict; break; default: throw new NotImplementedException("ErrorCondition." + errorCondition.ToString() + " needs a handler in ShowStatus()"); } BannerText.NewBanner(statusMessage, screenRect, false, Color.FromArgb(90, 255, 255, 255)); currentErrorCondition = errorCondition; }
/// <summary> /// Inserta una condicion a una propiedad. /// </summary> /// <param name="property">Propiedad</param> /// <param name="value">Valor de la condicion</param> /// <param name="Condition">Condicion que se va evaluar(mayor, menor , igual,etc.)</param> /// <param name="logic">Condicion logica de esta propiedad (AND,OR,NONE) </param> public void InsertCondition(string property, Nullable <int> value, ErrorCondition Condition, LogicalOperators logic) { properties[property].Validations.Add(Condition, new Values(value, logic)); }