Ejemplo n.º 1
0
    public IObjects Get(IObjects request)
    {
        FileListRequest req = (FileListRequest)request;

        // получили запрос. там внутри есть пользователь и дерево нужно туда для него засунуть

        // вообще, для файлов установлена группа, которая может его смотреть. смотрим у пользователя какая категория есть.
        // если совпадает - можем ему показать этот файлик
        // если в директории нет файлов, которые может смотреть этот пользователь - и директорию ему не показываем


        //files = new WatchingFileRights();
        //users = new WatchingUsers();
        currentUser = request.User;

        // есть начальная директория. есть пользователь, есть набор прав для него, есть для каждого файла набор групп которым можно его читать
        FileTree answer = new FileTree();

        // сюда запишем дерево файлов
        answer.FileList = MakeTree(Treeroot);

        req.answer = answer;

        return(req);
    }
Ejemplo n.º 2
0
        private void SendFileList(SimpleSocketSession <SocketData> session, FileListRequest request)
        {
            string            path  = request.Path;
            List <RemoteFile> files = new List <RemoteFile>();

            if (string.IsNullOrEmpty(path))
            {
                files = DriveInfo.GetDrives().Select(p => p.RootDirectory).Select(p => new RemoteFile(p, false)).ToList();
            }
            else
            {
                foreach (var dir in new DirectoryInfo(path).EnumerateFileSystemInfos())
                {
                    var file = new RemoteFile(dir, true);
                    files.Add(file);
                }
            }
            var data = new FileListResponse()
            {
                Files = files.OrderByDescending(p => p.IsDir).ToList(), Path = path
            };
            SocketData resp = new SocketData(Response, SocketDataAction.FileListResponse, data);

            Send(session, resp);
        }
Ejemplo n.º 3
0
        public async Task <FileListResponse> GetRemoteFileListAsync(string root)
        {
            var data = new FileListRequest()
            {
                Path = root
            };
            var request = new SocketData(Request, SocketDataAction.FileListRequest, data);

            Client.Session.Send(request);
            var resp = await Client.Session.WaitForNextReceiveAsync(Config.Instance.CommandTimeout);

            return(resp.Get <FileListResponse>());
        }
Ejemplo n.º 4
0
        public Task <Result> RequestFileListAsync(ServerInfo remoteServerInfo)
        {
            var fileListRequest = new FileListRequest
            {
                LocalServerInfo    = MyInfo,
                RemoteServerInfo   = remoteServerInfo,
                TransferFolderPath = remoteServerInfo.TransferFolder,
                Status             = RequestStatus.InProgress,
                Direction          = TransferDirection.Outbound
            };

            return(_requestHandler.SendRequestAsync(fileListRequest));
        }
Ejemplo n.º 5
0
 public async Task Files_List()
 {
     var request = new FileListRequest
     {
         Cursor = "BBB",
         ShowFilesHidenByLimit = true,
         User = "******"
     };
     await Utility.AssertEncodedWebApi(c => c.Files.List(request), "files.list", "Web_FilesList.json", nvc =>
     {
         Assert.Equal("BBB", nvc["cursor"]);
         Assert.Equal("W123", nvc["user"]);
         Assert.Equal("true", nvc["show_files_hidden_by_limit"]);
     });
 }
Ejemplo n.º 6
0
        public override Task <FileListResponse> GetFileList(FileListRequest request, ServerCallContext context)
        {
            var bubu = _testGoogleDrive.GetFileList();

            var fileListResponse = new FileListResponse();

            foreach (var item in bubu)
            {
                fileListResponse.FileList.Add(new FileData()
                {
                    FileName = item.Name, Id = item.Id
                });
            }

            return(Task.FromResult(fileListResponse));
        }
Ejemplo n.º 7
0
        public static async Task <FileListResponse> GetFileListAsync(SlackClient slackClient, string channelName)
        {
            var uploadFileResponse = await UploadFileAsync(slackClient, channelName);

            await UploadContentAsync(slackClient, channelName);

            // Because of slack cache... Files upload instantly, but they attach to group delayed
            await Task.Delay(30000);

            var firstFile       = uploadFileResponse.File;
            var fileListRequest = new FileListRequest
            {
                ChannelId     = firstFile.ChannelIds.FirstOrDefault() ?? firstFile.GroupIds.FirstOrDefault(),
                TimestampFrom = firstFile.CreatedTimestamp.ToString(),
            };

            return(await slackClient.Files.ListAsync(fileListRequest));
        }
