Esempio n. 1
0
 private static void OnException(ContextRouter router, ContextExceptionInfo info)
 {
     if (info.Data is HttpContext)
     {
         ((HttpContext)info.Data).Response.Write("<p><font  color='red'>" + info.Exception.Message + "</font></p>");
     }
 }
 public void Log(ContextRouter router, ContextItem item, [Context(nameof(LogTextBox))] TextBox textBox, LogInfo info)
 {
     textBox.BeginInvoke(() =>
     {
         textBox.AppendText(info.Message + CRLF);
     });
 }
Esempio n. 3
0
 public void HelloWorld(ContextRouter router, ContextItem item, [Context(nameof(GetPage))] HttpContext httpContext)
 {
     httpContext.Response.Write(String.Format("<p>{0} Hello World!</p>", DateTime.Now.ToString("ss.fff")));
     router.Publish <Wait1>(item.AsyncContext);
     router.Publish <GetPeople>(item.AsyncContext);
     router.Publish <GetPets>(item.AsyncContext);
 }
Esempio n. 4
0
        public static ContextRouter InitializeContext()
        {
            ContextRouter contextRouter = new ContextRouter();

            InitializeContext(contextRouter);
            AutoRegistration.AutoRegister <Listener>(contextRouter);

            return(contextRouter);
        }
Esempio n. 5
0
        public void OnGetPeople(ContextRouter router, ContextItem item)
        {
            // Simulate having queried people:
            var people = new People();

            // Simulate the query having taken some time.
            Thread.Sleep(250);
            router.Publish <People>(people, item.AsyncContext);
        }
Esempio n. 6
0
 /// <summary>
 /// Now we initialize our state, which means creating the ContextRouter if it doesn't exist.
 /// </summary>
 private static void InitializeContextRouter()
 {
     // If we don't have a context router for this session lifetime, create it now.
     if (contextRouter == null)
     {
         contextRouter              = new ContextRouter();
         contextRouter.OnException += (router, info) => OnException((ContextRouter)router, info);
         InitializeContextRouter(contextRouter);
         contextRouter.Run();
     }
 }
        public void ShowListeners(ContextRouter router, ContextItem item,
                                  [Context(nameof(OtherContextRouter))]   ContextRouter otherRouter,
                                  [Context(nameof(ListenerListBox))]      ListBox listBox)
        {
            var listeners = otherRouter.GetAllListeners();

            listBox.BeginInvoke(() =>
            {
                listBox.Items.AddRange(listeners.Select(l => l.Name).OrderBy(n => n).ToArray());
            });
        }
        public void ShowActiveListeners(ContextRouter router, ContextItem item,
                                        [Context(nameof(OtherContextRouter))]         ContextRouter otherRouter,
                                        [Context(nameof(ActiveListenersListBox))]     ListBox listBox,
                                        [Context(nameof(SelectedContext))]            string contextName)
        {
            var listenerTypes = otherRouter.GetListeners(contextName);

            listBox.BeginInvoke(() =>
            {
                listBox.Items.Clear();
                listBox.Items.AddRange(listenerTypes.Select(lt => lt.Name).ToArray());
            });
        }
        public void ShowListenerParameters(ContextRouter router, ContextItem item,
                                           [Context(nameof(OtherContextRouter))]   ContextRouter otherRouter,
                                           [Context(nameof(ParametersListBox))]    ListBox listBox,
                                           [Context(nameof(SelectedListener))]     string name)
        {
            var listener = otherRouter.GetAllListeners().Single(l => l.Name == name);

            listBox.BeginInvoke(() =>
            {
                listBox.Items.Clear();
                listBox.Items.AddRange(listener.GetParameters().ToArray());
            });
        }
Esempio n. 10
0
        public void Render(ContextRouter router, ContextItem item, People people, Pets pets, [Context(nameof(GetPage))] HttpContext httpContext)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<table style='border: 1px solid black; display:inline-table;'>");
            people.GetPeople().ForEach(p => sb.Append("<tr><td>" + p + "</td></tr>"));
            sb.Append("</table>");
            sb.Append("&nbsp;");
            sb.Append("<table style='border: 1px solid black; display:inline-table;'>");
            pets.GetPets().ForEach(p => sb.Append("<tr><td>" + p + "</td></tr>"));
            sb.Append("</table>");

            httpContext.Response.Write(sb.ToString());
        }
