Beispiel #1
0
        public void DisposingMultipleActions()
        {
            var lst = new List <string>();

            using (var d = new Disposable(() => lst.Add("Foo")))
            {
                d.Add(() => lst.Add("Bar"));
                d.Add(() => lst.Add("Baz"));
            }

            Assert.That(lst.Count, Is.EqualTo(3));
            Assert.That(lst[0], Is.EqualTo("Baz"));
            Assert.That(lst[1], Is.EqualTo("Bar"));
            Assert.That(lst[2], Is.EqualTo("Foo"));
        }
Beispiel #2
0
        protected virtual ILanguageClient CreateClient(Action <LanguageClientOptions>?clientOptionsAction = null)
        {
            _client = LanguageClient.PreInit(
                options => {
                var(reader, writer) = SetupServer();
                options
                .WithInput(reader)
                .WithOutput(writer)
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .WithAssemblies(TestOptions.Assemblies)
                .WithAssemblies(typeof(LanguageProtocolTestBase).Assembly, GetType().Assembly)
                .ConfigureLogging(x => x.SetMinimumLevel(LogLevel.Trace))
                .WithInputScheduler(options.InputScheduler)
                .WithOutputScheduler(options.OutputScheduler)
                .WithDefaultScheduler(options.DefaultScheduler)
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(Events as IRequestSettler);
                clientOptionsAction?.Invoke(options);
            }
                );

            Disposable.Add(_client);

            return(_client);
        }
Beispiel #3
0
        public void InvalidOperationToAddWhenAlreadyDisposed()
        {
            var d = new Disposable();

            ((IDisposable)d).Dispose();
            Assert.That(() => d.Add(Functions.NoOp), Throws.TypeOf <ObjectDisposedException>());
        }
Beispiel #4
0
 public PacketV2Decoder()
 {
     // the first byte is always STX
     _buffer[0] = PacketV2Helper.MagicMarkerV2;
     Disposable.Add(_decodeErrorSubject);
     Disposable.Add(_packetSubject);
 }
Beispiel #5
0
        protected virtual async Task <IDebugAdapterClient> InitializeClient(Action <DebugAdapterClientOptions>?clientOptionsAction = null)
        {
            _client = DebugAdapterClient.Create(
                options => {
                var(reader, writer) = SetupServer();
                options
                .WithInput(reader)
                .WithOutput(writer)
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .ConfigureLogging(
                    x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                }
                    )
                .WithInputScheduler(options.InputScheduler)
                .WithOutputScheduler(options.OutputScheduler)
                .WithDefaultScheduler(options.DefaultScheduler)
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(Events as IRequestSettler);
                clientOptionsAction?.Invoke(options);
            }
                );

            Disposable.Add(_client);

            await _client.Initialize(CancellationToken).ConfigureAwait(false);

            return(_client);
        }
Beispiel #6
0
        public ImageFilter Crop(int x, int y, int width, int height)
        {
            Disposable.Add(bitmap);
            var cropRectangle = new Rectangle(x, y, width, height);

            bitmap = bitmap.CropAtRect(cropRectangle);
            return(this);
        }
Beispiel #7
0
        public ValueBinding(IValue <T> first, IValue <T> second)
        {
            first.Validation().NotNull("first");
            second.Validation().NotNull("second");

            Disposable.Add(first.Get.Bind(second.Set));
            Disposable.Add(second.Get.Bind(first.Set));
        }