Ejemplo n.º 8
0
        private static FileListRequest ToFileListRequst(SlackRequest slackRequest)
        {
            var slackRequestTextList = ToSlackRequestTextList(slackRequest.text);

            var timeStampFrom = GetTimeStampFrom(slackRequestTextList);
            var timeStampTo   = GetTimeStampTo(slackRequestTextList);
            var channel       = GetTargetChannel(slackRequestTextList, slackRequest.channel_id);
            var user          = GetTargetUser(slackRequestTextList, slackRequest.user_id);

            var request = new FileListRequest
            {
                Token   = token,
                From    = timeStampFrom,
                To      = timeStampTo,
                Channel = channel,
                User    = user
            };

            return(request);
        }
Ejemplo n.º 9
0
 public Task <FileListResponse> List(FileListRequest request)
 {
     return(_client.MakeUrlEncodedCall <FileListResponse>("files.list", request));
 }
Ejemplo n.º 10
0
        public IActionResult GetFileInfoList([FromBody] FileListRequest request)
        {
            #region 获取数据
            FileInfo[] list = GetHostDirectoryInfo().GetFiles();
            #endregion

            string[] exceptFiles = new string[] { "clrcompression.dll", "clretwrc.dll", "clrjit.dll", "coreclr.dll", "dbgshim.dll", "hostfxr.dll", "hostpolicy.dll"
                                                  , "mscordaccore.dll", "mscordaccore_amd64_amd64_4.6.27414.05.dll", "mscordbi.dll", "mscorlib.dll", "mscorrc.debug.dll", "mscorrc.dll", "netstandard.dll"
                                                  , "sni.dll", "sos.dll", "SOS.NETCore.dll", "sos_amd64_amd64_4.6.27414.05.dll", "ucrtbase.dll", "WindowsBase.dll" };//默认不显示的文件

            #region 搜索、排序、分页
            if (list != null && list.Any())
            {
                if (!string.IsNullOrWhiteSpace(request.Name))
                {
                    list = list.Where(f => f.Name.Contains(request.Name.Trim(), StringComparison.OrdinalIgnoreCase)).ToArray();
                }
                if (request.CreateTimeStart.HasValue)
                {
                    list = list.Where(f => f.CreationTime >= request.CreateTimeStart).ToArray();
                }
                if (request.CreateTimeEnd.HasValue)
                {
                    list = list.Where(f => f.CreationTime <= request.CreateTimeEnd).ToArray();
                }
                if (request.AccessTimeStart.HasValue)
                {
                    list = list.Where(f => f.LastAccessTime >= request.AccessTimeStart).ToArray();
                }
                if (request.AccessTimeEnd.HasValue)
                {
                    list = list.Where(f => f.LastAccessTime <= request.AccessTimeEnd).ToArray();
                }
                if (request.WriteTimeStart.HasValue)
                {
                    list = list.Where(f => f.LastWriteTime >= request.WriteTimeStart).ToArray();
                }
                if (request.WriteTimeEnd.HasValue)
                {
                    list = list.Where(f => f.LastWriteTime <= request.WriteTimeEnd).ToArray();
                }
                if (!request.ShowDefaultDLL)
                {
                    list = list.Where(f => (
                                          !f.Name.StartsWith("api-ms", StringComparison.OrdinalIgnoreCase) &&
                                          !f.Name.StartsWith("Microsoft", StringComparison.OrdinalIgnoreCase) &&
                                          !f.Name.StartsWith("System", StringComparison.OrdinalIgnoreCase) &&
                                          !f.Name.StartsWith("mscordaccore_amd64_amd64", StringComparison.OrdinalIgnoreCase) &&
                                          !f.Name.StartsWith("sos_amd64_amd64", StringComparison.OrdinalIgnoreCase)
                                          )).ToArray();

                    foreach (string item in exceptFiles)
                    {
                        list = list.Where(f => !f.Name.Equals(item, StringComparison.OrdinalIgnoreCase)).ToArray();
                    }
                }

                int  orderIndex = request.Order[0].Column;
                bool isAsc      = request.Order[0].Dir.Equals("asc", StringComparison.OrdinalIgnoreCase);
                switch (orderIndex)
                {
                case 1:    //Name
                    if (isAsc)
                    {
                        list = list.OrderBy(f => f.Name).ToArray();
                    }
                    else
                    {
                        list = list.OrderByDescending(f => f.Name).ToArray();
                    }
                    break;

                case 2:    //Length
                    if (isAsc)
                    {
                        list = list.OrderBy(f => f.Length).ToArray();
                    }
                    else
                    {
                        list = list.OrderByDescending(f => f.Length).ToArray();
                    }
                    break;

                case 3:    //CreationTime
                    if (isAsc)
                    {
                        list = list.OrderBy(f => f.CreationTime).ToArray();
                    }
                    else
                    {
                        list = list.OrderByDescending(f => f.CreationTime).ToArray();
                    }
                    break;

                case 4:    //LastAccessTime
                    if (isAsc)
                    {
                        list = list.OrderBy(f => f.LastAccessTime).ToArray();
                    }
                    else
                    {
                        list = list.OrderByDescending(f => f.LastAccessTime).ToArray();
                    }
                    break;

                case 5:    //LastWriteTime
                    if (isAsc)
                    {
                        list = list.OrderBy(f => f.LastWriteTime).ToArray();
                    }
                    else
                    {
                        list = list.OrderByDescending(f => f.LastWriteTime).ToArray();
                    }
                    break;

                default:
                    break;
                }

                int pageIndex = request.Start / request.Length;//从第0页开始
                list = list.Skip(pageIndex * request.Length).Take(request.Length).ToArray();
            }
            #endregion
            //string url = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToString()}";
            #region 返回数据
            List <object[]> retTable = new List <object[]>();
            if (list != null && list.Any())
            {
                int index = 1;
                foreach (FileInfo item in list)
                {
                    #region 填充一行
                    List <object> retRow = new List <object>();
                    retRow.Add(index);
                    retRow.Add(item.Name);
                    retRow.Add(item.Length);         //字节
                    retRow.Add(item.CreationTime);   //创建时间
                    retRow.Add(item.LastAccessTime); //访问时间
                    retRow.Add(item.LastWriteTime);  //写入时间

                    StringBuilder btnHtml = new StringBuilder();
                    //btnHtml.AppendFormat("<a class='btn btn-xs btn-success' traget='_blank' href='{0}/api/Job/Download/{1}'><i class='fa fa-cloud-download'>下载</i></a>", url, Common.Util.Encrypt.Encrypt.MD5By32(item.FullName));
                    //btnHtml.AppendFormat("<a class='btn btn-xs btn-success' traget='_blank' href='/JobManager/Download/{0}'><i class='fa fa-cloud-download'>下载</i></a>", Common.Util.Encrypt.Encrypt.MD5By32(item.FullName));
                    btnHtml.AppendFormat("<a class='btn btn-xs btn-success' href='javascript:;' onclick='downloadFile(\"{0}\",this)'><i class='fa fa-cloud-download'>下载</i></a>", Common.Util.Encrypt.Encrypt.MD5By32(item.FullName));
                    retRow.Add(btnHtml.ToString());
                    retTable.Add(retRow.ToArray());
                    #endregion
                    index++;
                }
            }
            return(Json(new TableResult(retTable, request.Draw, list == null ? 0 : list.Length)));

            #endregion
        }
