Beispiel #1
0
        public async Task startStream()
        {
            await t.singleUserStream(delegate(){
                CurrentDispatcher.BeginInvoke((Action)(() =>
                {
                    showAlert("Connected to userstream");
                }));
            },
                                     delegate(string json){
                CurrentDispatcher.BeginInvoke((Action)(() => {
                    json = System.Net.WebUtility.HtmlDecode(json);
                    Extension.TweetType type = Extension.checkTweetType(json);
                    if (type != Extension.TweetType.Init)
                    {
                        switch (type)
                        {
                        case Extension.TweetType.Normal:
                            Tweet tweet = Json.Deserialize <Tweet>(json);
                            ((TimelineView)viewDict["timeline"]).InsertTweet(tweet);

                            if (tweet.Entities.Mentions.Count != 0)
                            {
                                bool _Mentioned = false;
                                foreach (Mention m in tweet.Entities.Mentions)
                                {
                                    if (m.Id == me.Id)
                                    {
                                        _Mentioned = true;
                                    }
                                }
                                if (tweet.Text.ToLower().Contains("@" + me.ScreenName.ToLower()))
                                {
                                    _Mentioned = true;
                                }
                                if (_Mentioned)
                                {
                                    ((ConnectView)viewDict["connect"]).InsertTweet(tweet);
                                }
                            }

                            break;

                        case Extension.TweetType.Message:
                            Message message = Json.Deserialize <MessageWrapper>(json).Message;
                            break;

                        case Extension.TweetType.Delete:
                            DeletedStatus status = Json.Deserialize <DeleteWrapper>(json).Delete.Status;
                            ((TimelineView)viewDict["timeline"]).RemoveTweet(status.Id);
                            break;
                        }
                    }
                }));
            }, delegate(){
                CurrentDispatcher.BeginInvoke((Action)(() =>
                {
                    showAlert("Unable to connect to userstream", AlertBox.MessageType.Error);
                }));
            });
        }
