예제 #1
0
        private MetaMetadataCompositeField GetMetaMetadata()
        {
            MetaMetadataCompositeField mm = _metaMetadata;

            //mm = await MetaMetadataTranslationScope.Get().Deserialize()
            if (_repository == null)
            {
                _repository = MetaMetadataRepositoryInit.GetRepository();
            }

            if (mm == null && _repository != null)
            {
                if (this.MetaMetadataName != null)  // get from saved composition
                {
                    mm = _repository.GetMMByName(this.MetaMetadataName.Value);
                }

                if (mm == null)
                {
                    ParsedUri location = Location == null ? null : Location.Value;
                    if (location != null)
                    {
                        mm = IsImage ? _repository.GetImageMM(location) : _repository.GetDocumentMM(location);

                        // TODO -- also try to resolve by mime type ???
                    }
                    if (mm == null)
                    {
                        mm = _repository.GetByClass(this.GetType());
                    }
                    if (mm == null && MetadataClassDescriptor != null)
                    {
                        mm = _repository.GetMMByName(MetadataClassDescriptor.TagName);
                    }
                }

                if (mm != null)
                {
                    MetaMetadata = mm;
                }
            }
            return(mm);
        }
        private void WebView_LoadCompleted(object sender, EventArgs e)
        {
            //if (Source == null || BLANK_PAGE.Equals(Source))// || loadingComplete)
            //   return;
            WebView webView = sender as WebView;

            if (webView == null)
            {
                return;
            }
            webView.Stop(); // Stopping further requests.
            Console.WriteLine("Finished loading in " + DateTime.Now.Subtract(timeStart).TotalMilliseconds + "ms. Executing javascript. -- ");
            Console.WriteLine("======================================= Time To Load : " + DateTime.Now.Subtract(timeStart).TotalMilliseconds);
            parseStart = DateTime.Now;
            MetaMetadataRepository repository = SemanticsSessionScope.MetaMetadataRepository;
            MetaMetadata           mmd        = repository.GetDocumentMM(_puri);

            Console.WriteLine("Got MMD: " + mmd.Name);
            String jsonMMD = WebBrowserPool.GetJsonMMD(mmd);

            //Console.WriteLine("json:\n" + jsonMMD + "\n");
            //jsonMMD = jsonMMD.Replace("\\", "\\\\");

            webView.JSConsoleMessageAdded += new JSConsoleMessageAddedEventHandler(JSConsoleEvent);

            webView.ExecuteJavascript(jsonMMD);
            webView.ExecuteJavascript(WebBrowserPool.MmdDomHelperJsString);
            Console.WriteLine("Done js code execution, calling function. --" + DateTime.Now + " : " + DateTime.Now.Millisecond);
            //TODO: Currently executes asynchronously. Can we make this asynchronous?

            webView.CreateObject("CallBack");
            webView.SetObjectCallback("CallBack", "MetadataExtracted", OnMetadataExtracted);

            //webView.ExecuteJavascript("CallBack.MetadataExtracted('some value');");
            //Return happens through the task, on completion of the method via the callback
            webView.ExecuteJavascript("extractMetadataWithCallback(mmd);");

            _requestTimedOut.Start();
        }