Esempio n. 1
0
        private void _listViewCopyInfoMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var selectItems = _listView.SelectedItems;

            if (selectItems == null)
            {
                return;
            }

            var sb = new StringBuilder();

            foreach (var seed in selectItems.Cast <DownloadListViewModel>().Select(n => n.Value))
            {
                if (seed == null)
                {
                    continue;
                }

                sb.AppendLine(AmoebaConverter.ToSeedString(seed));
                sb.AppendLine(MessageConverter.ToInfoMessage(seed));
                sb.AppendLine();
            }

            Clipboard.SetText(sb.ToString().TrimEnd('\r', '\n'));
        }
Esempio n. 2
0
 public static void SetSeeds(IEnumerable <Seed> seeds)
 {
     lock (_thisLock)
     {
         Clipboard.SetText(string.Join("\r\n", seeds.Select(n => AmoebaConverter.ToSeedString(n))));
     }
 }
Esempio n. 3
0
        public static IEnumerable <Tag> GetTags()
        {
            lock (_thisLock)
            {
                var list = new List <Tag>();

                foreach (var item in Clipboard.GetText().Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    try
                    {
                        var tag = AmoebaConverter.FromTagString(item);
                        if (tag == null)
                        {
                            continue;
                        }

                        list.Add(tag);
                    }
                    catch (Exception)
                    {
                    }
                }

                return(list);
            }
        }
Esempio n. 4
0
 public static void SetTags(IEnumerable <Tag> tags)
 {
     lock (_thisLock)
     {
         Clipboard.SetText(string.Join(Environment.NewLine, tags.Select(n => AmoebaConverter.ToTagString(n))));
     }
 }
Esempio n. 5
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var item = value as Seed;
            if (item == null) return null;

            return AmoebaConverter.ToSeedString(item);
        }
Esempio n. 6
0
 public static void SetNodes(IEnumerable <Node> nodes)
 {
     lock (_thisLock)
     {
         Clipboard.SetText(string.Join("\r\n", nodes.Select(n => AmoebaConverter.ToNodeString(n))));
     }
 }
        public void Test_AmoebaConverter_Box()
        {
            var box = new Box();

            box.Name         = "Box";
            box.Comment      = "Comment";
            box.CreationTime = DateTime.Now;
            box.Boxes.Add(new Box()
            {
                Name = "Box"
            });
            box.Seeds.Add(new Seed()
            {
                Name = "Seed"
            });

            DigitalSignature digitalSignature = new DigitalSignature("123", DigitalSignatureAlgorithm.EcDsaP521_Sha256);

            box.CreateCertificate(digitalSignature);

            Box box2;

            using (var streamBox = AmoebaConverter.ToBoxStream(box))
            {
                box2 = AmoebaConverter.FromBoxStream(streamBox);
            }

            Assert.AreEqual(box, box2, "AmoebaConverter #3");
        }
Esempio n. 8
0
        public static IEnumerable <Seed> GetSeeds()
        {
            lock (_thisLock)
            {
                var list = new List <Seed>();

                foreach (string item in Clipboard.GetText().Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (!item.StartsWith("Seed:"))
                    {
                        continue;
                    }

                    try
                    {
                        var seed = AmoebaConverter.FromSeedString(item);
                        if (seed == null)
                        {
                            continue;
                        }

                        list.Add(seed);
                    }
                    catch (Exception)
                    {
                    }
                }

                return(list);
            }
        }
        public void Test_AmoebaConverter_Seed()
        {
            var seed = new Seed();

            seed.Name = "aaaa.zip";
            seed.Keywords.AddRange(new KeywordCollection
            {
                "bbbb",
                "cccc",
                "dddd",
            });
            seed.CreationTime         = DateTime.Now;
            seed.Length               = 10000;
            seed.Comment              = "eeee";
            seed.Rank                 = 1;
            seed.Key                  = new Key(new byte[32], HashAlgorithm.Sha256);
            seed.CompressionAlgorithm = CompressionAlgorithm.Xz;
            seed.CryptoAlgorithm      = CryptoAlgorithm.Aes256;
            seed.CryptoKey            = new byte[32 + 32];

            DigitalSignature digitalSignature = new DigitalSignature("123", DigitalSignatureAlgorithm.Rsa2048_Sha256);

            seed.CreateCertificate(digitalSignature);

            var stringSeed = AmoebaConverter.ToSeedString(seed);
            var seed2      = AmoebaConverter.FromSeedString(stringSeed);

            Assert.AreEqual(seed, seed2, "AmoebaConverter #2");
        }
