Esempio n. 1
0
        public void SwitchToP2P(NetworkStream netStream, string key, Messagehandler mh)
        {
            if (window.InvokeRequired)
            {
                window.Invoke(new Action <NetworkStream, string, Messagehandler>(SwitchToP2P), new object[] { netStream, key, mh });
                return;
            }
            isP2P = true;
            int NumberChars = key.Length;

            byte[] personalKey = new byte[NumberChars / 2];
            for (int i = 0; i < NumberChars; i += 2)
            {
                personalKey[i / 2] = System.Convert.ToByte(key.Substring(i, 2), 16);
            }

            writer      = new P2PWriter(netStream, personalKey);
            p2pListener = new P2PListener(netStream, receiver, personalKey);
            writer      = new P2PWriter(netStream, personalKey);

            mh.Subscribe(p2pListener);
            p2pListener.StartListen();
            window.attachmentPanel.Visible = true;
            window.userStatusLabel.Text    = "Online";
        }
Esempio n. 2
0
        public IndividualChatDriver(string username, string receiver, FileManager fm, NetworkStream netstream, Messagehandler mh, string key, string status)
        {
            isP2P                = true;
            this.username        = username;
            this.receiver        = receiver;
            this.fm              = fm;
            window               = new IndividualChatWindow(receiver);
            window.WindowState   = FormWindowState.Minimized;
            window.ShowInTaskbar = false;
            window.getStatusTextLabel().Text = status;
            spam = new SpamProtector();
            SetupListners();

            int NumberChars = key.Length;

            byte[] personalKey = new byte[NumberChars / 2];
            for (int i = 0; i < NumberChars; i += 2)
            {
                personalKey[i / 2] = System.Convert.ToByte(key.Substring(i, 2), 16);
            }

            writer      = new P2PWriter(netstream, personalKey);
            p2pListener = new P2PListener(netstream, receiver, personalKey);
            writer      = new P2PWriter(netstream, personalKey);

            mh.Subscribe(p2pListener);
            p2pListener.StartListen();

            new Thread(() => Application.Run(window)).Start();
            Thread.Sleep(10);
        }
Esempio n. 3
0
        public void SwitchFromP2P(CustomStreamWriter streamWriter)
        {
            if (window.InvokeRequired)
            {
                window.Invoke(new Action <CustomStreamWriter>(SwitchFromP2P), new object[] { streamWriter });
                return;
            }
            window.attachmentPanel.Visible = false;
            window.userStatusLabel.Text    = "Offline";

            isP2P       = false;
            writer      = streamWriter;
            p2pListener = null;
        }
Esempio n. 4
0
 public IndividualChatDriver(CustomStreamWriter sllWriter, string Username, string Receiver, FileManager fm, string status)
 {
     isP2P      = false;
     username   = Username;
     receiver   = Receiver;
     fileToSend = null;
     this.fm    = fm;
     window     = new IndividualChatWindow(receiver);
     window.getStatusTextLabel().Text = status;
     spam = new SpamProtector();
     SetupListners();
     writer               = sllWriter;
     window.WindowState   = FormWindowState.Minimized;
     window.ShowInTaskbar = false;
     new Thread(() => Application.Run(window)).Start();
     Thread.Sleep(10);
     //new Thread(() => window.Show()).Start();
 }
        public ActionResult SendMail(int?id, string username = null)
        {
            //url : http://localhost:57129/Email/Index؟username=Ali&id=1
            // username or id could be null
            //this is sample username=Ali id =1

            if (Request.QueryString.Keys.Count == 0)
            {
                return(HttpNotFound());
            }

            DB db = new DB();

            db.Connect();

            SqlDataReader reader = db.SelectUser(username /*Request.QueryString["username"]*/, id);

            reader.Read();

            string email = reader.GetString(2);

            emailer.Instance.send(email);
            FileStream         fs = new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + logFile, FileMode.Append, FileAccess.Write);
            CustomStreamWriter customstreamwriter = new CustomStreamWriter(fs);

            customstreamwriter.Write(email);
            customstreamwriter.Dispose();
            fs.Close();
            fs.Dispose();

            string wellcom = string.Empty;

            if (id != null || username != null)
            {
                wellcom = String.IsNullOrEmpty(username)  ? "wellcome  " + id.ToString() : "wellcome " + username;
            }
            ViewData["wellcome"] = wellcom;
            return(View("Index"));
        }