Beispiel #8
0
        protected virtual async Task <(JsonRpcServer client, JsonRpcServer server)> Initialize(
            Action <JsonRpcServerOptions> clientOptionsAction,
            Action <JsonRpcServerOptions> serverOptionsAction
            )
        {
            var clientPipe = new Pipe(TestOptions.DefaultPipeOptions);
            var serverPipe = new Pipe(TestOptions.DefaultPipeOptions);

            var clientTask = JsonRpcServer.From(
                options => {
                options
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .WithServices(
                    services => services
                    .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                    .AddSingleton(ClientEvents as IRequestSettler)
                    .AddLogging(
                        x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                }
                        )
                    );
                ConfigureClientInputOutput(serverPipe.Reader, clientPipe.Writer, options);
                clientOptionsAction(options);
            }, CancellationToken
                );

            var serverTask = JsonRpcServer.From(
                options => {
                options
                .WithServices(
                    services => services
                    .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                    .AddSingleton(ServerEvents as IRequestSettler)
                    .AddLogging(
                        x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                    x.Services.AddSingleton(TestOptions.ServerLoggerFactory);
                }
                        )
                    );
                ConfigureServerInputOutput(clientPipe.Reader, serverPipe.Writer, options);
                serverOptionsAction(options);
            }, CancellationToken
                );

            await Task.WhenAll(clientTask, serverTask).ConfigureAwait(false);

#pragma warning disable VSTHRD103
            _client = clientTask.Result;
            _server = serverTask.Result;
#pragma warning restore VSTHRD103

            Disposable.Add(_client);
            Disposable.Add(_server);

            return(_client, _server);
        }
Beispiel #9
0
        protected RemoteCommand()
        {
            Log = LogManager.GetLogger(GetType());
            Disposable.Add(Cleaner);

            Formatter = new JsonMediaTypeFormatter {
                SerializerSettings = JsonHelper.SerializerSettings()
            };
        }
Beispiel #10
0
 private ReactiveProperty <T> BindSettings <T>(T val, string nameofParameter, ReactivePropertyMode mode = ReactivePropertyMode.Default)
 {
     return(new ReactiveProperty <T>(val, mode).Also(v =>
     {
         Disposable.Add(v.Subscribe(vv =>
         {
             typeof(Settings).GetProperty(nameofParameter).SetValue(settings, vv);
         }));
     }));
 }
Beispiel #11
0
        public MavlinkClient(IMavlinkV2Connection connection, MavlinkClientIdentity identity, MavlinkClientConfig config, IPacketSequenceCalculator sequence = null, bool disposeConnection = true)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            _seq               = sequence ?? new PacketSequenceCalculator();
            Identity           = identity;
            _mavlinkConnection = connection ?? throw new ArgumentNullException(nameof(connection));


            _rtt = new MavlinkTelemetry(_mavlinkConnection, identity, _seq);
            Disposable.Add(_rtt);

            _params = new MavlinkParameterClient(_mavlinkConnection, identity, _seq, new VehicleParameterProtocolConfig {
                ReadWriteTimeoutMs = config.ReadParamTimeoutMs, TimeoutToReadAllParamsMs = config.TimeoutToReadAllParamsMs
            });
            Disposable.Add(_params);

            _mavlinkCommands = new MavlinkCommandClient(_mavlinkConnection, identity, _seq, new CommandProtocolConfig {
                CommandTimeoutMs = config.CommandTimeoutMs
            });
            Disposable.Add(_mavlinkCommands);

            _mission = new MissionClient(_mavlinkConnection, identity, _seq, new MissionClientConfig {
                CommandTimeoutMs = config.CommandTimeoutMs
            });
            Disposable.Add(_mission);

            _mavlinkOffboard = new MavlinkOffboardMode(_mavlinkConnection, identity, _seq);
            Disposable.Add(_mavlinkOffboard);

            _mode = new MavlinkCommon(_mavlinkConnection, identity, _seq);
            Disposable.Add(_mode);

            _debugs = new DebugClient(_mavlinkConnection, identity, _seq);
            Disposable.Add(_debugs);

            _heartbeat = new HeartbeatClient(_mavlinkConnection, identity, _seq);
            Disposable.Add(_heartbeat);

            _logging = new LoggingClient(_mavlinkConnection, identity, _seq);
            Disposable.Add(_logging);

            _v2Ext = new V2ExtensionClient(_mavlinkConnection, _seq, identity);
            Disposable.Add(_v2Ext);

            _rtk = new DgpsClient(_mavlinkConnection, identity, _seq);
            Disposable.Add(_rtt);

            if (disposeConnection)
            {
                Disposable.Add(_mavlinkConnection);
            }
        }
