private void ParseDocuments([NotNull] XElement root) { Debug.ArgumentNotNull(root, nameof(root)); documents.Clear(); var documentElement = root.Element("documents"); if (documentElement == null) { return; } documentCount = documentElement.GetAttributeInt("count", 0); documentTotalCount = documentElement.GetAttributeInt("total", 0); foreach (var element in documentElement.Elements()) { var hitDescriptor = new DocumentDescriptor(); documents.Add(hitDescriptor); foreach (var f in element.Elements()) { var field = new DocumentFieldDescriptor { Name = f.GetAttributeValue("name"), Value = f.Value }; hitDescriptor.Fields.Add(field); } } }
private void DropDocument(POIFSReaderListener listener, DocumentDescriptor descriptor) { ArrayList listeners = (ArrayList)chosenDocumentDescriptors[descriptor]; listeners.Remove(listener); if (listeners.Count == 0) { chosenDocumentDescriptors.Remove(descriptor); } }
private void DropDocument(POIFSReaderListener listener, DocumentDescriptor descriptor) { List <object> listeners = (List <object>)chosenDocumentDescriptors[descriptor]; listeners.Remove(listener); if (listeners.Count == 0) { chosenDocumentDescriptors.Remove(descriptor); } }
/* ********** START implementation of POIFSReaderListener ********** */ /** * Process a POIFSReaderEvent that this listener had registered * for * * @param evt the POIFSReaderEvent */ public void ProcessPOIFSReaderEvent(POIFSReaderEvent evt) { DocumentInputStream istream = evt.Stream; POIFSDocumentPath path = evt.Path; String name = evt.Name; try { int size = (int)(istream.Length - istream.Position); byte[] data = new byte[size]; istream.Read(data); DocumentDescriptor descriptor = new DocumentDescriptor(path, name); Console.WriteLine("Adding document: " + descriptor + " (" + size + " bytes)"); dataMap[descriptor] = data; int pathLength = path.Length; DirectoryEntry entry = root; for (int k = 0; k < path.Length; k++) { String componentName = path.GetComponent(k); Entry nextEntry = null; try { nextEntry = entry.GetEntry(componentName); } catch (FileNotFoundException ignored) { try { nextEntry = entry.CreateDirectory(componentName); } catch (IOException e) { Console.WriteLine("Unable to Create directory"); //e.printStackTrace(); throw; } } entry = (DirectoryEntry)nextEntry; } entry.CreateDocument(name, size, this); } catch (IOException ignored) { } }
/// <summary> /// Créé une nouvelle instance de ElasticStore. /// </summary> /// <param name="dataSourceName">Nom de la datasource.</param> public ElasticStore(string dataSourceName) { try { _definition = DocumentDescriptor.GetDefinition(typeof(TDocument)); _documentTypeName = _definition.DocumentTypeName; _dataSourceName = dataSourceName ?? throw new ArgumentNullException("dataSourceName"); _indexName = ElasticManager.Instance.LoadSearchSettings(_dataSourceName).IndexName; _standardHandler = new StandardFacetHandler <TDocument>(_definition); _portfolioHandler = new PortfolioFacetHandler <TDocument>(_definition); } catch (Exception e) { if (_log.IsErrorEnabled) { _log.Error("Echec d'instanciation du store.", e); } throw new NotSupportedException("Search Broker<" + typeof(TDocument).FullName + "> " + e.Message, e); } }
/* ********** END implementation of POIFSReaderListener ********** */ /* ********** START implementation of POIFSWriterListener ********** */ /** * Process a POIFSWriterEvent that this listener had registered * for * * @param evt the POIFSWriterEvent */ public void ProcessPOIFSWriterEvent(POIFSWriterEvent evt) { try { DocumentDescriptor descriptor = new DocumentDescriptor(evt.Path, evt.Name); Console.WriteLine("looking up document: " + descriptor + " (" + evt.Limit + " bytes)"); evt.Stream.Write((byte[])dataMap[descriptor]); } catch (IOException) { Console.WriteLine("Unable to Write document"); //e.printStackTrace(); //System.exit(1); throw; } }
public void CanHandle() { // arrange var generator = new DocumentGenerator(); var descriptor = new DocumentDescriptor( "Queries", "Demo", new byte[] { 1, 2, 3 }, new byte[] { 4, 5, 6 }, new byte[] { 7, 8, 9 }, @"type Query { s: String }"); // act var canHandle = generator.CanHandle(descriptor); // assert Assert.True(canHandle); }
/** * Register a POIFSReaderListener for a particular document * * @param listener the listener * @param path the path of the document of interest * @param documentName the name of the document of interest */ public void RegisterListener(POIFSReaderListener listener, POIFSDocumentPath path, String documentName) { if (!omnivorousListeners.Contains(listener)) { // not an omnivorous listener (if it was, this method is a // no-op) ArrayList descriptors = (ArrayList)selectiveListeners[listener]; if (descriptors == null) { // this listener has not Registered before descriptors = new ArrayList(); selectiveListeners[listener] = descriptors; } DocumentDescriptor descriptor = new DocumentDescriptor(path, documentName); if (descriptors.Add(descriptor) >= 0) { // this listener wasn't alReady listening for this // document -- Add the listener to the Set of // listeners for this document ArrayList listeners = (ArrayList)chosenDocumentDescriptors[descriptor]; if (listeners == null) { // nobody was listening for this document before listeners = new ArrayList(); chosenDocumentDescriptors[descriptor] = listeners; } listeners.Add(listener); } } }
public async Task GenerateModel() { // arrange var sb = new StringBuilder(); var writer = new CodeWriter(sb); var generator = new DocumentGenerator(); var descriptor = new DocumentDescriptor( "Queries", "Demo", new byte[] { 1, 2, 3 }, new byte[] { 4, 5, 6 }, new byte[] { 7, 8, 9 }, @"type Query { s: String }"); // act await generator.WriteAsync(writer, descriptor); // assert sb.ToString().MatchSnapshot(); }
public void TestEquality() { String[] names = { "c1", "c2", "c3", "c4", "c5" }; POIFSDocumentPath a1 = new POIFSDocumentPath(); POIFSDocumentPath a2 = new POIFSDocumentPath(null); POIFSDocumentPath a3 = new POIFSDocumentPath(new String[0]); POIFSDocumentPath a4 = new POIFSDocumentPath(a1, null); POIFSDocumentPath a5 = new POIFSDocumentPath(a1, new String[0]); POIFSDocumentPath[] paths = { a1, a2, a3, a4, a5 }; for (int j = 0; j < paths.Length; j++) { for (int k = 0; k < paths.Length; k++) { for (int m = 0; m < names.Length; m++) { DocumentDescriptor d1 = new DocumentDescriptor(paths[j], names[m]); for (int n = 0; n < names.Length; n++) { DocumentDescriptor d2 = new DocumentDescriptor(paths[k], names[n]); if (m == n) { Assert.AreEqual(d1, d2, "" + j + "," + k + "," + m + "," + n); } else { Assert.IsTrue(!d1.Equals(d2), "" + j + "," + k + "," + m + "," + n); } } } } } a2 = new POIFSDocumentPath(a1, new String[] { "foo" }); a3 = new POIFSDocumentPath(a2, new String[] { "bar" }); a4 = new POIFSDocumentPath(a3, new String[] { "fubar" }); a5 = new POIFSDocumentPath(a4, new String[] { "foobar" }); POIFSDocumentPath[] builtUpPaths = { a1, a2, a3, a4, a5 }; POIFSDocumentPath[] fullPaths = { new POIFSDocumentPath(), new POIFSDocumentPath(new String[] { "foo" }), new POIFSDocumentPath(new String[] { "foo", "bar" }), new POIFSDocumentPath(new String[] { "foo", "bar", "fubar" }), new POIFSDocumentPath(new String[] { "foo", "bar", "fubar", "foobar" }) }; for (int k = 0; k < builtUpPaths.Length; k++) { for (int j = 0; j < fullPaths.Length; j++) { for (int m = 0; m < names.Length; m++) { DocumentDescriptor d1 = new DocumentDescriptor(fullPaths[j], names[m]); for (int n = 0; n < names.Length; n++) { DocumentDescriptor d2 = new DocumentDescriptor(builtUpPaths[k], names[n]); if ((k == j) && (m == n)) { Assert.AreEqual(d1, d2, "" + j + "," + k + "," + m + "," + n); } else { Assert.IsTrue(!(d1.Equals(d2)), "" + j + "," + k + "," + m + "," + n); } } } } } POIFSDocumentPath[] badPaths = { new POIFSDocumentPath(new String[] { "_foo" }), new POIFSDocumentPath(new String[] { "foo", "_bar" }), new POIFSDocumentPath(new String[] { "foo", "bar", "_fubar" }), new POIFSDocumentPath(new String[] { "foo", "bar", "fubar", "_foobar" }) }; for (int k = 0; k < builtUpPaths.Length; k++) { for (int j = 0; j < badPaths.Length; j++) { for (int m = 0; m < names.Length; m++) { DocumentDescriptor d1 = new DocumentDescriptor(badPaths[j], names[m]); for (int n = 0; n < names.Length; n++) { DocumentDescriptor d2 = new DocumentDescriptor(builtUpPaths[k], names[n]); Assert.IsTrue(!(d1.Equals(d2)), "" + j + "," + k + "," + m + "," + n); } } } } }