示例#1
0
        /// <summary>
        /// Read manifest file
        /// </summary>
        /// <param name="filePath">File path</param>
        /// <returns></returns>
        protected async Task <AppManifest> ReadManifestAsync(string filePath)
        {
            string savePath = FSHelper.NormalizeLocation(filePath);
            string result;

            using (StreamReader reader = File.OpenText(savePath))
            {
                result = await reader.ReadToEndAsync();
            }

            try
            {
                AppManifest manifest = JsonConvert.DeserializeObject <AppManifest>(result);
                manifest.Location = Path.GetDirectoryName(filePath);

                return(manifest);
            }
            catch (Exception ex)
            {
                LogError($"Corrupted app manifest at '{savePath}'. Error: {ex.Message}");
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Get list of applications from specific path
        /// </summary>
        /// <param name="path">Source path</param>
        /// <returns></returns>
        public async Task <Dictionary <string, AppManifest> > GetPackagesFromPath(string path)
        {
            if (!Directory.Exists(path))
            {
                LogWarn($"Packages path source not exists: '{path}'");
                return(null);
            }

            string[] directories = Directory.GetDirectories(path);

            if (directories.Length == 0)
            {
                return(null);
            }

            Dictionary <string, AppManifest> packages = new Dictionary <string, AppManifest>();

            foreach (string dir in directories)
            {
                string manifestFile = dir + @"\" + AppManifest.FileName;

                if (!File.Exists(manifestFile))
                {
                    continue;
                }

                AppManifest manifest = await ReadManifestAsync(manifestFile);

                if (manifest != null)
                {
                    packages.Add(manifest.Domain, manifest);
                }
            }

            return(packages);
        }