Esempio n. 10
0
        public static void SetBoxAndSeeds(IEnumerable <Box> boxes, IEnumerable <Seed> seeds)
        {
            lock (_thisLock)
            {
                var dataObject = new System.Windows.DataObject();
                dataObject.SetText(string.Join("\r\n", seeds.Select(n => AmoebaConverter.ToSeedString(n))));
                dataObject.SetData("Amoeba_Boxes", Clipboard.ToStream(boxes));

                System.Windows.Clipboard.SetDataObject(dataObject);
            }
        }
Esempio n. 11
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var item = value as Node;

            if (item == null)
            {
                return(null);
            }

            return(AmoebaConverter.ToNodeString(item));
        }
Esempio n. 12
0
        public static void SetChatTreeItems(IEnumerable <Windows.ChatTreeItem> items)
        {
            lock (_thisLock)
            {
                var dataObject = new System.Windows.DataObject();
                dataObject.SetText(string.Join("\r\n", items.Select(n => AmoebaConverter.ToTagString(n.Tag))));
                dataObject.SetData("Amoeba_ChatTreeItems", Clipboard.ToStream(items));

                System.Windows.Clipboard.SetDataObject(dataObject);
            }
        }
Esempio n. 13
0
        public static void SetSeeds(IEnumerable <Seed> seeds)
        {
            lock (_thisLock)
            {
                var sb = new StringBuilder();

                foreach (var seed in seeds)
                {
                    sb.AppendLine(AmoebaConverter.ToSeedString(seed));
                    sb.AppendLine(MessageUtils.ToInfoMessage(seed));
                    sb.AppendLine();
                }

                Clipboard.SetText(sb.ToString().TrimEnd('\r', '\n'));
            }
        }
Esempio n. 14
0
        public static void SetSeeds(IEnumerable <Seed> seeds)
        {
            lock (_thisLock)
            {
                {
                    var sb = new StringBuilder();

                    foreach (var item in seeds)
                    {
                        sb.AppendLine(AmoebaConverter.ToSeedString(item));
                    }

                    Clipboard.SetText(sb.ToString());
                }
            }
        }
Esempio n. 15
0
        public void Test_AmoebaConverter_Node()
        {
            Node node = null;

            {
                var id = new byte[32];
                _random.NextBytes(id);
                var uris = new string[] { "net.tcp://localhost:9000", "net.tcp://localhost:9001", "net.tcp://localhost:9002" };

                node = new Node(id, uris);
            }

            var stringNode = AmoebaConverter.ToNodeString(node);
            var node2      = AmoebaConverter.FromNodeString(stringNode);

            Assert.AreEqual(node, node2, "AmoebaConverter #1");
        }
Esempio n. 16
0
        public static void SetBoxAndSeeds(IEnumerable <Box> boxes, IEnumerable <Seed> seeds)
        {
            lock (_thisLock)
            {
                System.Windows.DataObject dataObject = new System.Windows.DataObject();

                {
                    var sb = new StringBuilder();

                    foreach (var item in seeds)
                    {
                        sb.AppendLine(AmoebaConverter.ToSeedString(item));
                    }

                    dataObject.SetText(sb.ToString());
                }

                dataObject.SetData("Amoeba_Boxes", Clipboard.ToStream(boxes));

                System.Windows.Clipboard.SetDataObject(dataObject);
            }
        }
Esempio n. 17
0
        private void _listViewCopyMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var selectItems = _listView.SelectedItems;

            if (selectItems == null)
            {
                return;
            }

            var sb = new StringBuilder();

            foreach (var seed in selectItems.Cast <UploadListViewItem>().Select(n => n.Value))
            {
                if (seed == null)
                {
                    continue;
                }

                sb.AppendLine(AmoebaConverter.ToSeedString(seed));
            }

            Clipboard.SetText(sb.ToString());
        }
Esempio n. 18
0
        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();
        }
