Esempio n. 1
0
        private static NetworkUser parseNetworkUser(string xml)
        {
            xml = XmlEncryption.decryptXml(xml);

            XmlDocument x = new XmlDocument();

            x.LoadXml(xml);
            XmlNode user      = x.SelectSingleNode("envelope/user");
            XmlNode computer  = x.SelectSingleNode("envelope/computer");
            XmlNode ip        = x.SelectSingleNode("envelope/ip");
            XmlNode message   = x.SelectSingleNode("envelope/message");
            XmlNode presence  = x.SelectSingleNode("envelope/presence");
            XmlNode icon      = x.SelectSingleNode("envelope/icon");
            XmlNode timestamp = x.SelectSingleNode("envelope/timestamp");

            //byte[] imgBits = Convert.FromBase64String(icon.InnerText);
            //MemoryStream ms = new MemoryStream(imgBits);
            //Image img = Image.FromStream(ms);
            //ms.Close();

            Lan.NetworkUser nc = new Lan.NetworkUser();
            nc.UserName     = user.InnerText;
            nc.ComputerName = computer.InnerText;
            nc.IPAddress    = IPAddress.Parse(ip.InnerText);
            nc.Presence     = (Presence)Enum.Parse(typeof(Presence), presence.InnerText);
            nc.TimeStamp    = DateTime.Parse(timestamp.InnerText);
            nc.UserUniqueId = (nc.UserName + nc.ComputerName);

            // nc.Icon = img;
            return(nc);
        }
Esempio n. 2
0
        public static void BroadcastPresence(Presence Presence)
        {
            try
            {
                Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
                s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, false);
                s.EnableBroadcast = true;

                IPAddress broadcast = IPAddress.Parse(Settings.Default.BroadcastAddress);// IPAddress.Broadcast;

                NetworkUser lc       = GetLocalComputer();
                string      presence = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>";
                presence += "<envelope><user>" + Environment.UserName;
                presence += "</user><computer>" + lc.ComputerName + "</computer>";
                presence += "<timestamp>" + DateTime.Now + "</timestamp>";
                presence += "<ip>" + lc.IPAddress + "</ip>";
                presence += "<presence>" + Enum.GetName(typeof(Presence), Presence) + "</presence>";
                presence += "</envelope>";

                string enc_presence = XmlEncryption.encryptXml(presence);



                byte[]     sendbuf = Encoding.ASCII.GetBytes(enc_presence);
                IPEndPoint ep      = new IPEndPoint(broadcast, (int)Settings.Default.BroadcastPort);

                s.SendTo(sendbuf, ep);
                s.Close();
            }
            catch
            {
            }
        }
Esempio n. 3
0
        private static void returnNewMessage(string envelope)
        {
            envelope = XmlEncryption.decryptXml(envelope);

            XmlDocument x = new XmlDocument();

            x.LoadXml(envelope);
            XmlNode user     = x.SelectSingleNode("envelope/user");
            XmlNode computer = x.SelectSingleNode("envelope/computer");
            XmlNode ip       = x.SelectSingleNode("envelope/ip");
            string  message  = ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(x.SelectSingleNode("envelope/message").InnerText));
            XmlNode presence = x.SelectSingleNode("envelope/presence");
            XmlNode dateSent = x.SelectSingleNode("envelope/timestamp");

            Lan.NetworkUser nc = new Lan.NetworkUser();
            nc.UserName     = user.InnerText;
            nc.ComputerName = computer.InnerText;
            nc.IPAddress    = IPAddress.Parse(ip.InnerText);
            nc.Presence     = (Lan.Presence)Enum.Parse(typeof(Lan.Presence), presence.InnerText);
            nc.TimeStamp    = DateTime.Parse(dateSent.InnerText);
            nc.UserUniqueId = (nc.UserName + nc.ComputerName).ToLower();

            if (NewMessage != null)
            {
                NewMessage(nc, message);
            }
        }
