Exemple #1
0
            public static void SetOptions(OptionsInfo options, AmoebaInterfaceManager serviceManager, DialogService dialogService)
            {
                try
                {
                    bool uploadFlag = false;

                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        // AccountInfo
                        {
                            var info = SettingsManager.Instance.AccountSetting;

                            if (info.Agreement == null || info.DigitalSignature != options.Account.DigitalSignature)
                            {
                                info.Agreement = new Agreement(AgreementAlgorithm.EcDhP521_Sha256);

                                uploadFlag = true;
                            }
                            else if (info.Comment != options.Account.Comment ||
                                     !CollectionUtils.Equals(info.TrustSignatures, options.Account.TrustSignatures) ||
                                     !CollectionUtils.Equals(info.UntrustSignatures, options.Account.UntrustSignatures) ||
                                     !CollectionUtils.Equals(info.Tags, options.Account.Tags))
                            {
                                uploadFlag = true;
                            }

                            info.DigitalSignature = options.Account.DigitalSignature;
                            info.Comment          = options.Account.Comment;
                            info.TrustSignatures.Clear();
                            info.TrustSignatures.AddRange(options.Account.TrustSignatures);
                            info.UntrustSignatures.Clear();
                            info.UntrustSignatures.AddRange(options.Account.UntrustSignatures);
                            info.Tags.Clear();
                            info.Tags.AddRange(options.Account.Tags);
                        }

                        // UpdateInfo
                        {
                            var info       = SettingsManager.Instance.UpdateSetting;
                            info.IsEnabled = options.Update.IsEnabled;
                            info.Signature = options.Update.Signature;
                        }

                        // SubscribeSignatures
                        {
                            SettingsManager.Instance.SubscribeSignatures.Clear();
                            SettingsManager.Instance.SubscribeSignatures.UnionWith(options.View.SubscribeSignatures);
                        }
                    }));

                    if (uploadFlag)
                    {
                        var info = SettingsManager.Instance.AccountSetting;

                        ProgressCircleService.Instance.Increment();

                        var task = serviceManager.SetProfile(
                            new ProfileContent(info.Comment,
                                               null,
                                               info.TrustSignatures,
                                               info.UntrustSignatures,
                                               info.Tags,
                                               info.Agreement.GetAgreementPublicKey()),
                            info.DigitalSignature,
                            CancellationToken.None);

                        task.ContinueWith((_) =>
                        {
                            ProgressCircleService.Instance.Decrement();
                        });
                    }

                    // AmoebaInterfaceManager
                    {
                        ServiceConfig serviceConfig;
                        {
                            ConnectionConfig connectionConfig;
                            {
                                TcpConnectionConfig tcpConnectionConfig;
                                {
                                    var type = TcpConnectionType.None;
                                    if (options.Connection.Tcp.Ipv4IsEnabled)
                                    {
                                        type |= TcpConnectionType.Ipv4;
                                    }
                                    if (options.Connection.Tcp.Ipv6IsEnabled)
                                    {
                                        type |= TcpConnectionType.Ipv6;
                                    }

                                    tcpConnectionConfig = new TcpConnectionConfig(
                                        type,
                                        options.Connection.Tcp.Ipv4Port,
                                        options.Connection.Tcp.Ipv6Port,
                                        options.Connection.Tcp.ProxyUri);
                                }

                                I2pConnectionConfig i2PConnectionConfig;
                                {
                                    i2PConnectionConfig = new I2pConnectionConfig(
                                        options.Connection.I2p.IsEnabled,
                                        options.Connection.I2p.SamBridgeUri);
                                }

                                CustomConnectionConfig customConnectionConfig;
                                {
                                    customConnectionConfig = new CustomConnectionConfig(
                                        options.Connection.Custom.LocationUris,
                                        options.Connection.Custom.ConnectionFilters,
                                        options.Connection.Custom.ListenUris);
                                }

                                CatharsisConfig catharsisConfig;
                                {
                                    var catharsisIpv4Config = new CatharsisIpv4Config(Array.Empty <string>(), Array.Empty <string>());

                                    catharsisConfig = new CatharsisConfig(catharsisIpv4Config);
                                }

                                connectionConfig = new ConnectionConfig(
                                    tcpConnectionConfig,
                                    i2PConnectionConfig,
                                    customConnectionConfig,
                                    catharsisConfig);
                            }

                            CoreConfig coreConfig;
                            {
                                NetworkConfig networkConfig;
                                {
                                    networkConfig = new NetworkConfig(
                                        options.Connection.Bandwidth.ConnectionCountLimit,
                                        options.Connection.Bandwidth.BandwidthLimit);
                                }

                                DownloadConfig downloadConfig;
                                {
                                    downloadConfig = new DownloadConfig(
                                        options.Data.Download.DirectoryPath,
                                        options.Data.Download.ProtectedPercentage);
                                }

                                coreConfig = new CoreConfig(networkConfig, downloadConfig);
                            }

                            MessageConfig messageConfig;
                            {
                                messageConfig = new MessageConfig(options.View.SubscribeSignatures);
                            }

                            serviceConfig = new ServiceConfig(coreConfig, connectionConfig, messageConfig);
                        }

                        serviceManager.SetConfig(serviceConfig);
                    }

                    // AmoebaInterfaceManager (Resize)
                    {
                        long orginalCacheSize = serviceManager.Size;

                        if (options.Data.Cache.Size < orginalCacheSize)
                        {
                            App.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                if (dialogService.ShowDialog(LanguagesManager.Instance.DataOptionsControl_CacheResize_Message,
                                                             MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.OK)
                                {
                                    Task.Run(() =>
                                    {
                                        ProgressCircleService.Instance.Increment();

                                        serviceManager.Resize(options.Data.Cache.Size);

                                        ProgressCircleService.Instance.Decrement();
                                    });
                                }
                            }));
                        }
                        else if (options.Data.Cache.Size > orginalCacheSize)
                        {
                            ProgressCircleService.Instance.Increment();

                            serviceManager.Resize(options.Data.Cache.Size);

                            ProgressCircleService.Instance.Decrement();
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }