예제 #1
0
        public async Task TestTryMoveFile()
        {
            using var tmpDir = _snapFilesystem.WithDisposableTempDirectory(_baseFixture.WorkingDirectory);
            var srcFilenameAbsolutePath = _snapFilesystem.PathCombine(tmpDir.WorkingDirectory, "test.txt");
            var dstFilenameAbsolutePath = _snapFilesystem.PathCombine(tmpDir.WorkingDirectory, "test2.txt");
            await _snapFilesystem.FileWriteUtf8StringAsync("test", srcFilenameAbsolutePath, default);

            _snapFilesystem.TryFileMove(srcFilenameAbsolutePath, dstFilenameAbsolutePath);
            Assert.True(_snapFilesystem.FileExists(dstFilenameAbsolutePath));
            Assert.Equal("test", _snapFilesystem.FileReadAllText(dstFilenameAbsolutePath));
        }
예제 #2
0
        static SnapApps BuildSnapAppsFromDirectory(
            [NotNull] ISnapFilesystem filesystem, [NotNull] ISnapAppReader reader, [NotNull] string workingDirectory)
        {
            if (filesystem == null)
            {
                throw new ArgumentNullException(nameof(filesystem));
            }
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }

            const string snapxYamlFilename = "snapx.yml";

            var snapsFilename = filesystem.PathCombine(workingDirectory, ".snapx", snapxYamlFilename);

            if (!filesystem.FileExists(snapsFilename))
            {
                SnapLogger.Error($"Unable to find application YML definition, it does not exist: {snapsFilename}");
                goto error;
            }

            var content = filesystem.FileReadAllText(snapsFilename);

            if (string.IsNullOrWhiteSpace(content))
            {
                SnapLogger.Error($"Application yml file is empty (does not containy any YML): {snapsFilename}");
                goto error;
            }

            try
            {
                var snapApps = reader.BuildSnapAppsFromYamlString(content);
                if (snapApps == null)
                {
                    goto error;
                }

                const int expectedSchemaVersion = 1;
                if (snapApps.Schema != expectedSchemaVersion)
                {
                    throw new Exception($"Invalid schema version: {snapApps.Schema}. Expected schema version: {expectedSchemaVersion}.");
                }

                snapApps.Generic ??= new SnapAppsGeneric();
                snapApps.Apps ??= new List <SnapsApp>();
                snapApps.Channels ??= new List <SnapsChannel>();

                return(snapApps);
            }
            catch (YamlException yamlException)
            {
                var moreHelpfulExceptionMaybe = yamlException.InnerException ?? yamlException;
                SnapLogger.ErrorException($"{snapxYamlFilename} file contains incorrect yaml syntax. Error message: {moreHelpfulExceptionMaybe.Message}.", moreHelpfulExceptionMaybe);
            }
            catch (Exception e)
            {
                SnapLogger.ErrorException($"Unknown error deserializing {snapxYamlFilename}", e);
            }

error:
            return(new SnapApps());
        }