コード例 #1
0
        /// <remarks>
        /// This method is thread safe.
        /// </remarks>
        public void ReleaseSync(IChatView chatView)
        {
            Trace.Call(chatView);

            if (chatView == null)
            {
                throw new ArgumentNullException("chatView");
            }

            var chatKey = GetChatKey(chatView.ChatModel);

#if LOG4NET
            Logger.Debug("ReleaseSync() <" + chatKey + "> releasing " +
                         "<" + chatView.ID + ">");
#endif
            lock (SyncReleaseQueue) {
                SyncReleaseQueue.Add(chatKey, chatView);
            }
            AutoResetEvent syncWait = null;
            lock (SyncWaitQueue) {
                SyncWaitQueue.TryGetValue(chatKey, out syncWait);
            }
            // release the sync worker
            syncWait.Set();
        }
コード例 #2
0
 void OnChatSynced(IChatView chatView)
 {
     if (ChatSynced != null)
     {
         ChatSynced(this, new ChatViewSyncedEventArgs(chatView));
     }
 }
コード例 #3
0
        public ChatPresenter(ChatView chatView, ChatDao dao)
        {
            Logger.debug("Initalizing Chat Presenter.", origin: "ChatMail.ChatPresenter");
            m_chatView = chatView;
            m_chatDao  = dao;

            Login();
            m_chatView.ShowUsername(m_currentUserDisplayname);
        }
コード例 #4
0
 public TabCycleNickCompleter()
 {
     PreviousNicks             = null;
     PreviousNickIndex         = -1;
     PreviousMatchPos          = -1;
     PreviousMatchLength       = -1;
     PreviousMatchCursorOffset = 0;
     PreviousChatView          = null;
 }
コード例 #5
0
        /// <summary>
        /// Sets the view.
        /// </summary>
        /// <returns>The view.</returns>
        /// <param name="view">View.</param>
        public void SetView(IChatView view)
        {
            _view = view;

            _signalRClient.OnDataReceived -= HandleSignalRDataReceived;
            _signalRClient.OnDataReceived += HandleSignalRDataReceived;

            ChatReceived -= HandleChatReceived;
            ChatReceived += HandleChatReceived;
        }
コード例 #6
0
        private void CreateAndSubscribeToChatWindow()
        {
            chatView = UICreator
                       .GetInstance()
                       .Create <ChatWindow>();

            if (chatView != null)
            {
                chatView.FocusChanged += OnFocusChanged;
                chatView.MessageAdded += OnMessageAdded;
            }
        }
コード例 #7
0
ファイル: ChatViewSyncManager.cs プロジェクト: shubhtr/smuxi
        void SyncWorker(ChatModel chatModel)
        {
            try {
                var            chatKey  = GetChatKey(chatModel);
                AutoResetEvent syncWait = null;
                lock (SyncWaitQueue) {
                    SyncWaitQueue.TryGetValue(chatKey, out syncWait);
                }
                if (syncWait != null)
                {
#if LOG4NET
                    Logger.Debug("SyncWorker() <" + chatKey + "> waiting for " +
                                 "sync lock release...");
#endif
                    // This chat was queued by QueueAdd() thus we need to wait
                    // till the ChatView is created and ready to be synced
                    syncWait.WaitOne();
#if LOG4NET
                    Logger.Debug("SyncWorker() <" + chatKey + "> " +
                                 "sync lock released");
#endif

                    // no longer need the sync lock
                    lock (SyncWaitQueue) {
                        SyncWaitQueue.Remove(chatKey);
                    }
                }

                IChatView chatView = null;
                lock (SyncReleaseQueue) {
                    if (!SyncReleaseQueue.TryGetValue(chatKey, out chatView))
                    {
#if LOG4NET
                        Logger.Warn("SyncWorker(): chatView is null! " +
                                    "probably a reconnect, bailing out...");
#endif
                        return;
                    }
                    // no longer need the release slot
                    // BUG: this breaks re-syncing an existing chat! For that
                    // reason the frontend _must_ notify us via Remove() if the
                    // chat sync state is no longer needed
                    //SyncReleaseQueue.Remove(chatKey);
                }

                Sync(chatView);
            } catch (Exception ex) {
#if LOG4NET
                Logger.Error("SyncWorker(): Exception!", ex);
#endif
                OnWorkerException(chatModel, ex);
            }
        }