Beispiel #12
0
        public ApiSender(string sessionId)
        {
            Disposable.Add(KanColleClient.Current.Proxy.ApiSessionSource
                           .Subscribe(OnSession));

            KcvdbClient = KCVDBClientService.Instance.CreateClient(Constants.KCVDB.AgentId, sessionId);
            Disposable.Add(KcvdbClient);

            KcvdbClient.FatalError    += KcvdbClient_FatalError;
            KcvdbClient.InternalError += KcvdbClient_InternalError;
            KcvdbClient.SendingError  += KcvdbClient_SendingError;
        }
        protected virtual async Task <(IDebugAdapterClient client, IDebugAdapterServer server)> Initialize(
            Action <DebugAdapterClientOptions> clientOptionsAction,
            Action <DebugAdapterServerOptions> serverOptionsAction
            )
        {
            var clientPipe = new Pipe(TestOptions.DefaultPipeOptions);
            var serverPipe = new Pipe(TestOptions.DefaultPipeOptions);

            _client = DebugAdapterClient.Create(
                options => {
                options
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .ConfigureLogging(
                    x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                    x.Services.AddSingleton(TestOptions.ClientLoggerFactory);
                }
                    )
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(ClientEvents as IRequestSettler);
                ConfigureClientInputOutput(serverPipe.Reader, clientPipe.Writer, options);
                clientOptionsAction(options);
            }
                );

            _server = DebugAdapterServer.Create(
                options => {
                options
                .WithLoggerFactory(TestOptions.ServerLoggerFactory)
                .ConfigureLogging(
                    x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                    x.Services.AddSingleton(TestOptions.ServerLoggerFactory);
                }
                    )
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(ServerEvents as IRequestSettler);
                ConfigureServerInputOutput(clientPipe.Reader, serverPipe.Writer, options);
                serverOptionsAction(options);
            }
                );

            Disposable.Add(_client);
            Disposable.Add(_server);

            return(await Observable.FromAsync(_client.Initialize).ForkJoin(
                       Observable.FromAsync(_server.Initialize),
                       (a, b) => (_client, _server)
                       ).ToTask(CancellationToken));
        }
Beispiel #14
0
        protected internal virtual (ILanguageClient client, ILanguageServer server) Create(
            Action <LanguageClientOptions> clientOptionsAction,
            Action <LanguageServerOptions> serverOptionsAction
            )
        {
            var clientPipe = new Pipe(TestOptions.DefaultPipeOptions);
            var serverPipe = new Pipe(TestOptions.DefaultPipeOptions);

            _client = LanguageClient.PreInit(
                options => {
                options
                .WithLoggerFactory(TestOptions.ClientLoggerFactory)
                .WithAssemblies(TestOptions.Assemblies)
                .ConfigureLogging(x => x.SetMinimumLevel(LogLevel.Trace))
                .WithAssemblies(typeof(LanguageProtocolTestBase).Assembly, GetType().Assembly)
                .WithInputScheduler(options.InputScheduler)
                .WithOutputScheduler(options.OutputScheduler)
                .WithDefaultScheduler(options.DefaultScheduler)
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(ClientEvents as IRequestSettler);
                ConfigureClientInputOutput(serverPipe.Reader, clientPipe.Writer, options);
                clientOptionsAction(options);
            }
                );

            _server = RealLanguageServer.PreInit(
                options => {
                options
                .WithLoggerFactory(TestOptions.ServerLoggerFactory)
                .WithAssemblies(TestOptions.Assemblies)
                .ConfigureLogging(x => x.SetMinimumLevel(LogLevel.Trace))
                .WithAssemblies(typeof(LanguageProtocolTestBase).Assembly, GetType().Assembly)
                .WithInputScheduler(options.InputScheduler)
                .WithOutputScheduler(options.OutputScheduler)
                .WithDefaultScheduler(options.DefaultScheduler)
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(ServerEvents as IRequestSettler);
                ConfigureServerInputOutput(clientPipe.Reader, serverPipe.Writer, options);
                serverOptionsAction(options);
            }
                );

            Disposable.Add(_client);
            Disposable.Add(_server);

            return(_client, _server);
        }
