コード例 #1
0
        public ActionResult GetItem(string fileId)
        {
            try
            {
                GetFileResponse payload = _indexService.GetFile(fileId);
                if (payload == null)
                {
                    return(Responses.NotFoundError(this, $"file {fileId} not found. Id is invalid, or has been deleted."));
                }

                if (payload.Content == null)
                {
                    throw new Exception($"File {fileId} has no content.");
                }

                return(File(payload.Content, "application/octet-stream", payload.FileName));
            }
            catch (InvalidFileIdentifierException)
            {
                return(Responses.InvalidFileId());
            }
            catch (Exception ex)
            {
                _log.LogError(ex, "An unexpected error occurred.");
                return(Responses.UnexpectedError());
            }
        }
コード例 #2
0
        private static SaveFileModel MapFileModel(GetFileResponse response)
        {
            var model = new SaveFileModel
            {
                Version               = response.Data.Version,
                FolderId              = response.Data.FolderId,
                Title                 = response.Data.Title,
                IsArchived            = response.Data.IsArchived,
                PublishedOn           = response.Data.PublishedOn,
                Description           = response.Data.Description,
                OriginalFileName      = response.Data.OriginalFileName,
                OriginalFileExtension = response.Data.OriginalFileExtension,
                FileUri               = response.Data.FileUri,
                PublicUrl             = response.Data.FileUrl,
                FileSize              = response.Data.FileSize,
                IsTemporary           = response.Data.IsTemporary,
                IsUploaded            = response.Data.IsUploaded,
                IsCanceled            = response.Data.IsCanceled,
                Tags = response.Tags != null?response.Tags.Select(t => t.Name).ToList() : null,
                           AccessRules = response.AccessRules,
                           ThumbnailId = response.Data.ThumbnailId,
                           Categories  = response.Data.Categories != null?response.Data.Categories.Select(t => t.Id).ToList() : null,
            };

            return(model);
        }
コード例 #3
0
ファイル: UploadDownloadFs3.cs プロジェクト: valiant-tms/PDM
        public void DownloadAttachedFile()
        {
            try {
                ModelObject[] objs = itemRev.IMAN_reference;
                if (objs.Length > 0 && objs[0] is Text)
                {
                    Teamcenter.Soa.Client.Model.Property refListProperty = objs[0].GetProperty("ref_list");
                    ModelObject[] refObjs = refListProperty.ModelObjectArrayValue;

                    if (refObjs.Length > 0 && refObjs[0] is ImanFile)
                    {
                        GetFileResponse fileResp = fmsFileManagement.GetFiles(refObjs);
                        FileInfo[]      files    = fileResp.GetFiles();
                        foreach (FileInfo fileInfo in files)
                        {
                            String name = Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH") + "\\Desktop\\" + fileInfo.Name;

                            fileInfo.MoveTo(name);
                        }
                    }
                }
            } catch (NotLoadedException e) {
                Console.WriteLine(e.StackTrace);
            }
        }
コード例 #4
0
ファイル: GetFile.cs プロジェクト: shukriadams/tetrifact
        public void GetNonExistentFile()
        {
            string          fileIdentifier = FileIdentifier.Cloak("nonexistent/path", "nonexistent-hash");
            GetFileResponse response       = IndexReader.GetFile(fileIdentifier);

            Assert.Null(response);
        }
コード例 #5
0
        public static PutFileRequest ToPutRequest(this GetFileResponse response)
        {
            var model = MapFileModel(response);

            return(new PutFileRequest {
                Data = model, Id = response.Data.Id
            });
        }
コード例 #6
0
        public static PostFileRequest ToPostRequest(this GetFileResponse response)
        {
            var model = MapFileModel(response);

            return(new PostFileRequest {
                Data = model
            });
        }
コード例 #7
0
ファイル: GrpcTests.cs プロジェクト: 360manu/ServiceStack
        private static void AssertSSUtils(GetFileResponse response)
        {
            Assert.That(response.Name, Is.EqualTo("ss-utils.js"));
            Assert.That(response.Length, Is.GreaterThan(0));
            Assert.That(response.Length, Is.EqualTo(response.Body.Length));
            var str = response.Body.FromUtf8Bytes();

            Assert.That(str, Does.Contain("if (!$.ss) $.ss = {};"));
        }