Esempio n. 4
0
        public static void BroadCastPresence(NetworkChat.Lan.Presence Presence)
        {
            IPEndPoint endPoint;

            NetworkChat.Lan.NetworkUser lc = NetworkChat.Lan.GetLocalComputer();
            string presence = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>";

            presence += "<envelope><user>" + Environment.UserName;
            presence += "</user><computer>" + lc.ComputerName + "</computer>";
            //Image Oimg = Image.FromFile(@"C:\Users\" + Environment.UserName + @"\AppData\Local\Temp\" + Environment.UserName + ".bmp");
            //Image Nimg = new Bitmap(Oimg, new Size(32, 32));

            //Image img = Nimg; // Image.FromFile(@"C:\Users\James\Downloads\mouse_silence.gif");//
            //MemoryStream ms = new MemoryStream();
            //img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            //byte[] buffer = ms.ToArray();
            //ms.Close();

            ////FileStream fs = new FileStream(@"C:\Users\" + Environment.UserName + @"\AppData\Local\Temp\" + Environment.UserName + ".bmp", FileMode.Open);
            ////byte[] buffer = new byte[fs.Length];
            ////fs.Read(buffer, 0, buffer.Length);
            ////fs.Close();

            ////ms.Write(buffer, 0, buffer.Length);
            //string ico = Convert.ToBase64String(buffer);
            //presence += "<icon>" + ico + "</icon>";
            presence += "<timestamp>" + DateTime.Now + "</timestamp>";
            presence += "<ip>" + lc.IPAddress + "</ip>";
            presence += "<presence>" + Enum.GetName(typeof(NetworkChat.Lan.Presence), Presence) + "</presence>";
            presence += "</envelope>";

            string enc_presence = XmlEncryption.encryptXml(presence);

            //try
            //{
            //Send multicast packets to the listener.
            Socket mcastSocket = new Socket(AddressFamily.InterNetwork,
                                            SocketType.Dgram,
                                            ProtocolType.Udp);

            endPoint = new IPEndPoint(mcastAddress, mcastPort);
            mcastSocket.SendTo(Encoding.ASCII.GetBytes(enc_presence), endPoint);
            // Console.WriteLine("Multicast data sent.....");
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine("\n" + e.ToString());
            //}

            mcastSocket.Close();
        }
