public ActionResult DiscoverServices() { IServiceDiscoverer discoverer = new ServiceDiscoverer(); var sets = discoverer.DiscoverSets(TimeSpan.FromSeconds(5)); return(Json(sets.DistinctBy(x => x.GetSetIdentifier()).Select(x => new FoundServicesModel(x)), JsonRequestBehavior.AllowGet)); }
private static void Main(string[] args) { var multiCastAddress = IPAddress.Parse("239.0.0.222"); _serviceDiscoverer = new ServiceDiscoverer<ICalculator>(multiCastAddress, 2222); _serviceDiscoverer.OnServiceFound += ServiceDiscovererOnOnServiceFound; Dispatcher.Run(); }
private static void Main(string[] args) { var multiCastAddress = IPAddress.Parse("239.0.0.222"); _serviceDiscoverer = new ServiceDiscoverer <ICalculator>(multiCastAddress, 2222); _serviceDiscoverer.OnServiceFound += ServiceDiscovererOnOnServiceFound; Dispatcher.Run(); }
private bool PerformCheck() { IServiceDiscoverer discoverer = new ServiceDiscoverer(); foreach (IServiceAddressSet set in discoverer.DiscoverSets(TimeSpan.FromSeconds(15))) { if (set.MASStream == null) { Log.Trace("Found service set {0} without MAS stream, ignoring...", set.GetSetIdentifier()); continue; } Log.Trace("Found service set {0} with MAS streams at {1}", set.GetSetIdentifier(), set.MASStream); var uri = new Uri(set.MASStream); if (!alreadyHandledClients.Contains(set.MASStream) && !NetworkInformation.IsLocalAddress(uri.Host)) { Log.Debug("Going to download channel logos from MAS installation at {0}", set.MASStream); if (!DownloadChannelLogos(logos, set.Connect())) { Log.Debug("Failed to download them without authorization, trying all our local accounts"); foreach (var user in Configuration.Authentication.Users) { if (DownloadChannelLogos(logos, set.Connect(user.Username, user.GetPassword()))) { Log.Debug("Downloaded channel logos with account {0}", user.Username); break; } } } alreadyHandledClients.Add(set.MASStream); } } // exit if we got all the logos ScanForRequiredLogos(); if (channelLogosRequired.Count == 0) { Log.Trace("Yes, got all channel logos now!"); return(true); } else { return(false); } }
static void Main(string[] args) { Console.CancelKeyPress += Console_CancelKeyPress; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; var identity = Guid.NewGuid().ToString("x"); typenm: Console.WriteLine("Please Enter your Service Name then press enter : "); var serviceName = Console.ReadLine(); if (string.IsNullOrEmpty(serviceName)) { Console.WriteLine("Service Name could not be null or empty!"); goto typenm; } var sendMsg = new ServiceDescMessage() { Identity = identity, ServiceIPAddress = NetworkHelper.GetLocalIpAddress().ToString(), Port = 3344, ServiceName = serviceName,//"Cache Service", ServiceTag = "ZP" }; discover = new ServiceDiscoverer(identity, sendMsg); discover.OnDiscovering += Discover_OnDiscovering; discover.Start(2000); Console.WriteLine("Press Enter Exit"); Console.ReadLine(); discover?.Dispose(); }
public InjectorClientViewModel() { WatchMask = "*.dll, *.exe"; DiscoveredServiceResponses = new ReactiveList <InjectorHostServiceResponse>(); _discoverer = new InjectorServiceDefinition().CreateServiceDiscoverer(); // TODO: Use CreateDerivedCollection _discoverer .DiscoveredServices .ObserveOn(SynchronizationContext.Current) .Where(svc => !DiscoveredServiceResponses.Any(s => s.ServiceGuid == svc.ServiceGuid)) .Subscribe(svc => DiscoveredServiceResponses.Add(svc)); // can watch when valid path in watchpath var canStartWatching = this.WhenAnyValue(x => x.WatchPath) .Select(x => !String.IsNullOrEmpty(x) && Directory.Exists(x)); // can connect when address and valid port var canConnect = this.WhenAnyValue(x => x.ConnectToAddress, x => x.ConnectToPort, (a, p) => !String.IsNullOrEmpty(a) && !String.IsNullOrEmpty(p) && p.ToCharArray().All(char.IsDigit) && Int32.Parse(p).IsWithinRange(1, 65536)); Connect = ReactiveCommand.CreateAsyncTask(canConnect, async _ => { await _injectorClient.ConnectAsync(ConnectToAddress, Int32.Parse(ConnectToPort)); return(_injectorClient.IsConnected); }); Disconnect = ReactiveCommand.CreateAsyncTask(async _ => { await _injectorClient.DisconnectAsync(); return(_injectorClient.IsConnected); }); StartWatching = ReactiveCommand.CreateAsyncTask(canStartWatching, _ => { _injectorClient.StartWatching(); return(Task.FromResult(_injectorClient.IsWatching)); }); StopWatching = ReactiveCommand.CreateAsyncTask(_ => { _injectorClient.StopWatching(); return(Task.FromResult(_injectorClient.IsWatching)); }); // commands return whether or not watching Observable .Merge(StartWatching, StopWatching) .ToProperty(this, x => x.IsWatching, out _isWatching); // commands return whether or not connected Observable .Merge(Connect, Disconnect) .ToProperty(this, x => x.IsConnected, out _isConnected); // pass through path changes to the injectorclient this.WhenAnyValue(x => x.WatchPath) .BindTo(_injectorClient, c => c.WatchPath); // pass through mask changes to the injectorclient this.WhenAnyValue(x => x.WatchMask) .BindTo(_injectorClient, c => c.WatchMask); // pump out errors // TODO: view needs a usererror handler Observable.Merge( Observable.Merge(Connect.ThrownExceptions, Disconnect.ThrownExceptions), Observable.Merge(StartWatching.ThrownExceptions, StopWatching.ThrownExceptions)) .Subscribe(ex => UserError.Throw("Error", ex)); }