コード例 #8
0
        public ChatViewModel(IChatView view, Model.ChatClient model)
        {
            Model             = model;
            _view             = view;
            _view.DataContext = this;
            SelectedUser      = null;
            Tabs                  = new ObservableCollection <ClosableTab>();
            SendCommand           = new RelayCommand(SendCommand_Execute, Send_CanExecute);
            OpenTabCommand        = new RelayCommand(OpenTabCommand_Execute);
            _view.CloseHandler   += _view_Closing;
            Model.PrivateMessage += PrivateMessageHandler;
            ResourceDictionary myResourceDictionary = new ResourceDictionary();

            myResourceDictionary.Source = new Uri("Styles.xaml", UriKind.Relative);
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
            AddLobbyTab();
        }
コード例 #9
0
        public MessagesViewModel(IServiceProvider provider, string contactGuid, IChatView messageThreadView)
        {
            this._contactId         = contactGuid;
            this.logger             = provider.Get <ILoggerFactory>().CreateLogger <MessagesViewModel>();
            this._repo              = provider.Get <AppRepository>();
            this._messagesLoader    = new MessagesLoader(this._repo, contactGuid);
            this._messageThreadView = messageThreadView;

            this._encryptionService  = provider.Get <IChatEncryptionService>();
            this._unreadManager      = provider.Get <UnreadManager>();
            this._contactListManager = provider.Get <ContactListManager>();

            this._chatClient = provider.Get <IChatClient>();
            this._chatWorker = provider.Get <ChatWorker>();
            this._chatWorker.SendMessageStateUpdated  += (sender, message) => this._messageThreadView.UpdateSendMessageStateFromBackgroundThread(message);
            this._chatWorker.IncomingMessageDecrypted += async(sender, message) => await AddIncomingDecryptedMessageFromChatworker(message);
        }
コード例 #10
0
        public void CommandGenerateMessages(CommandModel cmd, IChatView chat)
        {
            Trace.Call(cmd, chat);

            var count = 0;

            Int32.TryParse(cmd.Parameter, out count);

            var builder = new MessageBuilder();
            var sender  = new ContactModel("msg-tester", "msg-tester", "test", "test");

            builder.AppendMessage(sender, "time for a messsage generator command so I can test speed and memory usage");
            var text = builder.CreateText(" *formatted text* ");

            text.Bold = true;
            builder.Append(text);
            builder.AppendUrl("https://www.smuxi.org/");

            var msgs = new List <MessageModel>(count);

            for (var i = 0; i < count; i++)
            {
                var msg = builder.ToMessage();
                msgs.Add(msg);
            }

            DateTime start, stop;

            start = DateTime.UtcNow;
            foreach (var msg in msgs)
            {
                chat.AddMessage(msg);
            }
            stop = DateTime.UtcNow;

            builder = new MessageBuilder();
            builder.AppendText(
                "IChatView.AddMessage(): count: {0} took: {1:0} ms avg: {2:0.00} ms",
                count,
                (stop - start).TotalMilliseconds,
                (stop - start).TotalMilliseconds / count
                );
            chat.AddMessage(builder.ToMessage());
        }
コード例 #11
0
        void SyncWorker(ChatModel chatModel)
        {
            try {
                var            chatKey  = GetChatKey(chatModel);
                AutoResetEvent syncWait = null;
                lock (SyncWaitQueue) {
                    SyncWaitQueue.TryGetValue(chatKey, out syncWait);
                }
                if (syncWait != null)
                {
#if LOG4NET
                    Logger.Debug("SyncWorker() <" + chatKey + "> waiting for " +
                                 "sync lock release...");
#endif
                    // This chat was queued by QueueAdd() thus we need to wait
                    // till the ChatView is created and ready to be synced
                    syncWait.WaitOne();
#if LOG4NET
                    Logger.Debug("SyncWorker() <" + chatKey + "> " +
                                 "sync lock released");
#endif

                    // no longer need the sync lock
                    lock (SyncWaitQueue) {
                        SyncWaitQueue.Remove(chatKey);
                    }
                }

                IChatView chatView = null;
                lock (SyncReleaseQueue) {
                    SyncReleaseQueue.TryGetValue(chatKey, out chatView);
                }

                Sync(chatView);
            } catch (Exception ex) {
#if LOG4NET
                Logger.Error("SyncWorker(): Exception!", ex);
#endif
            }
        }
コード例 #12
0
        public void Sync(IChatView chatView)
        {
            Trace.Call(chatView);

            if (chatView == null)
            {
                throw new ArgumentNullException("chatView");
            }

#if LOG4NET
            DateTime start = DateTime.UtcNow;
#endif
            chatView.Sync();
#if LOG4NET
            DateTime stop     = DateTime.UtcNow;
            double   duration = stop.Subtract(start).TotalMilliseconds;
            Logger.Debug("Sync() <" + chatView.ID + ">.Sync() done, " +
                         " syncing took: " + Math.Round(duration) + " ms");
#endif

            OnChatSynced(chatView);
        }
コード例 #13
0
        public void Sync(IChatView chatView)
        {
            Trace.Call(chatView);

            if (chatView == null) {
                throw new ArgumentNullException("chatView");
            }

            #if LOG4NET
            DateTime start = DateTime.UtcNow;
            #endif
            chatView.Sync();
            #if LOG4NET
            DateTime stop = DateTime.UtcNow;
            double duration = stop.Subtract(start).TotalMilliseconds;
            Logger.Debug("Sync() <" + chatView.ID + ">.Sync() done, " +
                         " syncing took: " + Math.Round(duration) + " ms");
            #endif

            OnChatSynced(chatView);
        }
コード例 #14
0
        /// <remarks>
        /// This method is thread safe.
        /// </remarks>
        public void ReleaseSync(IChatView chatView)
        {
            Trace.Call(chatView);

            if (chatView == null) {
                throw new ArgumentNullException("chatView");
            }

            var chatKey = GetChatKey(chatView.ChatModel);
            #if LOG4NET
            Logger.Debug("ReleaseSync() <" + chatKey + "> releasing " +
                         "<" + chatView.ID + ">");
            #endif
            lock (SyncReleaseQueue) {
                SyncReleaseQueue.Add(chatKey, chatView);
            }
            AutoResetEvent syncWait = null;
            lock (SyncWaitQueue) {
                SyncWaitQueue.TryGetValue(chatKey, out syncWait);
            }
            if (syncWait == null) {
            #if LOG4NET
                Logger.Error("ReleaseSync(<" + chatView.ID + ">): failed to release " +
                             "<" + chatKey + "> as syncWait is null!");
            #endif
                return;
            }
            // release the sync worker
            syncWait.Set();
        }
コード例 #15
0
ファイル: ChatPresenter.cs プロジェクト: genesissupsup/ChatR
        public ChatPresenter(IChatView view, INavigationService navigationService)
        {
            _view = view;

            _view.Login += (s, e) => navigationService.NavigateTo("Login");
        }
コード例 #16
0
ファイル: CommandManager.cs プロジェクト: johansson/smuxi
        public void CommandGenerateMessages(CommandModel cmd, IChatView chat)
        {
            Trace.Call(cmd, chat);

            var count = 0;
            Int32.TryParse(cmd.Parameter, out count);

            var builder = new MessageBuilder();
            var sender = new ContactModel("msg-tester", "msg-tester", "test", "test");
            builder.AppendMessage(sender, "time for a messsage generator command so I can test speed and memory usage");
            var text = builder.CreateText(" *formatted text* ");
            text.Bold = true;
            builder.Append(text);
            builder.AppendUrl("https://www.smuxi.org/");

            var msgs = new List<MessageModel>(count);
            for (var i = 0; i < count; i++) {
                var msg = builder.ToMessage();
                msgs.Add(msg);
            }

            DateTime start, stop;
            start = DateTime.UtcNow;
            foreach (var msg in msgs) {
                chat.AddMessage(msg);
            }
            stop = DateTime.UtcNow;

            builder = new MessageBuilder();
            builder.AppendText(
                "IChatView.AddMessage(): count: {0} took: {1:0} ms avg: {2:0.00} ms",
                count,
                (stop - start).TotalMilliseconds,
                (stop - start).TotalMilliseconds / count
            );
            chat.AddMessage(builder.ToMessage());
        }