Beispiel #2
0
        private static IFrameDestination ShowVirtualDmd(BaseOptions options)
        {
            if (options.VirtualDmdPosition.Length != 3)
            {
                throw new InvalidOptionException("Argument --virtual-position must have three values: \"<Left> <Top> <Width>\".");
            }
            var dmd = new VirtualDmd {
                AlwaysOnTop = options.VirtualDmdOnTop,
                GripColor   = options.VirtualDmdHideGrip ? Brushes.Transparent : Brushes.White,
                Left        = options.VirtualDmdPosition[0],
                Top         = options.VirtualDmdPosition[1],
                Width       = options.VirtualDmdPosition[2],
                Height      = (int)((double)options.VirtualDmdPosition[2] / 4),
            };
            var thread = new Thread(() => {
                // Create our context, and install it:
                SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(CurrentDispatcher));

                // When the window closes, shut down the dispatcher
                dmd.Closed += (s, e) => CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
                dmd.Dispatcher.Invoke(() => {
                    dmd.Show();
                });

                // Start the Dispatcher Processing
                Run();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            return(dmd.Dmd);
        }
Beispiel #3
0
        public override IMessage Invoke(IMessage msg)
        {
            try
            {
                IMethodMessage     mm         = msg as IMethodMessage;
                IMethodCallMessage methodCall = (IMethodCallMessage)msg;
                if (mm.MethodName == "GetType")
                {
                    return(new ReturnMessage(
                               typeof(INotifyCollection <T>),
                               null, 0, mm.LogicalCallContext,
                               (IMethodCallMessage)msg));
                }

                MethodInfo method = (MethodInfo)mm.MethodBase;
                object[]   args   = mm.Args;

                object ret = CurrentDispatcher.Invoke(() =>
                {
                    return(method.Invoke(Collection, methodCall.InArgs));
                });

                return(new ReturnMessage(
                           ret, null, 0, mm.LogicalCallContext, (IMethodCallMessage)msg));
            }
            catch (Exception e)
            {
                throw;
            }
        }
Beispiel #4
0
        private bool SetWaitMouseCursor()
        {
            if (IsBusy)
            {
                return(false);
            }

            lock (_synlock)
            {
                if (IsBusy)
                {
                    return(false);
                }

                IsBusy = true;
                if (_previous == null)
                {
                    CurrentDispatcher.Invoke(() =>
                    {
                        _previous            = Mouse.OverrideCursor;
                        Mouse.OverrideCursor = Cursors.Wait;
                    });

                    return(true);
                }
                return(false);
            }
        }
Beispiel #5
0
        /// <summary> Обработчик изменения подписки контактов внутри логики C++ </summary>
        private void ChangedListModelContactSubscription(List <PackageModelContactSubscription> listPackageModelContactSubscriptions)
        {
            if (ListModelConctactChatMembers == null)
            {
                return;
            }

            //var dictionary = _dataSourceContact.GetDictionaryModelContactSubscriptionByArrayXmppId(arrayXmppId);

            foreach (var i in listPackageModelContactSubscriptions)
            {
                var modelContact = ListModelConctactChatMembers.FirstOrDefault(obj => obj.XmppId == i.XmppId);

                if (modelContact != null)
                {
                    Action action = () => { modelContact.ModelContactSubscriptionObj = i.ModelContactSubscriptionObj.GetDeepCopy(); };

                    CurrentDispatcher.BeginInvoke(action);

                    //modelContact.ModelContactSubscriptionObj = i.Value;
                }
            }

            DataSourceContact.RefreshModelContactStatus(ListModelConctactChatMembers.Where(obj => listPackageModelContactSubscriptions.Any(o => o.XmppId == obj.XmppId)).ToList());
        }
Beispiel #6
0
        /// <summary> Обработчик изменения сообщений чата </summary>
        private void OnListModelChatMessageChanged(object sender, List <ModelChatMessage> listModelChatMessages)
        {
            var listSingleModelChatMessages = new List <ModelChatMessage>();

            listSingleModelChatMessages = listModelChatMessages.Where(obj => !listSingleModelChatMessages.Any(message => message.Id == obj.Id)).ToList();

            var listExistMessage = listSingleModelChatMessages.Where(obj => obj.IdChat == CurrentModelChat.Id && ListModelChatMessage.Any(message => message.Id == obj.Id)).ToList();

            if (listExistMessage.Count > 0)
            {
                Action action = () => RefreshExistingModelChatMessage(listExistMessage);

                CurrentDispatcher.BeginInvoke(action);
            }

            var listNewMessage = listSingleModelChatMessages.Where(obj => obj.IdChat == CurrentModelChat.Id && !ListModelChatMessage.Any(message => message.Id == obj.Id)).ToList();

            if (listNewMessage.Count > 0)
            {
                Action action = () => AddNewModelChatMessage(listNewMessage);

                CurrentDispatcher.BeginInvoke(action);
            }

            OnPropertyChanged("ListModelChatMessage");
        }
Beispiel #7
0
 public void InvokeAutomaticRefresh()
 {
     if (AutomaticRefreshOn && IsIdle && AutomaticRefreshSubscriber != null)
     {
         CurrentDispatcher.Invoke(() => AutomaticRefreshSubscriber.OnAutomaticRefreshTriggered());
         Countdown.ResetCountdown();
     }
 }
Beispiel #8
0
        public void BeginExecute(DispatcherPriority priority, Action action)
        {
            if (CurrentDispatcher == null || action == null)
            {
                return;
            }

            CurrentDispatcher.BeginInvoke(action, priority);
        }
Beispiel #9
0
        public void BeginExecute(Action action)
        {
            if (CurrentDispatcher == null || action == null)
            {
                return;
            }

            CurrentDispatcher.BeginInvoke(action);
        }
Beispiel #10
0
        public void Execute(Action action)
        {
            if (action == null)
            {
                return;
            }

            CurrentDispatcher.Invoke(action);
        }
Beispiel #11
0
        /// <summary> Обработчик генерации секретного ключа </summary>
        private void OnSecretKeyMissing(object sender, EventArgs eventArgs)
        {
            Action action = () =>
            {
                OnEventViewModel("SecretKeyMissing");
            };

            CurrentDispatcher.BeginInvoke(action);
        }
        /// <summary> Обработчик изменения состояний подписки контактов </summary>
        private void OnListModelContactSubscriptionChanged(object sender, List <PackageModelContactSubscription> packageModelContactSubscriptions)
        {
            CurrentListModelContact = DataSourceContact.GetListModelContact().Where(obj => obj.IsDodicall && obj.Blocked == false && obj.IsAccessStatus).ToList();

            ListModelContactSort();

            Action action = () => OnEventViewModel("ChangedList");

            CurrentDispatcher.BeginInvoke(action);
        }
        /// <summary> Обработчик изменения списка контактов </summary>
        private void OnListModelContactChanged(List <ModelContact> listChangedModelContact, List <ModelContact> listDeletedModelContact)
        {
            foreach (var modelContact in listChangedModelContact.Where(obj => obj.Id > 0))
            {
                var changedModelContact = ListModelContact.FirstOrDefault(obj => obj.Id == modelContact.Id);

                if (changedModelContact != null)
                {
                    Action action = () =>
                    {
                        var modelContactCopy = modelContact.GetDeepCopy();

                        changedModelContact.Avatar     = modelContactCopy.Avatar;
                        changedModelContact.Blocked    = modelContactCopy.Blocked;
                        changedModelContact.DodicallId = modelContactCopy.DodicallId;
                        changedModelContact.NativeId   = modelContactCopy.NativeId;
                        changedModelContact.White      = modelContactCopy.White;
                        changedModelContact.XmppId     = modelContactCopy.XmppId;
                        changedModelContact.FirstName  = modelContactCopy.FirstName;
                        changedModelContact.MiddleName = modelContactCopy.MiddleName;
                        changedModelContact.LastName   = modelContactCopy.LastName;
                        changedModelContact.ModelEnumUserBaseStatusObj  = modelContactCopy.ModelEnumUserBaseStatusObj;
                        changedModelContact.UserExtendedStatus          = modelContactCopy.UserExtendedStatus;
                        changedModelContact.ModelContactSubscriptionObj = modelContactCopy.ModelContactSubscriptionObj;
                        changedModelContact.ListModelUserContact        = modelContactCopy.ListModelUserContact;
                        changedModelContact.ListModelUserContactExtra   = modelContactCopy.ListModelUserContactExtra;
                    };

                    CurrentDispatcher.BeginInvoke(action);
                }
                else
                {
                    Action action = () =>
                    {
                        var modelContactCopy = modelContact.GetDeepCopy();

                        ListModelContact.Add(modelContactCopy);
                    };

                    CurrentDispatcher.BeginInvoke(action);
                }
            }

            foreach (var modelContact in listDeletedModelContact)
            {
                var deletedModelContact = ListModelContact.FirstOrDefault(obj => obj.Id == modelContact.Id);

                Action action = () => { ListModelContact.Remove(deletedModelContact); };

                CurrentDispatcher.BeginInvoke(action);
            }

            CurrentDispatcher.BeginInvoke(new Action(ApplyFilter));
        }
        /// <summary> Обработчик изменения контактов </summary>
        private void InstanceOnListModelContactChanged(List <ModelContact> listChangedModelContact, List <ModelContact> listDeletedModelContact)
        {
            var modelCallHistoryDetail = DataSourceCall.GetChangedModelCallHistoryDetail(_modelCallHistoryPeerObj);

            Action action = () =>
            {
                ModelCallHistoryPeerObj.ListModelCallHistoryEntry = modelCallHistoryDetail.ListModelCallHistoryPeer.First().GetDeepCopy().ListModelCallHistoryEntry;
            };

            CurrentDispatcher.BeginInvoke(action);
        }
 public void InvokeOnUIThread(Action action)
 {
     if (CurrentDispatcher.CheckAccess())
     {
         action();
     }
     else
     {
         CurrentDispatcher.Invoke(action);
     }
 }
        public Task InvokeOnUIThreadAsync(Action action)
        {
            if (CurrentDispatcher.CheckAccess())
            {
                action();

                return(Task.CompletedTask);
            }
            else
            {
                return(CurrentDispatcher.InvokeAsync(action).Task);
            }
        }
Beispiel #17
0
        private static IDestination ShowVirtualDmd(BaseOptions options)
        {
            if (options.VirtualDmdPosition.Length != 3 && options.VirtualDmdPosition.Length != 4)
            {
                throw new InvalidOptionException("Argument --virtual-position must have three or four values: \"<Left> <Top> <Width> [<Height>]\".");
            }
            if (options.VirtualDmdDotSize <= 0 || options.VirtualDmdDotSize > 2)
            {
                throw new InvalidOptionException("Argument --virtual-dotsize must be larger than 0 and smaller than 10.");
            }
            int height; bool ignoreAr;

            if (options.VirtualDmdPosition.Length == 4)
            {
                height   = options.VirtualDmdPosition[3];
                ignoreAr = true;
            }
            else
            {
                height   = (int)((double)options.VirtualDmdPosition[2] / 4);
                ignoreAr = false;
            }
            var dmd = new VirtualDmd {
                AlwaysOnTop       = options.VirtualDmdOnTop,
                GripColor         = options.VirtualDmdHideGrip ? Brushes.Transparent : Brushes.White,
                Left              = options.VirtualDmdPosition[0],
                Top               = options.VirtualDmdPosition[1],
                Width             = options.VirtualDmdPosition[2],
                Height            = height,
                IgnoreAspectRatio = ignoreAr,
                DotSize           = options.VirtualDmdDotSize
            };
            var thread = new Thread(() => {
                // Create our context, and install it:
                SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(CurrentDispatcher));

                // When the window closes, shut down the dispatcher
                dmd.Closed += (s, e) => CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
                dmd.Dispatcher.Invoke(() => {
                    dmd.Dmd.Init();
                    dmd.Show();
                });

                // Start the Dispatcher Processing
                Run();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            return(dmd.Dmd);
        }
        /// <summary> Обработчик изменения истории вызовов </summary>
        private void OnModelCallHistoryChanged(object sender, ModelCallHistory modelCallHistory)
        {
            if (modelCallHistory.ListModelCallHistoryPeer.Any(obj => obj.ModelPeerObj.Id == _modelCallHistoryPeerObj.ModelPeerObj.Id))
            {
                var modelCallHistoryDetail = DataSourceCall.GetChangedModelCallHistoryDetail(_modelCallHistoryPeerObj);

                Action action = () =>
                {
                    ModelCallHistoryPeerObj.ListModelCallHistoryEntry = modelCallHistoryDetail.ListModelCallHistoryPeer.First().GetDeepCopy().ListModelCallHistoryEntry;
                };

                CurrentDispatcher.BeginInvoke(action);
            }
        }
        /// <summary> Обработчик изменения звонка </summary>
        private void OnModelCallChanged(object sender, ModelCall modelCall)
        {
            Action action = () =>
            {
                CurrentModelCall = modelCall?.GetDeepCopy();

                if (CurrentModelCall == null || CurrentModelCall.ModelEnumCallStateObj.Code == 6) // Ended (почему то иногда прилетает null, видимо в разных потоках уже закрытый звонок удаляется из списка активных в бизнес логике быстрее чем прилетает данный колбек в этом потоке)
                {
                    OnCloseView();
                }
            };

            CurrentDispatcher.BeginInvoke(action);
        }
Beispiel #20
0
        void Update()
        {
            if (CurrentDispatcher != null)
            {
                CurrentDispatcher.ProcessTasks();
            }

            var finishedThreads = registeredThreads.Where(thread => !thread.IsAlive).ToArray();

            foreach (var finishedThread in finishedThreads)
            {
                finishedThread.Dispose();
                registeredThreads.Remove(finishedThread);
            }
        }
        /// <summary> Обработчик изменения статусов контактов </summary>
        private void OnListModelContactStatusChanged(object sender, List <PackageModelContactStatus> listPackageModelContactStatuses)
        {
            if (_modelContactObj != null && listPackageModelContactStatuses.Any(obj => obj.XmppId == _modelContactObj.XmppId))
            {
                var packageModelContactStatus = listPackageModelContactStatuses.First(obj => obj.XmppId == _modelContactObj.XmppId);

                Action action = () =>
                {
                    ModelContactObj.ModelEnumUserBaseStatusObj = packageModelContactStatus.ModelEnumUserBaseStatusObj;

                    ModelContactObj.UserExtendedStatus = packageModelContactStatus.UserExtendedStatus;
                };

                CurrentDispatcher.BeginInvoke(action);
            }
        }
        public void AddMidiOutMessage(string message)
        {
            if (CurrentDispatcher == null)
            {
                return;
            }

            CurrentDispatcher.InvokeAsync(() =>
            {
                midiOutMessages.Add(message);
                while (midiOutMessages.Count > 1000)
                {
                    midiOutMessages.RemoveAt(0);
                }
            });
        }
Beispiel #23
0
        protected virtual void Update()
        {
            if (CurrentDispatcher != null)
            {
                CurrentDispatcher.ProcessTasks();
            }

            foreach (var thread in _registeredThreads.ToArray())
            {
                if (thread.IsAlive)
                {
                    continue;
                }
                thread.Dispose();
                _registeredThreads.Remove(thread);
            }
        }
        /// <summary> Обработчик изменения статусов контактов </summary>
        private void OnListModelContactStatusChanged(object sender, List <PackageModelContactStatus> listPackageModelContactStatuses)
        {
            foreach (var i in listPackageModelContactStatuses)
            {
                var modelContact = ListModelContact.FirstOrDefault(obj => obj.XmppId == i.XmppId);

                if (modelContact != null)
                {
                    Action action = () =>
                    {
                        modelContact.ModelEnumUserBaseStatusObj = i.ModelEnumUserBaseStatusObj;
                        modelContact.UserExtendedStatus         = i.UserExtendedStatus;
                    };

                    CurrentDispatcher.BeginInvoke(action);
                }
            }
        }
Beispiel #25
0
        void OnDestroy()
        {
            foreach (var thread in registeredThreads)
            {
                thread.Dispose();
            }

            if (CurrentDispatcher != null)
            {
                CurrentDispatcher.Dispose();
            }
            CurrentDispatcher = null;

            if (CurrentTaskDistributor != null)
            {
                CurrentTaskDistributor.Dispose();
            }
            CurrentTaskDistributor = null;
        }
Beispiel #26
0
        /// <summary> Обработчик изменения состояния подписок контактов </summary>
        private void OnListModelContactSubscriptionChanged(object sender, List <PackageModelContactSubscription> listPackageModelContactSubscriptions)
        {
            if (CurrentModelCallHistory == null)
            {
                return;
            }

            foreach (var i in listPackageModelContactSubscriptions)
            {
                var modelCallHistoryPeer = CurrentModelCallHistory.ListModelCallHistoryPeer.FirstOrDefault(obj => obj.ModelPeerObj.ModelContactObj != null ? obj.ModelPeerObj.ModelContactObj.XmppId == i.XmppId : false);

                if (modelCallHistoryPeer != null && modelCallHistoryPeer.ModelPeerObj.ModelContactObj.XmppId == i.XmppId)
                {
                    Action action = () => { modelCallHistoryPeer.ModelPeerObj.ModelContactObj.ModelContactSubscriptionObj = i.ModelContactSubscriptionObj.GetDeepCopy(); };

                    CurrentDispatcher.BeginInvoke(action);
                }
            }
        }
        /// <summary> Применить фильтр к контактам </summary>
        private void ApplyFilter()
        {
            if (!String.IsNullOrWhiteSpace(ContactListFilter))
            {
                var filter = ContactListFilter.Trim().ToLower();

                CurrentListModelContact = ListModelContact.Where(obj => obj.FullName.ToLower().Contains(filter)).ToList();
            }
            else
            {
                CurrentListModelContact = ListModelContact;
            }

            ListModelContactSort();

            Action action = () => OnEventViewModel("ChangedList");

            CurrentDispatcher.BeginInvoke(action);
        }
Beispiel #28
0
        private void SetDefaultMouseCursor()
        {
            if (!IsBusy)
            {
                return;
            }

            lock (_synlock)
            {
                if (!IsBusy)
                {
                    return;
                }

                IsBusy = false;
                CurrentDispatcher.Invoke(() => Mouse.OverrideCursor = _previous);
                _previous = null;
            }
        }
Beispiel #29
0
        ///// <summary> Обработчик изменения модели внутри логики C++ </summary>
        //public void DoCallback(object sender, DoCallbackArgs e)
        //{
        //if (e.ModelName == "Chats")
        //{
        //    Action action = () => ChangedListModelChat(e.EntityIds);

        //    CurrentDispatcher.BeginInvoke(action);
        //}

        //if (e.ModelName == "ChatMessages")
        //{
        //    Action action = () => ChangedListModelChatMessages(e.EntityIds);

        //    CurrentDispatcher.BeginInvoke(action);
        //}

        //if (e.ModelName == "ContactsPresence")
        //{
        //    CurrentDispatcher.BeginInvoke(new Action(ChangedStatusListModelContact));
        //}
        //}

        ///// <summary> Обработчик изменения списка чатов внутри логики C++ </summary>
        //private void ChangedListModelChatMessages(string[] entityIds)
        //{
        //    // вот этот код перенести в колбеки в обработку колбека "ChatMessages"

        //    var listChatIds = _dataSourceChat.GetListModelChatByIdMessage(entityIds);

        //    ChangedListModelChat(listChatIds, new List<ModelChat>());
        //}

        /// <summary> Обработчик изменения списка чатов внутри логики C++ </summary>
        private void ChangedListModelChat(List <ModelChat> listChangedModelChat, List <ModelChat> listDeletedModelChat)
        {
            var listModelChatCurrent = CurrentListModelChat.ToList();

            // удаление
            foreach (var i in listDeletedModelChat)
            {
                listModelChatCurrent.Remove(listModelChatCurrent.FirstOrDefault(obj => obj.Id == i.Id));
            }

            Action action = () =>
            {
                // добавление и обновление
                foreach (var i in listChangedModelChat)
                {
                    var modelChat = listModelChatCurrent.FirstOrDefault(obj => obj.Id == i.Id);

                    if (modelChat != null)
                    {
                        // изменение (пошел через переприсвоение свойств, а не через удалить и добавить заново, что бы не слетало выделение)
                        modelChat.ListModelContact = ListModelContactSort(i.ListModelContact);

                        modelChat.Active             = i.Active;
                        modelChat.LastMessage        = i.LastMessage;
                        modelChat.LastModifiedDate   = i.LastModifiedDate;
                        modelChat.NewMessagesCount   = i.NewMessagesCount;
                        modelChat.Title              = i.Title;// LocalizationApp.GetInstance().GetValueByKey(@"ModelChatMessage_Untitled");
                        modelChat.TotalMessagesCount = i.TotalMessagesCount;
                    }
                    else
                    {
                        listModelChatCurrent.Add(i);
                    }
                }

                CurrentListModelChat = new ObservableCollection <ModelChat>(SortCurrentListModelChat(listModelChatCurrent));

                DataSourceChat.RefreshModelContactChatStatus(CurrentListModelChat.ToList());
            };

            CurrentDispatcher.BeginInvoke(action);
        }
Beispiel #30
0
        /// <summary>
        /// Tuät ä nii Inschantz vom virtueuä DMD kreiärä und tuät drnah d
        /// Render-Graphä drabindä.
        /// </summary>
        private void CreateVirtualDmd()
        {
            var thread = new Thread(() => {
                _dmd = new VirtualDmd();
                SetupGraphs();

                // Create our context, and install it:
                SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(CurrentDispatcher));

                // When the window closes, shut down the dispatcher
                _dmd.Closed += (s, e) => CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
                _dmd.Dispatcher.Invoke(SetupVirtualDmd);

                // Start the Dispatcher Processing
                Run();
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }