Beispiel #1
0
        internal static WorkbookAppInstallation FromManifestObject(
            string manifestDirectory,
            string id,
            JObject appJson)
        {
            IEnumerable <string> Pathify(string path)
            {
                if (path == null)
                {
                    return(Array.Empty <string> ());
                }

                var fullPath = Path.Combine(manifestDirectory, path);

                foreach (var mapper in pathMappers)
                {
                    fullPath = mapper(fullPath);
                    if (fullPath == null)
                    {
                        return(Array.Empty <string> ());
                    }
                }

                if (path == "{systemGac}")
                {
                    return(GacCache.GacPaths);
                }

                return(new [] { fullPath });
            }

            var flavor = appJson.GetValue("flavor")?.Value <string> ();

            if (flavor == null)
            {
                return(null);
            }

            var sdkJson = appJson.GetValue("sdk") as JObject;

            if (sdkJson == null)
            {
                return(null);
            }

            var appPath = Pathify(appJson.GetValue("appPath")?.Value <string> ()).FirstOrDefault();

            if (appPath == null)
            {
                return(null);
            }
            if (!new FilePath(appPath).Exists)
            {
                Log.Error(TAG, $"appPath invalid for {id}: {appPath}");
                return(null);
            }

            var targetFramework = sdkJson.GetValue("targetFramework")?.Value <string> ();

            if (targetFramework == null)
            {
                return(null);
            }

            var assemblySearchPaths = sdkJson
                                      .GetValue("assemblySearchPaths")
                                      ?.ToObject <string []> ()
                                      ?.SelectMany(Pathify)
                                      .ToArray();

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

            var order = appJson.GetValue("order")?.Value <int> () ?? int.MaxValue;

            var sdk = new Sdk(
                id,
                new FrameworkName(targetFramework),
                assemblySearchPaths,
                sdkJson.GetValue("name")?.Value <string> (),
                sdkJson.GetValue("profile")?.Value <string> (),
                sdkJson.GetValue("version")?.Value <string> ());

            return(new WorkbookAppInstallation(
                       id,
                       flavor,
                       appJson.GetValue("icon")?.Value <string> (),
                       appJson.GetValue("optionalFeatures")?.ToObject <string []> (),
                       sdk,
                       appPath,
                       Pathify(appJson.GetValue("appManagerAssembly")?.Value <string> ())?.SingleOrDefault(),
                       order));
        }