public SiteConverter(string storagePath, string baseUri) { RebaseLinks = true; _baseUri = new Uri(baseUri, UriKind.Absolute); HttpCloneConfig config = Config.ReadConfig(_baseUri, storagePath); _mime = new MimeInfoMap(_baseUri, storagePath); CleanupRegex = new Regex(config.BadNameCharsExpression ?? @"[^\w]+", RegexOptions.IgnoreCase | RegexOptions.Singleline); _content = new ContentStorage(storagePath, true); }
public ContentIndexing(string storagePath, string baseUri) { _baseUri = new Uri(baseUri, UriKind.Absolute); _config = Config.ReadConfig(_baseUri, storagePath).Searching; _mimeInfo = new MimeInfoMap(_baseUri, storagePath); _content = new ContentStorage(storagePath, false); string directory = _content.IndexDirectory; DirectoryInfo dirInfo = new DirectoryInfo(directory); if (dirInfo.Exists) dirInfo.Delete(true); _writer = new IndexWriter(FSDirectory.Open(dirInfo), new StandardAnalyzer(Version.LUCENE_29), true, IndexWriter.MaxFieldLength.LIMITED); BlurbLength = (uint)_config.BlubXPath.MaxLength; }
public ContentIndexing(string storagePath, string baseUri) { _baseUri = new Uri(baseUri, UriKind.Absolute); _config = Config.ReadConfig(_baseUri, storagePath).Searching; _mimeInfo = new MimeInfoMap(_baseUri, storagePath); _content = new ContentStorage(storagePath, false); string directory = _content.IndexDirectory; DirectoryInfo dirInfo = new DirectoryInfo(directory); if (dirInfo.Exists) { dirInfo.Delete(true); } _writer = new IndexWriter(FSDirectory.Open(dirInfo), new StandardAnalyzer(Version.LUCENE_29), true, IndexWriter.MaxFieldLength.LIMITED); BlurbLength = (uint)_config.BlubXPath.MaxLength; }
private void OpenWith(string exe, string verb, bool wait, bool editable, string url) { MimeInfoMap mimeTypes = new MimeInfoMap(new Uri(url, UriKind.Absolute), StoragePath(url)); With(!editable || !wait, url, (s, r) => { if (r.HasContentStoreId) { string extension = mimeTypes.GetFileExtension(r.MimeType, r.ContentUri); using (TempFile tmp = TempFile.FromExtension(extension ?? ".txt")) { byte[] bytes = s.ReadContent(r, true); Hash hash = Hash.SHA256(bytes); tmp.WriteAllBytes(bytes); if(!editable) s.Dispose();//close storage if(exe != null) exe = FileUtils.FindFullPath(exe); ProcessStartInfo psi = new ProcessStartInfo(exe ?? tmp.TempPath); psi.UseShellExecute = exe == null && verb != null; if (verb != null) psi.Verb = verb; if (exe != null) psi.Arguments = tmp.TempPath; Process p = Process.Start(psi); if (wait) { Thread.Sleep(1000); p.WaitForExit(); if (editable) { Stream locked = null; while (locked == null) { try { locked = new FileStream(tmp.TempPath, FileMode.Open, FileAccess.Read, FileShare.None); } catch (FileNotFoundException) { throw; } catch (IOException) { Thread.Sleep(1000); } } using (locked) { bytes = IOStream.ReadAllBytes(locked); if (hash != Hash.SHA256(bytes)) { s.WriteContent(r, bytes); } } } } else tmp.Detatch(); } } else throw new ApplicationException("The path has no content."); }); }