Example #1
0
        public TataruModel()
        {
            CmdArgsStatus.LoadArgs();

            _PropertyBinders = new List <PropertyBinder>();
            _ChatWindows     = new List <ChatWindow>();

            _HotKeyManager = new HotKeyManager(UiWindow.Window);

            _SaveSettingsCancellationTokenSource = new CancellationTokenSource();

            _WebTranslator = new WebTranslator(new LoggerWrapper());

            _TataruUIModel = new TataruUIModel();

            _FFMemoryReader = new FFMemoryReader();

            _ChatProcessor = new ChatProcessor(_WebTranslator);

            _TataruViewModel = new TataruViewModel(this);
        }
Example #2
0
        private async Task AsyncOnSettingsWindowsListChanged(AsyncListChangedEventHandler <ChatWindowViewModelSettings> ea)
        {
            switch (ea.ChangedEventArgs.ListChangedType)
            {
            case ListChangedType.ItemAdded:
            {
                await UiWindow.Window.UIThreadAsync(() =>
                    {
                        ChatWindowViewModelSettings newElem = ea.ChangedElemnt;

                        ChatWindowViewModel reslut = null;

                        reslut = _TataruViewModel.ChatWindows.FirstOrDefault(x => x.WinId == newElem.WinId);


                        if (reslut == null)
                        {
                            try
                            {
                                TataruViewModel.AddNewChatWindow(newElem);
                            }
                            catch (Exception e)
                            {
                                Logger.WriteLog(e);
                            }

                            var binder = new PropertyBinder(newElem, _TataruViewModel.ChatWindows[_TataruViewModel.ChatWindows.Count - 1]);
                            CreateBinderCouples(binder);
                            _PropertyBinders.Add(binder);
                        }
                    });
            }
            break;

            case ListChangedType.ItemDeleted:
            {
                await Task.Run(() =>
                    {
                        SpinWait.SpinUntil(() => !deletingObject);
                        lock (lockObj)
                        {
                            deletingObject = true;
                        }
                    });

                await UiWindow.Window.UIThreadAsync(() =>
                    {
                        try
                        {
                            ChatWindowViewModelSettings deletedElem = ea.ChangedElemnt;

                            var elementToDelete = _TataruViewModel.ChatWindows.FirstOrDefault(x => x.WinId == deletedElem.WinId);

                            if (elementToDelete != null)
                            {
                                _TataruViewModel.DeleteChatWindow(_TataruViewModel.ChatWindows.IndexOf(elementToDelete));

                                RemoveChatWindow(_ChatWindows, elementToDelete.WinId);

                                var binder = _PropertyBinders.FirstOrDefault(x => x.Object1 == elementToDelete && x.Object2 == deletedElem);
                                if (binder == null)
                                {
                                    binder = _PropertyBinders.FirstOrDefault(x => x.Object2 == elementToDelete && x.Object1 == deletedElem);
                                }

                                if (binder != null)
                                {
                                    binder.Stop();

                                    _PropertyBinders.Remove(binder);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.WriteLog(e);
                        }
                    });

                deletingObject = false;
            }
            break;
            }
        }