public void UpdateProject(UnityProject project, UnityUser user) { if (m_PublisherClient != null) { m_PublisherClient.CloseAndWait(); } try { m_PublisherClient = CreatePublisher(project, user); } catch (Exception e) { Debug.LogError(e); m_PublisherClient?.CloseAndWait(); } if (m_PublisherClient == null) { Debug.LogError("Publisher failed to open"); throw new NullReferenceException("Publisher Missing"); } if (!m_PublisherClient.IsTypeSendable <SyncMarker>()) { Debug.LogError("SyncMarkers not supported"); throw new SyncModelNotSupportedException("SyncMarkers not supported by the project host"); } }
/// <summary> /// Internal helper /// </summary> /// <param name="client"></param> /// <param name="server"></param> /// <param name="opc"></param> /// <param name="logger"></param> private PublisherServices(IPublisherClient client, IPublisherServer server, IEndpointServices opc, ILogger logger) { _opc = opc ?? throw new ArgumentNullException(nameof(opc)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _server = server; _client = client; }
void Publish(PublishType publishType) { try { // This indicates the name and version of the software used for publishing. var pluginName = "C# Publisher Sample"; //var pluginName = "YanaiTest_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); var pluginVersion = Assembly.GetExecutingAssembly().GetName().Version; // Display the project selection external window and return when the project selection has ended (whether it succeeded or not). var settings = WindowFactory.ShowPublisherSettings(pluginName, pluginVersion, publishType); // If the user cancels (or in a few other cases), we don't want to export data. if (settings != null) { Logger.Info($"Logged in as {settings.User.DisplayName}"); Logger.Info($"Target project : {settings.TargetProject.Name}"); Logger.Info($"Target sync server : {settings.TargetProject.Host.ServerName}"); // Let's customize the settings before opening the client CustomizePublisherSettings(settings); // This is the public name of the Source Project you want to export (it doesn't have to be unique). var sourceName = "C# Sample Quad"; //var sourceName = "SourceName-YanaiTest_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); // This identifies the Source Project you want to export and must be unique and persistent over multiple publishing sessions. var sourceId = "internal guid"; //var sourceId = DateTime.Now.ToString("yyyyMMdd_HHmmss"); // Create a Publisher Client, that will allow us to publish data into the selected Target Project. m_PublisherClient = Publisher.OpenClient(sourceName, sourceId, settings); if (publishType == PublishType.Export) { // Simple export flow. PerformExportTransaction(); // Properly close the connection to the SyncServer. m_PublisherClient.CloseAndWait(); } else if (publishType == PublishType.ExportAndSync) { // Sync flow (first export + sync updates). PerformExportTransaction(); PerformSyncUpdates(); } } else { Logger.Warn("No project selected."); } } catch (Exception e) { Logger.Error(e.ToString()); } }
public void Configure(string logEndpointName) { if (String.IsNullOrEmpty(logEndpointName)) throw new ArgumentException("Log endpoint name is required.", "logEndpointName"); if (publisherDirectory.ContainsKey(logEndpointName) == false) throw new ArgumentException( String.Format("The specified endpoint [{0}] was not found.", logEndpointName), "logEndpointName"); publisherClient = publisherDirectory[logEndpointName].GetClient(); }
private static void StartWithOptions(CommandLineOptions opts) { Log.Info("Starting test server"); IPAddress ipAddress; try { ipAddress = IPAddress.Parse(opts.Hostname); } catch (Exception) { ipAddress = Dns.GetHostEntry(opts.Hostname).AddressList[0]; } Server server = new Server(ipAddress); server.StartListening(); if (opts.CreateLocalPublisher) { _localPublisher = server.CreateLocalPublisher(); _localPublisher.Publish("test-channel"); } if (opts.CreateLocalSubscriber) { _localSubscriber = server.CreateLocalSubscriber(); _localSubscriber.Subscribe("test-channel"); _localSubscriber.MessageReceived.Subscribe((s) => Log.Info($"LocalSubscriber received message: {s}")); } Log.Info("Test server ready"); if (opts.CreateLocalPublisher) { while (true) { var message = Console.ReadLine(); if (message == "dispose") { _localPublisher.Dispose(); } else { _localPublisher.Send(message); } } } else { Console.ReadKey(); } }
/// <summary> /// Connect to server and schedule retries if connection failed. /// </summary> /// <returns></returns> private async Task ReconnectAsync() { await _lock.WaitAsync(); try { if (_client != null && _client != kPublishUnsupported) { _logger.Error("Publish services started."); return; } IPublisherClient client = null; try { _pnp?.Change(Timeout.Infinite, Timeout.Infinite); _logger.Debug("Trying to connect to publisher..."); client = await _server.ConnectAsync(); } catch (Exception ex) { _logger.Error(ex, "Error during publisher discovery."); } if (client == null) { _retries++; client = kPublishUnsupported; if (_retries > kMaxRetries) { _logger.Information("No publisher found - Publish services not supported."); } else { var delay = Retry.GetExponentialDelay(_retries, 40000, kMaxRetries); _logger.Information("No publisher found - retrying in {delay} ms...", delay); if (_pnp == null) { _pnp = new Timer(OnReconnectTimer); } _pnp.Change(delay, Timeout.Infinite); } } else { _retries = 0; _logger.Information("Publisher connected!"); } _client = client; } finally { _lock.Release(); } }
/// <summary> /// Test connectivity by listing and ensuring no exception happens. /// </summary> /// <returns></returns> private async Task <ServiceResultModel> TestConnectivityAsync(IPublisherClient server) { try { var test = JsonConvertEx.SerializeObject(new GetNodesRequestModel { EndpointUrl = "opc.tcp://test" }); var(errorInfo, result) = await server.CallMethodAsync( "GetConfiguredNodesOnEndpoint", test, null); return(errorInfo); } catch { return(null); } }
public void Configure(string logEndpointName) { if (String.IsNullOrEmpty(logEndpointName)) { throw new ArgumentException("Log endpoint name is required.", "logEndpointName"); } if (publisherDirectory.ContainsKey(logEndpointName) == false) { throw new ArgumentException( String.Format("The specified endpoint [{0}] was not found.", logEndpointName), "logEndpointName"); } publisherClient = publisherDirectory[logEndpointName].GetClient(); }
/// <summary> /// Create Server /// </summary> /// <param name="client"></param> public ConfiguredPublisher(IPublisherClient client) { _client = client ?? throw new ArgumentNullException(nameof(client)); }
public HelloWorldPublisher(ILogger <HelloWorldPublisher> logger, IPublisherClient client) { _logger = logger; _client = client; }