Esempio n. 19
0
        public static void SetChatThreadInfos(IEnumerable <ChatThreadInfo> items)
        {
            lock (_thisLock)
            {
                var dataObject = new System.Windows.DataObject();
                dataObject.SetText(string.Join(Environment.NewLine, items.Select(n => AmoebaConverter.ToTagString(n.Tag))));
                dataObject.SetData("Amoeba_ChatThreadInfos", Clipboard.ToStream(items));

                System.Windows.Clipboard.SetDataObject(dataObject);
            }
        }
Esempio n. 20
0
        private void Init()
        {
            SettingsManager.Instance.Load();
            LanguagesManager.Instance.SetCurrentLanguage(SettingsManager.Instance.UseLanguage);

            {
                string configPath = Path.Combine(AmoebaEnvironment.Paths.ConfigPath, "Service");
                if (!Directory.Exists(configPath))
                {
                    Directory.CreateDirectory(configPath);
                }

                _serviceManager = new ServiceManager(configPath, AmoebaEnvironment.Config.Cache.BlocksPath, BufferManager.Instance);
                _serviceManager.Load();

                {
                    var locations = new List <Location>();

                    using (var reader = new StreamReader("Locations.txt"))
                    {
                        string line;

                        while ((line = reader.ReadLine()) != null)
                        {
                            locations.Add(AmoebaConverter.FromLocationString(line));
                        }
                    }

                    _serviceManager.SetCloudLocations(locations);
                }

                if (_serviceManager.Config.Core.Download.BasePath == null)
                {
                    lock (_serviceManager.LockObject)
                    {
                        var oldConfig = _serviceManager.Config;
                        _serviceManager.SetConfig(new ServiceConfig(new CoreConfig(oldConfig.Core.Network, new DownloadConfig(AmoebaEnvironment.Paths.DownloadsPath)), oldConfig.Connection, oldConfig.Message));
                    }
                }
            }

            {
                string configPath = Path.Combine(AmoebaEnvironment.Paths.ConfigPath, "Control", "Message");
                if (!Directory.Exists(configPath))
                {
                    Directory.CreateDirectory(configPath);
                }

                _messageManager = new MessageManager(configPath, _serviceManager);
                _messageManager.Load();
            }

            {
                this.Title = SettingsManager.Instance.AccountInfo.ObserveProperty(n => n.DigitalSignature)
                             .Select(n => $"Amoeba {AmoebaEnvironment.Version} - {n.ToString()}").ToReactiveProperty().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.ConfigPath, "View", "MainWindow");
                if (!Directory.Exists(configPath))
                {
                    Directory.CreateDirectory(configPath);
                }

                _settings = new Settings(configPath);
                int version = _settings.Load("Version", () => 0);

                this.WindowSettings.Value = _settings.Load(nameof(WindowSettings), () => new WindowSettings());
                this.DynamicOptions.SetProperties(_settings.Load(nameof(DynamicOptions), () => Array.Empty <DynamicOptions.DynamicPropertyInfo>()));
            }

            {
                this.CloudControlViewModel        = new CloudControlViewModel(_serviceManager, _dialogService);
                this.ChatControlViewModel         = new ChatControlViewModel(_serviceManager, _messageManager, _dialogService);
                this.StoreControlViewModel        = new StoreControlViewModel(_serviceManager, _dialogService);
                this.StorePublishControlViewModel = new UploadControlViewModel(_serviceManager, _dialogService);
                this.SearchControlViewModel       = new SearchControlViewModel(_serviceManager, _messageManager, _dialogService);
                this.DownloadControlViewModel     = new DownloadControlViewModel(_serviceManager, _dialogService);
                this.UploadControlViewModel       = new UploadControlViewModel(_serviceManager, _dialogService);
            }

            {
                _watchManager = new WatchManager(_serviceManager, _dialogService);
            }

            {
                Backup.Instance.SaveEvent += this.Save;
            }

            this.Setting_TrafficView();
        }