コード例 #17
0
        public override void Complete(ref string entryLine, ref int cursorPosition, IChatView currentChatView)
        {
            // isolate the nick to complete
            int    matchPosition;
            bool   appendSpace, leadingAt;
            string matchMe = IsolateNickToComplete(entryLine, cursorPosition, out matchPosition, out appendSpace, out leadingAt);

            int rematchCursorPosition = PreviousMatchPos + PreviousMatchLength + PreviousMatchCursorOffset;

            if (PreviousNickIndex != -1 && currentChatView == PreviousChatView && cursorPosition == rematchCursorPosition &&
                InitialMatch != null && (matchMe.Length == 0 || matchMe.StartsWith(InitialMatch)))
            {
                // re-match
                PreviousNickIndex = (PreviousNickIndex + 1) % PreviousNicks.Count;

                string nick   = PreviousNicks [PreviousNickIndex];
                string prefix = entryLine.Substring(0, PreviousMatchPos);
                string suffix = entryLine.Substring(PreviousMatchPos + PreviousMatchLength);

                PreviousMatchLength = nick.Length;
                entryLine           = prefix + nick + suffix;
                cursorPosition      = PreviousMatchPos + PreviousMatchLength + PreviousMatchCursorOffset;

                return;
            }

            // store this to check for re-matches
            InitialMatch = matchMe;

            // don't re-match even if the user moves the cursor back to the "correct" position
            PreviousNickIndex = -1;

            // don't complete empty strings
            if (matchMe.Length == 0)
            {
                return;
            }

            bool appendCompletionChar = (matchPosition == 0);
            int  additionalSteps      = 0;

            // find the matching nicknames
            IList <string> nicks = NicksMatchingPrefix(currentChatView.Participants, matchMe);

            if (nicks.Count == 0)
            {
                // no matches; do nothing
                return;
            }
            else
            {
                // bingo!
                string nick = nicks [0];

                // store the new values for the next completion
                PreviousNicks       = nicks;
                PreviousNickIndex   = 0;
                PreviousMatchPos    = matchPosition;
                PreviousMatchLength = nick.Length;
                PreviousChatView    = currentChatView;

                // suppress the completion character if we had an @
                if (leadingAt)
                {
                    appendCompletionChar = false;
                }

                // find the beginning and end of the string
                string prefix = entryLine.Substring(0, matchPosition);
                string suffix = entryLine.Substring(matchPosition + matchMe.Length);

                // append the completion character and a space, if requested
                if (appendSpace)
                {
                    suffix = ' ' + suffix;
                    ++additionalSteps;
                }
                if (appendCompletionChar)
                {
                    suffix = CompletionChar + suffix;
                    ++additionalSteps;
                }

                // assemble the line and move the cursor
                entryLine                 = prefix + nick + suffix;
                cursorPosition            = matchPosition + nick.Length + additionalSteps;
                PreviousMatchCursorOffset = additionalSteps;
            }
        }
コード例 #18
0
ファイル: NickCompleter.cs プロジェクト: pacificIT/smuxi
 /// <summary>
 /// Performs nickname tab completion on the specified input.
 /// </summary>
 /// <param name="entryLine">The text currently typed into the input text box.</param>
 /// <param name="cursorPosition">
 /// The current location of the cursor in the input text box. Equal to the index of the
 /// character after the current cursor position.
 /// </param>
 /// <param name="currentChatView">
 /// The current chat view. The list of participants is fetched from it; the completer may
 /// also append messages to the chat to provide further information.
 /// </param>
 public abstract void Complete(ref string entryLine, ref int cursorPosition, IChatView currentChatView);
