public MessageManager(string configPath, AmoebaInterfaceManager serviceManager) { _amoebaInterfaceManager = serviceManager; _settings = new Settings(configPath); _watchTaskManager = new TaskManager(this.WatchThread); }
public WatchManager(AmoebaInterfaceManager serviceManager) { _serviceManager = serviceManager; this.Setting_ChechUpdate(); this.Setting_CheckDiskSpace(); this.Setting_Backup(); }
public ChatMessageEditWindowViewModel(Tag tag, string comment, AmoebaInterfaceManager serviceManager, MessageManager messageManager, CancellationToken token) { _tag = tag; _amoebaInterfaceManager = serviceManager; _messageManager = messageManager; _token = token; this.Init(comment); }
public WatchManager(AmoebaInterfaceManager serviceManager, DialogService dialogService) { _amoebaInterfaceManager = serviceManager; _dialogService = dialogService; this.Setting_ChechUpdate(); this.Setting_CheckDiskSpace(); this.Setting_Backup(); }
public CloudControlViewModel(AmoebaInterfaceManager serviceManager, DialogService dialogService) { _amoebaInterfaceManager = serviceManager; _dialogService = dialogService; this.Init(); _watchTaskManager = new TaskManager(this.WatchThread); _watchTaskManager.Start(); }
public StoreControlViewModel(AmoebaInterfaceManager serviceManager, DialogService dialogService) { _amoebaInterfaceManager = serviceManager; _dialogService = dialogService; this.Init(); _watchTaskManager = new TaskManager(this.WatchThread); _watchTaskManager.Start(); this.DragAcceptDescription = new DragAcceptDescription() { Effects = DragDropEffects.Move, Format = "Amoeba_Store" }; this.DragAcceptDescription.DragDrop += this.DragAcceptDescription_DragDrop; }
public void ConnectTest() { var bufferManager = new BufferManager(1024 * 1024 * 256, 1024 * 1024 * 256); var serviceManager = new ServiceManager("config", "cache.blocks", bufferManager); serviceManager.Load(); serviceManager.Start(); var server = new AmoebaDaemonManager(); var client = new AmoebaInterfaceManager(); var endpoint = new IPEndPoint(IPAddress.Loopback, 4040); var task = server.Watch(serviceManager, endpoint); client.Connect(endpoint); var s = client.State; client.Exit(); task.Wait(); }
public CheckBlocksWindowViewModel(AmoebaInterfaceManager serviceManager) { _amoebaInterfaceManager = serviceManager; this.Init(); }
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); } }
public static OptionsInfo GetOptions(AmoebaInterfaceManager serviceManager) { try { var options = new OptionsInfo(); App.Current.Dispatcher.Invoke(new Action(() => { // Account { var info = SettingsManager.Instance.AccountSetting; options.Account.DigitalSignature = info.DigitalSignature; options.Account.Comment = info.Comment; options.Account.TrustSignatures.AddRange(info.TrustSignatures); options.Account.UntrustSignatures.AddRange(info.UntrustSignatures); options.Account.Tags.AddRange(info.Tags); } // View { options.View.SubscribeSignatures.AddRange(SettingsManager.Instance.SubscribeSignatures); } // Update { var info = SettingsManager.Instance.UpdateSetting; options.Update.IsEnabled = info.IsEnabled; options.Update.Signature = info.Signature; } })); { var config = serviceManager.Config; var cacheSize = serviceManager.Size; // Connection { // Tcp { options.Connection.Tcp.ProxyUri = config.Connection.Tcp.ProxyUri; options.Connection.Tcp.Ipv4IsEnabled = config.Connection.Tcp.Type.HasFlag(TcpConnectionType.Ipv4); options.Connection.Tcp.Ipv4Port = config.Connection.Tcp.Ipv4Port; options.Connection.Tcp.Ipv6IsEnabled = config.Connection.Tcp.Type.HasFlag(TcpConnectionType.Ipv6); options.Connection.Tcp.Ipv6Port = config.Connection.Tcp.Ipv6Port; } // I2p { options.Connection.I2p.IsEnabled = config.Connection.I2p.IsEnabled; options.Connection.I2p.SamBridgeUri = config.Connection.I2p.SamBridgeUri; } // Custom { options.Connection.Custom.LocationUris.AddRange(config.Connection.Custom.LocationUris); options.Connection.Custom.ConnectionFilters.AddRange(config.Connection.Custom.ConnectionFilters); options.Connection.Custom.ListenUris.AddRange(config.Connection.Custom.ListenUris); } // Bandwidth { options.Connection.Bandwidth.ConnectionCountLimit = config.Core.Network.ConnectionCountLimit; options.Connection.Bandwidth.BandwidthLimit = config.Core.Network.BandwidthLimit; } } // Data { // Cache { options.Data.Cache.Size = cacheSize; } // Download { options.Data.Download.DirectoryPath = config.Core.Download.BasePath; options.Data.Download.ProtectedPercentage = config.Core.Download.ProtectedPercentage; } } } return(options); } catch (Exception e) { Log.Error(e); throw 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(); }