public static CommentFileCreateResult CommentFileCreate(TaxonTreeNode _node) { if (_node == null) { return(CommentFileCreateResult.Failed); } if (TaxonComments.Manager.AvailableCollections.Count == 0) { return(CommentFileCreateResult.NoCollection); } CommentsCollection collection = TaxonComments.Manager.AvailableCollections[0]; string name = CommentFilename(_node.Desc); if (string.IsNullOrEmpty(name)) { return(CommentFileCreateResult.NoNameAndID); } string path = CommentFileDesc.BuildHtlmName(collection, name); if (File.Exists(path)) { return(CommentFileCreateResult.ExistsAlready); } Manager.CreateHtmlComment(path, name); Manager.CleanCommentInMemory(0); return(CommentFileCreateResult.Success); }
//--------------------------------------------------------------------------------------- public static CommentFileDesc CommentFile(TaxonTreeNode _node) { if (_node == null) { return(null); } string filename = CommentFilename(_node.Desc); CommentFileDesc result; foreach (CommentsCollection collection in TaxonComments.Manager.AvailableCollections) { if (filename != null && collection.IsDistant() && collection.DistantReferences.ContainsKey(filename)) { result = new CommentFileDesc(collection, filename); } else { result = CommentFileDesc.CreateOnlyIfFileExists(collection, filename); } if (result != null) { return(result); } } return(null); }
//========================================================================================= // HTML // string TransformHTMLComment(string comment, CommentFileDesc _desc) { if (_desc.IsDistantComment()) { return(comment.Replace("<img src=\"", "<img src=\"" + _desc.Collection.Location)); } return(comment.Replace("<img src=\"", "<img src=\"" + _desc.GetPath() + "\\")); }
//--------------------------------------------------------------------------------------- public static List <CommentFileDesc> GetAllCommentFile(TaxonTreeNode _node) { if (_node == null) { return(null); } List <CommentFileDesc> result = null; foreach (CommentsCollection collection in TaxonComments.Manager.AvailableCollections) { if (!_node.Desc.IsUnnamed) { string path = CommentFileDesc.BuildHtlmName(collection, _node.Desc.RefMultiName.Main); if (File.Exists(path)) { if (result == null) { result = new List <CommentFileDesc>(); } result.Add(new CommentFileDesc(collection, _node.Desc.RefMultiName.Main)); } } if (_node.Desc.OTTID != 0) { string path = CommentFileDesc.BuildHtlmName(collection, _node.Desc.OTTID.ToString()); if (File.Exists(path)) { if (result == null) { result = new List <CommentFileDesc>(); } result.Add(new CommentFileDesc(collection, _node.Desc.OTTID.ToString())); } } } return(result); }
void TaxonCommentsLoop() { while (!_Exit) { _LockEvent.WaitOne(); if (_ListRequest.Count == 0) { _LockEvent.Reset(); _Thread.Priority = ThreadPriority.Lowest; continue; } TaxonCommentRequest request = PopRequest(); Console.WriteLine(request.CurrentTaxon.Desc.RefMultiName.Main); if (request == null) { continue; } string comment = null; if (!GetCommentFromMemory(request.CurrentTaxon, ref comment)) { CommentFileDesc commentFile = CommentFile(request.CurrentTaxon); if (commentFile != null) { try { if (commentFile.Collection.IsDistant()) { using (WebClient client = new WebClient()) { client.Encoding = System.Text.Encoding.UTF8; string url = commentFile.GetDistantPath(); Console.WriteLine(url); comment = client.DownloadString(url); } } else { VinceToolbox.fileFunctions.readTextFile(commentFile.GetHtmlName(), ref comment); } comment = TransformHTMLComment(comment, commentFile); // StoreCommentInMemory(request.CurrentTaxon, comment); } catch { } } } // request.Callback(request.Owner, request.MainTaxon, request.CurrentTaxon, comment); if (request.Result == null) { request.Result = new TaxonCommentRequestResult() { Main = request.MainTaxon } } ; request.Result.Comments.Add(new Tuple <TaxonTreeNode, string>(request.CurrentTaxon, comment)); if (request.Recursive && request.CurrentTaxon.Father != null) { request.CurrentTaxon = request.CurrentTaxon.Father; PushRequest(request); } else { request.Callback(request.Owner, request.Result); } } } //========================================================================================= // Request list // List <TaxonCommentRequest> _ListRequest = new List <TaxonCommentRequest>();