Beispiel #15
0
        private void MainWindow_OnLoaded(object sender, EventArgs args)
        {
            Title += $" {GetApplicationVersion()}";

            try
            {
                _mainViewModel = new MainViewModel(this);
                Disposable.Add(_mainViewModel);
                DataContext = _mainViewModel;
            }
#pragma warning disable CA1031 // 一般的な例外の種類はキャッチしません
            catch (Exception e)
#pragma warning restore CA1031 // 一般的な例外の種類はキャッチしません
            {
                FileHelper.OutputErrorLogFile(e);
            }
        }
Beispiel #16
0
 public virtual void Configure(Settings value, Config.Config config,
                               CancellationToken token = default(CancellationToken))
 {
     Config   = config;
     Token    = token;
     Settings = value;
     Cleaner.DefaultRandomFileDir = config.TmpDir;
     if (errorMap.Count == 0)
     {
         if (!String.IsNullOrEmpty(Config.AltUri))
         {
             Config.AltUri.Split(',').Each(x => {
                 errorMap.Add(new Uri(x.Trim()).ToString(), 0);
             });
         }
         else if (Config.BaseUrl != null)
         {
             errorMap.Add(Config.BaseUrl.ToString(), 0);
         }
     }
     if (Client != null)
     {
         Client.Dispose();
         Disposable.Remove(Client);
     }
     if (HttpProgress != null)
     {
         HttpProgress.Dispose();
         Disposable.Remove(HttpProgress);
         HttpProgress.HttpReceiveProgress -= ReceiveProgress;
     }
     if (Handler != null)
     {
         Handler.Dispose();
         Disposable.Remove(Handler);
     }
     Client = Settings.GetHttpClient(Config, ref HttpProgress, ref Handler);
     Disposable.Add(Client);
     Disposable.Add(HttpProgress);
     Disposable.Add(Handler);
     HttpProgress.HttpReceiveProgress += ReceiveProgress;
 }
Beispiel #17
0
        public LwsViewModel()
        {
            model = new LwsModel();

            Output = model.Output.ToReadOnlyReactiveCollection();
            EnchantGroupList.AddRange(Const.EnchantmentList.Select(item => item.Name));

            ExecuteCommand.Subscribe(_ => Execute());
            ExitCommand.Subscribe(_ => Exit());

            SelectedGroupIndex.Subscribe(_ =>
            {
                EnchantNameList.Clear();
                EnchantNameList.AddRange(GetEnchantNameList().Select(i => i.Name));
                SelectedNameIndex.Value = 0;
            });

            Disposable.Add(Output);
            Disposable.Add(ExecuteCommand);
            Disposable.Add(ExitCommand);
        }
Beispiel #18
0
        public ReflectionValue(object instance, string getMemberName, string setMemberName, string eventMemberName)
        {
            source = new ReflectionSource <T>(instance, getMemberName, setMemberName);

            memberChanged = (IEventDescriptor)instance.Reflection().FindDescriptor(eventMemberName);

            if (memberChanged == null)
            {
                var propertyChanged = instance as INotifyPropertyChanged;

                if (propertyChanged == null)
                {
                    throw new ArgumentException("Not Supported");
                }

                Disposable.Add(propertyChanged.Observe(OnPropertyChanged));
            }
            else
            {
                Disposable.Add(memberChanged.Observe(instance, this, "OnMemberChanged"));
            }
        }
