Ejemplo n.º 1
0
 public Block(FileNode parent, String content)
     : this()
 {
     this.parent = parent;
     this.content = content;
     MD5 md5 = new MD5CryptoServiceProvider();
     byte[] result = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(content));
     name = System.Text.Encoding.UTF8.GetString(result);
 }
Ejemplo n.º 2
0
 public void Scan()
 {
     this.Nodes.Clear();
     //Get all the files in this directory, not these directories
     FileInfo[] fileList = (info as DirectoryInfo).GetFiles();
     foreach (FileInfo fi in fileList)
     {
         FileNode subNode = new FileNode(fi.FullName);
         this.Nodes.Add(subNode);
     }
     //Get all the directories in this directory, not these files
     DirectoryInfo[] dirList = (info as DirectoryInfo).GetDirectories();
     foreach (DirectoryInfo di in dirList)
     {
         DirectoryNode subNode = new DirectoryNode(di.FullName);
         this.Nodes.Add(subNode);
         subNode.Scan();
     }
 }
Ejemplo n.º 3
0
        protected override async Task Handle(CDNMessage msg)
        {
            try
            {
                String content = "";
                switch (msg.id)
                {
                case CDNMessage.MSGID.TEST:
                {
                }
                break;

                case CDNMessage.MSGID.SHOW:
                {
                    localRoot.Scan();
                    content = Serializer <DirectoryNode> .Serialize <SoapFormatter>(localRoot);
                }
                break;

                case CDNMessage.MSGID.DOWNLOAD:
                {
                    FileNode node = Serializer <FileNode> .Deserialize <SoapFormatter>(msg.content);

                    FileNode localNode = localRoot.Find(node.Text) as FileNode;
                    if (localNode != null)
                    {
                        using (FileStream fs = File.OpenRead(localNode.info.FullName))
                        {
                            using (StreamReader sr = new StreamReader(fs))
                            {
                                msg.content = localNode.info.Name + "|||" + sr.ReadToEnd();

                                Send(new IPEndPoint(IPAddress.Parse(msg.From().address), msg.From().port), msg);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No such file!");
                    }

                    using (FileStream fs = File.OpenRead(node.info.FullName))
                    {
                        using (StreamReader sr = new StreamReader(fs))
                        {
                            content  = node.info.Name + "|||";
                            content += sr.ReadToEnd();
                        }
                    }
                }
                break;

                default:
                    break;
                }
                CDNMessage newMsg = msg.Clone() as CDNMessage;
                newMsg.Fill(msg.id, content);
                Send(new IPEndPoint(IPAddress.Parse(msg.From().address), msg.From().port), newMsg);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }