/// <summary> /// Main entry point. Creates a bunch of services, and then kicks off /// the webserver, which is a blocking call (since it's the dispatcher /// thread) until the app exits. /// </summary> /// <param name="listeningPort"></param> /// <param name="args"></param> private static void StartWebServer(int listeningPort, string[] args) { try { Logging.Log("Starting Damselfly Services"); // Instantiate all of our services var status = new StatusService(); var thumbs = new ThumbnailService(); var indexing = new IndexingService(); var downloads = new DownloadService(); var basket = new BasketService(); var folder = new FolderService(); var search = new SearchService(); var tasks = new TaskService(); var config = new ConfigService(); var meta = new MetaDataService(); var wp = new WordpressService(); var proc = new ImageProcessService(); var select = new SelectionService(); Logging.Log("Starting Damselfly Webserver"); BuildWebHost(listeningPort, args).Run(); Logging.Log("Damselfly Webserver stopped. Exiting"); } catch (Exception ex) { Logging.Log("Damselfly Webserver terminated with exception: {0}", ex.Message); } }
public FormThumbnailSettings(ThumbnailService thumbnailService) { _thumbnailService = thumbnailService; thumbnailService.StartedThumbnailScan += ThumbnailService_StartedThumbnailScan; thumbnailService.CompletedThumbnailScan += ThumbnailService_CompletedThumbnailScan; InitializeComponent(); }
public ImageService(DocumentsApp app) : base(app) { ThumbnailUpdatingEnabled = false; AvatarService = new AvatarService(app); ThumbnailService = new ThumbnailService(app); }
// Analysis disable once InconsistentNaming public void LoadThumbnail_ReturnsNull_IfThumbnailDoesNotExist() { var fileSystem = new FileSystemMock(); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.LoadThumbnail(largeThumbnailUri); Assert.IsNull(result); }
// Analysis disable once InconsistentNaming public void GetThumbnailPath_ReturnsPathForNormalThumbnail() { var fileSystem = new FileSystemMock(); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnailPath(fileUri, ThumbnailSize.Normal); Assert.AreEqual(normalThumbnailUri, result); }
public override void ExecuteResult(ControllerContext context) { string fname = context.HttpContext.Server.MapPath(_sourceFileName); var service = new ThumbnailService(); _thumbFileName = service.GetOrCreateThumb(fname); base.ExecuteResult(context); }
private PagedListViewModel <MediaFileViewModel> GetPagedFilesBy(SiteDb siteDb, string by, int PageSize, int PageNumber) { string baseurl = siteDb.WebSite.BaseUrl(); // by = View, Page, Layout, TextContent, Style. byte consttype = ConstObjectType.GetByte(by); var images = siteDb.Images.ListUsedBy(consttype); int totalskip = 0; if (PageNumber > 1) { totalskip = (PageNumber - 1) * PageSize; } PagedListViewModel <MediaFileViewModel> Result = new PagedListViewModel <MediaFileViewModel>(); Result.TotalCount = images.Count(); Result.TotalPages = ApiHelper.GetPageCount(Result.TotalCount, PageSize); Result.PageSize = PageSize; Result.PageNr = PageNumber; List <MediaFileViewModel> list = new List <MediaFileViewModel>(); foreach (var item in images.Skip(totalskip).Take(PageSize)) { MediaFileViewModel model = new MediaFileViewModel(); model.Id = item.Id; model.Height = item.Height; model.Width = item.Width; model.Size = item.Size; model.Name = item.Name; model.LastModified = item.LastModified; model.Thumbnail = ThumbnailService.GenerateThumbnailUrl(item.Id, 90, 0, siteDb.Id); model.Url = ObjectService.GetObjectRelativeUrl(siteDb, item); model.IsImage = true; model.PreviewUrl = Lib.Helper.UrlHelper.Combine(baseurl, model.Url); var usedby = siteDb.Images.GetUsedBy(item.Id); if (usedby != null) { model.References = usedby.GroupBy(it => it.ConstType).ToDictionary( key => { return(ConstTypeService.GetModelType(key.Key).Name); }, value => value.Count()); } list.Add(model); } Result.List = list; return(Result); }
// Analysis disable once InconsistentNaming public void GetThumbnail_ReturnsNull_IfNoThumbnailerFound() { var fileSystem = new FileSystemMock(); var thumbnailerFactoryMock = new Mock <IThumbnailerFactory> (); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactoryMock.Object, fileSystem); var result = thumbnailService.GetThumbnail(fileUri, ThumbnailSize.Large); Assert.IsNull(result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfFileDoesNotExist() { var fileSystem = new FileSystemMock(); var pixbuf = PixbufMock.CreatePixbuf(fileUri, fileMTime + 1); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, pixbuf); Assert.IsFalse(result); }
// Analysis disable once InconsistentNaming public void DeleteThumbnail_DoesNotDeleteThumbnails_IfNotExist() { var fileSystem = new FileSystemMock(); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); thumbnailService.DeleteThumbnails(fileUri); fileSystem.FileMock.Verify(m => m.Delete(largeThumbnailUri), Times.Never()); fileSystem.FileMock.Verify(m => m.Delete(normalThumbnailUri), Times.Never()); }
// Analysis disable once InconsistentNaming public void LoadThumbnail_ReturnsPixbuf_IfThumbnailExists() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(largeThumbnailUri, 0, thumbnail); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.LoadThumbnail(largeThumbnailUri); Assert.IsNotNull(result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfPixbufIsNull() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, null); Assert.IsFalse(result); }
// Analysis disable once InconsistentNaming public void GetThumbnail_ReturnsPixbuf_IfValidPngExists() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); fileSystem.SetFile(largeThumbnailUri, 0, thumbnail); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnail(fileUri, ThumbnailSize.Large); Assert.IsNotNull(result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfMTimeIsDifferent() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileLastWrite); var pixbuf = PixbufMock.CreatePixbuf(fileUri, fileLastWrite.AddMilliseconds(1.0)); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, pixbuf); Assert.IsFalse(result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsFalse_IfFileUriIsDifferent() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); var pixbuf = PixbufMock.CreatePixbuf(new SafeUri("file:///some-uri"), fileMTime); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, pixbuf); Assert.IsFalse(result); }
// Analysis disable once InconsistentNaming public void IsValid_ReturnsTrue_IfPixbufIsValid() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); var pixbuf = PixbufMock.CreatePixbuf(fileUri, fileMTime); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.IsValid(fileUri, pixbuf); Assert.IsTrue(result); }
// Analysis disable once InconsistentNaming public void GetThumbnail_ReturnsNull_IfThumbnailCreationFails() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); thumbnailerMock.Setup(thumb => thumb.TryCreateThumbnail(largeThumbnailUri, ThumbnailSize.Large)).Returns(false); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnail(fileUri, ThumbnailSize.Large); Assert.IsNull(result); }
public async Task <IActionResult> Face(string faceId, CancellationToken cancel, [FromServices] ImageProcessService imageProcessor, [FromServices] ThumbnailService thumbService, [FromServices] ImageCache imageCache) { using var db = new ImageContext(); IActionResult result = Redirect("/no-image.png"); try { var query = db.ImageObjects.AsQueryable(); // TODO Massively optimise this - if the file already exists we don't need the DB if (int.TryParse(faceId, out var personId)) { query = query.Where(x => x.Person.PersonId == personId); } else { query = query.Where(x => x.Person.AzurePersonId == faceId); } // Sort by largest face picture, then by most recent date taken var face = await query .OrderByDescending(x => x.RectWidth) .ThenByDescending(x => x.RectHeight) .ThenByDescending(x => x.Image.SortDate) .FirstOrDefaultAsync(); if (cancel.IsCancellationRequested) { return(result); } if (face != null) { var thumbPath = await thumbService.GenerateFaceThumb(face); if (thumbPath != null && thumbPath.Exists) { result = PhysicalFile(thumbPath.FullName, "image/jpeg"); } } } catch (Exception ex) { Logging.LogError($"Unable to load face thumbnail for {faceId}: {ex.Message}"); } return(result); }
// Analysis disable once InconsistentNaming public void DeleteThumbnail_DeletesLargeAndNormalThumbnails_IfTheyExist() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(largeThumbnailUri); fileSystem.SetFile(normalThumbnailUri); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); thumbnailService.DeleteThumbnails(fileUri); fileSystem.FileMock.Verify(m => m.Delete(largeThumbnailUri), Times.Once()); fileSystem.FileMock.Verify(m => m.Delete(normalThumbnailUri), Times.Once()); }
public FormThumbnailView(FormAddBookmark formAddBookmark, ApplicationSettingsService applicationSettingsService, ImageCacheService imageCacheService, ThumbnailService thumbnailService, ImageLoaderService imageLoaderService) { _formAddBookmark = formAddBookmark; _applicationSettingsService = applicationSettingsService; _imageCacheService = imageCacheService; _thumbnailService = thumbnailService; _imageLoaderService = imageLoaderService; _thumbnailSize = ValidateThumbnailSize(_applicationSettingsService.Settings.ThumbnailSize); _maxThumbnails = _applicationSettingsService.Settings.MaxThumbnails; _applicationSettingsService.OnSettingsSaved += _applicationSettingsService_OnSettingsSaved; _thumbnailService.LoadThumbnailDatabase(); InitializeComponent(); }
// Analysis disable once InconsistentNaming public void LoadThumbnail_DeletesThumbnail_IfLoadFails() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(largeThumbnailUri, 0, thumbnail); fileSystem.FileMock.Setup(m => m.Read(largeThumbnailUri)).Throws <Exception> (); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.LoadThumbnail(largeThumbnailUri); Assert.IsNull(result); fileSystem.FileMock.Verify(file => file.Delete(largeThumbnailUri), Times.Once()); }
// Analysis disable once InconsistentNaming public void GetThumbnail_CreatesPngAndReturnsPixbuf_IfPngIsMissing() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(fileUri, fileMTime); thumbnailerMock.Setup(thumb => thumb.TryCreateThumbnail(largeThumbnailUri, ThumbnailSize.Large)) .Returns(true) .Callback(() => fileSystem.SetFile(largeThumbnailUri, 0, thumbnail)); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); var result = thumbnailService.GetThumbnail(fileUri, ThumbnailSize.Large); Assert.IsNotNull(result); }
public bool RenderThumbnail(FrontContext frontcontext) { string relativeUrl = frontcontext.RenderContext.Request.RelativeUrl; if (relativeUrl.StartsWith(Kooboo.Sites.SiteConstants.ThumbnailRootPath, StringComparison.OrdinalIgnoreCase)) { var thumbnail = ThumbnailService.GetThumbnail(frontcontext.RenderContext.WebSite.SiteDb(), relativeUrl); if (thumbnail != null) { frontcontext.RenderContext.Response.ContentType = thumbnail.ContentType; frontcontext.RenderContext.Response.Body = thumbnail.ContentBytes; } return(true); } return(false); }
// Analysis disable once InconsistentNaming public void DeleteThumbnail_IgnoresExceptionsOnDeletingThumbnails() { var fileSystem = new FileSystemMock(); fileSystem.SetFile(largeThumbnailUri); fileSystem.SetFile(normalThumbnailUri); fileSystem.FileMock.Setup(m => m.Delete(largeThumbnailUri)).Throws <Exception> (); fileSystem.FileMock.Setup(m => m.Delete(normalThumbnailUri)).Throws <Exception> (); var thumbnailService = new ThumbnailService(xdgDirectoryService, thumbnailerFactory, fileSystem); thumbnailService.DeleteThumbnails(fileUri); fileSystem.FileMock.Verify(m => m.Delete(largeThumbnailUri), Times.Once()); fileSystem.FileMock.Verify(m => m.Delete(normalThumbnailUri), Times.Once()); // test ends without the exceptions thrown by File.Delete beeing unhandled }
public HttpResponseMessage Post(string MediaType) { HttpResponseMessage result = null; var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { var docfiles = new List <string>(); bool amazonCall = false; string keyName = ""; foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; var localFilePath = HttpContext.Current.Server.MapPath("~/" + postedFile.FileName); var extentionType = Path.GetExtension(postedFile.FileName); int themeId = 196; keyName = Guid.NewGuid().ToString() + extentionType;//.Substring(0, 12); postedFile.SaveAs(localFilePath); amazonCall = MediaFileService.sendMyFileToS3(localFilePath, keyName); //creating thumbnail of image and sending to database var thumbPath = HttpContext.Current.Server.MapPath("~/thumbnail" + postedFile.FileName); ThumbnailService.ResizeImage(localFilePath, thumbPath, 400, 400, ImageFormat.Jpeg); amazonCall = MediaFileService.sendMyFileToS3(thumbPath, "thumbnail/" + keyName); MediaProfileRequest request = new MediaProfileRequest(); request.MediaType = MediaType; request.ContentType = MimeMapping.GetMimeMapping(postedFile.FileName); request.UserId = UserService.GetCurrentUserId(); request.FilePath = ConfigService.uploadFileS3Prefix + "/" + keyName; request.MediaThemeId = themeId++; int MediaId = this._mediaService.Post(request); ItemResponse <int> response = new ItemResponse <int>(); response.Item = MediaId; docfiles.Add(localFilePath); result = Request.CreateResponse(HttpStatusCode.OK, response); return(result); } result = Request.CreateResponse(HttpStatusCode.Created, keyName); } else { result = Request.CreateResponse(HttpStatusCode.BadRequest); } return(result); }
public List <PushItemViewModel> PushItems(ApiCall call) { List <PushItemViewModel> result = new List <PushItemViewModel>(); var sitedb = call.WebSite.SiteDb(); foreach (var item in sitedb.Synchronization.GetPushItems(call.ObjectId)) { var siteojbect = ObjectService.GetSiteObject(sitedb, item); if (siteojbect == null) { continue; } ChangeType changetype = ChangeType.Add; if (item.EditType == IndexedDB.EditType.Delete) { changetype = ChangeType.Delete; } else if (item.EditType == IndexedDB.EditType.Update) { changetype = ChangeType.Update; } PushItemViewModel viewmodel = new PushItemViewModel { Id = item.Id, ObjectType = ConstTypeService.GetModelType(siteojbect.ConstType).Name, Name = LogService.GetLogDisplayName(sitedb, item), KoobooType = siteojbect.ConstType, ChangeType = changetype, LastModified = siteojbect.LastModified, LogId = item.Id }; viewmodel.Size = CalculateUtility.GetSizeString(ObjectService.GetSize(siteojbect)); if (siteojbect.ConstType == ConstObjectType.Image) { viewmodel.Thumbnail = ThumbnailService.GenerateThumbnailUrl(siteojbect.Id, 50, 50, call.WebSite.Id); } result.Add(viewmodel); } return(result); }
public void TestMethod1() { ILogLevelSwitchService logSwitchService = new LogLevelSwitchService(); ICommandLineService commandLineService = new CommandLineService(); IDatabaseService db = new DatabaseService(); IOptionsService optionsService = new OptionsService(logSwitchService, commandLineService); IThumbnailService service = new ThumbnailService(db, optionsService); service.ClearThumbCache(); var folder = Path.Combine(FileUtils.GetUsersTempFolder(), "OnlyMIntegrationTests"); FileUtils.CreateDirectory(folder); var filePath = Path.Combine(folder, "TestImage01.jpg"); var bmp = Properties.Resources.Test01; bmp.Save(filePath, ImageFormat.Jpeg); var lastWrite = File.GetLastWriteTimeUtc(filePath); var dummyFfmpegFolder = string.Empty; // not needed when getting image thumbs var thumb1 = service.GetThumbnail(filePath, dummyFfmpegFolder, MediaClassification.Image, lastWrite.Ticks, out var foundInCache); Assert.IsNotNull(thumb1); Assert.IsFalse(foundInCache); // try again to check we get cached version var thumb2 = service.GetThumbnail(filePath, dummyFfmpegFolder, MediaClassification.Image, lastWrite.Ticks, out foundInCache); Assert.IsNotNull(thumb2); Assert.IsTrue(foundInCache); // now send wrong lastchanged value var thumb3 = service.GetThumbnail(filePath, dummyFfmpegFolder, MediaClassification.Image, 123456, out foundInCache); Assert.IsNotNull(thumb3); Assert.IsFalse(foundInCache); service.ClearThumbCache(); }
public ImageRecognitionService(StatusService statusService, ObjectDetector objectDetector, MetaDataService metadataService, AzureFaceService azureFace, AccordFaceService accordFace, EmguFaceService emguService, ThumbnailService thumbs, ConfigService configService, ImageClassifier imageClassifier, ImageCache imageCache, WorkService workService, ExifService exifService, ImageProcessService imageProcessor) { _thumbService = thumbs; _accordFaceService = accordFace; _azureFaceService = azureFace; _statusService = statusService; _objectDetector = objectDetector; _metdataService = metadataService; _emguFaceService = emguService; _configService = configService; _imageClassifier = imageClassifier; _imageProcessor = imageProcessor; _imageCache = imageCache; _workService = workService; _exifService = exifService; }
private List <MediaFileViewModel> GetFilesBy(SiteDb siteDb, string by) { string baseurl = siteDb.WebSite.BaseUrl(); // by = View, Page, Layout, TextContent, Style. byte consttype = ConstObjectType.GetByte(by); var images = siteDb.Images.ListUsedBy(consttype); List <MediaFileViewModel> Result = new List <MediaFileViewModel>(); foreach (var item in images) { MediaFileViewModel model = new MediaFileViewModel(); model.Id = item.Id; model.Height = item.Height; model.Width = item.Width; model.Size = item.Size; model.Name = item.Name; model.LastModified = item.LastModified; model.Thumbnail = ThumbnailService.GenerateThumbnailUrl(item.Id, 90, 0, siteDb.Id); model.Url = ObjectService.GetObjectRelativeUrl(siteDb, item); model.IsImage = true; model.PreviewUrl = Lib.Helper.UrlHelper.Combine(baseurl, model.Url); var usedby = siteDb.Images.GetUsedBy(item.Id); if (usedby != null) { model.References = usedby.GroupBy(it => it.ConstType).ToDictionary( key => { return(ConstTypeService.GetModelType(key.Key).Name); }, value => value.Count()); } Result.Add(model); } return(Result); }
public async Task GenerateThumbnail() { // Arrange var defs = new List <ThumbnailSizeDefinition> { new ThumbnailSizeDefinition { Name = ThumbnailSizeName.M, Width = 240 } }; var service = new ThumbnailService(defs); Image image = TestMediaLibrary.WithExif.AsImage(); // Act ThumbnailResult thumb = await service.GenerateThumbnailAsync( image, ThumbnailSizeName.M, default); // Assert //thumb.Dimensions.Width.Should() }