private static string ParseDivToXml(string productID, string value, DivType divType) { if (string.IsNullOrEmpty(productID) || string.IsNullOrEmpty(value)) { return(string.Empty); } XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.ConformanceLevel = ConformanceLevel.Document; try { using (StringWriter stream = new StringWriter()) { using (XmlWriter writer = XmlWriter.Create(stream, settings)) { writer.WriteStartDocument(); writer.WriteStartElement("Alatest"); switch (divType) { case DivType.Review: writer.WriteStartElement("Reviews"); break; case DivType.Rating: writer.WriteStartElement("Rating"); break; default: writer.WriteStartElement("UnknownType"); break; } writer.WriteStartElement("ProductID"); writer.WriteString(productID); writer.WriteEndElement(); writer.WriteString(Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(value))); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); return(stream.ToString()); } } } catch (Exception) { } return(string.Empty); }
private Division GetDivision(DivType type) { foreach (Division d in _divisions) { if (d.Type == type) { return(d); } } return(null); }
public TSVReader(string tsvFile) { this.tsvFile = tsvFile ?? throw new ArgumentNullException(nameof(tsvFile)); string fileName = Path.GetFileNameWithoutExtension(tsvFile); this.source = new Source(fileName); this.season = fileName; this.divType = DivType.Unknown; // Try and calculate Div Type and season foreach (DivType type in Enum.GetValues(typeof(DivType))) { if (fileName.Contains(type.ToString(), StringComparison.OrdinalIgnoreCase)) { divType = type; season = fileName.Substring(fileName.IndexOf(type.ToString()) + type.ToString().Length).Trim('-'); break; } } }
private static string GetAlatestValue(string ProductID, DivType type) { try { using (SqlConnection conn = new SqlConnection( ConfigurationManager.ConnectionStrings["DevTim"].ConnectionString)) { using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = RetrieveStoredProcedureName; cmd.Parameters.Add("@productID", SqlDbType.NChar).Value = ProductID; conn.Open(); using (DataSet ds = new DataSet()) { new SqlDataAdapter(cmd).Fill(ds); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { return(ds.Tables[0].Rows[0][type.ToString()].ToString()); } else { return(string.Empty); } } } } } catch (Exception) { //TODO:Log errors return(string.Empty); } }