Ejemplo n.º 1
0
        public async Task List(HttpProcessor arg)
        {
            if (arg.Request.Query.ContainsKey("dir"))
            {
                var dir = arg.Request.Query["dir"];
                if (!string.IsNullOrWhiteSpace(dir))
                {
                    if (!dir.EndsWith("\\"))
                    {
                        dir += "\\";
                    }

                    var dirInfos = Directory.GetDirectories(dir).Select(x =>
                    {
                        var attr = new System.IO.DirectoryInfo(x);
                        return new StorageItemInfo(attr);
                    }).ToList();

                    await arg.WriteJson(dirInfos);
                    return;
                }
            }

            var drives = Directory.GetLogicalDrives();
            var drivesInfo = drives.Select(x =>
            {
                var attr = new System.IO.DirectoryInfo(x);
                return new StorageItemInfo(attr);
            }).ToList();

            await arg.WriteJson(drivesInfo);
        }
Ejemplo n.º 2
0
        public async Task List(HttpProcessor arg)
        {
            if (arg.Request.Query.ContainsKey("dir"))
            {
                var dir = arg.Request.Query["dir"];
                if (!string.IsNullOrWhiteSpace(dir))
                {
                    if (!dir.EndsWith("\\"))
                    {
                        dir += "\\";
                    }

                    var dirInfos = Directory.GetFiles(dir).Select(x =>
                    {
                        var attr = new System.IO.DirectoryInfo(x);
                        return new StorageItemInfo(attr);
                    }).ToList();

                    await arg.WriteJson(dirInfos);
                    return;
                }
            }

            await arg.WriteFail(HttpStatusCode.BadRequest);
        }
Ejemplo n.º 3
0
        public override async Task HandlePOSTRequest(HttpProcessor p)
        {
            Console.WriteLine("{0} {1}", p.Request.Method, p.Request.URL);

            var action = RouteHelper.ResolvePost(p.Request.URL);

            if (action == null)
            {
                await p.WriteFail(HttpStatusCode.NotFound);
                return;
            }

            await action.Invoke(p);
        }
Ejemplo n.º 4
0
        public async void Start()
        {
            if (this.Port == 0)
            {
                Console.WriteLine("Port must be configured!");
                return;
            }

            Console.WriteLine("Server lanuching");

            var ipAdresses = await Dns.GetHostEntryAsync("localhost");
            this.IPAddress = ipAdresses.AddressList.FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork) ?? ipAdresses.AddressList.First();

            listener = new TcpListener(this.IPAddress, this.Port);
            listener.Start();

            Console.WriteLine("Server started on {0}:{1}", this.IPAddress, this.Port);

            IsActive = true;
            while (IsActive)
            {
                var delayTask = Task.Delay(1000);
                var sTask = listener.AcceptTcpClientAsync();

                var s = await Task.WhenAny(delayTask, sTask);

                if (s == sTask)
                {
                    var processor = new HttpProcessor(sTask.Result);
                    processor.Process();
                    await Task.Delay(1);
                }

                if (terminate)
                {
                    IsActive = false;
                }
            }
        }
Ejemplo n.º 5
0
 public abstract Task HandlePOSTRequest(HttpProcessor p);