コード例 #1
0
        public async Task <IActionResult> Index()
        {
            ApplicationUser user = await userManager.GetUserAsync(HttpContext.User);

            Collection collection = await context.Collections
                                    .FirstOrDefaultAsync(c => c.User == user);

            MediaMeta media = await context.MediaMeta
                              .FirstOrDefaultAsync(m => m.User == user);

            if (collection == null)
            {
                collection = new Collection();
            }
            if (media == null)
            {
                media = new MediaMeta
                {
                    LastUpdateSequenceNumber = 1,
                };
            }

            return(Ok(new
            {
                scm = ((DateTimeOffset)collection.SchemaModified.ToLocalTime()).ToUnixTimeMilliseconds(),
                ts = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                mod = ((DateTimeOffset)collection.Modified.ToLocalTime()).ToUnixTimeMilliseconds(),
                usn = collection.UpdateSequenceNumber,
                musn = media.LastUpdateSequenceNumber,
                msg = "",
                cont = true,
            }));
        }
コード例 #2
0
        public void GenerateReport(Guid reportId, Guid summaryId, string headerText)
        {
            // Find the Workflow Instance
            var report  = _rptUoW.Find <Report>(reportId);
            var summary = _summariesUnitOfWork.Find <Summary>(summaryId);

            // Generate Attachment and MediaData
            var mediaMeta = new MediaMeta();
            var mediaData = new MediaData();
            var document  = new Document();

            mediaMeta.AttachedDate = DateTime.Now;
            mediaMeta.AttachedBy   = report.CreatedBy.ToString();
            //Get Media Data memory Stream value
            document.MemoryStream = _documentService.RenderReport(report, AttachmentType.PDF, headerText);
            document.ReportName   = ReportInfoFormatter.GetLongName(report);
            mediaMeta.FileName    = document.ReportName;
            mediaData.Data        = document.MemoryStream;
            mediaMeta.Source      = AttachmentDescription.OfficerReport.GetDescription();
            mediaMeta.Id          = Guid.NewGuid();

            mediaMeta.ContentSubType = mediaMeta.Extension = AttachmentType.PDF.ToString();
            mediaMeta.ContentType    = "Application";
            mediaMeta.Size           = mediaData.Data.Length;
            mediaData.Id             = _mediaMetaService.CreateNewMedia(mediaMeta);
            _mediaDataService.UploadMediaData(mediaData);

            // Add officer Attachment file
            AttachOfficerReport(MapAttachment(mediaMeta), report, summary);

            _documentService.Dispose();
        }
コード例 #3
0
        public async Task <IActionResult> MediaChanges([FromBody] MediaChanges mediaChanges)
        {
            ApplicationUser user = await userManager.GetUserAsync(HttpContext.User);

            MediaMeta meta = await context.MediaMeta
                             .FirstOrDefaultAsync(m => m.User == user);

            if (mediaChanges.LastUpdateSequenceNumber == 0 || mediaChanges.LastUpdateSequenceNumber < meta.LastUpdateSequenceNumber)
            {
                var media = context.Media
                            .Where(me => me.User == user)
                            .Select(med => new object[]
                {
                    med.Filename,
                    meta.LastUpdateSequenceNumber,
                    med.Checksum,
                });

                return(Ok(new
                {
                    data = media,
                    err = "",
                }));
            }

            return(Ok(new
            {
                data = new List <Object>(),
                err = "",
            }));
        }
コード例 #4
0
        /// <summary>
        /// Process media upload form client.
        /// </summary>
        /// <param name="changes">Used to upload client media files.</param>
        /// <returns>Returns the count of media files processed, and the current update sequence number.</returns>
        public async Task <IActionResult> UploadChanges([FromForm] UploadChanges changes)
        {
            ApplicationUser user = await userManager.GetUserAsync(HttpContext.User);

            MediaMeta meta = await context.MediaMeta.FirstOrDefaultAsync(m => m.User == user);

            if (meta == null)
            {
                meta = new MediaMeta
                {
                    User = user,
                    DirectoryModified        = DateTimeOffset.UtcNow.DateTime,
                    LastUpdateSequenceNumber = 0,
                };
            }

            long processedCount = await mediaSyncer.Upload(user.Id, changes.Data);

            meta.LastUpdateSequenceNumber += processedCount;

            context.MediaMeta.Update(meta);

            await context.SaveChangesAsync();

            return(Ok(new
            {
                data = new long[] { processedCount, meta.LastUpdateSequenceNumber },
                err = ""
            }));
        }
コード例 #5
0
        public async Task <IActionResult> Begin()
        {
            ApplicationUser user = await userManager.GetUserAsync(HttpContext.User);

            MediaMeta meta = await context.MediaMeta
                             .FirstOrDefaultAsync(m => m.User == user);

            if (meta == null)
            {
                meta = new MediaMeta
                {
                    User = user,
                    LastUpdateSequenceNumber = 1,
                };
            }

            string hkey = HttpContext.Request.Form["k"];

            return(Ok(new
            {
                data = new
                {
                    sk = hkey,
                    usn = meta.LastUpdateSequenceNumber,
                },
                err = "",
            }));
        }