Beispiel #19
0
        protected virtual async Task <ILanguageClient> InitializeClient(Action <LanguageClientOptions> clientOptionsAction = null)
        {
            _client = LanguageClient.PreInit(options => {
                var(reader, writer) = SetupServer();
                options
                .WithInput(reader)
                .WithOutput(writer)
                .ConfigureLogging(x => {
                    x.SetMinimumLevel(LogLevel.Trace);
                    x.Services.AddSingleton(TestOptions.ClientLoggerFactory);
                })
                .Services
                .AddTransient(typeof(IPipelineBehavior <,>), typeof(SettlePipeline <,>))
                .AddSingleton(ServerEvents as IRequestSettler);
                clientOptionsAction?.Invoke(options);
            });

            Disposable.Add(_client);

            await _client.Initialize(CancellationToken);

            return(_client);
        }
Beispiel #20
0
        // FIXME: VMでやることじゃない
        public AxisStandardViewModel(
            INativeWindowManager nativeWindowManager,
            IScreenManager screenManager,
            IAudioManager audioManager,
            IVersionRepository versionRepository,
            ISettingService settingService)
        {
            settings              = settingService.Instance();
            Vertical              = BindSettings(settings.Vertical, nameof(settings.Vertical));
            Horizontal            = BindSettings(settings.Horizontal, nameof(settings.Horizontal));
            WindowFittingStandard = BindSettings(settings.WindowFittingStandard, nameof(settings.WindowFittingStandard));
            MuteCondition         = BindSettings(settings.MuteCondition, nameof(settings.MuteCondition));
            TargetApplicationName = BindSettings(settings.TargetApplicationName, nameof(TargetApplicationName));
            LatestVersion         = new ReactiveProperty <string>("");

            UseCurrentVerticalUserSetting   = BindSettings(settings.UseCurrentVerticalUserSetting, nameof(settings.UseCurrentVerticalUserSetting), ReactivePropertyMode.RaiseLatestValueOnSubscribe);
            UseCurrentHorizontalUserSetting = BindSettings(settings.UseCurrentHorizontalUserSetting, nameof(settings.UseCurrentHorizontalUserSetting), ReactivePropertyMode.RaiseLatestValueOnSubscribe);
            UserDefinedVerticalWindowRect   = BindSettings(settings.UserDefinedVerticalWindowRect, nameof(settings.UserDefinedVerticalWindowRect));
            UserDefinedHorizontalWindowRect = BindSettings(settings.UserDefinedHorizontalWindowRect, nameof(settings.UserDefinedHorizontalWindowRect));
            IsMostTop      = BindSettings(settings.IsMostTop, nameof(settings.IsMostTop));
            IsRemoveBorder = BindSettings(settings.IsRemoveBorder, nameof(settings.IsRemoveBorder));

            // FIXME: PollingじゃなくてGlobalHookとかでやりたい
            targetWindowHandle = Observable.Interval(TimeSpan.FromSeconds(5))
                                 .CombineLatest(TargetApplicationName)
                                 .Select(x => nativeWindowManager.GetWindowHandle(x.Second))
                                 .Distinct()
                                 .ToReadOnlyReactiveProperty();

            // FIXME: TargetApplicationNameが変わってもThreadが変わって動かなくなるわ…
            Disposable.Add(TargetApplicationName.Subscribe(x => nativeWindowManager.SetHook(x)));
            Disposable.Add(targetWindowHandle.Subscribe(x => nativeWindowManager.SetTargetProcessHandler(x)));

            var observableBorderChanged = Observable.FromEventPattern(nativeWindowManager, nameof(nativeWindowManager.OnBorderChanged)).StartWith(new object[] { null });
            var observableOnMoveChanged = Observable.FromEventPattern(nativeWindowManager, nameof(nativeWindowManager.OnMoveOrSizeChanged)).Throttle(TimeSpan.FromMilliseconds(200)).StartWith(new object[] { null });

            var windowRect = targetWindowHandle
                             .CombineLatest(
                observableOnMoveChanged,
                observableBorderChanged.Delay(TimeSpan.FromMilliseconds(500))
                )
                             .Select(x =>
            {
                if (x.First == IntPtr.Zero)
                {
                    return(WindowRect.Empty, WindowRect.Empty);
                }
                var windowClientRectPair = nativeWindowManager.GetWindowRect(x.First);
                var(r, _) = windowClientRectPair;
                if (r.IsEmpty)
                {
                    return(WindowRect.Empty, WindowRect.Empty);
                }
                return(windowClientRectPair);
            });

            Disposable.Add(UseCurrentHorizontalUserSetting.Subscribe(x =>
            {
                if (!x)
                {
                    return;
                }
                var handle = targetWindowHandle.Value;
                if (handle == IntPtr.Zero)
                {
                    return;
                }
                var(r, _) = nativeWindowManager.GetWindowRect(handle);
                if (r.IsEmpty)
                {
                    UserDefinedHorizontalWindowRect.Value = WindowRect.Empty;
                    return;
                }
                UserDefinedHorizontalWindowRect.Value = r;
                return;
            }));

            Disposable.Add(UseCurrentVerticalUserSetting.Subscribe(x =>
            {
                if (!x)
                {
                    return;
                }
                var handle = targetWindowHandle.Value;
                if (handle == IntPtr.Zero)
                {
                    return;
                }
                var(r, _) = nativeWindowManager.GetWindowRect(handle);
                if (r.IsEmpty)
                {
                    UserDefinedVerticalWindowRect.Value = WindowRect.Empty;
                    return;
                }
                UserDefinedVerticalWindowRect.Value = r;
                return;
            }));

            Disposable.Add(targetWindowHandle.CombineLatest(
                               MuteCondition,
                               Observable.CombineLatest(
                                   Observable.FromEventPattern <bool>(nativeWindowManager, nameof(nativeWindowManager.OnForeground))
                                   .Select(x => x.EventArgs.ToDefaultableBooleanLike()).StartWith(DefaultableBooleanLike.Default),
                                   Observable.FromEventPattern <bool>(nativeWindowManager, nameof(nativeWindowManager.OnMinimized))
                                   .Select(x => x.EventArgs.ToDefaultableBooleanLike()).StartWith(DefaultableBooleanLike.Default)
                                   )
                               .DistinctUntilChanged()
                               .Select(x =>
            {
                var maybeForeground = x[0];
                var maybeMinimized  = x[1];
                return((maybeForeground, maybeMinimized) switch
                {
                    (DefaultableBooleanLike.Default, DefaultableBooleanLike.Default) => ApplicationState.Foreground,
                    (DefaultableBooleanLike.Default, DefaultableBooleanLike.True) => ApplicationState.Minimized,
                    (DefaultableBooleanLike.Default, DefaultableBooleanLike.False) => ApplicationState.Background,
                    (DefaultableBooleanLike.True, DefaultableBooleanLike.Default) => ApplicationState.Foreground,
                    (DefaultableBooleanLike.True, DefaultableBooleanLike.True) => ApplicationState.Minimized,
                    (DefaultableBooleanLike.True, DefaultableBooleanLike.False) => ApplicationState.Foreground,
                    (DefaultableBooleanLike.False, DefaultableBooleanLike.Default) => ApplicationState.Background,
                    (DefaultableBooleanLike.False, DefaultableBooleanLike.True) => ApplicationState.Minimized,
                    (DefaultableBooleanLike.False, DefaultableBooleanLike.False) => ApplicationState.Background
                });
            })
Beispiel #21
0
 private void ShareWindow_OnLoaded(object sender, RoutedEventArgs e)
 {
     _shareViewModel = new ShareViewModel(_photo);
     Disposable.Add(_shareViewModel);
     DataContext = _shareViewModel;
 }
Beispiel #22
0
 public ImageFilter Resize(int size)
 {
     Disposable.Add(bitmap);
     bitmap = bitmap.ResizeToSize(256);
     return(this);
 }
Beispiel #23
0
 private void SettingWindow_OnLoaded(object sender, RoutedEventArgs e)
 {
     _settingViewModel = new SettingViewModel();
     Disposable.Add(_settingViewModel);
     DataContext = _settingViewModel;
 }