|
hi,
if i have a class like below:
[XmlRoot("MyData")]<br />
public class MyData:ArrayList<br />
{<br />
public MyData()<br />
{<br />
}<br />
public MyData(ArrayList shape, ArrayList color, ArrayList coord, ArrayList size, ArrayList gpd)<br />
{<br />
this.ShapeTypeList = shape;<br />
this.ColorList = color;<br />
this.CoordList = coord;<br />
this.SizeList = size;<br />
this.ArrS = gpd;<br />
}.......<br />
<br />
In the Form:
MyData data=new MyData();<br />
XmlSerializer s=new XmlSerializer(typeof(MyData));<br />
generates the error:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll<br />
<br />
Additional information: There was an error reflecting type 'DrawShape.MyData'.
How can i declare XmlSerializer for a Class MyData which inherits ArrayList class?
Thanks in advance
|
|
|
|
|
Hi cyn8
At first I couldn't understand why you derived MyData from ArrayList !!
and the problem :
it is one of the boring and annoying one.I tested and my brain was going to blown (thank god for saving me) it seems it happens because xmlSerializer can just serialize public class,and it's public memebers no more no less
here is a few things must be paid attention for xml serializtion
1-your class must be public
2-your class must have parameterless constructor
3-all members are chosen must be public and if they are property type they must have both get and set
4-if your class would be embedded in another class Xml in serialization the embedded class must have XmlInclude Attribute or in the outer class type of inner class must be passed through
(another way is pass it's type throught XmlSerializer constructor in extraTypes argument but I'm not sure it works well)
hope the post would be useful
good luck 
|
|
|
|
|
 and these are the codes I modified and tested (I'm really sorry about what I sent two days ago it didn't work well in desrialization )
Here is Correct ones
[XmlRoot("MyData")]
[Serializable]
public class MyData
{
ArrayList shapeTypeList;
ArrayList colorList;
ArrayList coordList;
ArrayList sizeList;
ArrayList graphicsPathDataList;
[XmlArray("ShapeData")]
[XmlArrayItem("Shape")]
public ArrayList ShapeTypeList
{
get { return this.shapeTypeList; }
set { this.shapeTypeList = value; }
}
[XmlArray("ColorData")]
[XmlArrayItem("Color")]
public ArrayList ColorList
{
get { return this.colorList; }
set { this.colorList = value; }
}
[XmlArray("CoorinationData")]
[XmlArrayItem("Coordination")]
public ArrayList CoordList
{
get { return this.coordList; }
set { this.coordList= value; }
}
[XmlArray("SizeData")]
[XmlArrayItem("Size")]
public ArrayList SizeList
{
get { return this.sizeList; }
set { this.sizeList = value; }
}
[XmlArray("GPDDataCollection")]
[XmlArrayItem("GPD",Type=typeof(GraphicsPathData))]
public ArrayList GraphicsPathDataList
{
get { return this.graphicsPathDataList; }
set { this.graphicsPathDataList = value; }
}
public MyData(ArrayList shape, ArrayList color, ArrayList coord, ArrayList size, ArrayList gpd)
{
this.shapeTypeList = shape;
this.colorList = color;
this.coordList = coord;
this.sizeList = size;
this.graphicsPathDataList = gpd;
}
private MyData()
{
}
static MyData BinLoad(string path)
{
BinaryFormatter binSer=new BinaryFormatter();
FileStream fo=new FileStream(path,FileMode.Open);
object data=binSer.Deserialize(fo);
fo.Close();
return data as MyData;
}
void BinSerialize(string path)
{
BinaryFormatter binSer=new BinaryFormatter();
FileStream fo=new FileStream(path,FileMode.OpenOrCreate);
binSer.Serialize(fo,this);
fo.Close();
}
static MyData XmlLoad(string path)
{
XmlSerializer xmlSer=new XmlSerializer(typeof(MyData));
FileStream fo=new FileStream(path,FileMode.Open);
object data=xmlSer.Deserialize(fo);
fo.Close();
return data as MyData;
}
void XmlSerialize(string path)
{
XmlSerializer xmlSer=new XmlSerializer(this.GetType());
FileStream fo=new FileStream(path,FileMode.OpenOrCreate);
xmlSer.Serialize(fo,this);
fo.Close();
}
public enum SerializeTo{XML,Binary};
public void Serialize(string path,SerializeTo to)
{
if(to==SerializeTo.Binary)
this.BinSerialize(path);
else
this.XmlSerialize(path);
}
public static MyData Load(string path,SerializeTo to)
{
if(to==SerializeTo.Binary)
return BinLoad(path);
else
return XmlLoad(path);
}
}
and the GraphicspathData must be modified somewhat like this
[Serializable]
[XmlRoot("GraphicsPathData")]
[XmlInclude(typeof(GraphicsPathData))]
public class GraphicsPathData
{
byte[] types;
PointF[] points;
FillMode fillMode;
[XmlArray("Types")]
public byte[] Types
{
get { return this.types; }
set { this.types = value; }
}
[XmlArray("Points")]
public PointF[] Points
{
get { return this.points; }
set { this.points = value; }
}
[XmlElement("FillMode")]
public FillMode FillMode
{
get { return this.fillMode; }
set { this.fillMode = value; }
}
public GraphicsPathData(GraphicsPath gp)
{
this.types = gp.PathTypes;
this.points = gp.PathPoints;
this.fillMode = gp.FillMode;
}
private GraphicsPathData()
{
}
public static System.IO.Stream Serialize(GraphicsPathData gpd)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bf.Serialize(ms, gpd);
ms.Flush();
return ms;
}
public static GraphicsPathData Deserialize(System.IO.Stream stream)
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
object obj = bf.Deserialize(stream);
GraphicsPathData gpd = obj as GraphicsPathData;
return gpd;
}
public static GraphicsPath GetGraphicsPath(GraphicsPathData gpd)
{
return new GraphicsPath(gpd.points, gpd.types, gpd.fillMode);
}
public static GraphicsPath GetGraphicsPath(System.IO.Stream gpdStream)
{
return GetGraphicsPath(Deserialize(gpdStream));
}
}
good luck 
|
|
|
|
|
 hi, i'm sorry to say that i'm still stuck. The XML file can be generated but it is the same as shown before where there is no root and all the element is "ArrayOfAnyType"
