Exemple #1
0
 public Channel(String pTitle, String pDescription, ParsedUri pLink, List <Item> pItems)
 {
     title       = pTitle;
     description = pDescription;
     link        = pLink;
     items       = pItems;
 }
        private async void BtnGetMetadata_Click(object sender, RoutedEventArgs e)
        {
            //            string serializedMetadata = UrlBox.Text;
            //            Object o = RepositoryMetadataTranslationScope.Get().Deserialize(serializedMetadata, StringFormat.Xml);
            //            StringBuilder sb = new StringBuilder();
            //            SimplTypesScope.Serialize(o, sb, StringFormat.Xml);
            //            String reserializedMetadatata = sb.ToString();
            //            Console.WriteLine(reserializedMetadatata);
            //Expander expander = new Expander();
            //TextBox metadataXML = new TextBox { TextWrapping = TextWrapping.Wrap, MinHeight = 100 };
            //metadataXML.Text = reserializedMetadatata;

            string urls = UrlBox.Text;

            List <Task <Document> >          extractionRequests = new List <Task <Document> >();
            Dictionary <ParsedUri, DateTime> timeStamps         = new Dictionary <ParsedUri, DateTime>();

            foreach (var s in urls.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
            {
                Console.WriteLine("Requesting async extraction of: " + s);

                ParsedUri puri = new ParsedUri(s);
                {
                    Task <Document> t = _semanticsSessionScope.GetDocument(puri);
                    timeStamps.Add(puri, DateTime.Now);
                    //Alternate, if you want the document here:
                    //Document doc = await _semanticsSessionScope.GetDocument(puri);

                    extractionRequests.Add(t);
                }
            }

            while (extractionRequests.Count > 0)
            {
                Task <Document> completedTask = await Task.WhenAny(extractionRequests);

                extractionRequests.Remove(completedTask);

                Document parsedDoc = await completedTask;
                if (parsedDoc == null)
                {
                    continue;
                }

                Expander expander = new Expander {
                    Header = parsedDoc.Title
                };
                TextBox metadataXML = new TextBox {
                    TextWrapping = TextWrapping.Wrap, MinHeight = 100
                };

                var s = timeStamps[parsedDoc.Location.Value];
                Console.WriteLine(" ---------------------------------- Time to complete: " +
                                  DateTime.Now.Subtract(s).TotalMilliseconds);
                metadataXML.Text = await Task.Run(() => SimplTypesScope.Serialize(parsedDoc, StringFormat.Xml));

                expander.Content = metadataXML;
                MetadataTitleXMLContainer.Children.Add(expander);
            }
        }
Exemple #3
0
        public ParsedUri Perform(ParsedUri input)
        {
            ParsedUri result = null;

            if (input != null && match != null)
            {
                String str     = input.ToString();
                Match  matcher = match.Match(str);
                if (matcher.Success)
                {
                    if (replace == null)
                    {
                        replace = "";
                    }
                    Debug.WriteLine(matcher.Groups[0].Value + " " + matcher.Groups[1].Value);
                    String rez = input.ToString().Replace(matcher.Groups[0].Value, replace);
                    for (int i = 1; i < matcher.Groups.Count; i++)
                    {
                        rez = rez.Replace("$" + i, matcher.Groups[i].Value);
                    }

                    result = new ParsedUri(rez);
                }
            }
            return(result);
        }
Exemple #4
0
        public override Input CreateConnector(ParsedUri uri)
        {
            string databasePath = uri.LocalPath;

            Logger.Info("Trying Skype database: {0} ...", databasePath);
            return(new SkypeInput(databasePath));
        }
Exemple #5
0
        public bool ProcessRedirect(Uri redirectedUri)
        {
            MetadataParsedURL originalMetadataPURL = originalDocument.Location;
            ParsedUri         originalPURL         = originalMetadataPURL == null ? null : originalMetadataPURL.Value;
            ParsedUri         redirectedPURL       = new ParsedUri(redirectedUri.AbsoluteUri);

            Debug.WriteLine("try redirecting: " + originalPURL + " > " + redirectedPURL);

            /*Document redirectedDocument = semanticsSessionScope.GetOrConstructDocument(redirectedPURL);
             * // note FIXME currently, GetOrConstructDocument does not return null!
             * if (redirectedDocument != null)
             * {
             *  // existing document: the redirected url has been visited already.
             *
             *  if (originalPURL != redirectedPURL)
             *      redirectedDocument.AddAdditionalLocation(originalMetadataPURL);
             *
             *  // TODO -- copy metadata from originalDocument?!!
             *
             *  documentClosure.ChangeDocument(redirectedDocument);
             *
             *  // TODO -- reconnect
             *
             *  return true;
             * }
             * else
             * {
             *  // TODO -- redirect to a new location.
             * }*/

            // TODO -- what if redirectedDocument is already in the queue or being downloaded?

            return(false);
        }
Exemple #6
0
        private static void ParseArguments(
            IDictionary <string, ValueObject> arguments,
            out Filter filter,
            out Grouper grouper,
            out FileSystem fileSystem,
            out Input input,
            out Output output)
        {
            filter  = new FilterHelper(arguments).Create();
            grouper = GrouperHelper.Create(arguments["--grouper"].AsList);

            string    fileSystemName = arguments["--file-system"].ToString();
            ParsedUri inputUri       = ParsedUriHelper.Parse(arguments["--input"]);
            ParsedUri outputUri      = ParsedUriHelper.Parse(arguments["--output"]);

            try
            {
                fileSystem = Everything.FileSystems.GetValue(fileSystemName).Create(outputUri);
                input      = Everything.Inputs.GetValue(inputUri.Scheme).CreateConnector(inputUri);
                output     = Everything.Outputs.GetValue(outputUri.Scheme).CreateConnector(outputUri, fileSystem);
            }
            catch (KeyNotFoundException e)
            {
                throw new InvalidArgumentInternalException(String.Format(
                                                               "Unknown scheme or name. {0}", e.Message));
            }
        }
Exemple #7
0
        /// <summary>
        ///
        /// Encapsulate the oodss client requst in a simpler GetMetadata call.
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public async Task <Document> RequestMetadata(ParsedUri uri)
        {
            Document result = null;

            if (_metadataClient != null)
            {
                Debug.WriteLine("Performing asynchronous call");
                ResponseMessage metadataResponse =
                    _metadataClient.RequestAsync(new MetadataRequest(uri.ToString())).Result;
                Debug.WriteLine("Received asynchronous request ");

                if (metadataResponse != null && metadataResponse is MetadataResponse)
                {
                    result = (metadataResponse as MetadataResponse).Metadata;
                }
                else if (metadataResponse != null && metadataResponse is SemanticServiceError)
                {
                    (metadataResponse as SemanticServiceError).Perform();
                }
                else
                {
                    throw new Exception();
                }
            }
            else
            {
                var requestUri = new ParsedUri(_serviceBaseUri, "?url=" + uri.AbsoluteUri);
                result = await _metadataTypeScope.DeserializeUri(requestUri, Format.Xml) as Document;
            }

            return(result);
        }
Exemple #8
0
        public override async Task <Document> GetDocument(ParsedUri puri)
        {
            if (puri == null)
            {
                Debug.WriteLine("Error: empty URL provided.");
                return(null);
            }

            var doc = await base.GetDocument(puri);

            if (doc == null)
            {
                try
                {
                    var response = await HttpClient.GetAsync(new Uri(MetadataServiceUri, "metadata.json?url=" + puri.AbsoluteUri));

                    if (response.IsSuccessStatusCode)
                    {
                        doc = this.MetadataTranslationScope.Deserialize(await response.Content.ReadAsStreamAsync(), Format.Json) as Document;
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine("failed to get document: {0}", e.Message);
                    doc = null;
                }
            }

            return(doc);
        }
Exemple #9
0
        public void Test()
        {
            char separator = '/';
            PrefixCollection <Object> pc = new PrefixCollection <Object>(separator);

            StringBuilder buffy = new StringBuilder(32);

            for (int i = 0; i < TEST_ADD.Length; i++)
            {
                //			println(TEST[i].directoryString());
                PrefixPhrase <Object> pp = pc.Add(TEST_ADD[i]);
                buffy.Clear();
                pp.ToStringBuilder(buffy, separator);
                Console.WriteLine(buffy);
            }
            Console.WriteLine("\n");

            for (int i = 0; i < TEST_MATCH.Length; i++)
            {
                ParsedUri purl = TEST_MATCH[i];

                Console.WriteLine(purl.ToString() + "\t" + pc.Match(purl));
            }
            Console.WriteLine("\n");

            foreach (String phrase in pc.Values())
            {
                Console.WriteLine(phrase);
            }
        }
 public void AddDocument(D doc, ParsedUri location)
 {
     if (doc == null || location == null)
     {
         throw new InvalidOperationException("Cannot add to SemanticsGlobalCollection");
     }
     Collection.Put(location, doc);
 }
        public bool Match(ParsedUri purl)
        {
            String host = purl.Host;
            // domainPrefix is a child of this, the root (with no parent)
            PrefixPhrase <O> hostPrefix = LookupChild(host);

            // children of hostPrefix
            return((hostPrefix == null) ? false : hostPrefix.Match(purl.LocalPath, separator));       //edit
        }
Exemple #12
0
 public Item(String pTitle, String pDescription, ParsedUri pLink, String pGuid, String pAuthor, List <String> pCategorySet)
 {
     title       = pTitle;
     description = pDescription;
     link        = pLink;
     guid        = pGuid;
     author      = pAuthor;
     categorySet = pCategorySet;
 }
Exemple #13
0
        public SemanticsSessionScope(SimplTypesScope metadataTranslationScope, string repoLocation, ParsedUri serviceUri,
                                     EventHandler <EventArgs> onCompleted)
            : base(metadataTranslationScope, repoLocation, onCompleted)
        {
            SemanticsSessionScope.Get = this;

            MetadataServiceUri = serviceUri;
            HttpClient         = new HttpClient();
        }
Exemple #14
0
        public override async Task <Document> GetOrConstructDocument(ParsedUri location)
        {
            Document doc = await base.GetOrConstructDocument(location);

            if (doc != null)
            {
                doc.SemanticsSessionScope = this;
            }
            return(doc);
        }
        public PrefixPhrase <O> getMatchingPrefix(ParsedUri purl)
        {
            String host = purl.Host;
            // domainPrefix is a child of this, the root (with no parent)
            PrefixPhrase <O> hostPrefix = LookupChild(host);

            // children of hostPrefix
            String path = purl.AbsolutePath;

            return((hostPrefix == null) ? null : hostPrefix.GetMatchingPrefix(path, 1, separator));             // skip over starting '/'
        }
        private static void GetPhotos(object State)
        {
            object[]         P           = (object[])State;
            int              i           = (int)P [0];
            IUPnPService     Service     = (IUPnPService)P [1];
            string           ContentType = (string)P [2];
            string           Extension   = (string)P [3];
            MailMessage      Msg         = (MailMessage)P [4];
            ManualResetEvent Done        = (ManualResetEvent)P [5];
            DateTime         Next        = DateTime.Now;

            try
            {
                UPnPAction GetDefaultImageURL = Service ["GetDefaultImageURL"];
                Variables  v = new Variables();
                GetDefaultImageURL.Execute(v);
                string ImageURL = (string)v ["RetImageURL"];

                ParsedUri    ImageURI = Web.ParseUri(ImageURL);
                HttpResponse Response;
                int          ms;
                int          j;

                using (HttpSocketClient Client = new HttpSocketClient(ImageURI.Host, ImageURI.Port, ImageURI.UriScheme is HttpsUriScheme, ImageURI.Credentials))
                {
                    Client.ReceiveTimeout = 20000;

                    for (j = 1; j <= 3; j++)
                    {
                        ms = (int)System.Math.Round((Next - DateTime.Now).TotalMilliseconds);
                        if (ms > 0)
                        {
                            Thread.Sleep(ms);
                        }

                        Response = Client.GET(ImageURI.PathAndQuery, ContentType);
                        Msg.EmbedObject("cam" + (i + 1).ToString() + "img" + j.ToString() + "." + Extension, ContentType, Response.Data);

                        Log.Information("Click.", EventLevel.Minor, Service.Device.FriendlyName);

                        Next = Next.AddSeconds(5);
                    }
                }
            } catch (ThreadAbortException)
            {
                Thread.ResetAbort();
            } catch (Exception ex)
            {
                Log.Exception(ex);
            } finally
            {
                Done.Set();
            }
        }
        public PrefixPhrase <O> Add(ParsedUri purl)
        {
            String host = purl.Host;        //edit
            // domainPrefix is a child of this, the root (with no parent)
            PrefixPhrase <O> hostPrefix = GetPrefix(null, host);

            // children of hostPrefix
            String pathStringToParse = usePathFile ? purl.ToString() : purl.LocalPath;        //.pathDirectoryString;

            return((hostPrefix != null) ? hostPrefix.Add(pathStringToParse, separator) : LookupChild(host));
        }
 public WebViewParser(DocumentClosure closure)
 {
     _closure = closure;
     SemanticsSessionScope = closure.SemanticsSessionScope;
     _webView         = SemanticsSessionScope.WebBrowserPool.Acquire();
     _puri            = closure.PURLConnection.ResponsePURL;
     _requestTimedOut = new DispatcherTimer()
     {
         Interval = EXTRACTION_TIMEOUT
     };
     _requestTimedOut.Tick += ExtractionRequestTimedOut;
 }
Exemple #19
0
        public Image ConstructImage(ParsedUri location)
        {
            MetaMetadata metaMetadata = GetImageMM(location);
            Image        result       = null;

            if (metaMetadata != null)
            {
                result          = (Image)metaMetadata.ConstructMetadata(this.MetadataTScope);
                result.Location = new MetadataParsedURL(location);
            }
            return(result);
        }
Exemple #20
0
        public string GetUriLeftPart(ParsedUri parsedUri)
        {
            var    urlWithQuery    = parsedUri.GetComponents(UriComponents.HttpRequestUrl, UriFormat.UriEscaped);
            var    query           = parsedUri.GetComponents(UriComponents.Query, UriFormat.UriEscaped);
            var    index           = urlWithQuery.IndexOf(query);
            string urlWithoutQuery = urlWithQuery;

            if (index != -1)
            {
                urlWithoutQuery = urlWithQuery.Remove(index);
            }
            return(urlWithoutQuery);
        }
Exemple #21
0
        public async Task <MetaMetadataRepository> LoadRepositoryFromServiceAsync(ParsedUri serviceUri, object cacheFile = null)
        {
            _metaMetadataRepository = (serviceUri != null) ? await RequestMetaMetadataRepository(new ParsedUri(serviceUri, "mmdrepository.xml")) : new MetaMetadataRepository();

            if (cacheFile != null)
            {
                SimplTypesScope.Serialize(_metaMetadataRepository, cacheFile, Format.Xml);
            }

            InitializeRepositoryAndPerformBinding();

            return(_metaMetadataRepository);
        }
        public virtual async Task <Document> GetDocument(ParsedUri location)
        {
            if (location == null)
            {
                return(null);
            }

            Document doc;

            GlobalDocumentCollection.TryGetDocument(location, out doc);

            return(doc);
        }
        public async Task <object> DeserializeUri(ParsedUri uri, Format format = Format.Xml, TranslationContext context = null, IDeserializationHookStrategy deserializationHookStrategy = null)
        {
            object result = null;

            var request = WebRequest.Create(uri);

            if (request != null)
            {
                WebResponse response = await request.GetResponseAsync();

                result = Deserialize(response.GetResponseStream(), context, deserializationHookStrategy, format);
            }

            return(result);
        }
        public virtual async Task <Document> GetOrConstructDocument(ParsedUri location)
        {
            var doc = await GetDocument(location);

            if (doc == null && MetaMetadataRepository != null)
            {
                doc = MetaMetadataRepository.ConstructDocument(location, false);
                if (doc != null)
                {
                    GlobalDocumentCollection.AddDocument(doc, location);
                }
            }

            return(doc);
        }
Exemple #25
0
        public Document ConstructDocument(ParsedUri location, bool isImage)
        {
            // if (location.IsImage) return constructImage(location);
            if (isImage)
            {
                return(ConstructImage(location));
            }
            MetaMetadata mmd    = GetDocumentMM(location);
            Document     result = mmd.ConstructMetadata(MetadataTScope) as Document;

            if (result != null)
            {
                result.Location = new MetadataParsedURL(location);
            }
            return(result);
        }
 ///<summary>
 /// Get the old location from this.
 /// Set the location of this to the newLocation.
 /// Add a mapping in the GlobalCollection from newLocation to this.
 /// Add the old location for this as an additionalLocation for this.
 ///</summary>
 public void ChangeLocation(ParsedUri newLocation)
 {
     if (newLocation != null)
     {
         MetadataParsedURL origLocation = Location;
         if (!origLocation.Value.Equals(newLocation))
         {
             Location = new MetadataParsedURL(newLocation);
             if (SemanticsSessionScope != null)
             {
                 SemanticsSessionScope.GlobalDocumentCollection.AddDocument(this, newLocation);
             }
             AddAdditionalLocation(origLocation);
         }
     }
 }
Exemple #27
0
        public override Input CreateConnector(ParsedUri uri)
        {
            string skypeId = uri.Host;

            Logger.Debug("Trying Skype ID: {0} ...", skypeId);
            string applicationDataPath = Environment.GetFolderPath(
                Environment.SpecialFolder.ApplicationData);
            string databasePath = Path.Combine(
                applicationDataPath, "Skype", skypeId, "main.db");

            Logger.Debug("Trying database path: {0} ...", databasePath);
            if (!File.Exists(databasePath))
            {
                throw new InvalidArgumentInternalException("Database file is not found for this Skype ID.");
            }
            Logger.Debug("Database file is found.");
            return(new SkypeInput(databasePath));
        }
Exemple #28
0
        private async void ShowFeeds()
        {
            Feeds.Clear();
            if (FeedURLs != null)
            {
                foreach (string url in FeedURLs.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var puri      = new ParsedUri(url);
                    var parsedDoc = await _sessionScope.GetDocument(puri);

                    var feedViewModels = FeedViewModelFactory.GetFeedViewModels(parsedDoc);
                    foreach (var viewModel in feedViewModels)
                    {
                        Feeds.Add(viewModel);
                    }
                    this.NotifyPropertyChanged("Feeds");
                }
            }
        }
        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);
        }
Exemple #30
0
        public MetadataServicesClient(SimplTypesScope metadatascope, SemanticsSessionScope semanticSessionScope, ParsedUri serviceUri, bool useWebSockets = false)
        {
            SimplTypesScope[] oodssAndMetadataScope = { metadatascope, DefaultServicesTranslations.Get() };

            _metadataTypeScope = SimplTypesScope.Get("MetadataServicesTranslationScope",
                                                     oodssAndMetadataScope,
                                                     typeof(MetadataRequest),
                                                     typeof(MetadataResponse),
                                                     typeof(SemanticServiceError)
                                                     );

            _serviceBaseUri = serviceUri;

            if (useWebSockets)
            {
                _metadataClient = new WebSocketOODSSClient("127.0.0.1", 2018, _metadataTypeScope, semanticSessionScope);
                _metadataClient.StartAsync();
            }
        }