public async Task <ResponseMessage> UploadFile(UserInfo user, [FromBody] FileInfoRequest fileInfoRequest, [FromQuery] string source, [FromRoute] string dest, [FromRoute] string buildingId)
        {
            ResponseMessage response = new ResponseMessage();

            if (!ModelState.IsValid)
            {
                response.Code    = ResponseCodeDefines.ArgumentNullError;
                response.Message = ModelState.GetAllErrors();
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})上传文件信息(UploadFile)模型验证失败:\r\n{response.Message ?? ""},请求参数为:\r\n(source){source},(dest){dest},(buildingId){buildingId}," + (fileInfoRequest != null ? JsonHelper.ToJson(fileInfoRequest) : ""));
                return(response);
            }
            try
            {
                await _fileScopeManager.CreateAsync(user, dest, buildingId, fileInfoRequest, HttpContext.RequestAborted);

                NameValueCollection nameValueCollection = new NameValueCollection();
                nameValueCollection.Add("appToken", "app:nwf");
                var nwf = CreateNwf(user, source, fileInfoRequest);
                Logger.Info("nwf协议:\r\n{0}", JsonHelper.ToJson(nwf));
                string response2 = await _restClient.Post(ApplicationContext.Current.NWFUrl, nwf, "POST", nameValueCollection);

                Logger.Info("返回:\r\n{0}", response2);
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})上传文件信息(UploadFile)报错:\r\n{e.ToString()},请求参数为:\r\n(source){source ?? ""},(dest){dest ?? ""},(buildingId){buildingId ?? ""}," + (fileInfoRequest != null ? JsonHelper.ToJson(fileInfoRequest) : ""));
            }
            return(response);
        }
Example #2
0
        private async void LoadClick(object sender, RoutedEventArgs e)
        {
            string input = searchBox_Textbox.Text;

            if (ContainsSpecialChars(input))
            {
                MessageBox.Show("Input can only contain numbers & alphanumeric characters");
                return;
            }

            // Server request
            ImageAnimationController controller = ImageBehavior.GetAnimationController(loadingGif_Image);

            controller.Play();

            Connection connection = new Connection();

            status_Textblock.Text = "Connecting...";
            await connection.Connect(Settings.Default.ServerIP, Settings.Default.ServerPort);

            status_Textblock.Text = "Connected";
            FileInfoRequest request = new FileInfoRequest(input);

            status_Textblock.Text = "Checking for file...";
            await connection.SendPacket(request);

            FileInfoResponse response = await connection.ReceivePacket() as FileInfoResponse;

            connection.Close();
            await Task.Delay(1000);

            status_Textblock.Text = "Got response...";
            controller.Pause();

            if (response != null && response.Exists)
            {
                DownloadWindow window = new DownloadWindow(response.File);
                window.Owner = this;
                window.Show();
                window.Closing += DownloadWindowClosing;

                windows.Add(window);
            }
            else
            {
                status_Textblock.Text = "Invalid response!";
            }
        }
Example #3
0
        /// <summary>
        /// Bekijkt wat voor soort packet er is gestuurd.
        /// </summary>
        /// <param name="jsonData"></param>
        /// <param name="socket"></param>
        private void HandlePacket(dynamic jsonData, StateObject state)
        {
            string packetType = (string)jsonData.packetType;

            switch (packetType)
            {
            case nameof(FileInfoRequest):
                HandleFileInfoRequest(FileInfoRequest.ToClass(jsonData), state);
                break;

            case nameof(FileDownloadRequest):
                HandleFileDownloadRequest(FileDownloadRequest.ToClass(jsonData), state.Client);
                break;

            case nameof(FileUploadRequest):
                HandleFileUploadRequest(FileUploadRequest.ToClass(jsonData), state.Client);
                break;

            default:
                break;
            }
        }