コード例 #19
0
 /// <summary>
 /// Performs nickname tab completion on the specified input.
 /// </summary>
 /// <param name="entryLine">The text currently typed into the input text box.</param>
 /// <param name="cursorPosition">
 /// The current location of the cursor in the input text box. Equal to the index of the
 /// character after the current cursor position.
 /// </param>
 /// <param name="currentChatView">
 /// The current chat view. The list of participants is fetched from it; the completer may
 /// also append messages to the chat to provide further information.
 /// </param>
 abstract public void Complete(ref string entryLine, ref int cursorPosition, IChatView currentChatView);
コード例 #20
0
 public ChatViewSyncedEventArgs(IChatView chatView)
 {
     ChatView = chatView;
 }
コード例 #21
0
 public ClientCommandProcessor()
 {
     chatView   = IocContainer.Resolve <IChatView>();
     chatClient = IocContainer.Resolve <IChatClient>();
     chatClient.ConnectionRequested += ChatClient_ConnectionRequested;
 }
コード例 #22
0
 void OnChatSynced(IChatView chatView)
 {
     if (ChatSynced != null) {
         ChatSynced(this, new ChatViewSyncedEventArgs(chatView));
     }
 }
コード例 #23
0
        public override void Complete(ref string entryLine, ref int cursorPosition, IChatView currentChatView)
        {
            // isolate the nick to complete
            int    matchPosition;
            bool   appendSpace, leadingAt;
            string matchMe = IsolateNickToComplete(entryLine, cursorPosition, out matchPosition, out appendSpace, out leadingAt);

            bool appendCompletionChar = (matchPosition == 0);
            int  additionalSteps      = 0;

            // find the matching nicknames
            var nicks = NicksMatchingPrefix(currentChatView.Participants, matchMe);

            if (nicks.Count == 0)
            {
                // no matches; do nothing
                return;
            }
            else if (nicks.Count == 1)
            {
                // bingo!
                string nick = nicks [0];

                // suppress the completion character if we had an @
                if (leadingAt)
                {
                    appendCompletionChar = false;
                }

                // find the beginning and end of the string
                string prefix = entryLine.Substring(0, matchPosition);
                string suffix = entryLine.Substring(matchPosition + matchMe.Length);

                // append the completion character and a space, if requested
                if (appendSpace)
                {
                    suffix = ' ' + suffix;
                    ++additionalSteps;
                }
                if (appendCompletionChar)
                {
                    suffix = CompletionChar + suffix;
                    ++additionalSteps;
                }

                // assemble the line and move the cursor
                entryLine      = prefix + nick + suffix;
                cursorPosition = matchPosition + nick.Length + additionalSteps;
            }
            else
            {
                // find the longest common prefix
                string lcp = LongestCommonPrefix(nicks);

                // assemble nickname string
                string nickString = string.Join(" ", nicks.ToArray());

                // output the matched prefixes
                currentChatView.AddMessage(
                    new MessageModel(String.Format("-!- {0}", nickString))
                    );

                // extend to the longest match
                string prefix = entryLine.Substring(0, matchPosition);
                string suffix = entryLine.Substring(matchPosition + matchMe.Length);

                // assemble the line and move the cursor
                entryLine      = prefix + lcp + suffix;
                cursorPosition = matchPosition + lcp.Length;
            }
        }
コード例 #24
0
 public ChatViewSyncedEventArgs(IChatView chatView)
 {
     ChatView = chatView;
 }
