Esempio n. 1
0
 public override void Dispose()
 {
     if (_command != null)
     {
         _command.Dispose();
         _command = null;
     }
 }
Esempio n. 2
0
 public void CloseQuery()
 {
     if (command != null)
     {
         command.Dispose();
         command = null;
     }
 }
Esempio n. 3
0
 public void OpenQuery(string queryText, string baseUri)
 {
     MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
     DocumentController controller = mainWindow.Controller;
     if (command != null)
         command.Dispose();
     command = new XQueryCommand(new XQueryDsContext(mainWindow.DatasourceController.Dictionary));
     command.CommandText = queryText;
     command.SearchPath = controller.SearchPath;
     if (!String.IsNullOrEmpty(baseUri))
         command.BaseUri = baseUri;
 }
Esempio n. 4
0
 private XQueryNodeIterator CreateCollection(XQueryCommand command, string id)
 {
     string[] items;
     if (_collection.TryGetValue(id, out items))
         return new NodeIterator(EnumerateItems(command.Context, items));
     return null;
 }
Esempio n. 5
0
 private XQueryCommand CreateCommand(TextWriter tw, XmlElement node)
 {
     string fileName = GetFilePath(node);
     tw.Write("{0}: ", node.GetAttribute("name"));
     if (!File.Exists(fileName))
     {
         _out.WriteLine("File {0} not exists.", fileName);
         throw new ArgumentException();
     }
     XQueryCommand command = new XQueryCommand();
     try
     {
         TextReader textReader = new StreamReader(fileName, true);
         command.CommandText = textReader.ReadToEnd();
         textReader.Close();
         command.OnResolveCollection += new ResolveCollectionEvent(command_OnResolveCollection);
         foreach (XmlNode child in node.ChildNodes)
         {
             XmlElement curr = child as XmlElement;
             if (curr == null || curr.NamespaceURI != XQTSNamespace)
                 continue;
             if (curr.LocalName == "module")
             {
                 string ns = curr.GetAttribute("namespace");
                 string id = curr.InnerText;
                 command.DefineModuleNamespace(ns, _module[id]);
             }
         }
         foreach (string[] schema in _schema.Values)
             command.DefineSchemaNamespace(schema[0], schema[1]);
         command.Compile();
         foreach (XmlNode child in node.ChildNodes)
         {
             XmlElement curr = child as XmlElement;
             if (curr == null || curr.NamespaceURI != XQTSNamespace)
                 continue;
             if (curr.LocalName == "input-file")
             {
                 string var = curr.GetAttribute("variable");
                 string id = curr.InnerText;
                 IXPathNavigable doc = command.Context.OpenDocument(_sources[id]);
                 command.Parameters.Add(new XQueryParameter(var, doc.CreateNavigator()));
             }
             else if (curr.LocalName == "contextItem")
             {
                 string id = curr.InnerText;
                 XmlReader reader = XmlReader.Create(_sources[id], command.Context.GetSettings());
                 XQueryDocument doc = new XQueryDocument(reader);
                 command.ContextItem = doc.CreateNavigator();
             }
             else if (curr.LocalName == "defaultCollection")
             {
                 string id = curr.InnerText;
                 command.OnResolveCollection += new ResolveCollectionEvent(delegate(object sender, ResolveCollectionArgs args)
                     {
                         if (args.CollectionName == "")
                             args.Collection = CreateCollection(command, id);
                     });
             }
             else if (curr.LocalName == "input-URI")
             {
                 string var = curr.GetAttribute("variable");
                 string value = curr.InnerText;
                 string expandedUri;
                 if (!_sources.TryGetValue(value, out expandedUri))
                     expandedUri = value;
                 command.Parameters.Add(new XQueryParameter(var, expandedUri));
             }
             else if (curr.LocalName == "input-query")
             {
                 string var = curr.GetAttribute("variable");
                 using (XQueryCommand command2 = new XQueryCommand())
                 {
                     TextReader textReader2 = new StreamReader(Path.Combine(
                         Path.GetDirectoryName(fileName), curr.GetAttribute("name") + ".xq"), true);
                     command2.CommandText = textReader2.ReadToEnd();
                     textReader2.Close();
                     command.Parameters.Add(new XQueryParameter(var, command2.Execute()));
                 }
             }
         }
         return command;
     }
     catch (Exception)
     {
         command.Dispose();
         throw;
     }
 }
Esempio n. 6
0
 private XQueryAdapterImpl(DatabaseDictionary dictionary, XmlNameTable nameTable, string commandText)
 {
     _command = new XQueryCommand(new XQueryDsContext(dictionary, nameTable));
     _command.SearchPath = dictionary.SearchPath;
     _command.CommandText = commandText;
 }
Esempio n. 7
0
 public WorkContext(XQueryCommand command, XmlNameTable nameTable)
     : base(nameTable)
 {
     m_command = command;
 }