private void ReadXml(string XMLInput) { string XMLstring = XMLInput.Replace("&", "%26"); // XMLstring =XMLString.replaceAll( "(<\\?[^<]*\\?>)?", ""); if (XMLstring.IndexOf("<soap:") > 0) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(XMLstring); var soapBody = xmlDocument.GetElementsByTagName("soap:Body")[0]; XMLstring = soapBody.InnerXml; } // System.out.println(XMLString); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(XMLstring); } catch (Exception e) { //Console.WriteLine(e.StackTrace); throw e; } XmlElement root = doc.DocumentElement; XmlNode firstchild = root.FirstChild.NextSibling; tablename = firstchild.Name; GWDataRow newrow = new GWDataRow(readnode(root, "", "")); data.Add(newrow); // data.add(item); }
private Dictionary <String, String> readnode(XmlNode node, string buildedKey, string lastkey) { string nodeName = node.Name; // int thislength=0; bool newone = false; if (nodeName.ToLower() != "#text") { //buildedKey = nodeName; String[] a = buildedKey.Split('.'); if (a.Length == 2) { //System.out.println("Added hashmap to array!" + parsedMap.get("company.staff.firstname")); if (parsedMap.Count > 0) { GWDataRow newrow = new GWDataRow(parsedMap); data.Add(newrow); parsedMap = new Dictionary <string, string>(); newone = false; } // parsedMap.put(buildedKey,node.getNodeValue()); } // System.out.println ("B is " + buildedKey + " " + a.length); lastkey = buildedKey; buildedKey += "." + nodeName; } //else nodeName = ""; if (node.Value != null) { buildedKey = buildedKey.Substring(1); string v = node.Value.Replace("%26", "&"); parsedMap.Add(buildedKey, v); // System.out.println(newone); // System.out.println ("This key: " + buildedKey + " Last: " + lastkey); // System.out.println("Adding to parsedmap"); } if (node.NodeType == XmlNodeType.Element) { if (node.Attributes.Count > 0) { XmlNamedNodeMap startAttr = node.Attributes; for (int i = 0; i < startAttr.Count; i++) { XmlNode attr = startAttr.Item(i); // buildedKey += attr.getNodeValue() + "."; } } } int c = 0; XmlNodeList children = node.ChildNodes; foreach (XmlNode child in children) { c++; readnode(child, buildedKey, lastkey); } return(parsedMap); }
public void Add(Dictionary <string, string> item) { Dictionary <string, string> newitem = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> entry in item) { string ColName = entry.Key; string ColValue = entry.Value; if (entry.Key.IndexOf(".") < 0) { ColName = tablename + "." + entry.Key; } newitem.Add(ColName, ColValue); } GWDataRow therow = new GWDataRow(newitem); data.Add(therow); }
private bool validatearray(GWDataRow row) { return(true); }
public string Fulfill(string Operation, List <string> Params, string format) { if (Operation == "") { return(this.showError("404 Not Found", "Missing Operation", format)); } //GWDataTable retval = new GWDataTable("","Results"); string FinalOutput = ""; GWDataTable GWServiceResults = new GWDataTable("", "Results"); GWDataTable WebServiceConfig = new GWDataTable(); if (!(System.IO.File.Exists(this.ServiceFile))) { return(this.showError("404 Not Found", "No such service available: " + this.ServiceName, format)); } string GWServiceFile = file_get_contents(this.ServiceFile); WebServiceConfig.loadXml(GWServiceFile); string OPType = ""; string OpSource = ""; string UserName = ""; try { GWDataTable FoundRows = WebServiceConfig.find("[ OperationName _EQ_ \"" + Operation + "\" ]"); if (FoundRows.length() == 0) { return(this.showError("404 Not Found", "No such operation available" + Operation, format)); } if (FoundRows.length() > 0) { GWDataRow FoundRow = (GWDataRow)FoundRows.GetRow(0); OPType = FoundRow.Get("OperationType"); OpSource = FoundRow.Get("OperationSource"); bool AuthEnabled = FoundRow.has_column("AllowedUsers"); if (AuthEnabled) { String UserAuthNames = FoundRow.Get("AllowedUsers"); if (this.UserName == "") { if (format.ToLower() == "xml") { return(this.fault403.toXml()); } if (format.ToLower() == "json") { return(this.fault403.toJSON()); } return(this.fault403.ToString()); } int has_semi = UserAuthNames.IndexOf(";"); string[] AllowedUsers; if (has_semi > 0) { AllowedUsers = UserAuthNames.Split(';'); } else { AllowedUsers = new String[1]; AllowedUsers[0] = UserAuthNames; } bool AccessGranted = false; for (int i = 0; i < AllowedUsers.Length; i++) { if (UserName.ToLower() == AllowedUsers[i].ToLower()) { AccessGranted = true; } } if (AccessGranted == false) { if (format.ToLower() == "xml") { return(this.fault403.toXml()); } if (format.ToLower() == "json") { return(this.fault403.toJSON()); } return(this.fault403.ToString()); } } int isStoredProcedure = OpSource.IndexOf(".dll"); if (isStoredProcedure > 0) { List <string> PArray = new List <string>(); //string[] MethodData; try { string[] MthdInfo = parseMethod(OPType); if (Params.Count != MthdInfo.Length - 2) { return(this.showError("500 Server Error", "Incorrect Parameters for Operation " + Operation, format)); } // AssemblyName an = AssemblyName.GetAssemblyName(MthdInfo[0]); AssemblyName an = AssemblyName.GetAssemblyName(OpSource); Assembly assembly = Assembly.Load(an); Type t = assembly.GetType(MthdInfo[0]); if (t == null) { return("Yep null"); } else { List <string> plist = new List <string>(); Dictionary <string, string> ParamsArray = orderParams(Params); if (ParamsArray != null) { foreach (KeyValuePair <string, string> entry in ParamsArray) { string datatype = entry.Value; plist.Add(datatype); } object[] parameters = plist.ToArray(); var o = Activator.CreateInstance(t); if (o == null) { return("Error Invoking!"); } else { MethodInfo methodinfo = t.GetMethod(MthdInfo[1]); if (methodinfo == null) { return("No such method!" + MthdInfo[1]); } else { object result = methodinfo.Invoke(o, parameters); string ResultStr = result.ToString(); StringReader sread; //If result is not XML we will make it xml string FirstChar = ResultStr.Substring(0, 1); if (FirstChar != "<") { Dictionary <String, String> RetVal = new Dictionary <string, string>(); RetVal.Add("Return", ResultStr); GWServiceResults.Add(RetVal); } else { sread = new StringReader(ResultStr); GWServiceResults.loadXml(sread.ToString()); } } } } } } catch (Exception e) { Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace); } } else { //stored procedure stuff GWDBConnection dbconn = new GWDBConnection(OpSource); OdbcConnection conn = dbconn.getConnection(); // conn.Open(); OdbcCommand cmd = new OdbcCommand(OPType, conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; Dictionary <string, string> ParamsArray = orderParams(Params); List <string> plist = new List <string>(); if (ParamsArray != null) { if (ParamsArray.Count > 0) { int i = 0; foreach (KeyValuePair <string, string> entry in ParamsArray) { // string datatype = entry.Value; //plist.Add(datatype); //} // TODO: array at 0 is the data value // at 1 is the date type // at 2 is optionally the size //OdbcType thetype = (OdbcType)Enum.Parse(typeof(OdbcType), datatype[1], true); //OdbcParameter ODBCParameter = new OdbcParameter("@" + entry.Key, thetype, Int32.Parse(datatype[2])); OdbcParameter ODBCParameter = new OdbcParameter("@P" + i.ToString(), OdbcType.VarChar); ODBCParameter.Value = entry.Value; cmd.Parameters.Add(ODBCParameter); //cmd.Parameters.AddWithValue("@P" + i.ToString(), entry.Value); i++; } } } OdbcDataReader rdr; DataTable dt; try { rdr = cmd.ExecuteReader(); dt = new DataTable(); } catch (OdbcException c) { //return "<ErrorMessage><Error>" + c.Message.ToString() + " " + c.Errors.Count.ToString() + "</Error></ErrorMessage>"; return(this.showError("ODBC Exception in " + this.ServiceName, c.Message.ToString() + " " + c.Errors.Count.ToString(), format)); } dt.Load(rdr); //DataTable dtCloned = dt.Clone(); //foreach (DataColumn dc in dtCloned.Columns) //dc.DataType = typeof(string); foreach (DataRow row in dt.Rows) { Dictionary <string, string> gwrow = new Dictionary <string, string>(); foreach (DataColumn col in dt.Columns) { gwrow.Add(col.ColumnName, row[col.ColumnName].ToString()); } GWServiceResults.Add(gwrow); } conn.Close(); } //ServiceResults.Tables.Add(dtCloned); } if (format.ToLower() == "xml") { return(GWServiceResults.toXml()); } if (format.ToLower() == "json") { return(GWServiceResults.toJSON()); } return("format: " + GWServiceResults.ToString()); } catch (Exception e) { Console.WriteLine(e.Message + Environment.NewLine + e.StackTrace); } return(null); }