public void Connect() { DocumentClosureConnectionHelper documentClosureConnectionHelper = new DocumentClosureConnectionHelper(SemanticsSessionScope, Document, this); Debug.WriteLine("Connect running from thread: " + Task.CurrentId); MetaMetadataCompositeField metaMetadata = Document.MetaMetadata; // then try to create a connection using the PURL string userAgentString = metaMetadata.UserAgentString; ParsedUri originalPURL = Document.Location.Value; PURLConnection = new PURLConnection(originalPURL); if (originalPURL.IsFile) { // TODO handle local files here! var file = PURLConnection.File; if (SemanticsPlatformSpecifics.Get().FileIsADictionary(file)) { // TODO FileDirectoryParser // DocumentParser = DocumentParser.GetDocumentParser(FILE_DIRECTORY_PARSER); } else { PURLConnection.FileConnect(); // we already have the correct meta-metadata, having used suffix to construct, or having gotten it from a restore. } } else { PURLConnection.NetworkConnect(documentClosureConnectionHelper, userAgentString); // HERE! if (PURLConnection.Good) { Document document = this.Document; // may have changed during redirect processing metaMetadata = document.MetaMetadata; // check for a parser that was discovered while processing a re-direct // if we made PURL connection but could not find parser using container if ((PURLConnection != null) && !originalPURL.IsFile) { string cacheValue = PURLConnection.Response.Headers == null ? null : PURLConnection.Response.Headers["X-Cache"]; bool cacheHit = cacheValue != null && cacheValue.Contains("HIT"); if (metaMetadata.IsGenericMetadata) { // see if we can find more specifc meta-metadata using mimeType MetaMetadataRepository repository = SemanticsSessionScope.MetaMetadataRepository; string mimeType = PURLConnection.MimeType; MetaMetadata mimeMmd = mimeType == null ? null : repository.GetMMByMime(mimeType); if (mimeMmd != null && !mimeMmd.Equals(metaMetadata)) { // new meta-metadata! if (!mimeMmd.MetadataClass.GetTypeInfo().IsAssignableFrom(document.GetType().GetTypeInfo())) //if (!mimeMmd.MetadataClass.IsAssignableFrom(document.GetType())) { // more specifc so we need new metadata! document = (Document)(mimeMmd).ConstructMetadata(); // set temporary on stack ChangeDocument(document); } metaMetadata = mimeMmd; } } } } } if (DocumentParser == null) { DocumentParser = DocumentParser.GetDocumentParser(metaMetadata.Parser); } if (DocumentParser != null) { DocumentParser.FillValues(SemanticsSessionScope, PURLConnection, metaMetadata, this); } else { Debug.WriteLine("WARNING: no parser found: " + metaMetadata); } // else if (!DocumentParser.isRegisteredNoParser(PURLConnection.getPurl())) // { // warning("No DocumentParser found: " + metaMetadata); // } }
public void Connect() { DocumentClosureConnectionHelper documentClosureConnectionHelper = new DocumentClosureConnectionHelper(SemanticsSessionScope, Document, this); Debug.WriteLine("Connect running from thread: " + Task.CurrentId); MetaMetadataCompositeField metaMetadata = Document.MetaMetadata; // then try to create a connection using the PURL string userAgentString = metaMetadata.UserAgentString; ParsedUri originalPURL = Document.Location.Value; PURLConnection = new PURLConnection(originalPURL); if (originalPURL.IsFile) { // TODO handle local files here! var file = PURLConnection.File; if (SemanticsPlatformSpecifics.Get().FileIsADictionary(file)) { // TODO FileDirectoryParser // DocumentParser = DocumentParser.GetDocumentParser(FILE_DIRECTORY_PARSER); } else { PURLConnection.FileConnect(); // we already have the correct meta-metadata, having used suffix to construct, or having gotten it from a restore. } } else { PURLConnection.NetworkConnect(documentClosureConnectionHelper, userAgentString); // HERE! if (PURLConnection.Good) { Document document = this.Document; // may have changed during redirect processing metaMetadata = document.MetaMetadata; // check for a parser that was discovered while processing a re-direct // if we made PURL connection but could not find parser using container if ((PURLConnection != null) && !originalPURL.IsFile) { string cacheValue = PURLConnection.Response.Headers == null ? null : PURLConnection.Response.Headers["X-Cache"]; bool cacheHit = cacheValue != null && cacheValue.Contains("HIT"); if (metaMetadata.IsGenericMetadata) { // see if we can find more specifc meta-metadata using mimeType MetaMetadataRepository repository = SemanticsSessionScope.MetaMetadataRepository; string mimeType = PURLConnection.MimeType; MetaMetadata mimeMmd = mimeType == null ? null : repository.GetMMByMime(mimeType); if (mimeMmd != null && !mimeMmd.Equals(metaMetadata)) { // new meta-metadata! if (!mimeMmd.MetadataClass.GetTypeInfo().IsAssignableFrom(document.GetType().GetTypeInfo())) //if (!mimeMmd.MetadataClass.IsAssignableFrom(document.GetType())) { // more specifc so we need new metadata! document = (Document) (mimeMmd).ConstructMetadata(); // set temporary on stack ChangeDocument(document); } metaMetadata = mimeMmd; } } } } } if (DocumentParser == null) DocumentParser = DocumentParser.GetDocumentParser(metaMetadata.Parser); if (DocumentParser != null) { DocumentParser.FillValues(SemanticsSessionScope, PURLConnection, metaMetadata, this); } else { Debug.WriteLine("WARNING: no parser found: " + metaMetadata); } // else if (!DocumentParser.isRegisteredNoParser(PURLConnection.getPurl())) // { // warning("No DocumentParser found: " + metaMetadata); // } }