<br />
[XmlRoot("MyData")]<br />
public class MyData<br />
{<br />
ArrayList shapeTypeList;<br />
ArrayList colorList;<br />
ArrayList coordList;<br />
ArrayList sizeList;<br />
ArrayList arrS;<br />
<br />
[XmlArray("ShapeData")]<br />
[XmlArrayItem("Shape",typeof(ShapeL))]<br />
public ArrayList ShapeTypeList<br />
{<br />
get { return this.shapeTypeList; }<br />
set{this.shapeTypeList=value;}<br />
}<br />
<br />
public class ShapeL<br />
{<br />
public ShapeL(){}<br />
public TypeOfShape c<br />
{<br />
get{return c;}<br />
set{c=value;}<br />
<br />
}<br />
<br />
}<br />
<br />
[XmlArray("ColorData")]<br />
[XmlArrayItem("Color",typeof(ColorL))]<br />
public ArrayList ColorList<br />
{<br />
get { return this.colorList; }<br />
set{this.colorList=value;}<br />
}<br />
<br />
public class ColorL<br />
{<br />
public ColorL(){}<br />
[XmlElement("color")]<br />
public Color c<br />
{<br />
get{return c;}<br />
set{c=value;}<br />
<br />
}<br />
<br />
}<br />
<br />
[XmlArray("CoordinateData")]<br />
[XmlArrayItem("Coordinate",typeof(Coordinate))]<br />
public ArrayList CoordList<br />
{<br />
get { return this.coordList; }<br />
set{this.coordList=value;}<br />
}<br />
<br />
public class Coordinate<br />
{<br />
public Coordinate(){}<br />
public Point[] point<br />
{<br />
get{return point;}<br />
set{point=value;}<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
[XmlArray("SizeData")]<br />
[XmlArrayItem("Size",typeof(SizeL))]<br />
public ArrayList SizeList<br />
{<br />
get { return this.sizeList; }<br />
set{this.sizeList=value;}<br />
}<br />
<br />
public class SizeL<br />
{<br />
public SizeL(){}<br />
public Size c<br />
{<br />
get{return c;}<br />
set{c=value;}<br />
<br />
}<br />
<br />
}<br />
<br />
[XmlArray("GPDData")]<br />
[XmlArrayItem("GPD",typeof(ArrSave))]<br />
public ArrayList ArrS<br />
{<br />
get { return this.arrS; }<br />
set{ this.arrS=value;}<br />
}<br />
public class ArrSave<br />
{<br />
public ArrSave(){}<br />
public MemoryStream c<br />
{<br />
get{return c;}<br />
set{c=value;}<br />
<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
public MyData()<br />
{<br />
}<br />
<br />
public MyData(ArrayList shape, ArrayList color, ArrayList coord, ArrayList size, ArrayList gpd)<br />
{<br />
this.ShapeTypeList = shape;<br />
this.ColorList = color;<br />
this.CoordList = coord;<br />
this.SizeList = size;<br />
this.ArrS = gpd;<br />
}<br />
<br />
<br />
<br />
public enum TypeOfShape<br />
{<br />
Square, Rect, Parallelogram, Trapezoid, Diamond, Triangle, RightAngleTriangle,Circle,Oval,Hexagon,Pentagon,None<br />
}<br />
<br />
<br />
public void save( string filename)<br />
{<br />
XmlSerializer ser = new XmlSerializer(typeof(ArrayList),new Type[] {typeof(Coordinate),typeof(ColorL),typeof(ShapeL),typeof(SizeL),typeof(ArrSave)} );<br />
<br />
ArrayList arr=new ArrayList();<br />
TextWriter w = new StreamWriter( filename );<br />
ser.Serialize( w, this.ShapeTypeList );<br />
ser.Serialize( w, this.ColorList );<br />
ser.Serialize( w,this.CoordList );<br />
ser.Serialize( w, this.SizeList );<br />
<br />
for(int i=0;i<this.ArrS.Count;i++)<br />
{<br />
GraphicsPathData gpd = new GraphicsPathData((GraphicsPath)this.ArrS[i]);
Stream gpdStream = GraphicsPathData.Serialize(gpd);<br />
arr.Add(gpdStream);<br />
<br />
}<br />
ser.Serialize( w, arr);<br />
<br />
w.Close();<br />
}
Then in save function located at the form, i write:
<br />
MyData d=new MyData(ShapeTypeList,ColorList,CoordList,SizeList,PathList);<br />
d.save(filename);
Please help...I'm been cracking my head for hours
Thanks for your helps...
-- modified at 23:13 Tuesday 21st August, 2007
|
|
|
|
|
I Saw your code you didn't pay attention to rules I said before
IF YOU SERIALIZE AN ARRAYLIST DIRECTLY IT WOULD GIVE YOU THE RESULTS LIKE THAT!
MyData class actually is scheme for xmlSerializer so you don't need to put each array in serializer (in addition I said before retriving the data would be difficult too)
just put MyData Class in Serializer and all memebers you marked with attributes would be serialized
another thing is Color Struct properties are readonly so you can't seriailize it with xmlSerializer you must create a new Color Class with specific attributes
and Please don't serialize GraphicpathData and then serialize the streams again with xmlserializer i have doubt it works in Deserializing atall and ofcourse it waste the Resources
at last i put a complete code in
http://hjk.4shared.com
or direct link
http://www.4shared.com/file/22596905/834df73f/XmlSerializationExample.html[^]
good luck
|
|
|
|
|
Sorry, the links does not seem to work. Can you please send it again? Thanks
|
|
|
|
|
Are you sure??
I test them and they works
here they are again
http://hjk.4shared.com
and there is xmlSerializationExample.Zip there after clicking on it to download
in download page yuo must wait alittle and the DownloadFile link would appear
here is the direct link to file
http://www.4shared.com/file/22596905/834df73f/XmlSerializationExample.html
here is the new link
http://rapidshare.com/files/50526458/XmlSerializationExample.zip.html
AS A TIP YOU CANNOT DOWNLOAD FROM THESE LINKS WITH DOWNLOAD MANAGERS AND ACCELERATORS
and sorry if you had problem in downloading them just give your mail if you want
hope these links work 
|
|
|
|
|
THANK YOU!!! You are a LIFE SAVER!!!
Man, it is the people like you that makes this world a better place to live in:P
Your codes works like a charm.
However, there is a small problem, there seem to extra shape(exactly same shape) that is overlap on each shape. When i drag and drop on of the shape, the extra shape is temporary will be display at the original coordinate. But later if i want to drag the extra shape, it cannot be dragged and sometimes after i dragged a shape, all the extra shapes that is position on the saved shape original position will disappear. What you think that it is caused by?
Below are the codes in the Load function located in the form( ShapeTypeList,CoordList,SizeList are arraylist that contains the data for the shapes to be drawn on the form):
<br />
<br />
OpenFileDialog openFileDialog = new OpenFileDialog();<br />
ArrayList arr =new ArrayList();<br />
ArrayList ColorArr =new ArrayList();<br />
if (openFileDialog.ShowDialog() == DialogResult.OK)<br />
{<br />
filename = openFileDialog.FileName;<br />
<br />
ClearArrayList();<br />
MyData deserializeData =MyData.Load(filename);<br />
ShapeTypeList=deserializeData.ShapeTypeList;<br />
CoordList=deserializeData.CoordList;<br />
ColorArr=deserializeData.ColorList;<br />
SizeList=deserializeData.SizeList;<br />
arr=deserializeData.GraphicsPathData;<br />
<br />
for(int j=0;j<ColorArr.Count;j++)<br />
{<br />
<br />
MyColor myC=(MyColor)ColorArr[j];<br />
ColorList.Add(Color.FromArgb(myC.A,myC.R,myC.G,myC.B));<br />
<br />
}<br />
<br />
GraphicsPath myPath=new GraphicsPath();<br />
int k=0;<br />
for(int i=0;i<arr.Count;i++)<br />
{<br />
if((TypeOfShape)ShapeTypeList[i]==TypeOfShape.Oval||(TypeOfShape)ShapeTypeList[i]==TypeOfShape.Circle)<br />
{<br />
Point[] p=(Point[])CoordList[i];<br />
Size s=(Size)SizeList[k];<br />
myPath.AddEllipse(p[0].X,p[0].Y,s.Width,s.Height);<br />
k++;<br />
}<br />
<br />
else<br />
{<br />
myPath.AddPolygon((Point[])CoordList[i]);<br />
}<br />
<br />
PathList.Add(myPath);<br />
}<br />
<br />
panel1.Invalidate();<br />
}<br />
What should i do to solve this problem?
Thanks a million
-- modified at 6:53 Thursday 23rd August, 2007
|
|
|
|
|
Hi
at first thank you .
and about the problem I don't know I get it or not but it seems you want to draw eeah sahpe in a single path right?
<code>GraphicsPath myPath=new GraphicsPath();</code>
int k=0;
for(int i=0;i {
if((TypeOfShape)ShapeTypeList[i]==TypeOfShape.Oval||(TypeOfShape)ShapeTypeList[i]==TypeOfShape.Circle)
{
Point[] p=(Point[])CoordList[i];
Size s=(Size)SizeList[k];
myPath.AddEllipse(p[0].X,p[0].Y,s.Width,s.Height);
k++;
}
else
{
myPath.AddPolygon((Point[])CoordList[i]);
}
<code>PathList.Add(myPath);</code>
}
panel1.Invalidate();
}
in the code above I marked some lines as red if i was right about what you want to do
in the first red line you create an instance of the GraphicPath and darw all of the shapes inside it but in the second red line with ireratinf in the shapes you add it to a arrayList
so infact you draw all your shapes in just ine Graphic path and then for each shape add it to the arraylist so you have same Graphicpath as many as your shapes and you draw it
I think on your test so it wll make extra shape!
for solving this simply put the first red line in the loop and it would create ab instance of Graphicpath each time and prevent from extra shapes.
hope this helps
Best regards
|
|
|
|
|
Hi,
Thanks...Your solution is just what i need to do!
Now it seems that all is working properly
Thanks and best regards
Have a nice day
|
|
|
|
|
your welcome
have a nice day too
|
|
|
|
|
I tried Ping class of VS.NET but Mono doesn't support this.How can i ping on Mono like "ping -c 1 123.123.123.123" and how to get its echo(return value)?
|
|
|
|
|
bug_aonz wrote: Mono doesn't support this
Any compilation or runtime issues?
|
|
|
|
|
i want to run my C# console app with Mono-project on Linux server.My app proposes to do a realtime ping IP addresses in the list and get the state that target IP online or offline.
|
|
|
|
|
Windows XP:
C# 2005
I want to get the installed software List from my Windowsxp operting
system.Anybody help me.
Continue...
|
|
|
|
|
|
How do you call a Matlab dll mexFunction from C# code? Assuming you declare the mexFunction using the DllImport attribute, how do declare mxArray params...?
e.g.
[DllImport("mexdll.dll", EntryPoint="mexFunction")]
private static extern void mexFunction(int nlhs, ?? plhs, int nrhs, ?? prhs);
Cheers
Goose
|
|
|
|
|
First, you may want to have a look at the MATLAB Builder for .NET[^]
Second, it would have been helpful to have posted the original C calling syntax for the mexFunction , which is
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]); There is an example here Integrating MATLAB with C#[^] that might help you as well, but you probably want the mxArray parameters to be declared as ref IntPtr or possibly out IntPtr[] parameters.
|
|
|
|
|
Hello,
VS 2005 & IIS 5.1
I am using an updater block, just so you know what I am talking about you can get it from this link:
http://www.microsoft.com/downloads/details.aspx?familyid=C6C09314-E222-4AF2-9395-1E0BD7060786&displaylang=en
I have a server which i have my updates and the manifest.
However, the client will download the manifest and in the updaterLog it will say manifest downloaded ok, but validation failed. See full error msg below.
However, If i create a virtual directory on the same computer as the client is running on, and have the updates in there. Then everything works fine. So all my code is working ok.
However, its when the updates are on the server which is on a network. That it does not work. It make me believe there is a difference in what I have to do to get this to work on the network.
I have tried 2 different computers running the client and having the updates located on each one. Both work well when the updates are on each of the local computers. But when I try and get the updates to work when they are on the server it fails.
Also, i have double checked the private and public keys. They are all in order.
Is there something I need to do on the network to get this to work? Maybe set some permission? Why does the manifest become invalid when it is download from the server on the network?
Your help with any suggestion would be most grateful,
Thanks,
Error from log file
<CODE>[DownloaderManager.ValidateManifestFile] :
MANIFEST VALIDATION FAILED:
The server Manifest located at
'C:\Program Files\CodeRed\Updates\Manifest.xml' failed validation.
It is being deleted; its signature did not match the signature of the file that was downloaded.</CODE>
|
|
|
|
|
Hi.
For my application, I need a text control that help to enter an IP address, like the one available in Visual C++. But I can't find that IP control, there's no NET control like this one and also I can't find it as COM control. In MSN we can find that IP control is in comctl32.ocx but, browsing for this library in Visual Studio, and trying to add it as component, it auto checks a few objects like listiew, treeview, etc, but nothing about IP conrol.
So, where is the fuc*** IP control?. (sorry)
I know, I'm sure that there's a NET control, there in the toolbar, but I can't figure out where. Instead, I'm using a MaskedTextBox, but it would be more easy with the IP Control.
Thank you.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
Forget it!.
I found the answer at: http://www.codeproject.com/cs/miscctrl/IpAddrCtrlLib.asp[^]
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
I have been tasked with creating a windows form that will be like a paint program. The user should be able to drag units from a toolbox and drop them on the map. Then be able to resize them and move them around on the map. This way they create a map over their facility with storage units.
I have never developed much GDI+ related stuff and i have no clue how to do this. Can someone please hint me where i can find some good articles on how to place items like this on a surface and then move them around.
Thanks for any help.
-- modified at 14:07 Monday 20th August, 2007
|
|
|
|
|
This is not a paint program, it's a drawing program. The difference is that when you paint, you leave behind pixels, when you draw, you leave shapes that you can then interact with. Basically, what you want to do is store a collection of a base shape class, and create derived classes for the shapes you draw. Then when you move the mouse, you need to iterate over those shapes to work out if the mouse is over one. If it is, you start using mouse actions to interact with the shape in question. Changing that instance of a shape class, obviously then changes how it is drawn on screen.
GDI+ actually does very little here, each shape knows how to draw itself, and presumably the drawings are not that complex. The real work is in working out what shape the mouse is over, and manipulating it.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I hate to think how many times this question has been asked, but here goes--
I have a "Back" button where "CausesValidation" is false. It closes the current dialog. The stupid thing is, the close dialog fires the validation routine!!! WTF? That's why I don't want validation. And I checked which control has focus when close fires, and it's the Back button.
So, what's the correct way of closing (as in, canceling) a dialog that has some controls that do validation, but the user's clicked on a back or cancel button (with CausesValidation set to false) so we obviously don't want to do validation?
Because, the stupid thing is, it's focused on a control that doesn't cause validation yet it's trying to validate a control!
Automatic validation, BTW, is one of the lamest, most poorly implemented features of .NET. I'm not even sure why I'm using it! It must have been by written by some highschool dropout on a bender.
Marc
|
|
|
|
|
Marc Clifton wrote:
Automatic validation, BTW, is one of the lamest, most poorly implemented features of .NET. I'm not even sure why I'm using it! It must have been by written by some highschool dropout on a bender.
Hahaha, that must be quite some guy??
Doesn't the this.DialogResult = DialogResult.Cancel work?
|
|
|
|
|