Пример #1
0
 public JSEngine(EnginePool parent)
 {
     _parent = parent;
     _engine = new Jint.Engine();
     parent._config.Initializer.Invoke(_engine);
 }
Пример #2
0
        public Extension(StorageFolder folder, ExtensionManifest manifest, bool isPacked, string javaScript, string javaScriptLibrary)
        {
            // If the id is missing
            if (manifest.Id == null)
            {
                throw new ManifestInvalidException(InvalidManifestError.MissingId);
            }

            // If the name is missing
            if (string.IsNullOrEmpty(manifest.Name))
            {
                throw new ManifestInvalidException(InvalidManifestError.MissingName);
            }

            // If the publisher is missing
            if (string.IsNullOrEmpty(manifest.Publisher))
            {
                throw new ManifestInvalidException(InvalidManifestError.MissingPublisher);
            }

            // Validate the provided extension version
            if (string.IsNullOrEmpty(manifest.Version) || !Version.TryParse(manifest.Version, out _))
            {
                throw new ManifestInvalidException(InvalidManifestError.MissingVersion);
            }

            // If there is no platform version specified
            if (!manifest.PlatformVersion.HasValue)
            {
                throw new ManifestInvalidException(InvalidManifestError.MissingPlatformVersion);
            }

            // Check to see if we support this version
            if (manifest.PlatformVersion.Value > ExtensionBootstrapper.ApiVersion)
            {
                throw new ManifestInvalidException(InvalidManifestError.UnsupportedPlatformVersion);
            }

            // If the description is missing
            if (string.IsNullOrEmpty(manifest.Description))
            {
                throw new ManifestInvalidException(InvalidManifestError.MissingDescription);
            }

            // If the short description is missing, set it to the main description
            if (string.IsNullOrEmpty(manifest.ShortDescription))
            {
                manifest.ShortDescription = manifest.Description;
            }

            // If there is no url, set it to the store URL
            if (string.IsNullOrEmpty(manifest.Url))
            {
                manifest.Url = "https://soundbytemedia.com/store/" + manifest.Id.ToString();
            }

            // If the platform is specified, make sure UWP is included
            if (manifest.Platforms != null)
            {
                if (!manifest.Platforms.Contains("uwp"))
                {
                    throw new ManifestInvalidException(InvalidManifestError.PlatformUnsupported);
                }
            }

            // Check that assets are included
            if (manifest.Assets == null || string.IsNullOrEmpty(manifest.Assets.StoreLogo))
            {
                throw new ManifestInvalidException(InvalidManifestError.MissingAssets);
            }

            // Fix the logos
            manifest.Assets.StoreLogo = folder.Path + "/" + manifest.Assets.StoreLogo;

            Identifier = manifest.Id.Value;
            Folder     = folder;
            Manifest   = manifest;
            IsPacked   = isPacked;

            // Setup the music provider
            if (manifest.Provider != null)
            {
                SetupMusicProvider(manifest.Provider);
            }

            // Create the JavaScript engine pool
            _enginePool = new EnginePool(new EnginePool.EnginePoolConfig(engine =>
            {
                try
                {
                    // Add the class types the app can access
                    engine.SetValue("Track", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(BaseTrack)));
                    engine.SetValue("User", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(BaseUser)));
                    engine.SetValue("Playlist", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(BasePlaylist)));
                    engine.SetValue("GenericItem", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(BaseSoundByteItem)));
                    engine.SetValue("SourceResponse", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(SourceResponse)));

                    engine.SetValue("FilteredListViewHolder", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(FilteredListViewModel.Holder)));
                    engine.SetValue("FilterViewItem", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(FilteredListViewModel.Filter)));
                    engine.SetValue("PageName", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(PageName)));

                    // Bind the platform
                    engine.SetValue("platform", new Platform());

                    // Load the Soundbyte library
                    engine.Execute(javaScriptLibrary);

                    // Load the music provider
                    engine.Execute(javaScript);
                }
                catch (Exception e)
                {
                    App.NotificationManager?.Show($"{Manifest?.Name ?? "Unknown"} (extension) is causing script errors: " + e.Message, 5000);
                }
            }));
        }