Ejemplo n.º 11
0
        async void HandleFileListRequest(object sender, FileListRequest fileListRequest)
        {
            MyInfo.TransferFolder = fileListRequest.TransferFolderPath;

            _eventLog.Add(new ServerEvent
            {
                EventType              = EventType.ReceivedFileListRequest,
                RemoteServerIpAddress  = fileListRequest.RemoteServerInfo.SessionIpAddress,
                RemoteServerPortNumber = fileListRequest.RemoteServerInfo.PortNumber,
                LocalFolder            = MyInfo.TransferFolder
            });

            EventOccurred?.Invoke(this, _eventLog.Last());

            if (!Directory.Exists(MyInfo.TransferFolder))
            {
                var foldesDoesNotExist = new Request(RequestType.RequestedFolderDoesNotExist)
                {
                    LocalServerInfo  = MyInfo,
                    RemoteServerInfo = fileListRequest.RemoteServerInfo,
                    Status           = RequestStatus.InProgress,
                    Direction        = TransferDirection.Outbound
                };

                await _requestHandler.SendRequestAsync(foldesDoesNotExist);

                return;
            }

            var fileInfoList = new FileInfoList(MyInfo.TransferFolder);

            if (fileInfoList.Count == 0)
            {
                var folderIsEmpty = new Request(RequestType.RequestedFolderIsEmpty)
                {
                    LocalServerInfo  = MyInfo,
                    RemoteServerInfo = fileListRequest.RemoteServerInfo,
                    Status           = RequestStatus.InProgress,
                    Direction        = TransferDirection.Outbound
                };

                await _requestHandler.SendRequestAsync(folderIsEmpty);

                return;
            }

            var fileListResponse = new FileListResponse
            {
                LocalServerInfo  = MyInfo,
                RemoteServerInfo = fileListRequest.RemoteServerInfo,
                FileInfoList     = fileInfoList,
                Status           = RequestStatus.InProgress,
                Direction        = TransferDirection.Outbound
            };

            var sendRequest = await _requestHandler.SendRequestAsync(fileListResponse);

            if (sendRequest.Failure)
            {
                return;
            }

            SuccessfullyProcessedRequest?.Invoke(this, fileListRequest);
        }