/// <summary> /// A wrapper class to automatically connect and disconnect when executing the specified action. /// </summary> /// <param name="action">The action to execute.</param> /// <param name="sessionType">Indicates the type of connection to perform.</param> private T Connect <T>(Func <T> action, RicohSessionType sessionType = RicohSessionType.SharedSession) { if (action == null) { return(default(T)); } // Are we connected in the right mode? If not, then disconnect to reestablish the connection if ((IsConnected) && (sessionType != SessionType)) { Disconnect(); } // Check to make sure we are connected, if not implicitly connect. bool connectionEstablished = false; if (!IsConnected) { connectionEstablished = true; Connect(null, sessionType); } // Invoke our external action. T result = action.Invoke(); // Did we connect automatically on behalf of the user? If so, disconnect. if (connectionEstablished) { Disconnect(); } return(result); }
/// <summary> /// GetValue's the internal session type used by the external service. /// </summary> /// <param name="type">The type to be converted.</param> /// <returns>The string representation required by the external service.</returns> internal static string ToExternalServiceValue(this RicohSessionType type) { return(type == RicohSessionType.SharedSession ? "S" : "X"); }