Esempio n. 11
0
        protected ContextRouter InitializeMyContextRouter()
        {
            // Remember, trigger parameters must be in the order of the parameters in the Execute handler.

            ContextRouter cr = new ContextRouter();

            cr
            .Register <Startup>(this)
            .TriggerOn <DrawContext, OtherContextRouter, CanvasController, StartingListener>();

            AutoRegistration.AutoRegister <Listener>(cr);

            return(cr);
        }
        public void RegisterClassTest()
        {
            ContextRouter cr = new ContextRouter();

            AutoRegistration.AutoRegister <Logger>(cr);

            var listeners = cr.GetAllListeners();

            listeners.Count.Should().Be(1);
            listeners[0].Name.Should().Be(typeof(Logger).Name);

            var contexts = cr.GetTriggerContexts(typeof(Logger), "LogMe");

            contexts.Count.Should().Be(2);
            contexts[0].Should().Be("LogTextBox");
            contexts[1].Should().Be("LogInfo");
        }
        // Directions to try depending on the number of target listeners.

        public void Execute(ContextRouter router, ContextItem item, ContextRouter otherRouter, CanvasController canvasController, string startingListenerName)
        {
            Box box;
            List <((int x, int y) p, CCListener listener, Direction dir)> placedListeners = new List <((int, int), CCListener, Direction)>();
            List <((int x, int y) p, GraphicElement el)> occupiedCells = new List <((int x, int y), GraphicElement)>();
            // listeners are of type "ReflectOnlyType" so we use name so we can compare System.RuntimeType with ReflectionOnlyType.
            Dictionary <string, GraphicElement> listenerShapes = new Dictionary <string, GraphicElement>();

            // https://stackoverflow.com/questions/398299/looping-in-a-spiral
            IEnumerable <(int x, int y)> Spiral(int X, int Y)
            {
                List <(int, int)> cells = new List <(int, int)>();
                int x, y, dx, dy;

                x  = y = dx = 0;
                dy = -1;
                int tm = Math.Max(X, Y);
                int maxI = tm * tm;

                for (int i = 0; i < maxI; i++)
                {
                    if ((-X / 2 <= x) && (x <= X / 2) && (-Y / 2 <= y) && (y <= Y / 2))
                    {
                        yield return(x, y);
                    }

                    if ((x == y) || ((x < 0) && (x == -y)) || ((x > 0) && (x == 1 - y)))
                    {
                        tm = dx;
                        dx = -dy;
                        dy = tm;
                    }

                    x += dx;
                    y += dy;
                }
            }

            (int, int, Direction) GetFreeCell(
                CCListener forListener,
                (int x, int y) srcCell,
                List <(int x, int y)> requiredCells,
                (int x, int y, Direction dir)[] tryPoints,
Esempio n. 14
0
        public CPDesigner()
        {
            InitializeComponent();

            AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += ReflectionOnlyAssemblyResolve;
            ContextRouter myContextRouter = InitializeMyContextRouter();

#if MyContext
            ContextRouter otherContextRouter = myContextRouter;
#else
            ContextRouter otherContextRouter = Listeners.Listeners.InitializeContext();
#endif
            myContextRouter.OnException += (_, cei) => MessageBox.Show(cei.Exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            WireUpEvents(myContextRouter);
            myContextRouter.Run();

            Shown           += (_, __) => myContextRouter.Publish <Startup>(otherContextRouter);
            canvasController = InitializeFlowSharp();
        }
Esempio n. 15
0
        protected void Execute(ContextRouter router, ContextItem item, ContextRouter otherContextRouter)
        {
            // Publish after the form is shown, otherwise the InvokeRequired will return false even though
            // we're handling the publish on a separate thread.
            router.Publish <ListenerTextBox>(tbListener, isStatic: true);
            router.Publish <LogTextBox>(tbLog, isStatic: true);
            router.Publish <ListenerListBox>(lbListeners, isStatic: true);
            router.Publish <ContextListBox>(lbContexts, isStatic: true);
            router.Publish <ParametersListBox>(lbParameters, isStatic: true);
            router.Publish <PublishesListBox>(lbPublishes, isStatic: true);
            router.Publish <ActiveListenersListBox>(lbActiveListeners, isStatic: true);
            router.Publish <ContextTypeMapsListBox>(lbContextTypeMaps, isStatic: true);
            router.Publish <OtherContextRouter>(otherContextRouter, isStatic: true);
            router.Publish <CanvasController>(canvasController, isStatic: true);
#if MyContext
            router.Publish <StartingListener>(nameof(CPDesigner));
#else
            router.Publish <StartingListener>("HelloWorld");
#endif
        }
Esempio n. 16
0
        // Using tuples gets ugly because we don't have any context of which listbox is which.
        // Consider using a class as a container, or a container for each listbox so we have strongly-typed parameters.

        protected void WireUpEvents(ContextRouter myContextRouter)
        {
            lbListeners.SelectedIndexChanged += (_, __) => myContextRouter.Publish <SelectedListener>(lbListeners.SelectedItem.ToString());
            lbContexts.SelectedIndexChanged  += (_, __) => myContextRouter.Publish <SelectedContext>(lbContexts.SelectedItem.ToString());
        }
Esempio n. 17
0
 private static void InitializeContextRouter(ContextRouter contextRouter)
 {
     Listeners.Listeners.InitializeContext(contextRouter);
 }
Esempio n. 18
0
 public static void InitializeContext(ContextRouter contextRouter)
 {
     contextRouter.AssociateType <HttpContext, GetPage>();
     AutoRegistration.AutoRegister <Listener>(contextRouter);
 }
Esempio n. 19
0
 public void OnWait2(ContextRouter router, ContextItem item, [Context(nameof(GetPage))] HttpContext httpContext)
 {
     Thread.Sleep(500);
     httpContext.Response.Write(String.Format("<p>{0} Wait 2</p>", DateTime.Now.ToString("ss.fff")));
 }
Esempio n. 20
0
 public void OnWait2Again(ContextRouter router, ContextItem item, [Context(nameof(GetPage))] HttpContext httpContext)
 {
     httpContext.Response.Write(String.Format("<p>{0} Wait 2 again</p>", DateTime.Now.ToString("ss.fff")));
 }
 public void ShowTypeMaps(ContextRouter router, ContextItem item,
                          [Context(nameof(OtherContextRouter))]       ContextRouter otherRouter,
                          [Context(nameof(ContextTypeMapsListBox))]   ListBox listBox)
 {
     listBox.BeginInvoke(() => listBox.Items.AddRange(otherRouter.GetTypeContexts().Select(tc => tc.type.Name + " => " + tc.context).ToArray()));
 }
 public void LogMe(ContextRouter router, ContextItem item,
                   [Context(nameof(LogTextBox))]   object textBox,
                   LogInfo info)     // context here defaults to the type name of the parameter.
 {
 }
 public void ShowListenerSelection(ContextRouter router, ContextItem item,
                                   [Context(nameof(ListenerTextBox))]      TextBox textBox,
                                   [Context(nameof(SelectedListener))]     string name)
 {
     textBox.BeginInvoke(() => textBox.Text = name);
 }
 public void ShowContexts(ContextRouter router, ContextItem item,
                          [Context(nameof(OtherContextRouter))]   ContextRouter otherRouter,
                          [Context(nameof(ContextListBox))]       ListBox listBox)
 {
     listBox.BeginInvoke(() => listBox.Items.AddRange(otherRouter.GetAllContexts().OrderBy(c => c).ToArray()));
 }
Esempio n. 25
0
 public void Count(ContextRouter router, ContextItem item, Pets pets, [Context(nameof(GetPage))] HttpContext httpContext)
 {
     httpContext.Response.Write(String.Format("<p>There are {0} pet types.</p>", pets.GetPets().Count));
 }