Esempio n. 1
0
        public List <QvxTable> Init(string server, string auth, string username, string password, string param, List <QvxTable> MTables, Func <string, IEnumerable <QvxTable>, QvxTable> FindTable)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "Init()");

            Dictionary <string, string> parameters = null;
            MyWebRequest q = prepareRequest(server, auth, username, password, param, out parameters);

            string s = q.GetResponse();

            List <QvxTable> lt = new List <QvxTable>();

            if (q.StatusCode == HttpStatusCode.OK)
            {
                XmlDocument doc = JsonConvert.DeserializeXmlNode("{\"root\":" + s + "}", "root");
                string      xml = doc.InnerXml;

                XmlToCsvUsingDataSetFromString converter = new XmlToCsvUsingDataSetFromString(xml, (parameters.ContainsKey("qualifySep")) ? parameters["qualifySep"] : null);
                XmlToCsvContext context = new XmlToCsvContext(converter);

                foreach (DataTable dt in converter.XmlDataSet.Tables)
                {
                    QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Found table " + dt.TableName + ": " + dt.Rows.Count.ToString());

                    List <QvxField> l = new List <QvxField>();
                    foreach (DataColumn dc in dt.Columns)
                    {
                        l.Add(new QvxField(dc.ColumnName, QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII));
                    }

                    lt.Add(new QvxTable
                    {
                        TableName = dt.TableName,
                        GetRows   = delegate() { return(GetJSONRows(dt, MTables, FindTable)); },
                        Fields    = l.ToArray()
                    });
                }
            }

            return(lt);
        }
        public IEnumerable <DataTable> getRawTables(Database database, Dictionary <string, string> args)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "+ getRawTables()");

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("getRawTables() : {0}", args.Count));
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("getRawTables() : {0}", String.Join(", ", args.Select(kv => String.Format("{0} : {1}", kv.Key, kv.Value)))));


            string response = null;


            if (args["Location"] == "File")
            {
                response = File.ReadAllText(args["File Name"], Encoding.UTF8);
            }
            else
            {
                MyWebRequest q;

                string param = args["Method"] == "POST" ? args["Params"] : null;

                if (args.ContainsKey("Http Method"))
                {
                    q = new MyWebRequest(
                        String.Format(
                            "{0}/{1}",
                            args["Host"],
                            args["Method"]
                            )
                        , args["Http Method"], param, "None", null, null);
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }

                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "getRawTables() : request prepared");

                //string s = q.GetResponse();
                //QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("getRawTables() : response : {0}", s.Substring(0, 50)));

                response = q.GetResponse();
                if (q.StatusCode != HttpStatusCode.OK)
                {
                    response = null;
                }

                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("getRawTables() : {0}", q.StatusCode));
            }



            List <QvxTable> lt = new List <QvxTable>();

            if (response != null)
            {
                XmlDocument doc;
                using (JsonTextReader jr = new JsonTextReader(new StringReader(response)))
                {
                    QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("getRawTables() : deserializing document"));

                    XmlNodeConverter converter = new XmlNodeConverter();
                    converter.DeserializeRootElementName = "root";
                    converter.WriteArrayAttribute        = false;

                    JsonSerializerSettings settings = new JsonSerializerSettings {
                        Converters = new JsonConverter[] { converter }
                    };

                    JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);
                    jsonSerializer.CheckAdditionalContent = true;

                    doc = (XmlDocument)jsonSerializer.Deserialize(jr, typeof(XmlDocument));

                    QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("getRawTables() : {0}", doc.InnerXml.Substring(0, Math.Min(5000, doc.InnerXml.Length))));
                }

                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("getRawTables() : JSON deserialized"));

                string qualifySep = null;
                if (args.ContainsKey("Qualify") && Convert.ToBoolean(args["Qualify"]))
                {
                    qualifySep = args["Qualify Sep"];
                }

                XmlToCsvUsingDataSetFromString csvConverter = new XmlToCsvUsingDataSetFromString(doc, qualifySep, "_");
                XmlToCsvContext context = new XmlToCsvContext(csvConverter);

                QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "getRawTables() : converted to xml");

                foreach (DataTable dt in csvConverter.XmlDataSet.Tables)
                {
                    QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, String.Format("getRawTables() : table found {0}", dt.TableName));

                    yield return(dt);
                }
            }

            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "- getRawTables()");
        }
        public List<QvxTable> Init(string server, string auth, string username, string password, string param, List<QvxTable> MTables, Func<string, IEnumerable<QvxTable>, QvxTable> FindTable)
        {
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "Init()");

            Dictionary<string, string> parameters = null;
            MyWebRequest q = prepareRequest(server, auth, username, password, param, out parameters);

            string s = q.GetResponse();

            List<QvxTable> lt = new List<QvxTable>();
            if (q.StatusCode == HttpStatusCode.OK) {

                XmlDocument doc = JsonConvert.DeserializeXmlNode("{\"root\":" + s + "}", "root");
                string xml = doc.InnerXml;

                XmlToCsvUsingDataSetFromString converter = new XmlToCsvUsingDataSetFromString(xml, (parameters.ContainsKey("qualifySep")) ? parameters["qualifySep"] : null);
                XmlToCsvContext context = new XmlToCsvContext(converter);

                foreach (DataTable dt in converter.XmlDataSet.Tables)
                {
                    QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Notice, "Found table " + dt.TableName + ": " + dt.Rows.Count.ToString());

                    List<QvxField> l = new List<QvxField>();
                    foreach(DataColumn dc in dt.Columns) {
                        l.Add(new QvxField(dc.ColumnName, QvxFieldType.QVX_TEXT, QvxNullRepresentation.QVX_NULL_FLAG_SUPPRESS_DATA, FieldAttrType.ASCII));
                    }

                    lt.Add(new QvxTable
                    {
                        TableName = dt.TableName,
                        GetRows = delegate() { return GetJSONRows(dt, MTables, FindTable); },
                        Fields = l.ToArray()
                    });
                }
            }

            return lt;
        }