Esempio n. 1
0
 public void Stack_leak_test()
 {
     RunInMainThread(() =>
     {
         AssertIsGarbageCollected(() =>
         {
             BehaviorSubject <IEnumerable <IControl> > innerControls =
                 new BehaviorSubject <IEnumerable <IControl> >(Enumerable.Empty <IControl>());
             var container = innerControls.StackFromLeft();
             container.MountRoot();
             return(new { innerControls, container });
         },
                                  x =>
         {
             var innerControls   = x.innerControls;
             var rectangleHeight = new BehaviorSubject <Points>(33);
             var rectangle       = Shapes.Rectangle(fill: Brush.Transparent);
             rectangle           = rectangle.WithWidth(rectangleHeight);
             Assert.That(rectangleHeight.HasObservers, Is.False);
             innerControls.OnNext(new[] { rectangle });
             Assert.That(rectangleHeight.HasObservers, Is.True);
             innerControls.OnNext(Enumerable.Empty <IControl>());
             Assert.That(rectangleHeight.HasObservers, Is.False);
             return(rectangle);
         });
     });
 }
Esempio n. 2
0
        static IControl CreateLogView(IObservable <string> mainLogStream, IObservable <IBinaryMessage> deviceMessages, ISubject <Unit> changed)
        {
// Keep a buffer of 10 tweets from the time before this control was mounted for the first time
            var bufferedStream = mainLogStream.Replay(10);            //10 * 140);

            bufferedStream.Connect();

            bufferedStream.Select(_ => Unit.Default).Subscribe(changed);

            var clearLog    = new Subject <Unit>();
            var doClear     = Command.Enabled(() => clearLog.OnNext(Unit.Default));
            var mainLogView = Fusion.LogView.Create(stream: bufferedStream, color: Theme.DefaultText, clear: clearLog, darkTheme: Theme.IsDark)
                              .WithPadding(new Thickness <Points>(5));
            var deviceLogs    = new List <DeviceLog>();
            var activeLogView = new BehaviorSubject <IControl>(mainLogView);
            var activeChanged = new Subject <Unit>();
            var mainLogButton = CreateLogSelectButton("All Output", mainLogView, activeLogView, activeChanged, true);
            var clearButton   = Label.Create("Clear", color: Theme.Active)
                                .OnMouse(pressed: doClear);

            var buttons = new BehaviorSubject <IEnumerable <IControl> >(CreateButtonList(mainLogButton, deviceLogs));

            deviceMessages.TryParse(DebugLog.MessageType, DebugLog.ReadDataFrom).Subscribe(
                l =>
            {
                var device = deviceLogs.FirstOrDefault(d
                                                       => (d.DeviceId == l.DeviceId) ||
                                                       (d.DeviceName == l.DeviceName && l.DeviceName == "Viewport"));

                if (device == null)
                {
                    device = new DeviceLog(l.DeviceId, l.DeviceName, activeLogView, activeChanged, clearLog);
                    deviceLogs.Add(device);
                    buttons.OnNext(CreateButtonList(mainLogButton, deviceLogs));
                }
                device.Write(l.Message);
            });

            return(Layout.Dock()
                   .Top(Layout.Dock()
                        .Right(clearButton)
                        .Left(buttons.StackFromLeft())
                        .Fill()
                        .WithPadding(new Thickness <Points>(10)))
                   .Fill(activeLogView.Switch()));
        }