Esempio n. 21
0
            public override VisualLineElement ConstructElement(int offset)
            {
                var result = this.FindMatch(offset);

                if (result != null)
                {
                    if (result.Type == "State")
                    {
                        var size = (double)new FontSizeConverter().ConvertFromString(Settings.Instance.Global_Fonts_Message_FontSize + "pt");

                        var image = new Image()
                        {
                            Height = (size - 3), Width = (size - 3), Margin = new Thickness(1.5, 1.5, 0, 0)
                        };
                        if (result.Value == "#")
                        {
                            image.Source = StatesIconManager.Instance.Green;
                        }
                        else if (result.Value == "!")
                        {
                            image.Source = StatesIconManager.Instance.Red;
                        }
                        else if (result.Value == "@")
                        {
                            image.Source = StatesIconManager.Instance.Yello;
                        }

                        var element = new CustomObjectElement(result.Value, image);

                        element.ClickEvent += (string text) =>
                        {
                            this.OnSelectEvent(new CustomElementRange(offset, offset + result.Value.Length));
                        };

                        return(element);
                    }
                    else if (result.Type == "Signature")
                    {
                        Brush brush;

                        if (Inspect.ContainTrustSignature(result.Value))
                        {
                            brush = new SolidColorBrush(_serviceManager.Config.Colors.Message_Trust);
                        }
                        else
                        {
                            brush = new SolidColorBrush(_serviceManager.Config.Colors.Message_Untrust);
                        }

                        var element = new CustomTextElement(result.Value);
                        element.Foreground = brush;

                        element.ClickEvent += (string text) =>
                        {
                            this.OnSelectEvent(new CustomElementRange(offset, offset + result.Value.Length));
                        };

                        return(element);
                    }
                    else if (result.Type == "Uri")
                    {
                        var uri = result.Value;

                        CustomObjectElement element = null;

                        if (uri.StartsWith("http:") | uri.StartsWith("https:"))
                        {
                            var textBlock = new TextBlock();
                            textBlock.Text    = uri.Substring(0, Math.Min(64, uri.Length)) + ((uri.Length > 64) ? "..." : "");
                            textBlock.ToolTip = HttpUtility.UrlDecode(uri);

                            if (Settings.Instance.Global_UrlHistorys.Contains(uri))
                            {
                                textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link);
                            }
                            else
                            {
                                textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link_New);
                            }

                            element = new CustomObjectElement(uri, textBlock);
                        }
                        else if (uri.StartsWith("Tag:"))
                        {
                            var tag = AmoebaConverter.FromTagString(uri);

                            var textBlock = new TextBlock();
                            textBlock.Text    = uri.Substring(0, Math.Min(64, uri.Length)) + ((uri.Length > 64) ? "..." : "");
                            textBlock.ToolTip = MessageConverter.ToInfoMessage(tag);

                            if (Settings.Instance.Global_TagHistorys.Contains(tag))
                            {
                                textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link);
                            }
                            else
                            {
                                textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link_New);
                            }

                            element = new CustomObjectElement(uri, textBlock);
                        }
                        else if (uri.StartsWith("Seed:"))
                        {
                            var seed = AmoebaConverter.FromSeedString(uri);

                            var textBlock = new TextBlock();
                            textBlock.Text    = uri.Substring(0, Math.Min(64, uri.Length)) + ((uri.Length > 64) ? "..." : "");
                            textBlock.ToolTip = MessageConverter.ToInfoMessage(seed);

                            if (Settings.Instance.Global_SeedHistorys.Contains(seed))
                            {
                                textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link);
                            }
                            else
                            {
                                textBlock.Foreground = new SolidColorBrush(_serviceManager.Config.Colors.Link_New);
                            }

                            element = new CustomObjectElement(uri, textBlock);
                        }

                        if (element != null)
                        {
                            element.ClickEvent += (string text) =>
                            {
                                this.OnSelectEvent(new CustomElementRange(offset, offset + result.Value.Length));
                                this.OnClickEvent(text);
                            };

                            return(element);
                        }
                    }
                }

                return(null);
            }