コード例 #6
0
ファイル: MediaMetaService.cs プロジェクト: sanjaybxl/inform
        public void UpdateMedia(MediaMeta media)
        {
            Medium meta = UnitOfWork.MediaRepository.Find(media.Id);

            media.MapInto(meta);
            UnitOfWork.Commit();
        }
コード例 #7
0
        public void MediaDataService_GetMediaById()
        {
            CreateNewMedia();
            var mediaMetaService = GetDependency <IMediaMetaService>();

            Assert.IsInstanceOfType(mediaMetaService, typeof(IMediaMetaService));
            MediaMeta mediaMetaDetails = mediaMetaService.GetMediaById(mediaId);

            Assert.IsNotNull(mediaMetaDetails);
        }
コード例 #8
0
ファイル: MediaServiceTests.cs プロジェクト: sanjaybxl/inform
        public MediaMeta Test_GetMediaById(Guid id)
        {
            MediaMeta media = null;

            using (var ioc = DependencyContainer.Resolve <IMediaMetaService>())
            {
                media = ioc.Instance.GetMediaById(id);
            }
            return(media);
        }
コード例 #9
0
ファイル: MediaServiceTests.cs プロジェクト: sanjaybxl/inform
        public override bool Execute()
        {
            Guid      mediaId   = Test_CreateNewMedia();
            MediaMeta mediaMeta = Test_GetMediaById(mediaId);

            Test_UploadMediaData(mediaId);
            Test_GetMediaData(mediaId);
            Test_DeleteMediaById(mediaId);
            return(true);
        }
コード例 #10
0
        public MediaMeta CreateAttachment(MediaMeta attachment)
        {
            attachment.AttachedDate = DateTime.Now;
            attachment.Source       = "InformRMSWeb";
            attachment.UriPath      = "api/attachments/upload";
            attachment.Id           = Guid.NewGuid();

            _mediaMetaService.CreateNewMedia(attachment);

            return(attachment);
        }
コード例 #11
0
        public void MediaDataService_UpdateMedia()
        {
            // Create
            CreateNewMedia();

            // Find
            var mediaMetaService = GetDependency <IMediaMetaService>();

            Assert.IsInstanceOfType(mediaMetaService, typeof(IMediaMetaService));
            MediaMeta mediaMetaDetails = mediaMetaService.GetMediaById(mediaId);

            // Update
            mediaMetaDetails.Description = "A Crismas eve overlooking the ocean.";
            mediaMetaService.UpdateMedia(mediaMetaDetails);

            // Find Post Update
            MediaMeta mediaMetaDetailsPostUpdate = mediaMetaService.GetMediaById(mediaId);

            Assert.IsTrue(Utils.ReflectiveEquals(mediaMetaDetails, mediaMetaDetailsPostUpdate));
        }
コード例 #12
0
        /// <summary>
        /// Map MediaMeta to Attachment
        /// </summary>
        private Attachment MapAttachment(MediaMeta mediaMeta)
        {
            var attachment = new Attachment
            {
                AttachedBy     = mediaMeta.AttachedBy,
                AttachedDate   = mediaMeta.AttachedDate,
                ContentSubType = mediaMeta.ContentSubType,
                ContentType    = mediaMeta.ContentType,
                Description    = mediaMeta.Description,
                EncodingType   = mediaMeta.EncodingType,
                FileName       = mediaMeta.FileName,
                Source         = mediaMeta.Source,
                UriPath        = mediaMeta.UriPath,
                Size           = mediaMeta.Size,
                Extension      = mediaMeta.Extension,
                Id             = Guid.NewGuid(),
                MediaId        = mediaMeta.Id
            };

            return(attachment);
        }
コード例 #13
0
        /// <summary>
        /// Map MediaMeta to Attachment
        /// </summary>
        private static Attachment MapAttachment(MediaMeta mediaMeta)
        {
            var attachment = new Attachment
            {
                AttachedBy              = mediaMeta.AttachedBy,
                AttachedDate            = mediaMeta.AttachedDate,
                ContentSubType          = mediaMeta.ContentSubType,
                ContentType             = mediaMeta.ContentType,
                Description             = mediaMeta.Description,
                EncodingType            = mediaMeta.EncodingType,
                FileName                = mediaMeta.FileName,
                Source                  = mediaMeta.Source,
                UriPath                 = mediaMeta.UriPath,
                Size                    = mediaMeta.Size,
                Extension               = mediaMeta.Extension,
                Id                      = Guid.NewGuid(),
                MediaId                 = mediaMeta.Id,
                CategoryType            = mediaMeta.CategoryType,
                AttachmentRelationships = new AttachmentRelationshipCollection(mediaMeta.AttachmentRelationship)
            };

            return(attachment);
        }
