Example #1
0
        private void EnsureValidImage(string imagePath, int imageIndex)
        {
            Log.Verbose("Checking image at {Path}, with index {Index}", imagePath, imageIndex);

            if (!fileSystemOperations.FileExists(imagePath))
            {
                throw new FileNotFoundException($"Image not found: {imagePath}. Please, verify that the file exists and it's accessible.");
            }

            Log.Verbose("Image file at '{ImagePath}' exists", imagePath);
        }
Example #2
0
        private string GetMetadataFilename()
        {
            string finalFilename;

            do
            {
                var fileName = Path.GetFileNameWithoutExtension(origin);
                finalFilename = fileName + "_" + Path.GetRandomFileName() + "Info.json";
            } while (fileSystemOperations.FileExists(finalFilename));

            return(finalFilename);
        }
Example #3
0
        private bool IsAlreadyInstalled()
        {
            var existingFile = Path.Combine(destinationFolder, DevMenuName);

            if (!fileSystemOperations.FileExists(existingFile))
            {
                return(false);
            }

            var newFile = Path.Combine("Core", "Developer Menu", DevMenuName);

            return(string.Equals(Checksum(existingFile), Checksum(newFile)));
        }
Example #4
0
        private async Task <RunContext> Load(Device device)
        {
            await DownloadFeed();

            var paths = new[] { ScriptsDownloadPath }.Concat(device.Identifier).Concat(new[] { MainScriptName });
            var scriptPath = Path.Combine(paths.ToArray());

            if (!fileSystemOperations.FileExists(scriptPath))
            {
                throw new DeploymentException($"Unsupported device {device}. The required script isn't present");
            }

            return(Load(scriptPath));
        }
        /// <summary>
        /// Returns a stream backed by the specified package if it exists; otherwise returns null.
        /// </summary>
        /// <param name="packageId">The ID of the package.</param>
        /// <param name="packageVersion">The version of the package.</param>
        /// <returns>Stream backed by the specified package if it exists; otherwise null.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="packageId"/> is null or contains only whitespace or <paramref name="packageVersion"/> is null.</exception>
        public override Stream OpenPackage(string packageId, SemanticVersion packageVersion)
        {
            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentNullException("packageId");
            }
            if (packageVersion == null)
            {
                throw new ArgumentNullException("packageVersion");
            }

            InitPackageStore();

            _logger.Debug("OpenPackage('" + packageId + "', '" + packageVersion + "') called");

            var packagePath = Path.Combine(RootPath, packageId);

            if (!_fileSystemOperations.DirectoryExists(packagePath))
            {
                _logger.Warn("Attempted to open package '" + packageId + "', version '" + packageVersion + "', in folder '" + packagePath + "' but the folder didn't exist");
                return(null);
            }

            var versionPath = Path.Combine(packagePath, packageId + "." + packageVersion + ".nupkg");

            if (!_fileSystemOperations.FileExists(versionPath))
            {
                _logger.Warn("Attempted to open package '" + packageId + "', version '" + packageVersion + "', at path '" + versionPath + "' but it didn't exist");
                return(null);
            }

            try
            {
                return(_fileSystemOperations.GetFileStream(versionPath, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete));
            }
            catch (FileNotFoundException ex)
            {
                _logger.Error("File not found error looking for package '" + packageId + "', version '" + packageVersion + "'.", ex);
                return(null);
            }
            catch (DirectoryNotFoundException ex)
            {
                _logger.Error("Directory not found error looking for package '" + packageId + "', version '" + packageVersion + "'.", ex);
                return(null);
            }
        }