示例#1
0
		public void Download(BrowseComponent browse)
		{
			Debug.Assert(browse != null);

			Entity entity = new Entity();
			EntityIdleComponent idle = new EntityIdleComponent();
			entity.Add(idle);

			EntityStoreComponent store = new EntityStoreComponent(browse.Owner);
			entity.Add(store);

			FileComponent file = new FileComponent(browse);
			entity.Add(file);

			TransferComponent transfer = new TransferComponent();
			entity.Add(transfer);

			DownloadMachineComponent machine = new DownloadMachineComponent(browse.ClientId);
			entity.Add<MachineComponent>(machine);
#if DEBUG
			LogComponent log = new LogComponent(LogController);
			entity.Add(log);
#endif
			Add(entity);
		}
示例#2
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);
        }
示例#3
0
        public List <BrowseComponent> Execute()
        {
            Clear();

            NetworkChannel         channel = null;
            List <BrowseComponent> list    = new List <BrowseComponent>();

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

                // Request
                JsonGroupRequestMessage jsonRequestMessage = new JsonGroupRequestMessage();
                JsonPacket jsonRequest = new JsonPacket(jsonRequestMessage);

                HttpRequest httpRequest = new HttpRequest(Session.Id)
                {
                    Data = Session.Encrypt(jsonRequest)
                };
                channel.Send(httpRequest);

                // Response
                HttpResponse httpResponse;
                channel.Receive(out httpResponse);
                Code = httpResponse.Code;

                if (httpResponse.Ok)
                {
                    JsonPacket jsonResponse = JsonPacket.Parse(Session.Decrypt(httpResponse.Data));
                    JsonGroupResponseMessage jsonResponseMessage = JsonGroupResponseMessage.Parse(jsonResponse.Message);

                    if (jsonResponseMessage != null)
                    {
                        // Clients
                        foreach (JsonClient jsonClient in jsonResponseMessage.Clients)
                        {
                            BrowseComponent browse = new BrowseComponent(jsonClient.Name)
                            {
                                ClientId = jsonClient.Id, Owner = Entity
                            };
                            list.Add(browse);
                        }
                    }
#if DEBUG
                    Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
                }
            }
            finally
            {
                if (channel != null)
                {
                    channel.Shutdown();
                }
            }

            return(list);
        }
示例#4
0
        private void BrowseTreeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeListItem item = WpfUtil.GetTreeListItem(e.OriginalSource);

            if (item == null)
            {
                return;
            }

            BrowseComponent browse = BrowseController.SelectedItem;

            if (browse != null)
            {
                if (browse.File)
                {
                    DownloadController.Download(browse);
                }
                else
                {
                    TreeNode node = BrowseTreeView.SelectedNode;

                    if (node != null)
                    {
                        if (Application.Current != null)
                        {
                            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(delegate
                            {
                                BrowseTreeView.SetIsExpanded(node, !node.IsExpanded);
                            }));
                        }
                    }
                }
            }

            BrowseTreeView.UnselectAll();
        }
示例#5
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);
            }
        }
示例#6
0
        public List <BrowseComponent> Execute(string clientId, string fileId)
        {
            Clear();

            NetworkChannel channel = null;

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

                // Request
                JsonClient jsonClient = new JsonClient(clientId);
                JsonBrowseRequestMessage jsonRequestMessage = new JsonBrowseRequestMessage()
                {
                    Client = jsonClient
                };

                JsonFile jsonFolder = !string.IsNullOrEmpty(fileId) ? new JsonFile(fileId) : null;
                JsonBrowseRequestData jsonRequestData = new JsonBrowseRequestData()
                {
                    Folder = jsonFolder
                };
                JsonPacket jsonRequest = new JsonPacket(jsonRequestMessage, Group.Encrypt(jsonRequestData));

                HttpRequest httpRequest = new HttpRequest(Session.Id)
                {
                    Data = Session.Encrypt(jsonRequest)
                };
                channel.Send(httpRequest);

                // Response
                HttpResponse httpResponse;
                channel.Receive(out httpResponse);
                Code = httpResponse.Code;

                if (httpResponse.Ok)
                {
                    JsonPacket jsonResponse = JsonPacket.Parse(Session.Decrypt(httpResponse.Data));
                    JsonBrowseResponseMessage jsonResponseMessage = JsonBrowseResponseMessage.Parse(jsonResponse.Message);
                    Debug.Assert(jsonResponseMessage != null);

                    JsonBrowseResponseData jsonResponseData = JsonBrowseResponseData.Parse(Group.Decrypt(jsonResponse.Data));
                    Debug.Assert(jsonResponseData != null);

                    // Data
                    List <BrowseComponent> list = new List <BrowseComponent>();

                    // Folders
                    if (jsonResponseData.Folders != null)
                    {
                        foreach (JsonFile json in jsonResponseData.Folders)
                        {
                            BrowseComponent comp = new BrowseComponent(json.Id, json.Name)
                            {
                                ClientId = jsonClient.Id, Owner = Entity
                            };
                            list.Add(comp);
                        }
                    }

                    // Files
                    if (jsonResponseData.Files != null)
                    {
                        foreach (JsonFile json in jsonResponseData.Files)
                        {
                            BrowseComponent comp = new BrowseComponent(json.Id, json.Name, json.Size)
                            {
                                ClientId = jsonClient.Id, Owner = Entity
                            };
                            list.Add(comp);
                        }
                    }
#if DEBUG
                    Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse);
#endif
                    return(list);
                }
            }
            finally
            {
                if (channel != null)
                {
                    channel.Shutdown();
                }
            }

            return(null);
        }