コード例 #14
0
ファイル: MediaMetaService.cs プロジェクト: sanjaybxl/inform
        public Guid CreateNewMedia(MediaMeta media)
        {
            if (media == null)
            {
                throw new ArgumentNullException("media");
            }

            using (
                var scope = new TransactionScope(TransactionScopeOption.Required,
                                                 new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted, Timeout = TransactionManager.MaximumTimeout
            }))
            {
                // Generate metadata.
                var meta = new Medium(media.Id);
                media.MapInto(meta);
                UnitOfWork.MediaRepository.Add(meta);
                UnitOfWork.Commit();

                scope.Complete();
                return(meta.Id);
            }
        }
コード例 #15
0
        public void MediaDataService_UpdateMediaWithInvalidId()
        {
            // Create
            CreateNewMedia();

            // Find
            var mediaMetaService = GetDependency <IMediaMetaService>();

            Assert.IsInstanceOfType(mediaMetaService, typeof(IMediaMetaService));
            MediaMeta mediaMetaDetails = mediaMetaService.GetMediaById(mediaId);

            try
            {
                // Update
                mediaMetaDetails.Id          = new Guid();
                mediaMetaDetails.Description = "A Crismas eve overlooking the ocean.";
                mediaMetaService.UpdateMedia(mediaMetaDetails);
                Assert.Fail();
            }
            catch (Exception exception)
            {
                Assert.IsNotNull(exception);
            }
        }
コード例 #16
0
        // TODO: This is duplicate code: Refactor into a common test.

        #region Arrest

        private Guid Test_Arrest_Report_Attachment()
        {
            Guid result   = Guid.Empty;
            var  agencies = GetAgencies();

            if (agencies.Count > 0)
            {
                using (var attachQuerySvc = DependencyContainer.Resolve <IAttachmentQueryService>())
                    using (var attachCmdSvc = DependencyContainer.Resolve <IAttachmentCommandService>())
                        using (var mediaSvc = DependencyContainer.Resolve <IMediaMetaService>())
                            using (var mediaDataSvc = DependencyContainer.Resolve <IMediaDataService>())
                                using (var reportCmdSvc = DependencyContainer.Resolve <IArrestReportCommandService>())
                                    using (var reportQuerySvc = DependencyContainer.Resolve <IArrestReportQueryService>())
                                        using (var deleteSvc = DependencyContainer.Resolve <IDeleteService>())
                                            using (Stream data = DTOFactory.NewMediaData)
                                            {
                                                // Create an Arrest Report in the Report database.
                                                var arrestDetails = DTOFactory.NewArrestReport;
                                                arrestDetails.CaseNumber = "Random Case #" + new Random().Next(int.MaxValue);
                                                Guid arrestReportId = reportCmdSvc.Instance.CreateReport(agencies[0].AgencyId, false, arrestDetails);

                                                // Generate an attachment and upload it to the Media database.
                                                var  media = DTOFactory.NewMedia;
                                                Guid mediaDbAttachmentId = mediaSvc.Instance.CreateNewMedia(media);
                                                mediaDataSvc.Instance.UploadMediaData(new MediaData()
                                                {
                                                    Id = mediaDbAttachmentId, Data = data
                                                });

                                                // Associate the attachment with the Report.
                                                var deAttachment = DTOFactory.NewDataEntryAttachment;
                                                deAttachment.MediaId = media.Id;
                                                Guid reportDbAttachmentId = attachCmdSvc.Instance.AddAttachmentToReport(deAttachment, arrestReportId);

                                                // Find all Attachments associated with the Report.
                                                List <Attachment> reportAttachments = attachQuerySvc.Instance.FindReportAttachments(arrestReportId);

                                                // Find the Attachment meta in the Report database.
                                                Application.Contracts.DataEntry.Attachments.DTO.Attachment foundAttachment = attachQuerySvc.Instance.FindReportAttachment(reportDbAttachmentId);

                                                // Update the attachment meta in the Report database.
                                                foundAttachment.Description = "MODIFIED";
                                                attachCmdSvc.Instance.UpdateReportAttachment(foundAttachment);

                                                // Find the Attachment meta in the Media database.
                                                MediaMeta foundMedia = mediaSvc.Instance.GetMediaById(foundAttachment.MediaId);

                                                // Get the Attachment data from the Media database.
                                                using (Stream foundData = mediaDataSvc.Instance.GetMediaData(foundMedia.Id))
                                                {
                                                    if (foundData.Length == 0)
                                                    {
                                                        Console.WriteLine("Couldn't find attachment data.");
                                                    }
                                                }

                                                // Update the attachment in the Media database.
                                                foundMedia.Description = "MODIFIED";
                                                mediaSvc.Instance.UpdateMedia(foundMedia);

                                                // Remove the attachment from the Report in the Report database.
                                                attachCmdSvc.Instance.DisassociateReportAttachment(reportDbAttachmentId);

                                                // Delete the Report from the Report database.
                                                deleteSvc.Instance.DeleteReport(arrestReportId);
                                                result = foundAttachment.Id;
                                            }
            }
            return(result);
        }
コード例 #17
0
 public void AssociateToSummary(Guid id, MediaMeta mediaMeta)
 {
     _attachmentCommandService.AddAttachmentToSummary(MapAttachment(mediaMeta), id);
 }