static void Main(string[] args) { using (var broker = new MessegesBroker(Console.Out)) { broker.Start(); List <MessengerClient> clients = new List <MessengerClient>(); int clientsCount = Configuration.ClientNames.Length; int messagesCount = Configuration.Messages.Length; foreach (var name in Configuration.ClientNames) { var client = new MessengerClient(name, broker, Console.Out); client.Connect(); clients.Add(client); } while (broker.IsConnected) { var client = clients[Random.Next(clientsCount)]; client.Connect(); for (int i = 0; i < Random.Next(1, messagesCount); i++) { Thread.Sleep(Random.Next(1000, 3000)); var message = Configuration.Messages[Random.Next(messagesCount)]; client.SendMessage(message); } client.Disconnect(); } } }
public void SetUp() { skype = MockRepository.GenerateMock<ISkype>(); chat = MockRepository.GenerateMock<IChat>(); userCollection = MockRepository.GenerateMock<IUserCollection>(); client = MockRepository.GenerateMock<IClient>(); user = MockRepository.GenerateMock<IUser>(); configurationLoader = new ConfigurationLoader(); httpGet = MockRepository.GenerateMock<IHttpGet>(); chats = MockRepository.GenerateMock<IChats>(); messengerClient = new MessengerClient(skype, userCollection, chats); buildCollection = MockRepository.GenerateMock<IBuildCollection>(); loader = new Loader(messengerClient, buildCollection); stopper = MockRepository.GenerateMock<IStopper>(); controller = new Controller(); controller.Container.Kernel.AddComponentInstance<ISkype>(skype); controller.Container.Kernel.AddComponentInstance<IUserCollection>(userCollection); controller.Container.Kernel.AddComponentInstance<IStopper>(stopper); controller.CcTrayUrl = "http://localhost/Cctray.xml"; controller.CcTrayUsername = "******"; controller.CcTrayPassword = "******"; controller.HttpTimeout = 30; controller.Configuration = @"RealUsers.xml"; }
private void Connect(string userName, string userPassword) { if (NetworkInterface.GetIsNetworkAvailable() == false) { MessageBox.Show("Offline mode"); return; } #region Login Data //mc = new MessengerClient("*****@*****.**", "ohudhqar"); mc = new MessengerClient(userName, userPassword); #endregion // Blocking! mc.Authenticate(); if (mc.Authenticated == false) { MessageBox.Show("Authenticated Failed"); return; } mc.SyncronizeContacts(); mc.ChangeStatus(ClientStatus.Online); mc.ChangePersonalMessage("ÀÁàáÈÉèéÌÍìíÒÓòóÙÚùúÂâÃãÊêÎîÔôÕõÛûÄäËëÏïÖöÜüÇçÑñ"); //const string user = "******"; //for (int i = 5; i >= 0; --i) //{ // Console.WriteLine("waiting to cal user: {0} in {1}", user, i*1000); // Thread.Sleep(1000); //} //mc.InviteUserToChatSession(user); }
public void Login() { new Task(() => Loading()).Start(); MessengerClient messengerClient = new MessengerClient(); string login = "", password = ""; Dispatcher.Invoke(() => password = tbPassword.Password); Dispatcher.Invoke(() => login = tbLogin.Text); AccountDTO account = messengerClient.Login(login, password); if (account != null) { MainWindow mainWindow = null; Dispatcher.Invoke(() => mainWindow = new MainWindow(account)); Dispatcher.Invoke(() => mainWindow.Show()); } else { Dispatcher.Invoke(() => { tbPassword.Password = ""; tbPassword.Foreground = Brushes.Red; MaterialDesignThemes.Wpf.HintAssist.SetHelperText(tbPassword, "Incorrect login or password"); }); } timer.Stop(); Dispatcher.Invoke(() => { pnlLoading.Visibility = Visibility.Hidden; tbLoading.Visibility = Visibility.Hidden; // this.Hide(); }); }
public LoginPage() { InitializeComponent(); Client = ((App)Application.Current).client; this.Loaded += LoginPage_Loaded; this.Unloaded += LoginPage_Unloaded; }
public void Publish() { var id = nameof(MessengerTest); var msg = "ClientToServer"; var actual = string.Empty; using (var server = new Messenger <string>(id)) using (var client = new MessengerClient <string>(id)) { var cts = new CancellationTokenSource(); Action <string> h = (x) => { actual = x; server.Publish(x); cts.Cancel(); }; IDisposable uns = null; try { uns = server.Subscribe(h); Task.Run(() => client.Publish(msg)).Forget(); Task.Delay(TimeSpan.FromSeconds(5), cts.Token).Wait(); } catch (AggregateException /* err */) { uns.Dispose(); } } Assert.That(actual, Is.EqualTo(msg)); }
public void SetUp() { skype = MockRepository.GenerateMock<ISkype>(); chat = MockRepository.GenerateMock<IChat>(); userCollection = MockRepository.GenerateMock<IUserCollection>(); client = MockRepository.GenerateMock<IClient>(); chats = MockRepository.GenerateMock<IChats>(); messengerClient = new MessengerClient(skype, userCollection, chats); }
static void MessengerRegister(MessengerClient client) { client.Register("HVV RoK Bot").ContinueWith(result => { if (!result.Result) { MessengerRegister(client); } }); }
public async Task CallSendApi_ByDefault_CallsHttpClientPost() { var messengerClient = new MessengerClient (_httpClient, _fbOptions); await messengerClient.CallSendApi(It.IsAny <string>(), It.IsAny <string>()); _handlerMock.Protected().Verify("SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage> (req => req.Method == HttpMethod.Post), ItExpr.IsAny <CancellationToken>()); }
public async Task CallSendApi_WhenRequestNotSuccessful_ThrowsApiCallException() { _response.StatusCode = HttpStatusCode.BadRequest; var messengerClient = new MessengerClient (_httpClient, _fbOptions); await Assert.ThrowsAsync <ApiCallException> (() => messengerClient.CallSendApi (It.IsAny <string>(), It.IsAny <string>())); }
public ServiceManager() { _aes = new Aes(); _rsa = new Rsa(); _rsa.SetKey(ConfigurationManager.AppSettings["RsaXmlPublicKey"]); var _timer = new DispatcherTimer(); _timer.Tick += Reconnect; _timer.Interval = TimeSpan.FromSeconds(2); _client = new MessengerClient(); Connect(); }
public async Task CallSendApi_ByDefault_CallsRightUri() { var messengerClient = new MessengerClient (_httpClient, _fbOptions); await messengerClient.CallSendApi(It.IsAny <string>(), It.IsAny <string>()); var expectedUri = new Uri(BaseUrl + $"?access_token="); _handlerMock.Protected().Verify("SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage> (req => req.RequestUri == expectedUri), ItExpr.IsAny <CancellationToken>()); }
public static void PopulateUsers(MessengerClient client) { var fbUsers = client.fetchAllUsers(); fbUsers.Wait(); if (fbUsers.Result.Any()) { users = fbUsers.Result; } var self = client.FetchProfile(); self.Wait(); users.Add(self.Result); }
public ChatDlg(Form parent, MessengerClient client, Guid groupSessionGuid, Guid userSessionGuid, string userToConnect) { mInkPicture = new Microsoft.Ink.InkPicture(); mOriginalPts = new List<Point[]>(); mClient = client; mUserSessionGuid = userSessionGuid; mGroupSessionGuid = groupSessionGuid; mParent = parent; InitializeComponent(); this.toolStrip1.Items.Add(this.toolStripButton1); this.toolStrip1.Items.Add(this.toolStripButton2); this.Text = userToConnect; button1.Enabled = false; this.splitContainer1.Panel1.Controls.Add(mInkPicture); mInkPicture.Dock = DockStyle.Fill; //mInkPicture.Width = this.ClientSize.Width; //mInkPicture.Height = this.ClientSize.Height; //GetXYIndexes(ref PACKET_IDX_PtX, ref PACKET_IDX_PtY); //Save the X and Y data locations within the packet data. mInkPicture.Stroke += new Microsoft.Ink.InkCollectorStrokeEventHandler(InkPicture_Stroke); /* mReceiveMessageCompletedHandler = new EventHandler<ReceiveMessageCompletedEventArgs>(OnReceiveMessageCompleted); mClient.ReceiveMessageCompleted += mReceiveMessageCompletedHandler; mReceiveStorokeCompetedHandler = new EventHandler<ReceiveStrokeCompletedEventArgs>(OnReceiveStrokeCompleted); mClient.ReceiveStrokeCompleted += mReceiveStorokeCompetedHandler; mReceiveBGImgChunkCompletedHandler = new EventHandler<ReceiveBGImgChunkCompletedEventArgs>(OnReceiveBGImgChunkCompleted); mClient.ReceiveBGImgChunkCompleted += mReceiveBGImgChunkCompletedHandler; */ mReceiveContentDataCompletedHandler = new EventHandler<ReceiveContentDataCompletedEventArgs>(OnReceiveContentDataCompleted); mClient.ReceiveContentDataCompleted += mReceiveContentDataCompletedHandler; Form1 form1 = (Form1)parent; mUserId = form1.UserId; /* mClient.ReceiveMessageAsync(mUserSessionGuid); mClient.ReceiveStrokeAsync(mUserSessionGuid); mClient.ReceiveBGImgChunkAsync(mUserSessionGuid); */ mClient.ReceiveContentDataAsync(mUserSessionGuid); string debug = string.Format("{0} - {1}", mUserId, userToConnect); WriteLine(debug, Color.Black); debug = string.Format("Group {0}", groupSessionGuid.ToString()); WriteLine(debug, Color.Black); debug = string.Format("Group {0}", userSessionGuid.ToString()); WriteLine(debug, Color.Black); }
public static void Main(string[] arguments) { if (NetworkInterface.GetIsNetworkAvailable() == false) { Console.WriteLine("Offline mode"); Console.ReadLine(); return; } if (Debugger.IsAttached) { ConfigureConsole(); } #region Login Data //MessengerClient mc = new MessengerClient("*****@*****.**", "ohudhqar"); MessengerClient mc = new MessengerClient("*****@*****.**", "ohudhqar"); #endregion // Blocking! mc.Authenticate(); if (mc.Authenticated == false) { Console.WriteLine("Authenticated Failed"); Console.ReadLine(); return; } mc.SyncronizeContacts(); mc.ChangeStatus(ClientStatus.Online); mc.ChangePersonalMessage("ÀÁàáÈÉèéÌÍìíÒÓòóÙÚùúÂâÃãÊêÎîÔôÕõÛûÄäËëÏïÖöÜüÇçÑñ"); Console.WriteLine("Hello"); //const string user = "******"; //for (int i = 5; i >= 0; --i) //{ // Console.WriteLine("waiting to cal user: {0} in {1}", user, i*1000); // Thread.Sleep(1000); //} //mc.InviteUserToChatSession(user); Console.ReadLine(); }
/* private MessengerClient CreateClient() { string key0 = ConfigurationManager.AppSettings["Key0"]; System.ServiceModel.BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); EndpointAddress ep = new EndpointAddress("http://localhost:55560/MessengerService.svc"); //EndpointAddress ep = new EndpointAddress("http://li4shi2.azurewebsites.net/MessengerService.svc"); return new MessengerClient(binding, ep); } */ private void Form1_Load(object sender, EventArgs e) { try { //mClient = CreateClient(); //mClient = new MessengerClient(); //mClient = new MessengerClient(new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None), new EndpointAddress("http://192.168.98.129:8000/Messenger")); mClient = new MessengerClient(new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None), new EndpointAddress("http://localhost:8000/Messenger")); // get ip address string ipaddr = string.Empty; IPHostEntry host; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { ipaddr = ip.ToString(); break; } } //mUserId = DateTime.Now.ToString("hhmmss"); mUserId = System.Environment.MachineName + "-" + System.Diagnostics.Process.GetCurrentProcess().Id; if (mClient.Login(mUserId) == false) { MessageBox.Show("Login failed."); Application.ExitThread(); return; } this.Text = mUserId; string list = mClient.GetMemberList(); updateMemberList(list); receiveMemberCompletedHandler = new EventHandler<ReceiveMemberListCompletedEventArgs>(OnReceiveMemberListCompleted); mClient.ReceiveMemberListCompleted += receiveMemberCompletedHandler; mClient.ReceiveMemberListAsync(mUserId); receiveConnectionCompletedHandler = new EventHandler<ReceiveConnectionCompletedEventArgs>(OnReceiveConnectionCompleted); mClient.ReceiveConnectionCompleted += receiveConnectionCompletedHandler; mClient.ReceiveConnectionAsync(mUserId); } catch (Exception ex) { MessageBox.Show(ex.Message); Application.ExitThread(); } }
static async Task Main(string[] args) { // initialize client _client = new MessengerClient(Environment.GetEnvironmentVariable("FB_ACCESS_TOKEN")); // initialize recipient _recipient = new PsidRecipient(Environment.GetEnvironmentVariable("TEST_PSID")); // call example method await SendTextAndQuickReplies(); // keep window open Console.ReadKey(); }
public void Login() { MessengerClient messengerClient = new MessengerClient(); string login = "", password = "", email = " ", name = ""; byte[] img = null; Dispatcher.Invoke(() => { password = Account.Password; login = Account.Login; email = Account.Email; name = Account.Name; img = Account.Image; }); messengerClient.Registrate(email, login, password, name, img); AccountDTO account = messengerClient.Login(login, password); MainWindow mainWindow = null; Dispatcher.Invoke(() => mainWindow = new MainWindow(account)); Dispatcher.Invoke(() => mainWindow.Show()); this.Hide(); }
private async void buttonConnect_Click(object sender, RoutedEventArgs e) { if (isConnected) { return; } channel = new Channel(textHost.Text + ":" + PORT.ToString(), ChannelCredentials.Insecure); client = new MessengerClient(channel); var currentClientTimeStamp = GetClientTimeStamp(); var loginRequest = new Messenger.LoginRequest { UserName = texUsername.Text }; var reply = await client.LoginAsync(loginRequest); if (reply.Result.Result == Messenger.ResultReply.Types.Result.Failed) { return; } userId = reply.UserId; lastTimeStamp = reply.TimeStamp; timeStampOffset = lastTimeStamp - currentClientTimeStamp; refreshTimer = new System.Windows.Threading.DispatcherTimer(); refreshTimer.Tick += new EventHandler(refreshTimer_Tick); refreshTimer.Interval = new TimeSpan(0, 0, 1); refreshTimer.Start(); sendTimer = new System.Windows.Threading.DispatcherTimer(); sendTimer.Tick += new EventHandler(sendTimer_Tick); sendTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); sendTimer.Start(); isConnected = true; }
public JoinViewModel(Imessanger imessanger) { messengerClient = imessanger.GetMessenger(ResponseMessage); }
static void MessengerListener() { ImageCodecInfo encoder = ImageCodecInfo.GetImageEncoders().First(i => i.FormatID == ImageFormat.Jpeg.Guid); EncoderParameters parameters = new EncoderParameters(1); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 30L); using (MessengerClient client = new MessengerClient("api.ahacafe.vn", 100)) { MessengerRegister(client); DateTime lastScreenRequest = DateTime.UtcNow; Parallel.Start(() => { while (true) { DateTime start = DateTime.UtcNow; if ((DateTime.UtcNow - lastScreenRequest).TotalSeconds < 10) { using (Bitmap screen = Device.Screen) { if (screen == null) { client.Delete("screen").Wait(); } else { using (MemoryStream ms = new MemoryStream()) { screen.Save(ms, encoder, parameters); client.Pusblish("screen", Convert.ToBase64String(ms.ToArray())).Wait(); } } } } Thread.CurrentThread.Join(Math.Max(1, 40 - (int)(DateTime.UtcNow - start).TotalMilliseconds)); } }); client.ChannelTerminated += () => MessengerRegister(client); client.PackageReceived += pkg => { switch (pkg.Type) { case "pull": lastScreenRequest = DateTime.UtcNow; break; case "push": string[] cmds = pkg.Data.Split(' '); if (cmds.Length == 3 && int.TryParse(cmds[1], out int x) && int.TryParse(cmds[2], out int y)) { switch (cmds[0]) { case "tap": Device.Tap(x, y); break; case "press": Device.Press(x, y); break; case "move": Device.MoveTo(x, y); break; case "release": Device.Release(); break; } } break; case "kill": try { foreach (Process process in Process.GetProcessesByName("MEmu")) { process.Kill(); } } catch (Exception e) { } break; } }; while (true) { Thread.CurrentThread.Join(1000); } } }
public LoginPage() { InitializeComponent(); Client = ((App)Application.Current).client; Client.Set2FACallback(On2FACallback); }
public void FillAllChats() { new Task(() => Loading()).Start(); MessengerClient msClient = new MessengerClient(); AccountDTO account = null; Dispatcher.Invoke(() => account = Account); List <ChatDTO> chats = msClient.GetAllMessagesInChats(account).ToList(); bool isExist = false; List <StackPanel> dialogPanels = new List <StackPanel>(); foreach (var item in chats) { foreach (var panel in dialogPanels) { ChatDTO chatPanel = null; Dispatcher.Invoke(() => chatPanel = panel.Tag as ChatDTO); if (item.Participants == chatPanel.Participants) { Dispatcher.Invoke(() => AddMessage(panel, msClient.GetMessageById(item.MessageId.Value))); isExist = true; Dispatcher.Invoke(() => panel.Tag = item); } } if (!isExist) { StackPanel panel = null; bool isContact = false; Dispatcher.Invoke(() => { foreach (Chip ac in panelContacts.Children) { if (item.Participants.Contains((ac.Tag as AccountDTO).Id.ToString())) { isContact = true; } } AccountDTO acc = messengerClient.GetUserById(messengerClient.GetMessageById(item.MessageId.Value).DeliverId.Value); if (!isContact & acc.Id != Account.Id) { ms = new MemoryStream(acc.Image); listMails.Items.Add(new SearchClass { Img = BitmapFrame.Create(ms), Text = acc.Name, Tag = acc }); } panel = new StackPanel { Tag = item, Width = 907 }; AddMessage(panel, msClient.GetMessageById(item.MessageId.Value)); }); dialogPanels.Add(panel); } isExist = false; } Dispatcher.Invoke(() => { DialogPanels.AddRange(dialogPanels.ToArray()); for (int i = 0; i < DialogPanels.Count; i++) { DialogPanels[i].Tag = dialogPanels[i].Tag as ChatDTO; } timer.Stop(); pnlLoading.Visibility = Visibility.Hidden; tbLoading.Visibility = Visibility.Hidden; }); IsChatsFill = true; }
public void CheckNewMessages() { if (IsChatsFill) { MessengerClient msClient = new MessengerClient(); bool isExist = false; List <ChatDTO> chats = msClient.GetChats(Account).ToList(); List <StackPanel> dialogPanels = null; Dispatcher.Invoke(() => dialogPanels = DialogPanels); foreach (var item in chats) { foreach (var panel in dialogPanels) { ChatDTO chatPanel = null; Dispatcher.Invoke(() => chatPanel = panel.Tag as ChatDTO); if (item.Participants == chatPanel.Participants) { isExist = true; if (item.MessageId > chatPanel.MessageId) { Dispatcher.Invoke(() => { chatPanel.MessageId = item.MessageId; AddMessage(panel, msClient.GetMessageById(item.MessageId.Value)); chatScroll.ScrollToVerticalOffset(Math.Pow(100, 100)); return; }); } } } if (!isExist) { bool isContact = false; Dispatcher.Invoke(() => { foreach (Chip acc in panelContacts.Children) { if (item.Participants.Contains((acc.Tag as AccountDTO).Id.ToString())) { isContact = true; } } AccountDTO account = messengerClient.GetUserById(messengerClient.GetMessageById(item.MessageId.Value).DeliverId.Value); if (!isContact & account.Id != Account.Id) { ms = new MemoryStream(account.Image); listMails.Items.Add(new SearchClass { Img = BitmapFrame.Create(ms), Text = account.Name, Tag = account }); } StackPanel panel = new StackPanel { Tag = item, Width = 907 }; AddMessage(panel, msClient.GetMessageById(item.MessageId.Value)); DialogPanels.Add(panel); }); } isExist = false; } } }
public BlockfriendViewModel(Imessanger imessanger) { messenger = imessanger.GetMessenger(ResponseMessage); _blockid = string.Empty; _Friendlist = new ObservableCollection <Frienddata>(); }
public PlusfriendViewModel(Imessanger imessanger) { messanger = imessanger.GetMessenger(ResponseMessage); _Friendlist = new ObservableCollection <Frienddata>(); }
public MessangerService() { messenger = new MessengerClient(); }