Beispiel #1
0
        public void Add(ClientComponent client, ServerComponent server, GroupComponent group)
        {
            Entity entity = new Entity();

            entity.Add(client);

            ClientOptionsComponent options = new ClientOptionsComponent();

            entity.Add(options);

            entity.Add(server);

            entity.Add(group);

            FolderListComponent folderList = new FolderListComponent();

            entity.Add(folderList);

            FileMapComponent fileMap = new FileMapComponent();

            entity.Add(fileMap);

            FolderMapComponent folderMap = new FolderMapComponent();

            entity.Add(folderMap);

            ClientMachineComponent machine = new ClientMachineComponent();

            entity.Add <MachineComponent>(machine);

            SessionComponent session = new SessionComponent();

            entity.Add(session);

            FileComponent file = new FileComponent();

            entity.Add(file);

            SearchListComponent search = new SearchListComponent(SearchController.Dispatcher);

            entity.Add(search);

            BrowseComponent browse = new BrowseComponent();

            entity.Add(browse);

            DownloadListComponent download = new DownloadListComponent(DownloadController.Dispatcher);

            entity.Add(download);

            UploadListComponent upload = new UploadListComponent(UploadController.Dispatcher);

            entity.Add(upload);
#if DEBUG
            LogComponent log = new LogComponent(LogController);
            entity.Add(log);
#endif
            Add(entity);
        }
Beispiel #2
0
        public override void Add(FileComponent file)
        {
            Entity entity = file.Owner;
            FolderListComponent folders = entity.Get <FolderListComponent>();

            folders.Add(file);

            View.Clear();
        }
Beispiel #3
0
        private void WriteFolders(XmlWriter writer, Entity entity)
        {
            FolderListComponent files = entity.Get <FolderListComponent>();

            writer.WriteStartElement(XmlTag.Folders);

            foreach (FileComponent file in files)
            {
                writer.WriteElementString(XmlTag.Path, file.Path);
            }

            writer.WriteEndElement();
        }
Beispiel #4
0
        public override bool Remove(FileComponent file)
        {
            bool removed = false;

            if (file.Drive)
            {
                Entity entity = file.Owner;
                FolderListComponent folders = entity.Get <FolderListComponent>();
                removed = folders.Remove(file);

                if (removed)
                {
                    View.Clear();
                }
            }

            return(removed);
        }
Beispiel #5
0
        public override void Add(Entity entity)
        {
            base.Add(entity);

            // Events
            ClientComponent client = entity.Get <ClientComponent>();

            client.ComponentChanged += Update;

            FolderListComponent folders = entity.Get <FolderListComponent>();

            folders.ComponentChanged += FileController.Update;

            ClientMachineComponent machine = (ClientMachineComponent)entity.Get <MachineComponent>();

            machine.ListAdded += SearchController.Add;


            MenuController.Add(entity);
        }
Beispiel #6
0
        private void ReadClient(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            bool   loop = true;
            string name = null;

            // Components
            Entity                 entity  = new Entity();
            ClientComponent        client  = new ClientComponent();
            ClientOptionsComponent options = new ClientOptionsComponent();

            GroupComponent  group  = new GroupComponent();
            ServerComponent server = new ServerComponent();
            List <string>   paths  = new List <string>();

            client.Enabled = bool.Parse(reader.GetAttribute(XmlTag.Enabled));

            while (loop && reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    name = reader.Name;

                    switch (name)
                    {
                    case XmlTag.Router:
                    {
                        ReadRouter(reader, ref server);
                        break;
                    }

                    case XmlTag.Options:
                    {
                        ReadOptions(reader, ref options);
                        break;
                    }

                    case XmlTag.Folders:
                    {
                        ReadFolders(reader, ref paths);
                        break;
                    }
                    }

                    break;
                }

                case XmlNodeType.Text:
                {
                    switch (name)
                    {
                    case XmlTag.Id:
                    {
                        entity.Id = reader.Value;
                        break;
                    }

                    case XmlTag.Name:
                    {
                        client.Name = reader.Value;
                        break;
                    }

                    case XmlTag.Download:
                    {
                        client.Download = reader.Value;
                        break;
                    }

                    case XmlTag.Group:
                    {
                        group.Path = reader.Value;
                        break;
                    }
                    }

                    break;
                }

                case XmlNodeType.EndElement:
                {
                    if (XmlTag.Client.Equals(reader.Name))
                    {
                        loop = false;
                    }

                    break;
                }
                }
            }

            // Components
            entity.Add(client);
            entity.Add(options);
            entity.Add(group);
            entity.Add(server);

            FolderListComponent folderList = new FolderListComponent();

            entity.Add(folderList);

            FileMapComponent fileMap = new FileMapComponent();

            entity.Add(fileMap);

            FolderMapComponent folderMap = new FolderMapComponent();

            entity.Add(folderMap);

            ClientMachineComponent machine = new ClientMachineComponent();

            entity.Add <MachineComponent>(machine);

            SessionComponent session = new SessionComponent();

            entity.Add(session);

            FileComponent file = new FileComponent();

            entity.Add(file);

            SearchListComponent search = new SearchListComponent(SearchController.Dispatcher);

            entity.Add(search);

            BrowseComponent browse = new BrowseComponent();

            entity.Add(browse);

            DownloadListComponent download = new DownloadListComponent(DownloadController.Dispatcher);

            entity.Add(download);

            UploadListComponent upload = new UploadListComponent(UploadController.Dispatcher);

            entity.Add(upload);
#if DEBUG
            LogComponent log = new LogComponent(LogController);
            entity.Add(log);
#endif
            ClientController.Add(entity);

            foreach (string path in paths)
            {
                FileComponent shared = new FileComponent(path)
                {
                    Owner = entity
                };
                folderList.Add(shared);
            }
        }
Beispiel #7
0
        public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest)
        {
            Clear();

            // Connect
            NetworkChannel channel = new NetworkChannel(Connection);

            // Request
            JsonBrowseRequestMessage jsonRequestMessage = JsonBrowseRequestMessage.Parse(jsonRequest.Message);
            JsonBrowseRequestData    jsonRequestData    = JsonBrowseRequestData.Parse(Group.Decrypt(jsonRequest.Data));
            JsonFile jsonFolder = (jsonRequestData != null) ? jsonRequestData.Folder : null;

            // Data
            List <JsonFile> folders = new List <JsonFile>();
            List <JsonFile> files   = new List <JsonFile>();

            if (jsonFolder != null)
            {
                FileComponent file = FolderMap.Get(jsonFolder.Id);

                if (file == null)
                {
                    channel.SendNotFound();
                    return;
                }

                // Folders
                foreach (FileComponent f in file.Folders)
                {
                    JsonFile json = (JsonFile)f;
                    folders.Add(json);
                }

                // Files
                foreach (FileComponent f in file.Files)
                {
                    JsonFile json = (JsonFile)f;
                    files.Add(json);
                }
            }
            else
            {
                // Folders
                FolderListComponent shared = Entity.Get <FolderListComponent>();

                foreach (FileComponent f in shared)
                {
                    JsonFile json = (JsonFile)f;
                    folders.Add(json);
                }
            }

            // Response
            JsonBrowseResponseMessage jsonResponseMessage = new JsonBrowseResponseMessage();
            JsonBrowseResponseData    jsonResponseData    = new JsonBrowseResponseData()
            {
                Files = files, Folders = folders
            };
            JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage, Group.Encrypt(jsonResponseData));

            HttpResponse httpResponse = new HttpResponse()
            {
                Data = Session.Encrypt(jsonResponse)
            };

            channel.Send(httpResponse);
#if DEBUG
            Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
        }