various problems with first test app


Author
Message
Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)
Group: Forum Members
Posts: 235, Visits: 309
I have built a bo library that corresponds to 3 tables in my database. The one I am working with is a table of users. It is my intention to test the new serialize to stream function.



There are 3 issues here



The table schema looks like this:

new DataColumn("ID", typeof(System.String)),

new DataColumn("LAST_NAME", typeof(System.String)),

new DataColumn("FIRST_NAME", typeof(System.String)),

new DataColumn("MI", typeof(System.String)),

new DataColumn("TITLE", typeof(System.String)),

new DataColumn("LIC_NO", typeof(System.String)),

new DataColumn("DEA", typeof(System.String)),

new DataColumn("EMP_NO", typeof(System.String)),

new DataColumn("INSVC_DATE", typeof(System.DateTime)),

new DataColumn("OSVC_DATE", typeof(System.DateTime))

etc...





I created a Strataframe windows app and added boAllUsers1 instance to the form and added a button with the follwoing handler:



private void button1_Click(object sender, EventArgs e)

{

Stream myStream;

boAllUsers1.NewRow();

boAllUsers1.ID = "FRED";

boAllUsers1.SerializeToStream(myStream);

BOLibrary.boAllUsers allUsers = (BOLibrary.boAllUsers)BusinessLayer.DeserializeBusinessObject(myStream);

MessageBox.Show(allUsers.ID);

}



1)---------------------------------------------------------------

The first error I get is in the attached jpeg and I don't understand it.



2)---------------------------------------------------------------

The second error is when I try to execute:

boAllUsers1.ID = "FRED";



The error is:

{"Input string was not in a correct format.Couldn't store in ID Column. Expected type is Int32."}



Since this is a string field in the DB and the BO was built knowing that it is a string field, why is it complaining that I cannot put a string in an integer field?



3)---------------------------------------------------------------

Since .NET does not provide a constructor that will create a new empty stream, perhaps it would be better if SerializeToStream returned a Stream and SerializeToByteArray returned a ByteArray rather than taking them as input parameters?



Thank you
Attachments
assembly version conflicts.jpg (246 views, 15.00 KB)
Replies
Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)
Group: Forum Members
Posts: 235, Visits: 309
The more I think about it, the more sure I am that bo.SeializeToStream should return Stream and bo.SerializeToByteArray should return ByteArray[].



In addition to the issue of not being able to create an empty stream for this function to fill, is that the way they are currently written without the parameter being a ref parameter, you could pass in a stream or a byteArray but you would never get it back out at all.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
The bo.SerializeToStream() method cannot return a stream because the framework has no idea what type of stream you are expecting (System.IO.MemoryStream, System.Net.NetworkStream, System.IO.FileStream), and the method certainly cannot return a System.IO.Stream because the class is abstract and it cannot create an instance of it. The SerializeToStream(System.IO.Stream) method accepts the stream TO WHICH you want the data to be written. And there is no need to accept the stream, write to it, and then return the same stream you just passed.



The System.IO.Stream does not need to be passed because ByRef because classes are reference objects, so passing a class by reference is only necessary if the actual reference is going to change (i.e., after the method call, the parameter you pass will be replaced by a different object).



If you need to create a new empty stream, you can use System.IO.MemoryStream st = new System.IO.MemoryStream(); and that will create a new empty stream. You can also create a new System.IO.FileStream by specifying the filename in the constructor.



The SerializeToByte() method already returns a System.Byte[], so it's works in the same manner as you would expect.
Daniel Essin
Daniel Essin
StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)StrataFrame User (339 reputation)
Group: Forum Members
Posts: 235, Visits: 309
In order to separate operational issues from philosophical discussion, I have posted the errors that occurred when trying to use this function in a separate message.



As far as the philosophical issues is concerned, I have a preference for functions like this returning an object as a result for the following reasons:



1) It makes it possible to nest the function that creates the new stream within a function call that consumes the stream.



2) If I read the .NET framework correctly (please correct me if necessary as I am kind of new to this area of .NET), there are only 4 basic types of streams: MemoryStream, FileStream, BufferedStream and .Net.NetworkStream. Any other type of stream that one chose to create would be done by subclassing one of these. This would admit several solutions to introducing a function that returned a new stream:



a) Create 4 functions. SerializeToMemoryStream, SerializeToFileStream, SerializeToBufferedStream and SerializeToNetworkStream.



b) Create the SerializeToStream function to take an enum as the input parameter. The Enum would be something like:



enum SerializeToStreamType{

MemoryStream,

FileStream,

BufferedStream

NetworkStream }



In either case if the user was working with a custom class that was subclassed from one of these, they could cast the return value to the type of their custom class.



3) It would create a syntactic unity between SerializeToStream and SerializeToByteArray which would soothe by obsessive, compulsive soul.



Clearly what you have created so far is workable (with the exception of the issues raised in the other post). If what I have suggested is really not possible because of other technical factors that you understand better than I, I can certainly live with it the way it is. I hope I have at least done an adequate job of explaining my preference and why I raised the issue.



Thank you.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search