Exemplo n.º 1
0
        public async Task DownloadExifTool_Windows_existVerbose()
        {
            var appSettings = new AppSettings {
                TempFolder = AppDomain.CurrentDomain.BaseDirectory,
                Verbose    = true
            };

            Directory.CreateDirectory(appSettings.TempFolder);
            Directory.CreateDirectory(Path.Combine(appSettings.TempFolder, "exiftool-windows"));

            var stream = new PlainTextFileHelper().StringToStream("#!/bin/bash");

            await new StorageHostFullPathFilesystem().WriteStreamAsync(stream,
                                                                       Path.Combine(appSettings.TempFolder, "exiftool-windows", "exiftool.exe"));

            var httpClientHelper = new HttpClientHelper(new FakeIHttpProvider(), _serviceScopeFactory, new FakeIWebLogger());
            var logger           = new FakeIWebLogger();

            var result = await new ExifToolDownload(httpClientHelper, appSettings, logger).DownloadExifTool(true);

            Assert.IsTrue(result);
            Assert.IsTrue(logger.TrackedInformation.FirstOrDefault().Item2
                          .Contains("[DownloadExifTool] " + appSettings.TempFolder));

            Directory.Delete(Path.Combine(appSettings.TempFolder, "exiftool-windows"), true);
        }
Exemplo n.º 2
0
        public FileIndexItem XmpGetSidecarFile(FileIndexItem databaseItem)
        {
            if (databaseItem == null)
            {
                databaseItem = new FileIndexItem();
            }

            // Parse an xmp file for this location
            var xmpSubPath =
                ExtensionRolesHelper.ReplaceExtensionWithXmp(databaseItem.FilePath);

            // also add when the file is a jpeg, we are not writing to it then
            if (_iStorage.ExistFile(xmpSubPath))
            {
                databaseItem.AddSidecarExtension("xmp");
            }

            // Read content from sidecar xmp file
            if (!ExtensionRolesHelper.IsExtensionForceXmp(databaseItem.FilePath) ||
                !_iStorage.ExistFile(xmpSubPath))
            {
                return(databaseItem);
            }

            // Read the text-content of the xmp file.
            var xmp = new PlainTextFileHelper().StreamToString(_iStorage.ReadStream(xmpSubPath));

            // Get the data from the xmp
            databaseItem = GetDataFromString(xmp, databaseItem);
            return(databaseItem);
        }
