Esempio n. 1
0
        static void Main(string[] args)
        {
        
            
            SerializedTestDS stDS = new SerializedTestDS();
            
            // retrieve the size of our binary data column using metadata..
            // sql used by this table adapter:
            //
            // select character_maximum_length from test_one.information_schema.columns 
            // where table_name = 'SerializedTest' and column_name = 'ObjectData';
                
            SerializedTestDSTableAdapters.SerializedTest_ObjectData_widthTableAdapter st_odwTA = 
                new DataWizInConsoleTest.SerializedTestDSTableAdapters.SerializedTest_ObjectData_widthTableAdapter();
            // get the width of the binary column..
            st_odwTA.Fill(stDS.SerializedTest_ObjectData_width);
            
            SerializedTestDS.SerializedTest_ObjectData_widthRow odw_row = 
                (SerializedTestDS.SerializedTest_ObjectData_widthRow)
                    stDS.SerializedTest_ObjectData_width.Rows[0];
            
            BIN_COLUMN_SIZE = odw_row.character_maximum_length;
            
        
#if true    
            WriteItOut();
#endif            
            // reading it back..
            ReadItBack();
        }
Esempio n. 2
0
        static void ReadItBack()
        {
            // get our data..
            SerializedTestDS stDS = new SerializedTestDS();
            SerializedTestDSTableAdapters.SerializedTestTableAdapter stTA = 
                new SerializedTestDSTableAdapters.SerializedTestTableAdapter();
            
            
            stTA.Fill(stDS.SerializedTest,1);

            SerializedTestDS.SerializedTestDataTable stTbl = 
                stDS.SerializedTest;
            byte [] final_buff = new byte[stTbl.Rows.Count * BIN_COLUMN_SIZE];
            int curr_offset = 0;
            foreach(SerializedTestDS.SerializedTestRow stRow in stTbl.Rows)
            {
                byte[] currBuff = stRow.ObjectData;
                Console.Write("UserID[" + stRow.UserID + "] ");
                Console.Write("sequence[" + stRow.sequence + "] ");
                Console.WriteLine("buffsize[" + currBuff.Length + "]");
                
                DumpBuffer(currBuff);
                
                for (int currByte = 0;
                     currByte < currBuff.Length;
                     currByte++)
                {
                    final_buff[curr_offset] = currBuff[currByte];
                    curr_offset++;
                }
                Console.WriteLine();
                Console.WriteLine();
            }
            
            // deserialize and print..
            MemoryStream ms = new MemoryStream(final_buff);
            IFormatter formatter = new BinaryFormatter();
            MyContainer my_c = (MyContainer) formatter.Deserialize(ms);
            Console.WriteLine(my_c.ToString());
        
        }
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(System.Xml.Schema.XmlSchemaSet xs) {
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     SerializedTestDS ds = new SerializedTestDS();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any1 = new System.Xml.Schema.XmlSchemaAny();
     any1.Namespace = "http://www.w3.org/2001/XMLSchema";
     any1.MinOccurs = new decimal(0);
     any1.MaxOccurs = decimal.MaxValue;
     any1.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any1);
     System.Xml.Schema.XmlSchemaAny any2 = new System.Xml.Schema.XmlSchemaAny();
     any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
     any2.MinOccurs = new decimal(1);
     any2.ProcessContents = System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any2);
     System.Xml.Schema.XmlSchemaAttribute attribute1 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute1.Name = "namespace";
     attribute1.FixedValue = ds.Namespace;
     type.Attributes.Add(attribute1);
     System.Xml.Schema.XmlSchemaAttribute attribute2 = new System.Xml.Schema.XmlSchemaAttribute();
     attribute2.Name = "tableTypeName";
     attribute2.FixedValue = "SerializedTest_ObjectData_widthDataTable";
     type.Attributes.Add(attribute2);
     type.Particle = sequence;
     return type;
 }
Esempio n. 4
0
        static void WriteItOut()
        {
            // create or contained classes..
            // 
            MyContainer mc = new MyContainer();
            Console.WriteLine(mc.ToString());  
            // serialize our classes to a byte array
            MemoryStream serializeStream = new MemoryStream();
            IFormatter formatter = new BinaryFormatter();
            formatter.Serialize(serializeStream,mc);

            byte [] strm_buff = serializeStream.GetBuffer();
            Console.WriteLine("stream length[" + serializeStream.Length + "]");
            Console.WriteLine("buffer length[" + strm_buff.Length + "]");
            int buff_len = (int) Math.Min(serializeStream.Length,
                                          strm_buff.Length);
            DumpBuffer(strm_buff);
            
            
            // pop it to DB..
            SerializedTestDS stDS = new SerializedTestDS();
            SerializedTestDSTableAdapters.SerializedTestTableAdapter stTA = 
                new SerializedTestDSTableAdapters.SerializedTestTableAdapter();
            
            // for this test, we assume that we are editing user #1..
            // get all userID 1 rows into DS..
            stTA.Fill(stDS.SerializedTest,1);

            SerializedTestDS.SerializedTestDataTable stTbl = 
                stDS.SerializedTest;
            
            // since we are writing, delete the old rows since we are now replacing the old w/ the new.
            foreach(SerializedTestDS.SerializedTestRow row in stTbl.Rows)
            {
                row.Delete();
            }
            // write out our buffer to the DB..
            int bytes_to_write = buff_len;
            int curr_offset = 0;
            int curr_sequence = 1;
            byte [] write_buff = null;
            while (bytes_to_write > 0)
            {
                // we need a new buffer for each row, since the
                // dataset doesn't do a copy of the buffer, but 
                // obviously just keeps a reference to the buffer 
                // before writing.
                write_buff = new byte [BIN_COLUMN_SIZE];
                for(int currByte = 0;
                    currByte < write_buff.Length;
                    currByte++)
                {
                    write_buff[currByte] = strm_buff[currByte + curr_offset];
                }
                // write it..
                SerializedTestDS.SerializedTestRow stRow = 
                    stTbl.NewSerializedTestRow();
                stRow.UserID = 1;
                stRow.ObjectData = write_buff;
                stRow.sequence = curr_sequence;
                stTbl.AddSerializedTestRow(stRow);
                Console.WriteLine("Writing @ current_offset[" 
                                  + curr_offset 
                                  + "] "
                                  + write_buff.Length
                                  + " bytes "
                                  + "into row sequence["
                                  + curr_sequence
                                  + "] ");
                // adjust offsets.
                curr_offset += write_buff.Length;
                bytes_to_write -= write_buff.Length;
                curr_sequence++;
            }
            stTA.Update(stDS);
            Console.WriteLine();
            Console.WriteLine();
        }
 public static System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(System.Xml.Schema.XmlSchemaSet xs) {
     SerializedTestDS ds = new SerializedTestDS();
     System.Xml.Schema.XmlSchemaComplexType type = new System.Xml.Schema.XmlSchemaComplexType();
     System.Xml.Schema.XmlSchemaSequence sequence = new System.Xml.Schema.XmlSchemaSequence();
     xs.Add(ds.GetSchemaSerializable());
     System.Xml.Schema.XmlSchemaAny any = new System.Xml.Schema.XmlSchemaAny();
     any.Namespace = ds.Namespace;
     sequence.Items.Add(any);
     type.Particle = sequence;
     return type;
 }