Пример #1
0
 void DoHistoryAction(Action <HistoryManager> action)
 {
     if (EnableLogging)
     {
         ExceptionMonster.EatTheException(() => action(history), "logging history.");
     }
 }
Пример #2
0
 void channel_MessageReceived(object sender, MessageReceivedEventArgs e)
 {
     ExceptionMonster.EatTheException(() =>
     {
         if (e.Message is LoginMessage)
         {
             OnLoginMessage(e.Message);
         }
         else if (e.Message is HiMessage)
         {
             OnHiMessage((HiMessage)e.Message);
         }
         else if (e.Message is HelloMessage)
         {
             OnHelloMessage((HelloMessage)e.Message);
         }
         else if (e.Message is UserUpdateMessage)
         {
             OnUpdateMessage((UserUpdateMessage)e.Message);
         }
         else if (e.Message is GiveUserInfoMessage)
         {
             OnGiveUserInfoMessage((GiveUserInfoMessage)e.Message);
         }
         else if (e.Message is UserInfoMessage)
         {
             OnUserInfoMessage((UserInfoMessage)e.Message);
         }
         else if (e.Message is LogoutMessage)
         {
             OnLogoutMessage((LogoutMessage)e.Message);
         }
     }, "handling presence message in userdiscovery class");
 }
Пример #3
0
 public void NotifyTyping()
 {
     Task.Run(() =>
     {
         ExceptionMonster.EatTheException(() => session.NotifyTyping(), "sending typing message");
     });
 }
Пример #4
0
        async void SignIn(SignInOptions options, bool byUser)
        {
            if (context.ChatClient.IsLoggedIn)
            {
                return;
            }

            busyIndicator.IsBusy = true;

            Exception ex = null;

            await Task.Run(() =>
            {
                clientAvailable.Wait();
                SettingsProvider.Current.Load();
                var loginHelper = new LoginHelper(context.PluginLoader.AuthenticationProvider, SettingsProvider.Current.Settings, context.ChatClient);
                ExceptionMonster.EatTheException(() => loginHelper.Login(options), "logging in", out ex);
            });

            busyIndicator.IsBusy = false;

            if (ex != null && byUser)
            {
                MessageBox.Show(ex.Message, Translation.Instance.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            OnSignIn(options);
        }
Пример #5
0
        async void SignOut(bool byUser)
        {
            if (context.ChatClient == null || !context.ChatClient.IsLoggedIn)
            {
                return;
            }

            clientAvailable.Begin();

            // Can't chat with chat service stopped. End all sessions.
            foreach (var window in chatWindows)
            {
                window.EndChat();
            }

            DestroyMonitor();

            chatControl.SignIn.DisplayName = context.ChatClient.CurrentUser.DisplayName;
            chatControl.SignIn.GroupName   = context.ChatClient.CurrentUser.Properties.GroupName;

            await Task.Run(() =>
            {
                ExceptionMonster.EatTheException(() => context.ChatClient.Logout(), "logging out client");
                clientAvailable.End();
            });

            OnSignout(byUser);
        }
Пример #6
0
 public void Leave()
 {
     Task.Run(() =>
     {
         ExceptionMonster.EatTheException(() => session.End(), "leaving chat");
         LogHistory(EventType.Left, self);
     });
 }
Пример #7
0
 public void Like()
 {
     Task.Run(() =>
     {
         ExceptionMonster.EatTheException(() => session.Like(), "sending like");
         LogHistory(EventType.Like, self);
     });
 }
Пример #8
0
 public void Invite(IBuddy buddy)
 {
     Task.Run(() =>
     {
         var endpoint = new SquiggleEndPoint(buddy.Id, ((Buddy)buddy).ChatEndPoint);
         ExceptionMonster.EatTheException(() => session.Invite(endpoint), "sending chat invite to " + endpoint);
     });
 }
Пример #9
0
 public void SendBuzz()
 {
     Task.Run(() =>
     {
         ExceptionMonster.EatTheException(() => session.SendBuzz(), "sending buzz");
         LogHistory(EventType.Buzz, self);
     });
 }
        public void SendMessage(Message message)
        {
            byte[] data = SerializationHelper.Serialize(message);

            ExceptionMonster.EatTheException(() =>
            {
                client.Send(data, data.Length, multicastEndPoint);
            }, "sending presence mcast message");
        }
Пример #11
0
 void RouteChatMessageToLocalUser(RouteAction action, SquiggleEndPoint sender, SquiggleEndPoint recipient)
 {
     ExceptionMonster.EatTheException(() =>
     {
         sender = new SquiggleEndPoint(sender.ClientID, bridgeEndPointInternal);
         IPEndPoint endpoint = routeTable.GetLocalChatEndPoint(recipient.ClientID);
         action(true, endpoint, sender, new SquiggleEndPoint(recipient.ClientID, endpoint));
     }, "routing chat message to local user");
 }
Пример #12
0
        private bool GetRunAtStartup()
        {
            bool run = ExceptionMonster.EatTheException(() =>
            {
                return(WinStartup.IsAdded("squiggle", GetStartupPath()));
            }, "reading startup info from registry");

            return(run);
        }
Пример #13
0
        public bool Accept()
        {
            bool success = ExceptionMonster.EatTheException(() =>
            {
                ChatHost.AcceptActivityInvite(Id, localUser, remoteUser);
            }, "accepting activity invite from " + remoteUser);

            return(success);
        }
Пример #14
0
        public static void OpenDownloadsFolder()
        {
            string downloadsFolder = GetDownloadsFolderPath();

            if (Shell.CreateDirectoryIfNotExists(downloadsFolder))
            {
                ExceptionMonster.EatTheException(() => Process.Start(downloadsFolder), "opening downloads folder");
            }
        }
        public void SendMessage(Message message)
        {
            message.ChannelID = ChannelID;

            ExceptionMonster.EatTheException(() =>
            {
                host.Send(message);
            }, "sending presence message to " + message.Recipient);
        }
 void BeginReceive()
 {
     if (started)
     {
         ExceptionMonster.EatTheException(() =>
         {
             client.BeginReceive(OnReceive, null);
         }, "receiving mcast data on presence channel");
     }
 }
Пример #17
0
 void LogStatus(IBuddy buddy)
 {
     if (EnableLogging)
     {
         ExceptionMonster.EatTheException(() =>
         {
             history.AddStatusUpdate(buddy.Id, buddy.DisplayName, (int)buddy.Status);
         }, "logging history.");
     }
 }
Пример #18
0
        void OnInviteReceived(ChatInviteReceivedEventArgs e)
        {
            CreateRemoteUsers(e.Participants);

            ExceptionMonster.EatTheException(() =>
            {
                BroadCast(endpoint => chatHost.JoinChat(Id, localUser, endpoint));
            }, "responding to chat invite");

            GroupChatStarted(this, EventArgs.Empty);
        }
Пример #19
0
 void RouteMessageToRemoteUser(RouteAction action, SquiggleEndPoint sender, SquiggleEndPoint recipient)
 {
     ExceptionMonster.EatTheException(() =>
     {
         IPEndPoint bridge = routeTable.FindBridge(recipient.ClientID);
         if (bridge != null)
         {
             action(false, bridge, sender, recipient);
         }
     }, "routing message to remote user");
 }
Пример #20
0
        public void SendData(byte[] chunk, Action <Exception> onError)
        {
            Exception ex;

            if (!ExceptionMonster.EatTheException(() =>
            {
                ChatHost.ReceiveActivityData(Id, localUser, remoteUser, chunk);
            }, "sending data to " + remoteUser.ToString(), out ex))
            {
                onError(ex);
            }
        }
Пример #21
0
        public static void Deserialize <T>(byte[] data, Action <T> onDeserialize, string entityName) where T : class
        {
            T obj = null;

            if (ExceptionMonster.EatTheException(() =>
            {
                obj = SerializationHelper.Deserialize <T>(data);
            }, "deserializing " + entityName + " of type " + typeof(T).Name))
            {
                onDeserialize(obj);
            }
        }
        public void Save()
        {
            ConfigReader reader = GetConfigReader();

            Settings.WriteTo(Properties.Settings.Default, reader);

            ExceptionMonster.EatTheException(() =>
            {
                Properties.Settings.Default.Save();
                reader.Save();
            }, "saving configuration settings");

            SettingsUpdated(this, EventArgs.Empty);
        }
Пример #23
0
 public void Initialize(bool needSessionInfo)
 {
     if (needSessionInfo)
     {
         ExceptionMonster.EatTheException(() =>
         {
             chatHost.GetSessionInfo(Id, localUser, PrimaryUser);
         }, "requesting session info");
     }
     else
     {
         OnInitialized();
     }
 }
        async void AsyncInvoke(Action action, Action onComplete)
        {
            busyIndicator.IsBusy = true;
            await Task.Run(() =>
            {
                Exception ex;
                if (!ExceptionMonster.EatTheException(action, "searching history", out ex))
                {
                    MessageBox.Show(ex.Message);
                }
            });

            onComplete();
            busyIndicator.IsBusy = false;
        }
Пример #25
0
        void chatHost_SessionInfoRequested(object sender, SessionEventArgs e)
        {
            if (e.SessionID != Id)
            {
                return;
            }

            Task.Run(() =>
            {
                ExceptionMonster.EatTheException(() =>
                {
                    var participants = RemoteUsers.Except(Enumerable.Repeat(e.Sender, 1)).ToArray();
                    chatHost.ReceiveSessionInfo(Id, localUser, e.Sender, participants);
                }, "sending session info");
            });
        }
Пример #26
0
 public void SendMessage(Guid id, string fontName, int fontSize, Color color, FontStyle fontStyle, string message)
 {
     Task.Run(() =>
     {
         Exception ex;
         if (!ExceptionMonster.EatTheException(() =>
         {
             session.SendMessage(id, fontName, fontSize, color, fontStyle, message);
         }, "sending chat message", out ex))
         {
             MessageFailed(this, new MessageFailedEventArgs()
             {
                 Message   = message,
                 Exception = ex
             });
         }
         LogHistory(EventType.Message, self, message);
     });
 }
Пример #27
0
        public void End()
        {
            chatHost.ChatInviteReceived         -= chatHost_ChatInviteReceived;
            chatHost.ActivityInvitationReceived -= chatHost_ActivityInvitationReceived;
            chatHost.TextMessageReceived        -= chatHost_MessageReceived;
            chatHost.TextMessageUpdated         -= chatHost_MessageUpdated;
            chatHost.UserTyping           -= chatHost_UserTyping;
            chatHost.BuzzReceived         -= chatHost_BuzzReceived;
            chatHost.UserJoined           -= chatHost_UserJoined;
            chatHost.UserLeft             -= chatHost_UserLeft;
            chatHost.SessionInfoRequested -= chatHost_SessionInfoRequested;
            chatHost.SessionInfoReceived  -= chatHost_SessionInfoReceived;

            ExceptionMonster.EatTheException(() =>
            {
                BroadCast(endpoint => chatHost.LeaveChat(Id, localUser, endpoint));
            }, "sending leave message");
            SessionEnded(this, EventArgs.Empty);
        }
Пример #28
0
 public void UpdateMessage(Guid id, string message)
 {
     Task.Run(() =>
     {
         Exception ex;
         if (!ExceptionMonster.EatTheException(() =>
         {
             session.UpdateMessage(id, message);
         }, "sending chat message update", out ex))
         {
             MessageFailed(this, new MessageFailedEventArgs()
             {
                 Message   = message,
                 Exception = ex
             });
         }
         LogHistory(EventType.Message, self, message);
     });
 }
Пример #29
0
        private void SetRunAtStartup(bool run)
        {
            Exception ex;

            if (!ExceptionMonster.EatTheException(() =>
            {
                var runKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
                if (run)
                {
                    WinStartup.Add("squiggle", GetStartupPath());
                }
                else
                {
                    WinStartup.Remove("squiggle");
                }
            }, "setting squiggle startup option in registry", out ex))
            {
                MessageBox.Show("Could not set Squiggle to run at startup due to exception: " + ex.Message, "Squiggle", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        void OnReceive(IAsyncResult ar)
        {
            byte[]     data           = null;
            IPEndPoint remoteEndPoint = null;

            ExceptionMonster.EatTheException(() =>
            {
                data = client.EndReceive(ar, ref remoteEndPoint);
            }, "receiving mcast presence message");

            if (data != null)
            {
                SerializationHelper.Deserialize <Message>(data, message =>
                {
                    OnMessageReceived(message);
                }, "presence message");
            }

            BeginReceive();
        }