コード例 #8
0
ファイル: ProtobufTests.cs プロジェクト: 360manu/ServiceStack
        public void Can_serialize_bytes()
        {
            var dto = new GetFileResponse {
                Body = "abc".ToUtf8Bytes(),
            };
            var toDto = SerializeGrpc(dto);

            Assert.That(toDto.Body, Is.EqualTo(dto.Body));
        }
コード例 #9
0
        public async Task Given_a_successful_request_when_DownloadFile_is_called_it_returns_a_successful_response_object()
        {
            //arrange
            var request          = TestHelper.Generate_ValidGetRequest();
            var expectedResponse = new GetFileResponse();

            mockS3Client.Setup(x => x.DownloadFile(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(expectedResponse);

            //act
            var response = await classUnderTest.DownloadFile(request);

            //assert
            Assert.AreSame(response, expectedResponse);
        }
コード例 #10
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetFileResponse response = new GetFileResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("blobId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.BlobId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("commitId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.CommitId = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("fileContent", targetDepth))
                {
                    var unmarshaller = MemoryStreamUnmarshaller.Instance;
                    response.FileContent = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("fileMode", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.FileMode = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("filePath", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.FilePath = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("fileSize", targetDepth))
                {
                    var unmarshaller = LongUnmarshaller.Instance;
                    response.FileSize = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
コード例 #11
0
        public void CreateBasic()
        {
            List <PackageCreateItem> files = new List <PackageCreateItem>();
            string fileContent             = "some file content";
            int    filesToAdd = 10;
            string packageId  = "my package";

            for (int i = 0; i < filesToAdd; i++)
            {
                Stream fileStream = StreamsHelper.StreamFromString(fileContent);
                files.Add(new PackageCreateItem(fileStream, $"folder{i}/file{i}"));
            }

            PackageCreateArguments package = new PackageCreateArguments
            {
                Id    = packageId,
                Files = files
            };

            PackageCreateResult result = PackageCreate.CreatePackage(package);

            Assert.True(result.Success);
            Assert.Null(result.PublicError);
            Assert.NotEmpty(result.PackageHash);
            Assert.Null(result.ErrorType);

            // check that package can be listed
            IEnumerable <string> packageIds = IndexReader.GetAllPackageIds();

            Assert.Contains(packageId, packageIds);
            Assert.Single(packageIds);

            // check that package can be retrieved as manifest
            Manifest manifest = IndexReader.GetManifest(packageId);

            Assert.NotNull(manifest);
            Assert.Equal(manifest.Files.Count, filesToAdd);

            // check that a file can be retrieved directly using manifest id
            GetFileResponse response = IndexReader.GetFile(manifest.Files[0].Id);

            using (StreamReader reader = new StreamReader(response.Content)) {
                string retrievedContent = reader.ReadToEnd();
                Assert.Equal(retrievedContent, fileContent);
            }

            // ensure that workspace has been cleaned up
            Assert.Empty(Directory.GetDirectories(base.Settings.TempPath));
        }
コード例 #12
0
 public static byte[] DownloadFile(this Robot bot, GetFileResponse getFileResponse)
 {
     if (string.IsNullOrEmpty(getFileResponse?.Result?.FilePath))
         return null;
     using (var client = new WebClient())
     {
         try
         {
             return client.DownloadData($"{Robot.ApiUrl}/file/bot{bot.ApiToken}/{getFileResponse.Result.FilePath}");
         }
         catch
         {
             return null;
         }
     }
 }
コード例 #13
0
    static async Task ProcessHttpRequest(object request, NetworkStream client_stream)
    {
        var req = request as GetHttpRequest;
        object response = null;
        var exception = false;
        _Logger.IncReq();
        try
        {
            _Logger.Log(String.Format("Getting : {0}", req.Uri));
            WebResponse webResponse = await HttpWebRequest.Create(req.Uri).GetResponseAsync();
           

            var memoryStream = new MemoryStream();
            var stream = webResponse.GetResponseStream();
            var buf = new byte[1024];
            var count = 0;
            while ((count = await stream.ReadAsync(buf, 0, 1024)) != 0)
                memoryStream.Write(buf, 0, count);

            await MessageUtils.SendMsg(new GetFileResponse(memoryStream.Length), client_stream);
            memoryStream.Seek(0, SeekOrigin.Begin);
            await MessageUtils.SendFile(memoryStream, client_stream, new CancellationTokenSource());
        }
        catch (WebException e)
        {
            exception = true;
            response = new GetFileResponse(e.Message);
           
            
        }
        catch (UriFormatException)
        {
            exception = true;
            response = new GetFileResponse("the uri is not valid");
        }
        catch (TaskCanceledException ex)
        {
            _Logger.Log("Server: User Cancelled the uri copy");
        }
       
        if(exception)
            await MessageUtils.SendMsg(response, client_stream);
        
        
        
    }
コード例 #14
0
        public async Task Given_a_valid_request_when_getFileController_method_is_called_then_it_returns_200_Ok_response()
        {
            //arrange
            var expectedResponseCode = 200;
            var request  = TestHelper.Generate_ValidGetRequest();
            var response = new GetFileResponse();

            _mockGetUseCase.Setup(u => u.Execute(request)).ReturnsAsync(response);

            //act
            var controllerResponse = await _filesController.GetFile(request);

            var result = controllerResponse.Result as ObjectResult;

            //assert
            Assert.AreEqual(expectedResponseCode, result.StatusCode);
            Assert.IsInstanceOf <OkObjectResult>(result);
        }
コード例 #15
0
ファイル: GetFile.cs プロジェクト: shukriadams/tetrifact
        public void Basic()
        {
            // create a file and write to repository using path convention of path/to/file/bin
            string hash     = "somehash";
            string path     = "some/path/filename.file";
            string content  = "file content";
            string rootPath = Path.Combine(base.Settings.RepositoryPath, path, hash);

            Directory.CreateDirectory(rootPath);
            File.WriteAllText(Path.Combine(rootPath, "bin"), content);
            string fileIdentifier = FileIdentifier.Cloak(path, hash);

            GetFileResponse response = IndexReader.GetFile(fileIdentifier);

            using (StreamReader reader = new StreamReader(response.Content))
            {
                string retrievedContent = reader.ReadToEnd();
                Assert.Equal(content, retrievedContent);
            }
        }
コード例 #16
0
        /// <summary>
        /// Download a file as a byte array async using a GetFileResponse.
        /// </summary>
        public static async Task <byte[]> DownloadFileAsync(this TeleBot bot, GetFileResponse getFileResponse)
        {
            bot.Log.Info(nameof(DownloadFileAsync));

            if (string.IsNullOrEmpty(getFileResponse?.Result?.FilePath))
            {
                return(null);
            }

            using (var client = new WebClient())
            {
                try
                {
                    return(await client.DownloadDataTaskAsync($"{TeleBot.ApiUrl}/file/bot{bot.ApiToken}/{getFileResponse.Result.FilePath}"));
                }
                catch
                {
                    return(null);
                }
            }
        }
コード例 #17
0
 public ActionResult File(string id)
 {
     try
     {
         logger.Info("begin");
         GetFileRequest request = new GetFileRequest();
         request.UserInfo      = NavigationHandler.CurrentUser;
         request.IdDoc         = id;
         request.IdGruppo      = NavigationHandler.RuoloInfo.IdGruppo;
         request.IdCorrGlobali = NavigationHandler.RuoloInfo.Id;
         GetFileResponse response = WSStub.getFile(request);
         if (response.Code == GetFileResponseCode.OK)
         {
             //forza il content-type ad octet-stream se vuoto
             if (response.File.ContentType == "")
             {
                 if (response.File.FullName.ToUpper().Contains(".PDF"))
                 {
                     response.File.ContentType = "Content-type: application/pdf";
                 }
                 else
                 {
                     response.File.ContentType = "Content-type: application/octet-stream";
                 }
             }
             logger.Info("return doc");
             return(File(response.File.Content, response.File.ContentType, response.File.OriginalFileName));
         }
         else
         {
             logger.Info("doc not found");
             return(View("DocNotFound"));
         }
     }
     catch (Exception e)
     {
         logger.Error("eccezione: " + e);
         return(View("DocNotFound"));
     }
 }
コード例 #18
0
        public async Task <IActionResult> Get(string path = "", int?width = null, int?height = null)
        {
            var pathInfo = await this.mediator.Send(new GetPathInfoRequest(path));

            if (pathInfo.Exists)
            {
                if (pathInfo.IsDirectory)
                {
                    var directoryEntries = await this.mediator.Send(new GetDirectoryItemsRequest(path));

                    return(Ok(directoryEntries));
                }
                else
                {
                    if (this.Request.Headers.TryGetIfModifiedSince(out var lastModifiedSince))
                    {
                        if (!await this.mediator.Send(new IsModifiedSinceRequest(path, lastModifiedSince)))
                        {
                            return(this.StatusCode(304, "Page has not been modified"));
                        }
                    }

                    GetFileResponse fileResponse = null;
                    if (width.HasValue || height.HasValue)
                    {
                        fileResponse = await this.mediator.Send(new GetFilePreviewRequest(path, width, height));
                    }
                    else
                    {
                        fileResponse = await this.mediator.Send(new GetFileRequest(path));
                    }

                    this.Response.Headers["Last-Modified"] = fileResponse.LastModified.ToString("R");
                    this.Response.Headers["Cache-Control"] = "no-cache, must-revalidate";
                    return(File(fileResponse.Stream, fileResponse.ContentType));
                }
            }
            return(NotFound());
        }
コード例 #19
0
        public async Task Given_a_successful_request_when_getFileController_method_is_called_then_it_returns_a_GetFileResponse()
        {
            //arrange
            var request  = new GetFileRequest();
            var metadata = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("testMetadata", "metadataKeyValue")
            };
            var response = new GetFileResponse
            {
                Metadata = metadata
            };

            _mockGetUseCase.Setup(u => u.Execute(request)).ReturnsAsync(response);

            //act
            var controllerResponse = await _filesController.GetFile(request);

            var result = controllerResponse.Result as ObjectResult;

            //assert
            Assert.AreSame(response, result.Value);
            Assert.IsInstanceOf <GetFileResponse>(result.Value);
        }
コード例 #20
0
 /// <summary> Setter constructor. </summary>
 public GetFile(GetFileRequest request)
 {
     Request  = request;
     Response = new GetFileResponse();
 }
コード例 #21
0
ファイル: TeleBot.cs プロジェクト: svetlitsky/TeleBotDotNet
 public GetFileResponse GetFile(GetFileRequest getFileRequest)
 {
     Log.Info(nameof(GetFile));
     return(GetFileResponse.Parse(ExecuteAction(getFileRequest)));
 }
コード例 #22
0
        /// <summary>
        /// Download a file as a byte array using a GetFileResponse.
        /// </summary>
        public static byte[] DownloadFile(this TeleBot bot, GetFileResponse getFileResponse)
        {
            bot.Log.Info(nameof(DownloadFile));

            return(DownloadFileAsync(bot, getFileResponse).Result);
        }
コード例 #23
0
    static async Task ProcessFileRequest(object request, NetworkStream client_stream)
    {
        var gfr = request as GetFileRequest;
        object response = null;
        bool exception = false;

        _Logger.IncReq();
        var filePath = String.Format("{0}\\{1}", SERVER_DIRECTORY, gfr.FileName);
        _Logger.Log(String.Format("Server: get file \"{0}\"", filePath));
        try
        {
            var file = new FileStream(filePath, FileMode.Open, FileSystemRights.Read, FileShare.Read, 4096 * 2, FileOptions.Asynchronous);
            //byte[] fbytes = File.ReadAllBytes(filePath);
            response = new GetFileResponse(file.Length);

            //Send ok message do user
            await MessageUtils.SendMsg(response, client_stream);
            await MessageUtils.SendFile(file, client_stream, new CancellationTokenSource());
            _Logger.Log(String.Format("Server: return file \"{0}\" OK", gfr.FileName));
        }
        catch (IOException ex)
        {
            exception = true;
            response = new GetFileResponse(ex.Message);
            _Logger.Log(String.Format("Server: error on get file \"{0}\": {1}",
                                     gfr.FileName, ex.Message));

        }
        catch (TaskCanceledException ex)
        {
            _Logger.Log("Server: User Cancelled the file copy");
        }
        if (exception)
            await MessageUtils.SendMsg(response, client_stream);


    }
コード例 #24
0
 /// <summary> Empty constructor. </summary>
 public GetFile()
 {
     Request  = new GetFileRequest();
     Response = new GetFileResponse();
 }
コード例 #25
0
        public static GetFileResponse Unmarshall(UnmarshallerContext _ctx)
        {
            GetFileResponse getFileResponse = new GetFileResponse();

            getFileResponse.HttpResponse   = _ctx.HttpResponse;
            getFileResponse.RequestId      = _ctx.StringValue("GetFile.RequestId");
            getFileResponse.Success        = _ctx.BooleanValue("GetFile.Success");
            getFileResponse.ErrorCode      = _ctx.StringValue("GetFile.ErrorCode");
            getFileResponse.ErrorMessage   = _ctx.StringValue("GetFile.ErrorMessage");
            getFileResponse.HttpStatusCode = _ctx.IntegerValue("GetFile.HttpStatusCode");

            GetFileResponse.GetFile_Data data = new GetFileResponse.GetFile_Data();

            GetFileResponse.GetFile_Data.GetFile_File file = new GetFileResponse.GetFile_Data.GetFile_File();
            file.ConnectionName  = _ctx.StringValue("GetFile.Data.File.ConnectionName");
            file.ParentId        = _ctx.LongValue("GetFile.Data.File.ParentId");
            file.IsMaxCompute    = _ctx.BooleanValue("GetFile.Data.File.IsMaxCompute");
            file.CreateTime      = _ctx.LongValue("GetFile.Data.File.CreateTime");
            file.CreateUser      = _ctx.StringValue("GetFile.Data.File.CreateUser");
            file.BizId           = _ctx.LongValue("GetFile.Data.File.BizId");
            file.FileFolderId    = _ctx.StringValue("GetFile.Data.File.FileFolderId");
            file.FileName        = _ctx.StringValue("GetFile.Data.File.FileName");
            file.FileType        = _ctx.IntegerValue("GetFile.Data.File.FileType");
            file.UseType         = _ctx.StringValue("GetFile.Data.File.UseType");
            file.FileDescription = _ctx.StringValue("GetFile.Data.File.FileDescription");
            file.Content         = _ctx.StringValue("GetFile.Data.File.Content");
            file.NodeId          = _ctx.LongValue("GetFile.Data.File.NodeId");
            file.CurrentVersion  = _ctx.IntegerValue("GetFile.Data.File.CurrentVersion");
            file.Owner           = _ctx.StringValue("GetFile.Data.File.Owner");
            file.LastEditUser    = _ctx.StringValue("GetFile.Data.File.LastEditUser");
            file.LastEditTime    = _ctx.LongValue("GetFile.Data.File.LastEditTime");
            file.CommitStatus    = _ctx.IntegerValue("GetFile.Data.File.CommitStatus");
            data.File            = file;

            GetFileResponse.GetFile_Data.GetFile_NodeConfiguration nodeConfiguration = new GetFileResponse.GetFile_Data.GetFile_NodeConfiguration();
            nodeConfiguration.AutoRerunTimes          = _ctx.IntegerValue("GetFile.Data.NodeConfiguration.AutoRerunTimes");
            nodeConfiguration.AutoRerunIntervalMillis = _ctx.IntegerValue("GetFile.Data.NodeConfiguration.AutoRerunIntervalMillis");
            nodeConfiguration.RerunMode           = _ctx.StringValue("GetFile.Data.NodeConfiguration.RerunMode");
            nodeConfiguration.Stop                = _ctx.BooleanValue("GetFile.Data.NodeConfiguration.Stop");
            nodeConfiguration.ParaValue           = _ctx.StringValue("GetFile.Data.NodeConfiguration.ParaValue");
            nodeConfiguration.StartEffectDate     = _ctx.LongValue("GetFile.Data.NodeConfiguration.StartEffectDate");
            nodeConfiguration.EndEffectDate       = _ctx.LongValue("GetFile.Data.NodeConfiguration.EndEffectDate");
            nodeConfiguration.CronExpress         = _ctx.StringValue("GetFile.Data.NodeConfiguration.CronExpress");
            nodeConfiguration.CycleType           = _ctx.StringValue("GetFile.Data.NodeConfiguration.CycleType");
            nodeConfiguration.DependentType       = _ctx.StringValue("GetFile.Data.NodeConfiguration.DependentType");
            nodeConfiguration.DependentNodeIdList = _ctx.StringValue("GetFile.Data.NodeConfiguration.DependentNodeIdList");
            nodeConfiguration.ResourceGroupId     = _ctx.LongValue("GetFile.Data.NodeConfiguration.ResourceGroupId");

            List <GetFileResponse.GetFile_Data.GetFile_NodeConfiguration.GetFile_NodeInputOutput> nodeConfiguration_inputList = new List <GetFileResponse.GetFile_Data.GetFile_NodeConfiguration.GetFile_NodeInputOutput>();

            for (int i = 0; i < _ctx.Length("GetFile.Data.NodeConfiguration.InputList.Length"); i++)
            {
                GetFileResponse.GetFile_Data.GetFile_NodeConfiguration.GetFile_NodeInputOutput nodeInputOutput = new GetFileResponse.GetFile_Data.GetFile_NodeConfiguration.GetFile_NodeInputOutput();
                nodeInputOutput.Input = _ctx.StringValue("GetFile.Data.NodeConfiguration.InputList[" + i + "].Input");

                nodeConfiguration_inputList.Add(nodeInputOutput);
            }
            nodeConfiguration.InputList = nodeConfiguration_inputList;

            List <GetFileResponse.GetFile_Data.GetFile_NodeConfiguration.GetFile_NodeInputOutput1> nodeConfiguration_outputList = new List <GetFileResponse.GetFile_Data.GetFile_NodeConfiguration.GetFile_NodeInputOutput1>();

            for (int i = 0; i < _ctx.Length("GetFile.Data.NodeConfiguration.OutputList.Length"); i++)
            {
                GetFileResponse.GetFile_Data.GetFile_NodeConfiguration.GetFile_NodeInputOutput1 nodeInputOutput1 = new GetFileResponse.GetFile_Data.GetFile_NodeConfiguration.GetFile_NodeInputOutput1();
                nodeInputOutput1.Output       = _ctx.StringValue("GetFile.Data.NodeConfiguration.OutputList[" + i + "].Output");
                nodeInputOutput1.RefTableName = _ctx.StringValue("GetFile.Data.NodeConfiguration.OutputList[" + i + "].RefTableName");

                nodeConfiguration_outputList.Add(nodeInputOutput1);
            }
            nodeConfiguration.OutputList = nodeConfiguration_outputList;
            data.NodeConfiguration       = nodeConfiguration;
            getFileResponse.Data         = data;

            return(getFileResponse);
        }
コード例 #26
0
ファイル: MediaExtensions.cs プロジェクト: k4gdw/BetterCMS
        private static SaveFileModel MapFileModel(GetFileResponse response)
        {
            var model = new SaveFileModel
                            {
                                Version = response.Data.Version,
                                FolderId = response.Data.FolderId,
                                Title = response.Data.Title,
                                IsArchived = response.Data.IsArchived,
                                PublishedOn = response.Data.PublishedOn,
                                Description = response.Data.Description,
                                OriginalFileName = response.Data.OriginalFileName,
                                OriginalFileExtension = response.Data.OriginalFileExtension,
                                FileUri = response.Data.FileUri,
                                PublicUrl = response.Data.FileUrl,
                                FileSize = response.Data.FileSize,
                                IsTemporary = response.Data.IsTemporary,
                                IsUploaded = response.Data.IsUploaded,
                                IsCanceled = response.Data.IsCanceled,
                                Tags = response.Tags != null ? response.Tags.Select(t => t.Name).ToList() : null,
                                AccessRules = response.AccessRules,
                                ThumbnailId = response.Data.ThumbnailId,
                            };

            return model;
        }
コード例 #27
0
ファイル: Session.cs プロジェクト: coolmaxx/Howell5198Server
        /// <summary>
        /// 发送媒体数据
        /// </summary>
        /// <param name="frameType">媒体帧类型:1-流头结构,2-音频帧,3-I帧,4-P帧,5-B帧,6-MJPEG帧</param>
        /// <param name="payload">载荷数据</param>
        public void Send(Int32 frameType, Byte[] payload)
        {
            if (payload == null || payload.Length == 0)
            {
                return;
            }
            //录像视频
            if (this.Context.IsFileStream == true)
            {
                GetFileResponse p = new GetFileResponse();
                if (frameType == 1)
                {
                    p.Type = 0;
                }
                else
                {
                    p.Type = 1;
                }

                p.Buffer    = payload;
                p.ChannelNo = this.Context.StreamIdentifier.ChannelNo;
                p.Datalen   = payload.Length;
                p.Buffer    = payload;
                Byte[] data = p.GetBytes();
                ProtocolSession.Send(new FixedHeaderPackageInfo <ProtocolHeader>(Guid.NewGuid().ToString("N"),
                                                                                 new ProtocolHeader()
                {
                    proType = ProtocolType.GetFile, errornum = 0, dataLen = (UInt32)data.Length
                }, data));
            }
            //实时视频
            else
            {
                FramePayload p = new FramePayload();
                p.FrameData = payload;
                //实时主码流
                if (this.Context.StreamIdentifier.StreamNo == 0)
                {
                    if (frameType == 1)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_HEAD;
                    }
                    else if (frameType == 2)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_AUDIO;
                    }
                    else if (frameType == 3)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_I;
                    }
                    else if (frameType == 4)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_P;
                    }
                    else if (frameType == 5)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_B;
                    }
                    else if (frameType == 6)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_MJPEG;
                    }
                    else
                    {
                        return;
                    }
                    Byte[] data = p.GetBytes();
                    ProtocolSession.Send(new FixedHeaderPackageInfo <ProtocolHeader>(Guid.NewGuid().ToString("N"),
                                                                                     new ProtocolHeader()
                    {
                        proType = ProtocolType.Main_stream, errornum = 0, dataLen = (UInt32)data.Length
                    }, data));
                }
                else
                {
                    //实时子码流
                    if (frameType == 1)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_SUB_HEAD;
                    }
                    else if (frameType == 2)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_AUDIO;
                    }
                    else if (frameType == 3)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_SUB_I;
                    }
                    else if (frameType == 4)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_SUB_P;
                    }
                    else if (frameType == 5)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_SUB_B;
                    }
                    else if (frameType == 6)
                    {
                        p.FrameType = FramePayload.frametype.HW_FRAME_VIDEO_SUB_MJPEG;
                    }
                    else
                    {
                        return;
                    }
                    Byte[] data = p.GetBytes();
                    ProtocolSession.Send(new FixedHeaderPackageInfo <ProtocolHeader>(Guid.NewGuid().ToString("N"),
                                                                                     new ProtocolHeader()
                    {
                        proType = ProtocolType.Sub_stream, errornum = 0, dataLen = (UInt32)data.Length
                    }, data));
                }
            }
        }