コード例 #25
0
        public override void Complete(ref string entryLine, ref int cursorPosition, IChatView currentChatView)
        {
            // isolate the nick to complete
            int matchPosition;
            bool appendSpace, leadingAt;
            string matchMe = IsolateNickToComplete(entryLine, cursorPosition, out matchPosition, out appendSpace, out leadingAt);

            bool appendCompletionChar = (matchPosition == 0);
            int additionalSteps = 0;

            // find the matching nicknames
            var nicks = NicksMatchingPrefix(currentChatView.Participants, matchMe);

            if (nicks.Count == 0) {
                // no matches; do nothing
                return;
            } else if (nicks.Count == 1) {
                // bingo!
                string nick = nicks [0];

                // suppress the completion character if we had an @
                if (leadingAt) {
                    appendCompletionChar = false;
                }

                // find the beginning and end of the string
                string prefix = entryLine.Substring(0, matchPosition);
                string suffix = entryLine.Substring(matchPosition + matchMe.Length);

                // append the completion character and a space, if requested
                if (appendSpace) {
                    suffix = ' ' + suffix;
                    ++additionalSteps;
                }
                if (appendCompletionChar) {
                    suffix = CompletionChar + suffix;
                    ++additionalSteps;
                }

                // assemble the line and move the cursor
                entryLine = prefix + nick + suffix;
                cursorPosition = matchPosition + nick.Length + additionalSteps;
            } else {
                // find the longest common prefix
                string lcp = LongestCommonPrefix(nicks);

                // assemble nickname string
                string nickString = string.Join(" ", nicks.ToArray());

                // output the matched prefixes
                currentChatView.AddMessage(
                    new MessageModel(String.Format("-!- {0}", nickString))
                );

                // extend to the longest match
                string prefix = entryLine.Substring(0, matchPosition);
                string suffix = entryLine.Substring(matchPosition + matchMe.Length);

                // assemble the line and move the cursor
                entryLine = prefix + lcp + suffix;
                cursorPosition = matchPosition + lcp.Length;
            }
        }
コード例 #26
0
ファイル: TabCycleNickCompleter.cs プロジェクト: glwu/smuxi
        public override void Complete(ref string entryLine, ref int cursorPosition, IChatView currentChatView)
        {
            // isolate the nick to complete
            int matchPosition;
            bool appendSpace, leadingAt;
            string matchMe = IsolateNickToComplete(entryLine, cursorPosition, out matchPosition, out appendSpace, out leadingAt);

            int rematchCursorPosition = PreviousMatchPos + PreviousMatchLength + PreviousMatchCursorOffset;
            if (PreviousNickIndex != -1 && currentChatView == PreviousChatView && cursorPosition == rematchCursorPosition) {
                // re-match
                PreviousNickIndex = (PreviousNickIndex + 1) % PreviousNicks.Count;

                string nick = PreviousNicks [PreviousNickIndex];
                string prefix = entryLine.Substring(0, PreviousMatchPos);
                string suffix = entryLine.Substring(PreviousMatchPos + PreviousMatchLength);

                PreviousMatchLength = nick.Length;
                entryLine = prefix + nick + suffix;
                cursorPosition = PreviousMatchPos + PreviousMatchLength + PreviousMatchCursorOffset;

                return;
            }

            // don't re-match even if the user moves the cursor back to the "correct" position
            PreviousNickIndex = -1;

            // don't complete empty strings
            if (matchMe.Length == 0) {
                return;
            }

            bool appendCompletionChar = (matchPosition == 0);
            int additionalSteps = 0;

            // find the matching nicknames
            IList<string> nicks = NicksMatchingPrefix(currentChatView.Participants, matchMe);

            if (nicks.Count == 0) {
                // no matches; do nothing
                return;
            } else {
                // bingo!
                string nick = nicks [0];

                // store the new values for the next completion
                PreviousNicks = nicks;
                PreviousNickIndex = 0;
                PreviousMatchPos = matchPosition;
                PreviousMatchLength = nick.Length;
                PreviousChatView = currentChatView;

                // suppress the completion character if we had an @
                if (leadingAt) {
                    appendCompletionChar = false;
                }

                // find the beginning and end of the string
                string prefix = entryLine.Substring(0, matchPosition);
                string suffix = entryLine.Substring(matchPosition + matchMe.Length);

                // append the completion character and a space, if requested
                if (appendSpace) {
                    suffix = ' ' + suffix;
                    ++additionalSteps;
                }
                if (appendCompletionChar) {
                    suffix = CompletionChar + suffix;
                    ++additionalSteps;
                }

                // assemble the line and move the cursor
                entryLine = prefix + nick + suffix;
                cursorPosition = matchPosition + nick.Length + additionalSteps;
                PreviousMatchCursorOffset = additionalSteps;
            }
        }
コード例 #27
0
 public ChatPresenter(IChatView view)
 {
     this.view  = view;
     interactor = new ChatInteractor(this);
 }