Exemple #1
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
            {
            }
        }
Exemple #2
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();
        }
Exemple #3
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)
            {
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
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);
                }
            }
        }
Exemple #8
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();
        }