Ejemplo n.º 1
0
 public void DispatchedTasksAreExecutedOnlyWhenCallingExecuteNextTask()
 {
     var pollingDispatcher = new PollingDispatcher();
     pollingDispatcher.Dispatch(() => this.processedValues.Add(1));
     Check.That(this.processedValues).HasSize(0);
     
     pollingDispatcher.ExecuteNextTask();
     Check.That(this.processedValues).HasSize(1).And.ContainsExactly(1);
 }
Ejemplo n.º 2
0
        public void DispatchedTasksAreExecutedOnlyWhenCallingExecuteNextTask()
        {
            var pollingDispatcher = new PollingDispatcher();

            pollingDispatcher.Dispatch(() => this.processedValues.Add(1));
            Check.That(this.processedValues).HasSize(0);

            pollingDispatcher.ExecuteNextTask();
            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(1);
        }
Ejemplo n.º 3
0
        public void TheLastDispatchedTaskIsNotExecutedMoreThanOnce()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher     = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));

            pollingRootDispatcher.ExecuteNextTask();
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(2);
        }
Ejemplo n.º 4
0
        public void TheLastDispatchedTaskIsNotExecutedMoreThanOnce()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));

            pollingRootDispatcher.ExecuteNextTask();
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(2);
        }
Ejemplo n.º 5
0
 public void BindNativeProperty_memory_usage()
 {
     Assert.That(MemBenchmark(() =>
     {
         var isRooted      = Observable.Return(true);
         var source        = new BehaviorSubject <int>(1234);
         var dispatcher    = new PollingDispatcher(Thread.CurrentThread);
         var mountLocation = CreateMountLocation();
         return(new { isRooted, source, dispatcher, mountLocation });
     },
                              x =>
     {
         PropertyBindingExtensions.BindNativeProperty(x.isRooted, x.dispatcher, String.Empty, x.source, v => { /*Console.WriteLine("Got update " + v);*/ });
         return(x);
     }), Is.LessThan(1500));
 }
Ejemplo n.º 6
0
        public void TasksDispatchedWhileBusyAreDiscarded()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher     = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));

            balkingDispatcher.Dispatch(() => this.processedValues.Add(3));
            pollingRootDispatcher.ExecuteNextTask();

            // Should have executed only the latest task before the ExecuteNextTask
            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(3);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(4));
            pollingRootDispatcher.ExecuteNextTask();

            balkingDispatcher.Dispatch(() => this.processedValues.Add(5));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(6));
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(3).And.ContainsExactly(3, 4, 6);
        }
Ejemplo n.º 7
0
        public void TasksDispatchedWhileBusyAreDiscarded()
        {
            var pollingRootDispatcher = new PollingDispatcher();
            var balkingDispatcher = new BalkingDispatcher(pollingRootDispatcher);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(1));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(2));
            
            balkingDispatcher.Dispatch(() => this.processedValues.Add(3));
            pollingRootDispatcher.ExecuteNextTask();
            
            // Should have executed only the latest task before the ExecuteNextTask
            Check.That(this.processedValues).HasSize(1).And.ContainsExactly(3);

            balkingDispatcher.Dispatch(() => this.processedValues.Add(4));
            pollingRootDispatcher.ExecuteNextTask();

            balkingDispatcher.Dispatch(() => this.processedValues.Add(5));
            balkingDispatcher.Dispatch(() => this.processedValues.Add(6));
            pollingRootDispatcher.ExecuteNextTask();

            Check.That(this.processedValues).HasSize(3).And.ContainsExactly(3, 4, 6);
        }
Ejemplo n.º 8
0
        public void CallingExecuteNextTaskDoesNotThrowWhenNoTaskIsDispatched()
        {
            var pollingDispatcher = new PollingDispatcher();

            pollingDispatcher.ExecuteNextTask();
        }
