Exemplo n.º 1
0
 // Constructor
 public HGridFormat(string mime, HGridReader reader, HGridWriter writer)
 {
     if (mime.IndexOf(';') >= 0)
     {
         throw new ArgumentException("mime has semicolon " + mime, "mime");
     }
     m_strMime    = mime;
     m_gridReader = reader;
     m_gridWriter = writer;
     m_registry   = new Dictionary <string, HGridFormat>();
     m_syncLock   = new object();
     // The original implmentation had a storage of the generic type aginst the formats - but I see this
     // as a distinct issue because:
     //  1. if this is not storing a real instance with underlying streams attempts to use it should cause
     //     issues unless makereader /writer is called with the instance - this makes the interface not well
     //     designed to oo principals and design patterns - implementation should not hide obvious pitfalls in
     //     calling
     // Solution has been to get the underlying stream and construct a real instance
     register(new HGridFormat("text/plain", new HZincReader(reader.BaseStream), new HZincWriter(writer.BaseStream)));
     register(new HGridFormat("text/zinc", new HZincReader(reader.BaseStream), new HZincWriter(writer.BaseStream)));
     //register(new HGridFormat("text/csv",         null, HCsvWriter.class));
     register(new HGridFormat("application/json", null, new HJsonWriter(writer.BaseStream)));
 }
Exemplo n.º 2
0
 // Make instance of "writer"; constructor with OutputStream is expected.
 public HGridWriter makeWriter(StreamWriter outstm)
 {
     if (m_gridWriter == null)
     {
         throw new Exception("Format doesn't support writer: " + m_strMime);
     }
     try
     {
         if (m_gridWriter is HZincWriter)
         {
             m_gridWriter = new HZincWriter(outstm);
         }
         else if (m_gridWriter is HJsonWriter)
         {
             m_gridWriter = new HJsonWriter(outstm);
         }
         return(m_gridWriter);
     }
     catch (Exception e)
     {
         throw new Exception("Cannot construct: " + m_gridWriter.GetType() + "(OutputStream)", e);
     }
 }