/////////////////////////////////////////////////////////////////////// #region IComparable Members public int CompareTo( object obj ) { IAnyTriplet <T1, T2, T3> anyTriplet = obj as IAnyTriplet <T1, T2, T3>; if (anyTriplet == null) { throw new ArgumentException(); } return(CompareTo(anyTriplet)); }
/////////////////////////////////////////////////////////////////////// #region System.Object Overrides public override bool Equals( object obj ) { IAnyTriplet <T1, T2, T3> anyTriplet = obj as IAnyTriplet <T1, T2, T3>; if (anyTriplet != null) { return(GenericOps <T1> .Equals(this.X, anyTriplet.X) && GenericOps <T2> .Equals(this.Y, anyTriplet.Y) && GenericOps <T3> .Equals(this.Z, anyTriplet.Z)); } else { return(false); } }
public static bool Extract( IAnyTriplet <T1, T2, T3> triplet, ref T4 x, ref T5 y, ref T6 z ) { try { // // HACK: This is not ideal; however, we cannot use the "as" // operator unless we place a restrictions on all the // types (i.e. they must be classes). // T4 x2 = (T4)(object)triplet.X; /* throw */ T5 y2 = (T5)(object)triplet.Y; /* throw */ T6 z2 = (T6)(object)triplet.Z; /* throw */ // // NOTE: Assign to the variables provided by the caller now // that we know the casts were all successful. These // statements cannot throw. // x = x2; y = y2; z = z2; // // NOTE: All of the casts succeeded. // return(true); } catch { // do nothing. } // // NOTE: One of the casts failed. // return(false); }
/////////////////////////////////////////////////////////////////////// #region IComparer<IAnyTriplet<T1,T2,T3>> Members public int Compare( IAnyTriplet <T1, T2, T3> x, IAnyTriplet <T1, T2, T3> y ) { if ((x == null) && (y == null)) { return(0); } else if (x == null) { return(-1); } else if (y == null) { return(1); } else { int result = Comparer <T1> .Default.Compare(x.X, y.X); if (result != 0) { return(result); } result = Comparer <T2> .Default.Compare(x.Y, y.Y); if (result != 0) { return(result); } return(Comparer <T3> .Default.Compare(x.Z, y.Z)); } }
/////////////////////////////////////////////////////////////////////// #region Upload File Event Handlers private static void UploadFileAsyncCompleted( object sender, UploadFileCompletedEventArgs e ) { try { if (e == null) { return; } ICallback callback = e.UserState as ICallback; if (callback == null) { return; } Uri uri = null; string method = null; string fileName = null; IClientData clientData = callback.ClientData; if (clientData != null) { IAnyTriplet <WebClient, Uri, IAnyPair <string, string> > anyTriplet = clientData.Data as IAnyTriplet <WebClient, Uri, IAnyPair <string, string> >; if (anyTriplet != null) { WebClient webClient = anyTriplet.X; if (webClient != null) { webClient.Dispose(); webClient = null; } uri = anyTriplet.Y; IAnyPair <string, string> anyPair = anyTriplet.Z; if (anyPair != null) { method = anyPair.X; fileName = anyPair.Y; } } clientData.Data = null; } ReturnCode code; Result result = null; code = callback.Invoke( GetAsyncCompletedArguments( uri, method, null, null, fileName, e), ref result); if (code != ReturnCode.Ok) { DebugOps.Complain(code, result); } } catch (Exception ex) { DebugOps.Complain(ReturnCode.Error, ex); } }
/////////////////////////////////////////////////////////////////////// #region Upload Values Event Handlers private static void UploadValuesAsyncCompleted( object sender, UploadValuesCompletedEventArgs e ) { try { if (e == null) { return; } ICallback callback = e.UserState as ICallback; if (callback == null) { return; } Uri uri = null; string method = null; NameValueCollection collection = null; IClientData clientData = callback.ClientData; if (clientData != null) { IAnyTriplet <WebClient, Uri, IAnyPair <string, NameValueCollection> > anyTriplet = clientData.Data as IAnyTriplet <WebClient, Uri, IAnyPair <string, NameValueCollection> >; if (anyTriplet != null) { WebClient webClient = anyTriplet.X; if (webClient != null) { webClient.Dispose(); webClient = null; } uri = anyTriplet.Y; IAnyPair <string, NameValueCollection> anyPair = anyTriplet.Z; if (anyPair != null) { method = anyPair.X; collection = anyPair.Y; } } clientData.Data = null; } /* NO RESULT */ callback.FireEventHandler(sender, e, GetAsyncCompletedArguments( uri, method, null, collection, null, e)); } catch (Exception ex) { DebugOps.Complain(ReturnCode.Error, ex); } }
/////////////////////////////////////////////////////////////////////// #region IEquatable<IAnyTriplet<T1,T2,T3>> Members public bool Equals( IAnyTriplet <T1, T2, T3> other ) { return(CompareTo(other) == 0); }
/////////////////////////////////////////////////////////////////////// #region IComparable<IAnyTriplet<T1,T2,T3>> Members public int CompareTo( IAnyTriplet <T1, T2, T3> other ) { return(Compare(this, other)); }