Esempio n. 5
0
        //adds task to xml file...
        public static void AddTask(Task Task)
        {
            try
            {
                XmlDocument xdocEn = new XmlDocument();
                xdocEn.Load(fil);

                XmlDocument xdoc = new XmlDocument();
                xdoc.LoadXml(XmlEncryption.decryptXml(xdocEn.InnerXml));


                XmlNode tasksNode = xdoc.SelectSingleNode("Tasks");

                XmlElement taskNode = xdoc.CreateElement("Task");


                XmlAttribute taskTaskId = xdoc.CreateAttribute("TaskId");
                taskTaskId.InnerText = getNewId().ToString();
                taskNode.Attributes.Append(taskTaskId);

                XmlElement taskTitleNode = xdoc.CreateElement("TaskTitle");
                taskTitleNode.InnerText = Task.TaskTitle;
                taskNode.AppendChild(taskTitleNode);

                XmlElement taskTaskDetails = xdoc.CreateElement("TaskDetails");
                taskTaskDetails.InnerText = Task.TaskDetails;
                taskNode.AppendChild(taskTaskDetails);

                XmlElement taskTaskStatus = xdoc.CreateElement("TaskStatus");
                taskTaskStatus.InnerText = Enum.GetName(typeof(TaskStatus), Task.TaskStatus);
                taskNode.AppendChild(taskTaskStatus);

                XmlElement taskLastEditDate = xdoc.CreateElement("LastEditDate");
                taskLastEditDate.InnerText = Task.LastEditDate.ToString();
                taskNode.AppendChild(taskLastEditDate);

                XmlElement taskLastEditBy = xdoc.CreateElement("LastEditBy");
                taskLastEditBy.InnerText = Task.LastEditBy;
                taskNode.AppendChild(taskLastEditBy);

                tasksNode.AppendChild(taskNode);

                xdoc.InnerXml = XmlEncryption.encryptXml(xdoc.InnerXml);

                xdoc.Save(fil);
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 6
0
        public void SendMessage(Lan.NetworkUser User, string Message, string[] Files)
        {
            try
            {
                string toSend = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>";
                toSend += "<envelope><user>" + Environment.UserName + "</user><computer>" + Environment.MachineName + "</computer>";

                toSend += "<ip>" + User.IPAddress + "</ip>";
                toSend += "<presence>" + Enum.GetName(typeof(Lan.Presence), User.Presence) + "</presence>";
                toSend += "<timestamp>" + DateTime.Now.ToString() + "</timestamp>";
                toSend += "<message>" + Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(Message)) + "</message>";
                toSend += "</envelope>";
                string enc_toSend = XmlEncryption.encryptXml(toSend);

                Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                s.SendTimeout = (int)Settings.Default.Timeout;
                s.Connect(User.IPAddress, (int)Settings.Default.ChatPort);
                byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(enc_toSend);
                int    i           = s.Send(bytesToSend);
                s.Close();


                //send files
                if (Files.Length > 0)
                {
                    foreach (string file in Files)
                    {
                        Thread.Sleep(1000);
                        sendFile(file, User);

                        if (FileSent != null)
                        {
                            FileSent(Files.Length);
                        }
                    }
                }

                if (MessageSent != null)
                {
                    MessageSent();
                }
            }
            catch (Exception ex)
            {
                //fire the event alertin to a lost user User...
                // userOffline(User);
            }
        }
Esempio n. 7
0
        public static void DeleteTask(string Id)
        {
            XmlDocument xdocEn = new XmlDocument();

            xdocEn.Load(fil);

            XmlDocument xdoc      = new XmlDocument();
            string      decRypted = XmlEncryption.decryptXml(xdocEn.InnerXml);

            xdoc.LoadXml(decRypted);

            XmlNode task = xdoc.SelectSingleNode("Tasks/Task[@TaskId='" + Id + "']");

            xdoc.DocumentElement.RemoveChild(task);

            xdoc.InnerXml = XmlEncryption.encryptXml(xdoc.InnerXml);
            xdoc.Save(fil);
        }
Esempio n. 8
0
        private static List <Task> getTasksFromXml()
        {
            List <Task> tasks = new List <Task>();

            try
            {
                if (!File.Exists(fil))
                {
                    return(null);
                }

                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(fil);
                XmlDocument xx = new XmlDocument();
                xx.LoadXml(XmlEncryption.decryptXml(xdoc.InnerXml));

                XmlNodeList tasksNodes = xx.SelectNodes("Tasks/Task");

                if (tasksNodes != null)
                {
                    for (int i = 0; i < tasksNodes.Count; i++)
                    {
                        XmlNode task = tasksNodes[i];

                        Task t = new Task();
                        t.LastEditBy   = task.SelectSingleNode("LastEditBy").InnerText;
                        t.LastEditDate = DateTime.Parse(task.SelectSingleNode("LastEditDate").InnerText);
                        t.TaskDetails  = task.SelectSingleNode("TaskDetails").InnerText;
                        t.TaskId       = task.Attributes["TaskId"].InnerText;
                        t.TaskStatus   = (TaskStatus)Enum.Parse(typeof(TaskStatus), task.SelectSingleNode("TaskStatus").InnerText);
                        t.TaskTitle    = task.SelectSingleNode("TaskTitle").InnerText;
                        tasks.Add(t);
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(tasks);
        }
Esempio n. 9
0
        public static void UpdateTask(Task Task)
        {
            XmlDocument xdocEn = new XmlDocument();

            xdocEn.Load(fil);

            XmlDocument xdoc = new XmlDocument();

            xdoc.Load(XmlEncryption.decryptXml(xdocEn.InnerXml));

            XmlNode task = xdoc.SelectSingleNode("Tasks/Task[@TaskId='" + Task.TaskId + "']");

            task.SelectSingleNode("TaskDetails").InnerText  = Task.TaskDetails;
            task.SelectSingleNode("LastEditBy").InnerText   = Task.LastEditBy;
            task.SelectSingleNode("LastEditDate").InnerText = Task.LastEditDate.ToString();
            task.SelectSingleNode("TaskStatus").InnerText   = Enum.GetName(typeof(TasksLocalShare.TaskStatus), Task.TaskStatus);

            xdoc.InnerXml = XmlEncryption.encryptXml(xdoc.InnerXml);
            xdoc.Save(fil);
        }
Esempio n. 10
0
        public static void CreateTaskFile(string Path)
        {
            Path += @"\Tasks.xml.txt";
            if (!File.Exists(Path))
            {
                try
                {
                    // System.Security.AccessControl.FileSecurity acs = new System.Security.AccessControl.FileSecurity();

                    FileStream fs;
                    fs = new FileStream(Path, FileMode.Create, FileAccess.Write);// File.Create(Path);//,0, FileOptions.None, acs);
                    string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Tasks></Tasks>";
                    xml = XmlEncryption.encryptXml(xml);
                    byte[] bits = ASCIIEncoding.ASCII.GetBytes(xml);
                    fs.Write(bits, 0, bits.Length);
                    fs.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// creates or opens the task file
        /// </summary>
        public static void CreateTaskFile()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Tasks></Tasks>";

            xml = XmlEncryption.encryptXml(xml);
            string Uri = "ftp://" + Settings.Default.FTPHost + @"/Tasks.xml.txt";

            NetworkCredential nc = new NetworkCredential();

            nc.UserName = Settings.Default.FTPUser;
            nc.Password = Settings.Default.FTPPassword;

            FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(Uri);

            request.Method      = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = nc;

            MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml));

            StreamReader sourceStream = new StreamReader(ms);

            byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();
            request.ContentLength = fileContents.Length;

            Stream requestStream = request.GetRequestStream();

            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

            response.Close();
        }