Exemplo n.º 3
0
        public async Task SetLocalAppData_ShouldRead()
        {
            var appDataFolderFullPath =
                Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "setup_app_settings_test");

            _hostStorage.CreateDirectory(appDataFolderFullPath);
            var path = Path.Combine(appDataFolderFullPath, "appsettings.json");

            var example =
                new PlainTextFileHelper().StringToStream(
                    "{\n \"app\" :{\n   \"isAccountRegisterOpen\": \"true\"\n }\n}\n");

            await _hostStorage.WriteStreamAsync(example, path);

            Environment.SetEnvironmentVariable("app__appsettingspath", path);
            var builder = await SetupAppSettings.AppSettingsToBuilder();

            var services    = new ServiceCollection();
            var appSettings = SetupAppSettings.ConfigurePoCoAppSettings(services, builder);

            Assert.IsFalse(string.IsNullOrEmpty(appSettings.AppSettingsPath));
            Assert.IsTrue(appSettings.IsAccountRegisterOpen);
            Assert.AreEqual(path, appSettings.AppSettingsPath);

            _hostStorage.FolderDelete(appDataFolderFullPath);
            Environment.SetEnvironmentVariable("app__appsettingspath", null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a simple xmp starter file
        /// </summary>
        /// <param name="xmpPath">location</param>
        public void XmpCreate(string xmpPath)
        {
            if (_iStorage.ExistFile(xmpPath))
            {
                return;
            }

            var plainTextStream = new PlainTextFileHelper().StringToStream(XmpStartContent);

            _iStorage.WriteStream(plainTextStream, xmpPath);
        }
Exemplo n.º 5
0
        private byte[] ExampleManifest()
        {
            var input = "{\n  \"Name\": \"Test\",\n  " +
                        "\"Copy\": {\n    \"1000/0_kl1k.jpg\": " +
                        "true,\n    \"_settings.json\": false\n  },\n" +
                        "  \"Slug\": \"test\",\n  \"Export\": \"20200808121411\",\n" +
                        "  \"Version\": \"0.3.0.0\"\n}";
            var stream = new PlainTextFileHelper().StringToStream(input) as MemoryStream;

            return(stream.ToArray());
        }
Exemplo n.º 6
0
        public async Task <bool> WriteTagsAsync(string subPath, string command)
        {
            Console.WriteLine("Fake ExifTool + " + subPath + " " + command);

            if (subPath.EndsWith(".xmp"))
            {
                var stream = new PlainTextFileHelper().StringToStream(XmpInjection);
                await _iStorage.WriteStreamAsync(stream, subPath);
            }
            return(true);
        }
Exemplo n.º 7
0
        public async Task <KeyValuePair <bool, string> > WriteTagsAndRenameThumbnailAsync(string subPath, string command)
        {
            Console.WriteLine("Fake ExifTool + " + subPath + " " + command);

            if (subPath.EndsWith(".xmp"))
            {
                var stream = new PlainTextFileHelper().StringToStream(XmpInjection);
                await _iStorage.WriteStreamAsync(stream, subPath);
            }

            var newFileHash = (await new FileHash(_iStorage).GetHashCodeAsync(subPath)).Key;

            return(new KeyValuePair <bool, string>(true, newFileHash));
        }
Exemplo n.º 8
0
        internal async Task <Dictionary <string, bool> > GenerateWebHtml(List <AppSettingsPublishProfiles> profiles,
                                                                         AppSettingsPublishProfiles currentProfile, string itemName, string[] base64ImageArray,
                                                                         IEnumerable <FileIndexItem> fileIndexItemsList, string outputParentFullFilePathFolder)
        {
            if (string.IsNullOrEmpty(currentProfile.Template))
            {
                _console.WriteLine("CurrentProfile Template not configured");
                return(new Dictionary <string, bool>());
            }

            // Generates html by razorLight
            var viewModel = new WebHtmlViewModel
            {
                ItemName         = itemName,
                Profiles         = profiles,
                AppSettings      = _appSettings,
                CurrentProfile   = currentProfile,
                Base64ImageArray = base64ImageArray,
                // apply slug to items, but use it only in the copy
                FileIndexItems = fileIndexItemsList.Select(c => c.Clone()).ToList(),
            };

            // add to IClonable
            foreach (var item in viewModel.FileIndexItems)
            {
                item.FileName = _appSettings.GenerateSlug(item.FileCollectionName, true) +
                                Path.GetExtension(item.FileName);
            }

            // has a direct dependency on the filesystem
            var embeddedResult = await new ParseRazor(_hostFileSystemStorage)
                                 .EmbeddedViews(currentProfile.Template, viewModel);

            var stream = new PlainTextFileHelper().StringToStream(embeddedResult);
            await _hostFileSystemStorage.WriteStreamAsync(stream,
                                                          Path.Combine(outputParentFullFilePathFolder, currentProfile.Path));

            _console.Write(_appSettings.IsVerbose() ? embeddedResult + "\n" : "•");

            return(new Dictionary <string, bool>
            {
                {
                    currentProfile.Path.Replace(outputParentFullFilePathFolder, string.Empty),
                    currentProfile.Copy
                }
            });
        }
Exemplo n.º 9
0
        public static List <GeoListItem> ReadGpxFile(Stream stream, List <GeoListItem>?geoList = null, int returnAfter = int.MaxValue)
        {
            if (geoList == null)
            {
                geoList = new List <GeoListItem>();
            }

            // Some files are having problems with gpxDoc.Load()
            var fileString = new PlainTextFileHelper().StreamToString(stream);

            try
            {
                return(ParseGpxString(fileString, geoList, returnAfter));
            }
            catch (XmlException e)
            {
                Console.WriteLine($"XmlException>>\n{e}\n <<XmlException");
                return(geoList);
            }
        }
Exemplo n.º 10
0
        public async Task Thumbnail_CorruptImage_NoContentResult_Test()
        {
            // Arrange
            var storage         = ArrangeStorage();
            var plainTextStream = new PlainTextFileHelper().StringToStream("CorruptImage");
            await storage.WriteStreamAsync(plainTextStream, ThumbnailNameHelper.Combine(
                                               "hash-corrupt-image", ThumbnailSize.ExtraLarge));

            await _query.AddItemAsync(new FileIndexItem("/test2.jpg"){ FileHash = "hash-corrupt-image" });

            // Act
            var controller = new ThumbnailController(_query, new FakeSelectorStorage(storage));

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var actionResult = controller.Thumbnail("hash-corrupt-image",
                                                    false, true) as NoContentResult;

            Assert.AreEqual(204, actionResult.StatusCode);

            // remove files + database item
            await _query.RemoveItemAsync(await _query.GetObjectByFilePathAsync("/test2.jpg"));
        }
Exemplo n.º 11
0
        private static async Task <AppSettings> CreateTempFolderWithExifTool(string name = "test temp")
        {
            var appSettings = new AppSettings {
                TempFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, name)
            };

            Directory.CreateDirectory(appSettings.TempFolder);
            Directory.CreateDirectory(Path.Combine(appSettings.TempFolder, "exiftool-unix"));
            var stream = new PlainTextFileHelper().StringToStream("#!/bin/bash");

            try
            {
                await new StorageHostFullPathFilesystem().WriteStreamAsync(stream,
                                                                           Path.Combine(appSettings.TempFolder, "exiftool-unix", "exiftool"));
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(appSettings);
        }
Exemplo n.º 12
0
        public void ExifToolCmdHelper_XmpCreate()
        {
            var folderPaths = new List <string> {
                "/"
            };
            var inputSubPaths = new List <string> {
                "/test.dng"
            };
            var storage =
                new FakeIStorage(folderPaths, inputSubPaths,
                                 new List <byte[]> {
                FakeCreateAn.CreateAnImage.Bytes
            });

            var fakeReadMeta = new ReadMeta(storage);
            var fakeExifTool = new FakeExifTool(storage, _appSettings);

            new ExifCopy(storage, storage, fakeExifTool, fakeReadMeta).XmpCreate("/test.xmp");
            var result = new PlainTextFileHelper().StreamToString(storage.ReadStream("/test.xmp"));

            Assert.AreEqual("<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='Starsky'>\n" +
                            "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n</rdf:RDF>\n</x:xmpmeta>", result);
        }
Exemplo n.º 13
0
 public PublishManifest(IStorage storage, PlainTextFileHelper plainTextFileHelper)
 {
     _storage             = storage;
     _plainTextFileHelper = plainTextFileHelper;
 }
Exemplo n.º 14
0
 private async Task WriteErrorMessageToBlockLog(string subPath, string resizeMessage)
 {
     var stream = new PlainTextFileHelper().StringToStream("Thumbnail error " + resizeMessage);
     await _iStorage.WriteStreamAsync(stream, GetErrorLogItemFullPath(subPath));
 }