Example #4
0
        /// <summary>
        /// Handelt een bestand info aanvraag af.
        /// </summary>
        /// <param name="request"></param>
        private void HandleFileInfoRequest(FileInfoRequest request, StateObject state)
        {
            string path = Settings.Default.FileFolder + request.ID;
            string fileWithExtension = NetworkUtils.GetAssociatedFile(Settings.Default.FileFolder, request.ID);
            bool   exists            = File.Exists(fileWithExtension);


            FileInfoResponse response = new FileInfoResponse();

            if (exists)
            {
                string      text = File.ReadAllText(path + ".json");
                dynamic     json = JsonConvert.DeserializeObject(text);
                NetworkFile file = Util.NetworkUtils.FromJson(json);
                FileInfo    fi   = new FileInfo(fileWithExtension);

                file.FileSize     = fi.Length;
                file.CreationDate = fi.CreationTimeUtc;
                response          = new FileInfoResponse(file);
            }
            //state.Client.Socket.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReceiveMessageCallback, state);
            SendPacket(state.Client, response, SendCallback, FollowUpTask.RECEIVE_MSG);
        }
        public async Task <ResponseMessage <string> > UploadFiles(UserInfo user, [FromBody] FileInfoRequest fileInfoRequests, [FromQuery] string source, [FromRoute] string dest)
        {
            ResponseMessage <string> response = new ResponseMessage <string>();

            if (fileInfoRequests == null)
            {
                response.Code    = ResponseCodeDefines.ArgumentNullError;
                response.Message = "请求参数错误";
                Logger.Warn($"用户{user?.UserName ?? ""}({user?.Id ?? ""})批量上传文件信息(UploadFiles)模型验证失败:\r\n{response.Message ?? ""},请求参数为:\r\n(source){source ?? ""},(dest){dest ?? ""}," + (fileInfoRequests != null ? JsonHelper.ToJson(fileInfoRequests) : ""));
                return(response);
            }

            try
            {
                NameValueCollection nameValueCollection = new NameValueCollection();
                var nwf = CreateNwf(user, source, fileInfoRequests);

                nameValueCollection.Add("appToken", "app:nwf");
                Logger.Info("nwf协议");
                string response2 = await _restClient.Post(ApplicationContext.Current.NWFUrl, nwf, "POST", nameValueCollection);

                Logger.Info("返回:\r\n{0}", response2);

                await _humanManage.CreateFileScopeAsync(user.Id, dest, fileInfoRequests, HttpContext.RequestAborted);

                response.Message = response2;
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.ToString();
                Logger.Error($"上传文件信息回调(FileCallback)模型验证失败:\r\n{e.ToString()},请求参数为:\r\n" + (fileInfoRequests != null ? JsonHelper.ToJson(fileInfoRequests) : ""));
            }


            return(response);
        }
        private NWF CreateNwf(UserInfo user, string source, FileInfoRequest fileInfoRequest)
        {
            NWF nwf      = new NWF();
            var bodyinfo = new BodyInfoType();
            var header   = new HeaderType();

            bodyinfo.FileInfo = new List <FileInfoType>();

            nwf.BodyInfo = bodyinfo;
            nwf.Header   = header;


            header.TaskGuid     = "";
            header.ContentGuid  = fileInfoRequest.SourceId;
            header.Action       = "ImageProcess";
            header.SourceSystem = source;

            header.ExtraAttribute = new List <AttributeType>();
            header.ExtraAttribute.Add(new AttributeType()
            {
                Name = "UserID", Value = user.Id
            });
            header.ExtraAttribute.Add(new AttributeType()
            {
                Name = "SubSystem", Value = "humanfile"
            });
            bodyinfo.Priority = 0;
            bodyinfo.TaskName = fileInfoRequest.Name;
            if (String.IsNullOrEmpty(bodyinfo.TaskName))
            {
                bodyinfo.TaskName = $"{user.UserName}-{source ?? ""}";
            }

            var extra = new List <AttributeType>();

            extra.Add(new AttributeType {
                Name = "WXAppID", Value = fileInfoRequest.AppId
            });
            extra.Add(new AttributeType {
                Name = "From", Value = fileInfoRequest.From
            });
            extra.Add(new AttributeType {
                Name = "Source", Value = fileInfoRequest.Source
            });
            extra.Add(new AttributeType {
                Name = "Name", Value = fileInfoRequest.Name
            });
            extra.Add(new AttributeType {
                Name = "FileExt", Value = fileInfoRequest.FileExt
            });
            bodyinfo.ExtraAttribute = extra;

            FileInfoType fileInfoType = new FileInfoType();

            fileInfoType.FilePath       = fileInfoRequest.WXPath;
            fileInfoType.FileExt        = fileInfoRequest.FileExt;
            fileInfoType.FileGuid       = fileInfoRequest.FileGuid;
            fileInfoType.QualityType    = 0;
            fileInfoType.FileTypeId     = "ROW";
            fileInfoType.ExtraAttribute = new List <AttributeType>();

            nwf.BodyInfo.FileInfo.Add(fileInfoType);
            return(nwf);
        }
        public virtual async Task CreateAsync(UserInfo user, string source, string buildingId, FileInfoRequest fileInfoRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (fileInfoRequest == null)
            {
                throw new ArgumentNullException(nameof(fileInfoRequest));
            }

            if (source == "shops")
            {
                var shopsfile = _mapper.Map <ShopsFileScope>(fileInfoRequest);
                shopsfile.IsDeleted = false;
                shopsfile.ShopsId   = fileInfoRequest.SourceId;

                await _shopsFileScopeStore.SaveAsync(_mapper.Map <SimpleUser>(user), buildingId, new List <ShopsFileScope>() { shopsfile }, cancellationToken);
            }
            else if (source == "building")
            {
                var buildingfile = _mapper.Map <BuildingFileScope>(fileInfoRequest);
                buildingfile.IsDeleted  = false;
                buildingfile.BuildingId = fileInfoRequest.SourceId;

                await _buildingFileScopeStore.SaveAsync(_mapper.Map <SimpleUser>(user), buildingId, new List <BuildingFileScope>() { buildingfile }, cancellationToken);
            }
            else if (source == "updaterecord")
            {
                var updateRecordfile = _mapper.Map <UpdateRecordFileScope>(fileInfoRequest);
                updateRecordfile.IsDeleted      = false;
                updateRecordfile.UpdateRecordId = fileInfoRequest.SourceId;
                await _updateRecordFileScopeStore.SaveAsync(_mapper.Map <SimpleUser>(user), buildingId, new List <UpdateRecordFileScope>() { updateRecordfile }, cancellationToken);
            }
            else if (source == "buildingnotice")
            {
                var buildingNoticeFile = _mapper.Map <BuildingNoticeFileScope>(fileInfoRequest);
                buildingNoticeFile.IsDeleted        = false;
                buildingNoticeFile.BuildingNoticeId = fileInfoRequest.SourceId;
                await _buildingNoticeFileScopeStore.SaveAsync(_mapper.Map <SimpleUser>(user), buildingId, new List <BuildingNoticeFileScope>() { buildingNoticeFile }, cancellationToken);
            }
        }
        public virtual async Task CreateAsync(UserInfo user, string source, string contractId, string modifyId, FileInfoRequest fileInfoRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (fileInfoRequest == null)
            {
                throw new ArgumentNullException(nameof(fileInfoRequest));
            }

            var contractfile = _mapper.Map <AnnexInfo>(fileInfoRequest);

            contractfile.IsDeleted     = false;
            contractfile.ContractID    = contractId;
            contractfile.CurrentModify = modifyId;
            if (string.IsNullOrEmpty(contractfile.ID))
            {
                contractfile.ID = Guid.NewGuid().ToString();
            }

            await _contractFileScopeStore.SaveAsync(_mapper.Map <SimpleUser>(user), contractId, new List <AnnexInfo>() { contractfile }, cancellationToken);
        }
 public async Task <GnmaTextFileResponse> GetGnmaTextFile([FromBody] FileInfoRequest request)
 {
     return(await this.fileDataAccess.GetGnmaTextFileAsync(request));
 }
 public async Task <FileInfoResponse> GetFileInfos([FromBody] FileInfoRequest request)
 {
     request.Path = this.appSettings.Value.GnmaTextFilePath;
     return(await this.fileDataAccess.GetFileInfosAsync(request));
 }
        public virtual async Task CreateFileScopeAsync(string userId, string humanid, FileInfoRequest fileInfoRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (fileInfoRequest == null)
            {
                throw new ArgumentNullException(nameof(fileInfoRequest));
            }

            var contractfile = _mapper.Map <AnnexInfo>(fileInfoRequest);

            if (string.IsNullOrEmpty(contractfile.ID))
            {
                contractfile.ID = humanid;
            }

            contractfile.CreateUser = userId;
            contractfile.CreateTime = DateTime.Now;

            await _Store.CreateAsync(contractfile, cancellationToken);
        }