internal HubRepository(DateTimeOffset?expirationDt, Guid?serverRepositoryId, Version protocolVersion, string publicKey, NetworkConnectionOptions agentOptions, NetworkConnectionOptions clientOptions) { ExpirationDt = expirationDt; ServerRepositoryId = serverRepositoryId; ProtocolVersion = protocolVersion; PublicKey = publicKey; AgentLiveStreamOptions = agentOptions; ClientLiveStreamOptions = clientOptions; }
/// <summary> /// Create a new connection with the specified options /// </summary> public LiveSessionPublisher(NetworkMessenger messenger, NetworkConnectionOptions options, int majorVersion, int minorVersion) : base(options, true, majorVersion, minorVersion) { if (!Log.SilentMode) { Log.Write(LogMessageSeverity.Verbose, LogCategory, "New live sessions publisher being created", "Configuration:\r\n{0}", options); } lock (m_Lock) //since we promptly access these variables from another thread, I'm adding this as paranoia to ensure they get synchronized. { m_Messenger = messenger; } }
/// <summary> /// Connects to the specified hub (or another hub if this hub is redirecting) /// </summary> /// <returns>The last web channel it was able to connect to after processing redirections.</returns> private static async Task <HubConnectionStatus> Connect(ServerConfiguration configuration) { WebChannel channel = null; bool canConnect = true; HubStatus status = HubStatus.Maintenance; //a reasonable default. string statusMessage = null; Guid? serverRepositoryId = null; DateTimeOffset? expirationDt = null; Version protocolVersion = new Version(0, 0); NetworkConnectionOptions agentLiveStream = null; NetworkConnectionOptions clientLiveStream = null; //first, is it a valid config? No point in trying to connect if it's a bum config. HubConnectionStatus connectionStatus; try { configuration.Validate(); } catch (Exception ex) { canConnect = false; statusMessage = "Invalid configuration: " + ex.Message; connectionStatus = new HubConnectionStatus(configuration, false, status, statusMessage); return(connectionStatus); } //and now try to connect to the server try { channel = CreateChannel(configuration); var configurationGetRequest = new HubConfigurationGetRequest(); await channel.ExecuteRequest(configurationGetRequest, 1) .ConfigureAwait(false); //we'd like it to succeed, so we'll give it one retry var configurationXml = configurationGetRequest.Configuration; //now, if we got back a redirect we need to go THERE to get the status. if (configurationXml.redirectRequested) { //recursively try again. channel.Dispose(); connectionStatus = await Connect(configurationXml.ToServerConfiguration()).ConfigureAwait(false); } else { //set the right status message status = (HubStatus)configurationXml.status; switch (status) { case HubStatus.Available: break; case HubStatus.Expired: statusMessage = "The Server's license has expired. " + (configuration.UseGibraltarService ? "You can reactivate your license in seconds at www.GibraltarSoftware.com." : "To renew your license, run the Administration tool on the Loupe Server." ); break; case HubStatus.Maintenance: statusMessage = "The Server is currently undergoing maintenance and can't process requests."; break; default: throw new ArgumentOutOfRangeException("status"); } if (configurationXml.id != null) { serverRepositoryId = new Guid(configurationXml.id); } if (configurationXml.expirationDt != null) { expirationDt = DataConverter.FromDateTimeOffsetXml(configurationXml.expirationDt); } string publicKey = configurationXml.publicKey; if (string.IsNullOrEmpty(configurationXml.protocolVersion) == false) { protocolVersion = new Version(configurationXml.protocolVersion); } LiveStreamServerXml liveStreamConfig = configurationXml.liveStream; if (liveStreamConfig != null) { agentLiveStream = new NetworkConnectionOptions { HostName = channel.HostName, Port = liveStreamConfig.agentPort, UseSsl = liveStreamConfig.useSsl }; clientLiveStream = new NetworkConnectionOptions { HostName = channel.HostName, Port = liveStreamConfig.clientPort, UseSsl = liveStreamConfig.useSsl }; } //We've connected for sure, time to set up our connection status to return to our caller with the full connection info connectionStatus = new HubConnectionStatus(configuration, channel, new HubRepository(expirationDt, serverRepositoryId, protocolVersion, publicKey, agentLiveStream, clientLiveStream), true, status, statusMessage); } } catch (WebChannelFileNotFoundException) { canConnect = false; if (configuration.UseGibraltarService) { //we'll treat file not found (e.g. customer never existed) as expired to get the right UI behavior. status = HubStatus.Expired; statusMessage = "The specified customer name is not valid"; } else { statusMessage = "No service could be found with the provided information"; } connectionStatus = new HubConnectionStatus(configuration, false, status, statusMessage); } catch (WebChannelBadRequestException) { canConnect = false; //we want to be somewhat more intelligent in our responses to decode what these might MEAN. if (configuration.UseGibraltarService) { status = HubStatus.Expired; statusMessage = "The specified customer name is not valid"; } else { statusMessage = "The server does not support this service or the specified directory is not valid"; } connectionStatus = new HubConnectionStatus(configuration, false, status, statusMessage); } catch (Exception ex) { canConnect = false; statusMessage = ex.Message; connectionStatus = new HubConnectionStatus(configuration, false, status, statusMessage); } //before we return make sure we clean up an errant channel if we don't need it. if ((canConnect == false) && (channel != null)) { channel.Dispose(); channel = null; } return(connectionStatus); }
/// <summary> /// Create a new connection with the specified options /// </summary> public LiveSessionPublisher(NetworkMessenger messenger, NetworkConnectionOptions options) : this(messenger, options, FileHeader.DefaultMajorVersion, FileHeader.DefaultMinorVersion) { }