Esempio n. 22
0
 public static void SetLocations(IEnumerable <Location> locations)
 {
     lock (_thisLock)
     {
         Clipboard.SetText(string.Join(Environment.NewLine, locations.Select(n => AmoebaConverter.ToLocationString(n))));
     }
 }
            public override VisualLineElement ConstructElement(int offset)
            {
                var result = this.FindMatch(offset);

                if (result != null)
                {
                    if (result.Type == "State")
                    {
                        double size = (double)new FontSizeConverter().ConvertFromString(SettingsManager.Instance.ViewInfo.Fonts.Chat_Message.FontSize + "pt");

                        var image = new Image()
                        {
                            Height = (size - 3), Width = (size - 3), Margin = new Thickness(1.5, 1.5, 0, 0)
                        };
                        if (result.Value == "!")
                        {
                            image.Source = AmoebaEnvironment.Images.YelloBall;
                        }
                        else if (result.Value == "#")
                        {
                            image.Source = AmoebaEnvironment.Images.GreenBall;
                        }

                        var element = new CustomObjectElement(result.Value, image);

                        element.ClickEvent += (string text) =>
                        {
                            this.OnSelectEvent(new CustomElementRange(offset, offset + result.Value.Length));
                        };

                        return(element);
                    }
                    else if (result.Type == "Signature")
                    {
                        Brush brush;

                        if (_trustSignatures.Contains(Signature.Parse(result.Value)))
                        {
                            brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(SettingsManager.Instance.ViewInfo.Colors.Message_Trust));
                        }
                        else
                        {
                            brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(SettingsManager.Instance.ViewInfo.Colors.Message_Untrust));
                        }

                        var element = new CustomTextElement(result.Value);
                        element.Foreground = brush;

                        element.ClickEvent += (string text) =>
                        {
                            this.OnSelectEvent(new CustomElementRange(offset, offset + result.Value.Length));
                        };

                        return(element);
                    }
                    else if (result.Type == "Uri")
                    {
                        string uri = result.Value;

                        CustomObjectElement element = null;

                        if (uri.StartsWith("http:") | uri.StartsWith("https:"))
                        {
                            var textBlock = new TextBlock();
                            textBlock.Text    = uri.Substring(0, Math.Min(64, uri.Length)) + ((uri.Length > 64) ? "..." : "");
                            textBlock.ToolTip = HttpUtility.UrlDecode(uri);

                            element = new CustomObjectElement(uri, textBlock);
                        }
                        else if (uri.StartsWith("Tag:"))
                        {
                            var tag = AmoebaConverter.FromTagString(uri);

                            var textBlock = new TextBlock();
                            textBlock.Text = uri.Substring(0, Math.Min(64, uri.Length)) + ((uri.Length > 64) ? "..." : "");

                            element = new CustomObjectElement(uri, textBlock);
                        }
                        else if (uri.StartsWith("Seed:"))
                        {
                            var seed = AmoebaConverter.FromSeedString(uri);

                            var textBlock = new TextBlock();
                            textBlock.Text = uri.Substring(0, Math.Min(64, uri.Length)) + ((uri.Length > 64) ? "..." : "");

                            element = new CustomObjectElement(uri, textBlock);
                        }

                        if (element != null)
                        {
                            element.ClickEvent += (string text) =>
                            {
                                this.OnSelectEvent(new CustomElementRange(offset, offset + result.Value.Length));
                                this.OnClickEvent(text);
                            };

                            return(element);
                        }
                    }
                }

                return(null);
            }
Esempio n. 24
0
        private void Watch()
        {
            try
            {
                for (;;)
                {
                    Thread.Sleep(1000 * 3);

                    if (!Directory.Exists(_serviceManager.Paths["Input"]))
                    {
                        continue;
                    }

                    foreach (var filePath in Directory.GetFiles(_serviceManager.Paths["Input"]))
                    {
                        if (!System.IO.Path.GetFileName(filePath).StartsWith("seed") || !filePath.EndsWith(".txt"))
                        {
                            continue;
                        }

                        try
                        {
                            using (FileStream stream = new FileStream(filePath, FileMode.Open))
                                using (StreamReader reader = new StreamReader(stream))
                                {
                                    try
                                    {
                                        var seed = AmoebaConverter.FromSeedString(reader.ReadLine());
                                        if (!seed.VerifyCertificate())
                                        {
                                            seed.CreateCertificate(null);
                                        }

                                        var path = reader.ReadLine();

                                        _amoebaManager.Download(seed, path, 3);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                        }
                        catch (IOException)
                        {
                            continue;
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            File.Delete(filePath);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }