private void Connect() { IWuRemoteService service = null; var callbackReceiver = new CallbackReceiver(); lock (ServiceLock) { ThrowIfDisposed(); service = _serviceFactory.GetInstance(_binding, _address, callbackReceiver); if (!(service is IChannel)) { throw new InvalidOperationException( $"{nameof(service)} must implement interface {nameof(IChannel)}."); } if (service != null) { var channel = ((IChannel)service); channel.Faulted += (s, e) => { OnPropertyChanged("ConnectionState"); }; channel.Closed += (s, e) => { OnPropertyChanged("ConnectionState"); }; channel.Closing += (s, e) => { OnPropertyChanged("ConnectionState"); }; channel.Opened += (s, e) => { OnPropertyChanged("ConnectionState"); }; channel.Opening += (s, e) => { OnPropertyChanged("ConnectionState"); }; _callbackReceiver = callbackReceiver; _callbackReceiver.Endpoint = this; Service = service; } } OnPropertyChanged("ConnectionState"); }
protected override void EnterStateInternal(WuProcessState oldState) { lock (JobLock) { var callbackReceiver = new CallbackReceiver(this); Job = new WuApiSearchJobAdapter(_searcher.BeginSearch("IsInstalled=0 and Type='Software' and IsHidden=0", callbackReceiver, null)); } }
protected override void EnterStateInternal(WuProcessState oldState) { lock (JobLock) { _uDownloader.Updates = (UpdateCollection)_updates; var callbackReceiver = new CallbackReceiver(this); Job = new WuApiDownloadJobAdapter(_uDownloader.BeginDownload(callbackReceiver, callbackReceiver, null)); StateDesc = $"Starting download of {_updates.Count} update(s)"; } }
public void TestAsynchronousPruneCallback() { using ( ParticleSystemManager manager = new ParticleSystemManager( this.mockedGraphicsDeviceService ) ) { CallbackReceiver receiver = new CallbackReceiver(); object state = new object(); IAsyncResult asyncResult = manager.BeginPrune(receiver.Callback, state); manager.EndPrune(asyncResult); Assert.AreSame(state, receiver.State); Assert.IsFalse(asyncResult.CompletedSynchronously); } }
protected override void EnterStateInternal(WuProcessState oldState) { lock (JobLock) { if (_uInstaller.IsBusy) { throw new InvalidOperationException("Update installer is busy."); } if (_uInstaller.RebootRequiredBeforeInstallation) { throw new InvalidOperationException("A reboot is required before update installation can start."); } _uInstaller.Updates = (UpdateCollection)_updates; var callbackReceiver = new CallbackReceiver(this); Job = new WuApiInstallJobAdapter(_uInstaller.BeginInstall(callbackReceiver, callbackReceiver, null)); StateDesc = $"Starting installation of {_updates.Count} update(s)"; } }
protected virtual void MoveWater() { noiseSeed += waterSurfaceChangeSpeed * Time.deltaTime; waterDistance += WaveTravelSpeed * Time.deltaTime; Vector2 progress = GlobalPosToProgress(Center.position); Vector2 startPosition = ProgressToXAndZIndex(progress); int calculatedWaterSize = PersistentGameDataController.Settings.waterCalculationSize; ModifyShape(ref vertices, Mathf.RoundToInt(startPosition.x - (calculatedWaterSize / 2)), Mathf.RoundToInt(startPosition.y - (calculatedWaterSize / 2)), calculatedWaterSize); //ReshapeY(ref vertices); if (CallbackReceiver != null) { CallbackReceiver.OnWaterChange(); } }
public void Dispose() { lock (ServiceLock) { if (Log.IsDebugEnabled) { Log.Debug($"Disposing endpoint {_fqdn}"); } try { ((IChannel)Service)?.Close(); } catch (Exception e) { Log.Warn(e); } finally { _callbackReceiver = null; Service = null; IsDisposed = true; } } }
virtual internal IWuRemoteService GetInstance(Binding binding, EndpointAddress remoteAddress, CallbackReceiver callback) { if (binding == null) { throw new ArgumentNullException(nameof(binding)); } if (remoteAddress == null) { throw new ArgumentNullException(nameof(remoteAddress)); } if (callback == null) { throw new ArgumentNullException(nameof(callback)); } IWuRemoteService service; DuplexChannelFactory <IWuRemoteService> channelFactory = null; try { Log.Debug($"Creating channel for {remoteAddress.Uri}"); channelFactory = new DuplexChannelFactory <IWuRemoteService>(callback, binding, remoteAddress); service = channelFactory.CreateChannel(); ((IChannel)service).Open(); Log.Debug($"{remoteAddress.Uri}: Register for callbacks."); service.RegisterForCallback(); } catch (EndpointNotFoundException e) { channelFactory?.Abort(); Log.Warn($"Could not create channel for {remoteAddress.Uri}", e); throw new EndpointNotFoundException($"Could not connect to the remote host. Verify that the serivce is installed on the remote host and is not blocked by the firewall. {((e.InnerException != null) ? e.InnerException.Message : e.Message) }", e); } catch (Exception e) { Log.Warn($"Could not create channel for {remoteAddress.Uri}", e); channelFactory?.Abort(); throw; } return(service); }
public override void run(string[] args) { Dictionary <string, string> properties = createTestProperties(ref args); // // We must disable connection warnings, because we attempt to // ping the router before session establishment, as well as // after session destruction. Both will cause a // ConnectionLostException. // properties["Ice.Warn.Connections"] = "0"; using (var communicator = initialize(properties)) { IObjectPrx routerBase; { Console.Out.Write("testing stringToProxy for router... "); Console.Out.Flush(); routerBase = IObjectPrx.Parse($"Glacier2/router:{getTestEndpoint(50)}", communicator); Console.Out.WriteLine("ok"); } Glacier2.IRouterPrx router; { Console.Out.Write("testing checked cast for router... "); Console.Out.Flush(); router = Glacier2.IRouterPrx.CheckedCast(routerBase); test(router != null); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing router finder... "); Console.Out.Flush(); IRouterFinderPrx finder = IRouterFinderPrx.Parse($"Ice/RouterFinder:{getTestEndpoint(50)}", communicator); test(finder.GetRouter().Identity.Equals(router.Identity)); Console.Out.WriteLine("ok"); } { Console.Out.Write("installing router with communicator... "); Console.Out.Flush(); communicator.SetDefaultRouter(router); Console.Out.WriteLine("ok"); } { Console.Out.Write("getting the session timeout... "); Console.Out.Flush(); long sessionTimeout = router.GetSessionTimeout(); long acmTimeout = router.GetACMTimeout(); test(sessionTimeout == 30 && acmTimeout == 30); Console.Out.WriteLine("ok"); } IObjectPrx @base; { Console.Out.Write("testing stringToProxy for server object... "); Console.Out.Flush(); @base = IObjectPrx.Parse($"c1/callback:{getTestEndpoint(0)}", communicator); Console.Out.WriteLine("ok"); } { Console.Out.Write("trying to ping server before session creation... "); Console.Out.Flush(); try { @base.IcePing(); test(false); } catch (ConnectionLostException) { Console.Out.WriteLine("ok"); } catch (TransportException) { test(false); } } { Console.Out.Write("trying to create session with wrong password... "); Console.Out.Flush(); try { router.CreateSession("userid", "xxx"); test(false); } catch (Glacier2.PermissionDeniedException) { Console.Out.WriteLine("ok"); } catch (Glacier2.CannotCreateSessionException) { test(false); } } { Console.Out.Write("trying to destroy non-existing session... "); Console.Out.Flush(); try { router.DestroySession(); test(false); } catch (Glacier2.SessionNotExistException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("creating session with correct password... "); Console.Out.Flush(); try { router.CreateSession("userid", "abc123"); } catch (Glacier2.PermissionDeniedException) { test(false); } catch (Glacier2.CannotCreateSessionException) { test(false); } Console.Out.WriteLine("ok"); } { Console.Out.Write("trying to create a second session... "); Console.Out.Flush(); try { router.CreateSession("userid", "abc123"); test(false); } catch (Glacier2.PermissionDeniedException) { test(false); } catch (Glacier2.CannotCreateSessionException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("pinging server after session creation... "); Console.Out.Flush(); @base.IcePing(); Console.Out.WriteLine("ok"); } { Console.Out.Write("pinging object with client endpoint... "); IObjectPrx baseC = IObjectPrx.Parse($"collocated:{getTestEndpoint(50)}", communicator); try { baseC.IcePing(); } catch (ObjectNotExistException) { } Console.Out.WriteLine("ok"); } ICallbackPrx twoway; { Console.Out.Write("testing checked cast for server object... "); Console.Out.Flush(); twoway = ICallbackPrx.CheckedCast(@base); test(twoway != null); Console.Out.WriteLine("ok"); } Ice.ObjectAdapter adapter; { Console.Out.Write("creating and activating callback receiver adapter... "); Console.Out.Flush(); communicator.SetProperty("Ice.PrintAdapterReady", "0"); adapter = communicator.CreateObjectAdapterWithRouter("CallbackReceiverAdapter", router); adapter.Activate(); Console.Out.WriteLine("ok"); } string category; { Console.Out.Write("getting category from router... "); Console.Out.Flush(); category = router.GetCategoryForClient(); Console.Out.WriteLine("ok"); } CallbackReceiver callbackReceiverImpl; ICallbackReceiver callbackReceiver; ICallbackReceiverPrx twowayR; ICallbackReceiverPrx fakeTwowayR; { Console.Out.Write("creating and adding callback receiver object... "); Console.Out.Flush(); callbackReceiverImpl = new CallbackReceiver(); callbackReceiver = callbackReceiverImpl; Identity callbackReceiverIdent = new Identity("callbackReceiver", category); twowayR = adapter.Add(callbackReceiverIdent, callbackReceiver, ICallbackReceiverPrx.Factory); Identity fakeCallbackReceiverIdent = new Identity("callbackReceiver", "dummy"); fakeTwowayR = adapter.Add(fakeCallbackReceiverIdent, callbackReceiver, ICallbackReceiverPrx.Factory); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing oneway callback... "); Console.Out.Flush(); ICallbackPrx oneway = twoway.Clone(oneway: true); ICallbackReceiverPrx onewayR = twowayR.Clone(oneway: true); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "o"; oneway.initiateCallback(onewayR, context); callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing twoway callback... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; twoway.initiateCallback(twowayR, context); callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("ditto, but with user exception... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; try { twoway.initiateCallbackEx(twowayR, context); test(false); } catch (CallbackException ex) { test(ex.someValue == 3.14); test(ex.someString.Equals("3.14")); } callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("trying twoway callback with fake category... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; try { twoway.initiateCallback(fakeTwowayR, context); test(false); } catch (Ice.ObjectNotExistException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("testing whether other allowed category is accepted... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; ICallbackPrx otherCategoryTwoway = twoway.Clone(Identity.Parse("c2/callback"), ICallbackPrx.Factory); otherCategoryTwoway.initiateCallback(twowayR, context); callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } { Console.Out.Write("testing whether disallowed category gets rejected... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; try { ICallbackPrx otherCategoryTwoway = twoway.Clone(Identity.Parse("c3/callback"), ICallbackPrx.Factory); otherCategoryTwoway.initiateCallback(twowayR, context); test(false); } catch (ObjectNotExistException) { Console.Out.WriteLine("ok"); } } { Console.Out.Write("testing whether user-id as category is accepted... "); Console.Out.Flush(); Dictionary <string, string> context = new Dictionary <string, string>(); context["_fwd"] = "t"; ICallbackPrx otherCategoryTwoway = twoway.Clone(Identity.Parse("_userid/callback"), ICallbackPrx.Factory); otherCategoryTwoway.initiateCallback(twowayR, context); callbackReceiverImpl.callbackOK(); Console.Out.WriteLine("ok"); } if (args.Length >= 1 && args[0].Equals("--shutdown")) { Console.Out.Write("testing server shutdown... "); Console.Out.Flush(); twoway.shutdown(); // No ping, otherwise the router prints a warning message if it's // started with --Ice.Warn.Connections. Console.Out.WriteLine("ok"); /* * try * { * base.IcePing(); * test(false); * } * // If we use the glacier router, the exact exception reason gets * // lost. * catch(Ice.UnknownLocalException ex) * { * Console.Out.WriteLine("ok"); * } */ } { Console.Out.Write("destroying session... "); Console.Out.Flush(); try { router.DestroySession(); } catch (System.Exception) { test(false); } Console.Out.WriteLine("ok"); } { Console.Out.Write("trying to ping server after session destruction... "); Console.Out.Flush(); try { @base.IcePing(); test(false); } catch (ConnectionLostException) { Console.Out.WriteLine("ok"); } catch (TransportException) { test(false); } } if (args.Length >= 1 && args[0].Equals("--shutdown")) { { Console.Out.Write("uninstalling router with communicator... "); Console.Out.Flush(); communicator.SetDefaultRouter(null); Console.Out.WriteLine("ok"); } IObjectPrx processBase; { Console.Out.Write("testing stringToProxy for admin object... "); processBase = IObjectPrx.Parse($"Glacier2/admin -f Process:{getTestEndpoint(51)}", communicator); Console.Out.WriteLine("ok"); } /* * { * Console.Out.Write("uninstalling router with process object... "); * processBase.ice_router(null); * Console.Out.WriteLine("ok"); * } */ IProcessPrx process; { Console.Out.Write("testing checked cast for process object... "); process = IProcessPrx.CheckedCast(processBase); process.IcePing(); Console.Out.WriteLine("ok"); } Console.Out.Write("testing Glacier2 shutdown... "); process.Shutdown(); try { process.IcePing(); test(false); } catch (System.Exception) { Console.Out.WriteLine("ok"); } } } }
public static Ice.DispatchStatus callback___(CallbackReceiver obj__, IceInternal.Incoming inS__, Ice.Current current__) { checkMode__(Ice.OperationMode.Normal, current__.mode); IceInternal.BasicStream is__ = inS__.istr(); is__.startReadEncaps(); int num; num = is__.readInt(); is__.endReadEncaps(); obj__.callback(num, current__); return Ice.DispatchStatus.DispatchOK; }