Ejemplo n.º 9
0
        static void Main(string[] argsArray)
        {
            var shell     = new Shell();
            var systemId  = SystemGuidLoader.LoadOrCreateOrEmpty();
            var sessionId = Guid.NewGuid();
            var log       = ReportFactory.GetReporter(systemId, sessionId, "UnoHost");

            AppDomain.CurrentDomain.ReportUnhandledExceptions(log);

            DpiAwareness.SetDpiAware(DpiAwareness.ProcessDpiAwareness.SystemAware);

            NativeResources.Load();

            var args = UnoHostArgs.RemoveFrom(argsArray.ToList(), shell);

            // Load metadata
            var unoHostProject = UnoHostProject.Load(args.MetadataPath, shell);

            var form = new DpiAwareForm()
            {
                FormBorderStyle = FormBorderStyle.None,
                ShowInTaskbar   = false
            };

            //if (args.IsDebug)
            //	InitDebugMode(form);

            var unoControl = new UnoControl(form, log);

            form.Controls.Add(unoControl);
            form.ShowIcon = false;


            var openGlVersion   = new Subject <OpenGlVersion>();
            var backgroundQueue = new QueuedDispatcher();
            var lostFocus       = Observable.FromEventPattern(unoControl, "LostFocus").ObserveOn(backgroundQueue);

            var messagesTo = new Subject <IBinaryMessage>();

            var output = Observable.Merge(
                messagesTo.Do(message => Console.WriteLine(message.Type)),
                openGlVersion.Select(OpenGlVersionMessage.Compose),
                Observable.FromEventPattern(unoControl, "GotFocus").Select(_ => WindowFocusMessage.Compose(FocusState.Focused)),
                lostFocus.Select(_ => WindowFocusMessage.Compose(FocusState.Blurred)),
                lostFocus.Select(_ => WindowContextMenuMessage.Compose(false)),
                Observable.FromEventPattern <MouseEventArgs>(unoControl, "MouseUp")
                .Where(m => m.EventArgs.Button == System.Windows.Forms.MouseButtons.Right)
                .Select(_ => WindowContextMenuMessage.Compose(true)),
                Observable.FromEventPattern <MouseEventArgs>(unoControl, "MouseDown")
                .Select(_ => WindowContextMenuMessage.Compose(false)),
                Observable.FromEventPattern <MouseEventArgs>(unoControl, "MouseWheel")
                .Select(m => WindowMouseScrollMessage.Compose(m.EventArgs.Delta)),
                Observable.FromEventPattern <KeyEventArgs>(unoControl, "KeyDown")
                .Select(m => WindowKeyDown.Compose(m.EventArgs.KeyCode)),
                Observable.FromEventPattern <KeyEventArgs>(unoControl, "KeyUp")
                .Select(m => WindowKeyUp.Compose(m.EventArgs.KeyCode)));

            args.OutputPipe.BeginWritingMessages(
                "Designer",
                ex => Console.WriteLine("UnoHost failed to write message to designer: " + ex),
                output.ObserveOn(new QueuedDispatcher()));

            unoControl.Initialize(unoHostProject, openGlVersion);

            // Set hand cursor so we know when we're interacting with the UnoHost and not in the designer
            unoControl.Cursor = System.Windows.Forms.Cursors.Hand;

            // notify studio about the window
            messagesTo.OnNext(WindowCreatedMessage.Compose(form.Handle));

            var dispatcher = new PollingDispatcher(Thread.CurrentThread);

            unoControl.PerFrame.Subscribe(f => dispatcher.DispatchCurrent());


            var density = Observable.Return(new Ratio <Points, Pixels>(1));

            var size = Observable.FromEventPattern(unoControl, "SizeChanged")
                       .StartWith(new EventPattern <object>(null, null))
                       .Select(_ => unoControl.Size.ToSize())
                       .CombineLatest(density, (s, d) => s.Mul(d))
                       .Transpose();



            var messagesFrom = args.InputPipe
                               .ReadMessages("Designer")
                               .RefCount()
                               .ObserveOn(dispatcher)
                               .Publish();

            messagesFrom.Subscribe(next => { }, e => form.Exit(1), () => form.Exit(0));

            // Run the uno entrypoints, this initializes Uno.Application.Current

            unoHostProject.ExecuteStartupCode();
            var app = Uno.Application.Current as dynamic;


            // Init plugins

            FusionImplementation.Initialize(dispatcher, args.UserDataPath, app.Reflection);
            var overlay = PluginManager.Initialize(messagesFrom, messagesTo, dispatcher, unoControl.PerFrame, size);

            app.ResetEverything(true, overlay);


            // Ready to go

            messagesFrom.Connect();
            messagesTo.OnNext(new Ready());

            unoControl.Run();
        }
Ejemplo n.º 10
0
 public void CallingExecuteNextTaskDoesNotThrowWhenNoTaskIsDispatched()
 {
     var pollingDispatcher = new PollingDispatcher();
     pollingDispatcher.ExecuteNextTask();
 }