Esempio n. 1
0
        public void Test22_EventsWithClass()
        {
            var listener = new CustomListener();
            var app      = new App(
                commandsTypes: new List <Type> {
                typeof(Common.Commands.T22.Command1)
            },
                addDefaultAppHandler: false
                );

            app.AddApplicationHandler(listener);
            app.Console.Out = new StringWriter();
            app.Run("-a Y");

            var output   = app.Console.Out.ToString();
            var expected =
                @"OnBeforeMemberInvoke: a Y
OnAfterMemberInvoke: a: Y
OnBeforeMemberInvoke: Main 
OnAfterMemberInvoke: Main: Main
OnPrint: Main: Main
OnComplete
OnException: Exception!!";

            Assert.True(TestHelper.CompareString(expected, output));
        }
Esempio n. 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            SetContentView(Resource.Layout.ScaleImage);

            // Register our sensor listener
            _sensorManager  = (SensorManager)GetSystemService(SensorService);
            _sensorListener = new CustomListener(_sensorManager);
            _sensorListener.AccelerationProcessor.OnValueChanged += AccelerationProcessorOnValueChanged;
            _sensorListener.RotationProcessor.OnValueChanged     += RotationProcessorOnValueChanged;

            // Class that will handle drawing of the map
            _mapMaker = new MapMaker();
            _mapMaker.Initialize(Resources);

            var graphAsset    = Assets.Open("dcsGroundFloor.xml");
            var graphInstance = Graph.Load(graphAsset);

            _mapMaker.PathfindingGraph = graphInstance;

            _collision = new Collision(graphInstance, new StepDetector());
            _collision.SetLocation(707.0f, 677.0f);
            _collision.PassHeading(90);

            _collision.PositionChanged     += CollisionOnPositionChanged;
            _collision.StepDetector.OnStep += StepDetectorOnStep;

            collisionMap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.dcsFloor);

            _walCol            = new WallCollision((x, y) => collisionMap.GetPixel(x, y));
            _collision.WallCol = _walCol;


            pf = new Pathfinding.Pathfinding(new Dictionary <int, Stream>()
            {
                { 0, Assets.Open("dcsGroundFloor.xml") },
                { 1, Assets.Open("dcsFloor1.xml") }
            }, Assets.Open("Rooms.xml"));
            pf.CurrentFloor = 0;


            while (true)
            {
                if (pf.Ready)
                {
                    break;
                }
                Thread.Sleep(500);
            }

            var result = pf.FindPath(new GraphLocatable(609, 457, 1), new GraphLocatable(1256, 80, 0));


            setUpUITabs();
        }
 public EngineTestRig(string savePath, int piecelength, PieceWriter writer)
 {
     if (writer == null)
         writer = new MemoryWriter(new NullWriter());
     Listener = new CustomListener();
     Engine = new ClientEngine(new EngineSettings(), Listener, writer);
     TorrentDict = CreateTorrent(piecelength);
     Torrent = Torrent.Load(TorrentDict);
     Manager = new TorrentManager(Torrent, savePath, new TorrentSettings());
     Engine.Register(Manager);
     //manager.Start();
 }
    public static void register <E> (this CustomListener listener) where E : CustomEvent
    {
        Type eventType = typeof(E);

        if (!registeredListeners.ContainsKey(eventType))
        {
            registeredListeners.Add(eventType, new List <CustomListener> ());
        }
        if (registeredListeners [eventType].Contains(listener))
        {
            return;
        }
        registeredListeners [eventType].Add(listener);
    }
//	public static Dictionary<Type, List<CustomListener>> registeredListeners = new Dictionary<Type, List<CustomListener>> ();

//	public static List<CustomListener> registeredListeners = new List<CustomListener> ();

//	public static void subscribe<E> (this CustomListener listener) where E : CustomEvent {
//		Type eventType = typeof (E);
//		if (!registeredListeners.ContainsKey (eventType))
//			registeredListeners.Add (eventType, new List<CustomListener> ());
//		registeredListeners [eventType].Add (listener);
//	}

