private void SignatureNew() { var viewModel = new NameEditWindowViewModel("Anonymous", Signature.MaxNameLength); viewModel.Callback += (name) => { var digitalSignature = new DigitalSignature(name, DigitalSignatureAlgorithm.EcDsaP521_Sha256_v3); this.Options.DigitalSignature = digitalSignature; }; _dialogService.ShowDialog(viewModel); }
private void TabNewSearch() { if (this.TabSelectedItem.Value is SearchViewModel searchViewModel) { var viewModel = new SearchInfoEditWindowViewModel(new SearchInfo() { Name = "default" }); viewModel.Callback += (info) => { searchViewModel.Model.Children.Add(info); }; _dialogService.ShowDialog(viewModel); } }
private void TabNewCategory() { if (this.TabSelectedItem.Value is StoreCategoryViewModel categoryViewModel) { var viewModel = new NameEditWindowViewModel("", 256); viewModel.Callback += (name) => { categoryViewModel.Model.CategoryInfos.Add(new StoreCategoryInfo() { Name = name }); }; _dialogService.ShowDialog(viewModel); } this.Refresh(); }
private void TabNewCategory() { var viewModel = new NameEditWindowViewModel("", 256); viewModel.Callback += (name) => { var chatCategoryViewModel = this.TabSelectedItem.Value as ChatCategoryViewModel; if (chatCategoryViewModel == null) { return; } chatCategoryViewModel.Model.CategoryInfos.Add(new ChatCategoryInfo() { Name = name }); }; _dialogService.ShowDialog(viewModel); }
private void Setting_CheckDiskSpace() { bool watchFlag = true; _checkDiskSpaceTimer = new WatchTimer(() => { if (!watchFlag) { return; } try { var paths = new List <string>(); paths.Add(AmoebaEnvironment.Config.Cache.BlocksPath); bool flag = false; foreach (string path in paths) { var drive = new DriveInfo(Path.GetFullPath(path)); if (drive.AvailableFreeSpace < NetworkConverter.FromSizeString("256MB")) { flag |= true; break; } } if (_serviceManager.Report.Core.Cache.FreeSpace < NetworkConverter.FromSizeString("10GB")) { flag |= true; } if (!flag) { if (_serviceManager.State == ManagerState.Stop) { _serviceManager.Start(); Log.Information("Start"); } } else { if (_serviceManager.State == ManagerState.Start) { _serviceManager.Stop(); Log.Information("Stop"); watchFlag = false; App.Current.Dispatcher.InvokeAsync(() => { if (_dialogService.ShowDialog(LanguagesManager.Instance.MainWindow_SpaceNotFound_Message, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel) == MessageBoxResult.OK) { watchFlag = true; } }); } } } catch (Exception e) { Log.Error(e); } }); _checkDiskSpaceTimer.Start(new TimeSpan(0, 0, 0), new TimeSpan(0, 3, 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); } }
private void Init() { SettingsManager.Instance.Load(); LanguagesManager.Instance.SetCurrentLanguage(SettingsManager.Instance.UseLanguage); { string configPath = Path.Combine(AmoebaEnvironment.Paths.ConfigDirectoryPath, "Service"); if (!Directory.Exists(configPath)) { Directory.CreateDirectory(configPath); } _amoebaInterfaceManager = new AmoebaInterfaceManager(); { var info = UriUtils.Parse(AmoebaEnvironment.Config.Communication.TargetUri); var endpoint = new IPEndPoint(IPAddress.Parse(info.GetValue <string>("Address")), info.GetValue <int>("Port")); _amoebaInterfaceManager.Connect(endpoint, CancellationToken.None); _amoebaInterfaceManager.Load(); } if (_amoebaInterfaceManager.Config.Core.Download.BasePath == null) { lock (_amoebaInterfaceManager.LockObject) { var oldConfig = _amoebaInterfaceManager.Config; _amoebaInterfaceManager.SetConfig(new ServiceConfig(new CoreConfig(oldConfig.Core.Network, new DownloadConfig(AmoebaEnvironment.Paths.DownloadsDirectoryPath, oldConfig.Core.Download.ProtectedPercentage)), oldConfig.Connection, oldConfig.Message)); } } } { string configPath = Path.Combine(AmoebaEnvironment.Paths.ConfigDirectoryPath, "Control", "Message"); if (!Directory.Exists(configPath)) { Directory.CreateDirectory(configPath); } _messageManager = new MessageManager(configPath, _amoebaInterfaceManager); _messageManager.Load(); } { this.Title = SettingsManager.Instance.AccountSetting.ObserveProperty(n => n.DigitalSignature) .Select(n => $"Amoeba {AmoebaEnvironment.Version} - {n.ToString()}").ToReadOnlyReactiveProperty().AddTo(_disposable); this.RelationCommand = new ReactiveCommand().AddTo(_disposable); this.RelationCommand.Subscribe(() => this.Relation()).AddTo(_disposable); this.OptionsCommand = new ReactiveCommand().AddTo(_disposable); this.OptionsCommand.Subscribe(() => this.Options()).AddTo(_disposable); this.CheckBlocksCommand = new ReactiveCommand().AddTo(_disposable); this.CheckBlocksCommand.Subscribe(() => this.CheckBlocks()).AddTo(_disposable); this.LanguageCommand = new ReactiveCommand <string>().AddTo(_disposable); this.LanguageCommand.Subscribe((n) => LanguagesManager.Instance.SetCurrentLanguage(n)).AddTo(_disposable); this.WebsiteCommand = new ReactiveCommand().AddTo(_disposable); this.WebsiteCommand.Subscribe(() => this.Website()).AddTo(_disposable); this.VersionCommand = new ReactiveCommand().AddTo(_disposable); this.VersionCommand.Subscribe(() => this.Version()).AddTo(_disposable); this.IsProgressDialogOpen = new ReactiveProperty <bool>().AddTo(_disposable); this.ReceivingSpeed = new ReactiveProperty <decimal>().AddTo(_disposable); this.SendingSpeed = new ReactiveProperty <decimal>().AddTo(_disposable); this.WindowSettings = new ReactiveProperty <WindowSettings>().AddTo(_disposable); } { string configPath = Path.Combine(AmoebaEnvironment.Paths.ConfigDirectoryPath, "View", "MainWindow"); if (!Directory.Exists(configPath)) { Directory.CreateDirectory(configPath); } _settings = new Settings(configPath); int version = _settings.Load("Version", () => 0); bool isInitialized = _settings.Load("IsInitialized", () => false); this.WindowSettings.Value = _settings.Load(nameof(this.WindowSettings), () => new WindowSettings()); this.DynamicOptions.SetProperties(_settings.Load(nameof(this.DynamicOptions), () => Array.Empty <DynamicOptions.DynamicPropertyInfo>())); if (!isInitialized) { var cloudUri = @"https://alliance-network.cloud/amoeba/locations.php"; if (_dialogService.ShowDialog($"Are you sure you want to connect to \"{cloudUri}\"?", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes) { try { using (var httpClient = new HttpClient()) using (var response = httpClient.GetAsync(cloudUri).Result) using (var stream = response.Content.ReadAsStreamAsync().Result) { var list = new List <Location>(); foreach (var line in JsonUtils.Load <IEnumerable <string> >(stream)) { try { list.Add(AmoebaConverter.FromLocationString(line)); } catch (Exception) { } } _amoebaInterfaceManager.SetCloudLocations(list); } } catch (Exception) { } } } } { this.CloudControlViewModel = new CloudControlViewModel(_amoebaInterfaceManager, _dialogService); this.ChatControlViewModel = new ChatControlViewModel(_amoebaInterfaceManager, _messageManager, _dialogService); this.StoreControlViewModel = new StoreControlViewModel(_amoebaInterfaceManager, _dialogService); this.StorePublishControlViewModel = new UploadControlViewModel(_amoebaInterfaceManager, _dialogService); this.SearchControlViewModel = new SearchControlViewModel(_amoebaInterfaceManager, _messageManager, _dialogService); this.DownloadControlViewModel = new DownloadControlViewModel(_amoebaInterfaceManager, _dialogService); this.UploadControlViewModel = new UploadControlViewModel(_amoebaInterfaceManager, _dialogService); } { _watchManager = new WatchManager(_amoebaInterfaceManager, _dialogService); } { EventHooks.Instance.SaveEvent += this.Save; } this.Setting_TrafficView(); }
private void Relation() { _dialogService.ShowDialog(new RelationWindowViewModel(_messageManager)); }