//	public static void registerHandler<E> (this CustomListener listener, CustomEventMethod<E> handler) where E : CustomEvent {
//		Type eventType = typeof (E);
//		if (!registeredHandlers.ContainsKey (eventType))
//			registeredHandlers.Add (eventType, new CustomEventMethod<CustomEvent> ());
//		registeredHandlers [eventType].Add (
//			new KeyValuePair<CustomListener, CustomEventMethod<CustomEvent>> (listener, handler as CustomEventMethod<CustomEvent>));
//	}
    public static void registerHandler <E> (this CustomListener listener, CustomEventMethod <E> handler) where E : CustomEvent
    {
        Type listenerType = listener.GetType();
        Type eventType    = typeof(E);

        Debug.Log("Registering " + handler.Target + "." + handler.Method.Name + " for " + eventType);
        if (!handlerList.ContainsKey(eventType))
        {
            handlerList.Add(eventType, new Dictionary <Type, MethodInfo> ());
        }
        if (handlerList [eventType].ContainsKey(listenerType))
        {
            return;
        }
        handlerList [eventType].Add(listenerType, handler.Method);
        listener.register <E> ();

//		registeredHandlers [eventType].Add (new KeyValuePair<CustomListener, MethodInfo> (listener, handler.Method));
    }
Esempio n. 6
0
        public async Task DisposedScriptLoggerFactory_UsesFullStackTrace()
        {
            var host = new TestFunctionHost(@"TestScripts\CSharp",
                                            configureScriptHostServices: s =>
            {
                s.AddSingleton <IExtensionConfigProvider, CustomTriggerExtensionConfigProvider>();
                s.Configure <ScriptJobHostOptions>(o => o.Functions = new[] { "CustomTrigger" });
            });

            await CustomListener.RunAsync("one");

            host.Dispose();

            // In this scenario, the logger throws an exception before we enter the try/catch for the function invocation.
            var ex = await Assert.ThrowsAsync <HostDisposedException>(() => CustomListener.RunAsync("two"));

            Assert.Equal($"The host is disposed and cannot be used. Disposed object: '{typeof(ScriptLoggerFactory).FullName}'; Found IListener in stack trace: '{typeof(CustomListener).AssemblyQualifiedName}'", ex.Message);
            Assert.Contains("CustomListener.RunAsync", ex.StackTrace);
        }
Esempio n. 7
0
        public async Task DisposedResolver_UsesFullStackTrace()
        {
            var host = new TestFunctionHost(@"TestScripts\CSharp",
                                            configureScriptHostServices: s =>
            {
                s.AddSingleton <IExtensionConfigProvider, CustomTriggerExtensionConfigProvider>();
                s.Configure <ScriptJobHostOptions>(o => o.Functions = new[] { "CustomTrigger" });
                s.AddSingleton <ILoggerFactory, TestScriptLoggerFactory>();
            });

            await CustomListener.RunAsync("one");

            host.Dispose();

            // In this scenario, the function is considered failed even though the function itself was never called.
            var result = await CustomListener.RunAsync("two");

            Assert.False(result.Succeeded);

            var ex = result.Exception;

            Assert.Equal($"The host is disposed and cannot be used. Disposed object: '{typeof(ScopedResolver).FullName}'; Found IListener in stack trace: '{typeof(CustomListener).AssemblyQualifiedName}'", ex.Message);
            Assert.Contains("CustomListener.RunAsync", ex.StackTrace);
        }
Esempio n. 8
0
        private TestRig(string savePath, int piecelength, TestWriter writer, string[][] trackers, TorrentFile[] files,
            bool metadataMode)
        {
            this.files = files;
            this.savePath = savePath;
            this.piecelength = piecelength;
            tier = trackers;
            MetadataMode = metadataMode;
            MetadataPath = "metadataSave.torrent";
            Listener = new CustomListener();
            Engine = new ClientEngine(new EngineSettings(), Listener, writer);
            Writer = writer;

            RecreateManager();
        }
Esempio n. 9
0
        public TrackerTestRig()
        {
            Tracker = new Tracker();
            Listener = new CustomListener();
            Tracker.RegisterListener(Listener);

            GenerateTrackables();
            GeneratePeers();
        }