Showing posts with label collection. Show all posts
Showing posts with label collection. Show all posts

Monday, March 26, 2012

serialization - include collection property

Why the collection property is not included in the ouput
serialization ?

I have a custom generic collection (implements icollection): Events of
objects: Event.

Event is a simple class exposing, let's say, one property: name

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class

Events Implements ICollection
Public EventColor as string
......

Everything works except when I save the xml file I'm expecting to get
smth like:

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>

EVENTCOLOR attribute is not in the xml, any idea ?

Thanks,
xkeIn your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"xke" <xkeops@.gmail.comwrote in message
news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?
>
I have a custom generic collection (implements icollection): Events of
objects: Event.
>
Event is a simple class exposing, let's say, one property: name
>
Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class
>
>
Events Implements ICollection
Public EventColor as string
......
>
Everything works except when I save the xml file I'm expecting to get
smth like:
>
<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>
>
EVENTCOLOR attribute is not in the xml, any idea ?
>
Thanks,
xke
>


Hi Andrew,

Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.

It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.

Thanks,
xke

On Oct 22, 10:06 pm, "Andrew Faust" <and...@.andrewfaust.comwrote:

Quote:

Originally Posted by

In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?
>
--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com
>
"xke" <xke...@.gmail.comwrote in message
>
news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...
>
>
>

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?


>

Quote:

Originally Posted by

I have a custom generic collection (implements icollection): Events of
objects: Event.


>

Quote:

Originally Posted by

Event is a simple class exposing, let's say, one property: name


>

Quote:

Originally Posted by

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class


>

Quote:

Originally Posted by

Events Implements ICollection
Public EventColor as string
......


>

Quote:

Originally Posted by

Everything works except when I save the xml file I'm expecting to get
smth like:


>

Quote:

Originally Posted by

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>


>

Quote:

Originally Posted by

EVENTCOLOR attribute is not in the xml, any idea ?


>

Quote:

Originally Posted by

Thanks,
xke- Hide quoted text -


>
- Show quoted text -


Sorry. Misread your original post.

According to this article the Serializer only supports writing out the
actual objects contained in an ICollection and not the actual properties of
the collection itself.

http://www.diranieh.com/NETSerializ...rialization.htm
I would recommend a slight restructuring to something like this

class Events
{
public string EventColor;
private List<Eventm_Events;
public Event[] UpcomingEvents
{
get { return m_Events.ToArray(); }
set {
m_Events = new List<Event>();
m_Events.AddRange(value);
}
}
}

Then serialize the Events class.

"xke" wrote:

Quote:

Originally Posted by

Hi Andrew,
>
Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.
>
It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.
>
Thanks,
xke
>
On Oct 22, 10:06 pm, "Andrew Faust" <and...@.andrewfaust.comwrote:

Quote:

Originally Posted by

In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?

--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com

"xke" <xke...@.gmail.comwrote in message

news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?


Quote:

Originally Posted by

I have a custom generic collection (implements icollection): Events of
objects: Event.


Quote:

Originally Posted by

Event is a simple class exposing, let's say, one property: name


Quote:

Originally Posted by

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class


Quote:

Originally Posted by

Events Implements ICollection
Public EventColor as string
......


Quote:

Originally Posted by

Everything works except when I save the xml file I'm expecting to get
smth like:


Quote:

Originally Posted by

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>


Quote:

Originally Posted by

EVENTCOLOR attribute is not in the xml, any idea ?


Quote:

Originally Posted by

Thanks,
xke- Hide quoted text -


- Show quoted text -


>
>
>


beautiful idea / will give it a try tomorrow

thanks,
xke

On Oct 23, 1:28 pm, Andrew Faust <afa...@.nospam.nospamwrote:

Quote:

Originally Posted by

Sorry. Misread your original post.
>
According to this article the Serializer only supports writing out the
actual objects contained in an ICollection and not the actual properties of
the collection itself.
>
http://www.diranieh.com/NETSerializ...rialization.htm
>
I would recommend a slight restructuring to something like this
>
class Events
{
public string EventColor;
private List<Eventm_Events;
public Event[] UpcomingEvents
{
get { return m_Events.ToArray(); }
set {
m_Events = new List<Event>();
m_Events.AddRange(value);
}
}
>
}
>
Then serialize the Events class.
>
>
>
"xke" wrote:

Quote:

Originally Posted by

Hi Andrew,


>

Quote:

Originally Posted by

Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.


>

Quote:

Originally Posted by

It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.


>

Quote:

Originally Posted by

Thanks,
xke


>

Quote:

Originally Posted by

On Oct 22, 10:06 pm, "Andrew Faust" <and...@.andrewfaust.comwrote:

Quote:

Originally Posted by

In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com


>

Quote:

Originally Posted by

Quote:

Originally Posted by

"xke" <xke...@.gmail.comwrote in message


>

Quote:

Originally Posted by

Quote:

Originally Posted by

>news:1193083502.735588.136230@.e34g2000pro.googlegr oups.com...


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Why the collection property is not included in the ouput
serialization ?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

I have a custom generic collection (implements icollection): Events of
objects: Event.


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Event is a simple class exposing, let's say, one property: name


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Events Implements ICollection
Public EventColor as string
......


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Everything works except when I save the xml file I'm expecting to get
smth like:


>

Quote:

Originally Posted by

Quote:

Originally Posted by

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>


>

Quote:

Originally Posted by

Quote:

Originally Posted by

EVENTCOLOR attribute is not in the xml, any idea ?


>

Quote:

Originally Posted by

Quote:

Originally Posted by

Thanks,
xke- Hide quoted text -


>

Quote:

Originally Posted by

Quote:

Originally Posted by

- Show quoted text -- Hide quoted text -


>
- Show quoted text -

Saturday, March 24, 2012

Serialization Question

Hi,
I have a collection class called Printers that implement the ICollection and
IEnumerable. This class contains a private ArrayList that holds the Printer
objects. The printer class is a serializable class that contains only the
public name attribute.
After serialization, I want to get the following xml structure;
<Printers>
<Printer>
<Name></Name>
</Printer>
<Printers>
When I want to serialize this Printers collection, I get instead something
like;
<ArrayOfPrinter>
<Printer>
<Name></Name>
</Printer>
</ArrayOfPrinter>
If I take out the ICollection and IEnumerable away, (turning the class into
a normal one) and make the ArrayList public, then I get the following;
<Printers>
<NameOfMyArrayList>
<Printer>
<Name></Name>
</Printer>
</NameOfMyArrayList>
</Printers>
For clarity, I don't include any code at the moment.
Any help appreciated,
EthemHello Ethem,
I'm assuming you mean XmlSerialization... Given that, either the XmlRoot
(if its the top level node) or XmlElement attributes will work.
[XmlRoot("Printers")]
public class PrinterCollection
{
// rest of your code
}
Matt Berther
http://www.mattberther.com

> Hi,
> I have a collection class called Printers that implement the
> ICollection and IEnumerable. This class contains a private ArrayList
> that holds the Printer objects. The printer class is a serializable
> class that contains only the public name attribute.
> After serialization, I want to get the following xml structure;
> <Printers>
> <Printer>
> <Name></Name>
> </Printer>
> <Printers>
> When I want to serialize this Printers collection, I get instead
> something like;
> <ArrayOfPrinter>
> <Printer>
> <Name></Name>
> </Printer>
> </ArrayOfPrinter>
> If I take out the ICollection and IEnumerable away, (turning the class
> into a normal one) and make the ArrayList public, then I get the
> following;
> <Printers>
> <NameOfMyArrayList>
> <Printer>
> <Name></Name>
> </Printer>
> </NameOfMyArrayList>
> </Printers>
> For clarity, I don't include any code at the moment.
> Any help appreciated,
> Ethem
>
Hi Matt,
Thanks for the response. Unfortunately, my collection class implements
ICollection and IEnumerable. If the collection implements these interfaces,
you cannot define an XmlRoot attribute (or any other attribute) on the class
level. Same applies if you derive the collection class from the
CollectionBase.
For my problem, I found a workaround in the following site:
http://dotnet.org.za/armand/archive...09/21/4164.aspx
It seems that you can make it programmatically instead of decleratively.
Thanks,
Ethem
"Matt Berther" wrote:

> Hello Ethem,
> I'm assuming you mean XmlSerialization... Given that, either the XmlRoot
> (if its the top level node) or XmlElement attributes will work.
> [XmlRoot("Printers")]
> public class PrinterCollection
> {
> // rest of your code
> }
> --
> Matt Berther
> http://www.mattberther.com
>
>
>

Serialization Question

Hi,

I have a collection class called Printers that implement the ICollection and
IEnumerable. This class contains a private ArrayList that holds the Printer
objects. The printer class is a serializable class that contains only the
public name attribute.

After serialization, I want to get the following xml structure;

<Printers>
<Printer>
<Name></Name>
</Printer>
<Printers
When I want to serialize this Printers collection, I get instead something
like;

<ArrayOfPrinter>
<Printer>
<Name></Name>
</Printer>
</ArrayOfPrinter
If I take out the ICollection and IEnumerable away, (turning the class into
a normal one) and make the ArrayList public, then I get the following;

<Printers>
<NameOfMyArrayList>
<Printer>
<Name></Name>
</Printer>
</NameOfMyArrayList>
</Printers
For clarity, I don't include any code at the moment.

Any help appreciated,

EthemHello Ethem,

I'm assuming you mean XmlSerialization... Given that, either the XmlRoot
(if its the top level node) or XmlElement attributes will work.

[XmlRoot("Printers")]
public class PrinterCollection
{
// rest of your code
}

--
Matt Berther
http://www.mattberther.com

> Hi,
> I have a collection class called Printers that implement the
> ICollection and IEnumerable. This class contains a private ArrayList
> that holds the Printer objects. The printer class is a serializable
> class that contains only the public name attribute.
> After serialization, I want to get the following xml structure;
> <Printers>
> <Printer>
> <Name></Name>
> </Printer>
> <Printers>
> When I want to serialize this Printers collection, I get instead
> something like;
> <ArrayOfPrinter>
> <Printer>
> <Name></Name>
> </Printer>
> </ArrayOfPrinter>
> If I take out the ICollection and IEnumerable away, (turning the class
> into a normal one) and make the ArrayList public, then I get the
> following;
> <Printers>
> <NameOfMyArrayList>
> <Printer>
> <Name></Name>
> </Printer>
> </NameOfMyArrayList>
> </Printers>
> For clarity, I don't include any code at the moment.
> Any help appreciated,
> Ethem
Hi Matt,

Thanks for the response. Unfortunately, my collection class implements
ICollection and IEnumerable. If the collection implements these interfaces,
you cannot define an XmlRoot attribute (or any other attribute) on the class
level. Same applies if you derive the collection class from the
CollectionBase.

For my problem, I found a workaround in the following site:

http://dotnet.org.za/armand/archive...09/21/4164.aspx

It seems that you can make it programmatically instead of decleratively.

Thanks,

Ethem

"Matt Berther" wrote:

> Hello Ethem,
> I'm assuming you mean XmlSerialization... Given that, either the XmlRoot
> (if its the top level node) or XmlElement attributes will work.
> [XmlRoot("Printers")]
> public class PrinterCollection
> {
> // rest of your code
> }
> --
> Matt Berther
> http://www.mattberther.com
> > Hi,
> > I have a collection class called Printers that implement the
> > ICollection and IEnumerable. This class contains a private ArrayList
> > that holds the Printer objects. The printer class is a serializable
> > class that contains only the public name attribute.
> > After serialization, I want to get the following xml structure;
> > <Printers>
> > <Printer>
> > <Name></Name>
> > </Printer>
> > <Printers>
> > When I want to serialize this Printers collection, I get instead
> > something like;
> > <ArrayOfPrinter>
> > <Printer>
> > <Name></Name>
> > </Printer>
> > </ArrayOfPrinter>
> > If I take out the ICollection and IEnumerable away, (turning the class
> > into a normal one) and make the ArrayList public, then I get the
> > following;
> > <Printers>
> > <NameOfMyArrayList>
> > <Printer>
> > <Name></Name>
> > </Printer>
> > </NameOfMyArrayList>
> > </Printers>
> > For clarity, I don't include any code at the moment.
> > Any help appreciated,
> > Ethem
>

Serializing

I need to store some sort of Name-Value collection in the Application State.

I keep trying different ones, but it errors out saying that they are not
serializable. Do I need to write my own or is there one in the Framework
that is serializable?

I've tried NameValueCollection, Dictionairy<string,string>,
StringDictionairy, etc...

What type does everyone else use that can be serialized?Hello INeedADip,

Application is itself a Name Value collection. So you can use the same.

HTH,
r.

> I need to store some sort of Name-Value collection in the Application
> State.
> I keep trying different ones, but it errors out saying that they are
> not serializable. Do I need to write my own or is there one in the
> Framework that is serializable?
> I've tried NameValueCollection, Dictionairy<string,string>,
> StringDictionairy, etc...
> What type does everyone else use that can be serialized?

Serializing

I need to store some sort of Name-Value collection in the Application State.
I keep trying different ones, but it errors out saying that they are not
serializable. Do I need to write my own or is there one in the Framework
that is serializable?
I've tried NameValueCollection, Dictionairy<string,string>,
StringDictionairy, etc...
What type does everyone else use that can be serialized?Hello INeedADip,
Application is itself a Name Value collection. So you can use the same.
HTH,
r.

> I need to store some sort of Name-Value collection in the Application
> State.
> I keep trying different ones, but it errors out saying that they are
> not serializable. Do I need to write my own or is there one in the
> Framework that is serializable?
> I've tried NameValueCollection, Dictionairy<string,string>,
> StringDictionairy, etc...
> What type does everyone else use that can be serialized?
>

Serializing an object from HttpApplicationState

Hi!
I have an object stored in the HttpApplicationState collection of my
site, but i would like to mantain the state of this object even if the
application restart, so in case of any problem or when I change
something in the web.config or add anything to the bin directory, i can
load the last values from somewhere and continue the work.
I'm using serialization to accomplish this, and it works ok. But i'm
serializing the object to a file in the "HttpApplication.EndRequest"
event. The problem is that with this event, it saves the file in the end
of every instance of HttpApplication, which occours almost every second.
I tested locally, and it saves the file everytime i access any page.
I know that the HttpApplicationState is shared among all the instances
of HttpApplication, and I would like to save the file only before
ApplicationState is destroyed, not the application...
There is no event in HttpApplicationState, so is there any way of doing
this?
Thanks in advance.Hi Natan:
One of the safest things you could do is re-save the file anytime the
value changes (if it is not changing too frequently). This would take
care of even catostrophic failures.
There is an Application_End method you can use in the code behind for
Global.asax. This method should fire whenever the application shuts
down or recycles.
Scott
http://www.OdeToCode.com
On Sun, 26 Sep 2004 19:06:03 -0300, Natan <nvivo@.mandic.com.br> wrote:

>Hi!
>I have an object stored in the HttpApplicationState collection of my
>site, but i would like to mantain the state of this object even if the
>application restart, so in case of any problem or when I change
>something in the web.config or add anything to the bin directory, i can
>load the last values from somewhere and continue the work.
>I'm using serialization to accomplish this, and it works ok. But i'm
>serializing the object to a file in the "HttpApplication.EndRequest"
>event. The problem is that with this event, it saves the file in the end
>of every instance of HttpApplication, which occours almost every second.
>I tested locally, and it saves the file everytime i access any page.
>I know that the HttpApplicationState is shared among all the instances
>of HttpApplication, and I would like to save the file only before
>ApplicationState is destroyed, not the application...
>There is no event in HttpApplicationState, so is there any way of doing
>this?
>
>Thanks in advance.
Scott Allen wrote:
> Hi Natan:
> One of the safest things you could do is re-save the file anytime the
> value changes (if it is not changing too frequently). This would take
> care of even catostrophic failures.
That's what i would like to avoid. File writes are too expensive, and
this would be like 3 or 4 per second. although the file size is aprox.
20k, it is still unnecessary.

> There is an Application_End method you can use in the code behind for
> Global.asax. This method should fire whenever the application shuts
> down or recycles.
Application_End is tied to the EndRequest actually, which is not the
Application in IIS itself, but HttpApplication instance. Many instances
are created and destroyed everytime by the server... take a look at the
documentation.
I really would like to save it only when necessary. Maybe i'll need to
implement it in another way...
Hi Natan:

>Application_End is tied to the EndRequest actually, which is not the
>Application in IIS itself, but HttpApplication instance. Many instances
>are created and destroyed everytime by the server... take a look at the
>documentation.
>
Negative: Application_EndRequest fires as the last event in the
pipeline before the request moves to the HttpHandler for the requested
resource. This happens on every request. Furthermore, the
HttpApplication instance is not destroyed, but is kept in a pool to
service another request.
Application_End, like Application_Start, is invoked only once, and
only invoked on a single HttpApplication instance, the first instance
in the pool. It will fire before the application domain unloads,
although there is some evidence that this behavior is not 100.00%
reliable.
I've been through the documentation many times, but even better I have
code that can demonstrate this behavior. You can watch the output
window of the debugger as you make requests to the web app with the
following code in global. Do an IISRESET to watch Application_End
fire.
public Global()
{
InitializeComponent();
id = System.Threading.Interlocked.Increment(ref counter);
}
protected void Application_Start(Object sender, EventArgs e)
{
Debug.WriteLine("Application_Start on ID: " + id.ToString());
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
Debug.WriteLine("Application_EndRequest on ID: " + id.ToString());
}
protected void Application_End(Object sender, EventArgs e)
{
Debug.WriteLine("Application_End on ID: " + id.ToString());
}
static int counter = 0;
int id = 0;
Hope this helps,
Scott
http://www.OdeToCode.com
Scott Allen wrote:
> Negative: Application_EndRequest fires as the last event in the
> pipeline before the request moves to the HttpHandler for the requested
> resource. This happens on every request. Furthermore, the
> HttpApplication instance is not destroyed, but is kept in a pool to
> service another request.
> Application_End, like Application_Start, is invoked only once, and
> only invoked on a single HttpApplication instance, the first instance
> in the pool. It will fire before the application domain unloads,
> although there is some evidence that this behavior is not 100.00%
> reliable.
Hmmm... thanks. The sdk documentation has some wrong links.
Anyway, the problem with Application_End is that the applicationstate
object is already destroyed, so I can't use it...
=/
Hi Scott!
Suddenly I had the brilliant idea of creating a destructor for my object
(duh... why didn't i thought about it before?), and applying a singleton
pattern for it, so there is only one instance of it and when it is
destroyed, no matter where he is, it serializes itself to the file. When
the application restarts it checks for the file and load the state again.
Thanks anyway!

Serializing an object from HttpApplicationState

Hi!

I have an object stored in the HttpApplicationState collection of my
site, but i would like to mantain the state of this object even if the
application restart, so in case of any problem or when I change
something in the web.config or add anything to the bin directory, i can
load the last values from somewhere and continue the work.

I'm using serialization to accomplish this, and it works ok. But i'm
serializing the object to a file in the "HttpApplication.EndRequest"
event. The problem is that with this event, it saves the file in the end
of every instance of HttpApplication, which occours almost every second.
I tested locally, and it saves the file everytime i access any page.

I know that the HttpApplicationState is shared among all the instances
of HttpApplication, and I would like to save the file only before
ApplicationState is destroyed, not the application...

There is no event in HttpApplicationState, so is there any way of doing
this?

Thanks in advance.Hi Natan:

One of the safest things you could do is re-save the file anytime the
value changes (if it is not changing too frequently). This would take
care of even catostrophic failures.

There is an Application_End method you can use in the code behind for
Global.asax. This method should fire whenever the application shuts
down or recycles.

--
Scott
http://www.OdeToCode.com

On Sun, 26 Sep 2004 19:06:03 -0300, Natan <nvivo@.mandic.com.br> wrote:

>Hi!
>I have an object stored in the HttpApplicationState collection of my
>site, but i would like to mantain the state of this object even if the
>application restart, so in case of any problem or when I change
>something in the web.config or add anything to the bin directory, i can
>load the last values from somewhere and continue the work.
>I'm using serialization to accomplish this, and it works ok. But i'm
>serializing the object to a file in the "HttpApplication.EndRequest"
>event. The problem is that with this event, it saves the file in the end
>of every instance of HttpApplication, which occours almost every second.
>I tested locally, and it saves the file everytime i access any page.
>I know that the HttpApplicationState is shared among all the instances
>of HttpApplication, and I would like to save the file only before
>ApplicationState is destroyed, not the application...
>There is no event in HttpApplicationState, so is there any way of doing
>this?
>
>Thanks in advance.
Scott Allen wrote:
> Hi Natan:
> One of the safest things you could do is re-save the file anytime the
> value changes (if it is not changing too frequently). This would take
> care of even catostrophic failures.

That's what i would like to avoid. File writes are too expensive, and
this would be like 3 or 4 per second. although the file size is aprox.
20k, it is still unnecessary.

> There is an Application_End method you can use in the code behind for
> Global.asax. This method should fire whenever the application shuts
> down or recycles.

Application_End is tied to the EndRequest actually, which is not the
Application in IIS itself, but HttpApplication instance. Many instances
are created and destroyed everytime by the server... take a look at the
documentation.

I really would like to save it only when necessary. Maybe i'll need to
implement it in another way...
Hi Natan:

>Application_End is tied to the EndRequest actually, which is not the
>Application in IIS itself, but HttpApplication instance. Many instances
>are created and destroyed everytime by the server... take a look at the
>documentation.

Negative: Application_EndRequest fires as the last event in the
pipeline before the request moves to the HttpHandler for the requested
resource. This happens on every request. Furthermore, the
HttpApplication instance is not destroyed, but is kept in a pool to
service another request.

Application_End, like Application_Start, is invoked only once, and
only invoked on a single HttpApplication instance, the first instance
in the pool. It will fire before the application domain unloads,
although there is some evidence that this behavior is not 100.00%
reliable.

I've been through the documentation many times, but even better I have
code that can demonstrate this behavior. You can watch the output
window of the debugger as you make requests to the web app with the
following code in global. Do an IISRESET to watch Application_End
fire.

public Global()
{
InitializeComponent();
id = System.Threading.Interlocked.Increment(ref counter);
}

protected void Application_Start(Object sender, EventArgs e)
{
Debug.WriteLine("Application_Start on ID: " + id.ToString());
}

protected void Application_EndRequest(Object sender, EventArgs e)
{
Debug.WriteLine("Application_EndRequest on ID: " + id.ToString());
}

protected void Application_End(Object sender, EventArgs e)
{
Debug.WriteLine("Application_End on ID: " + id.ToString());
}

static int counter = 0;
int id = 0;

Hope this helps,

--
Scott
http://www.OdeToCode.com
Scott Allen wrote:
> Negative: Application_EndRequest fires as the last event in the
> pipeline before the request moves to the HttpHandler for the requested
> resource. This happens on every request. Furthermore, the
> HttpApplication instance is not destroyed, but is kept in a pool to
> service another request.
> Application_End, like Application_Start, is invoked only once, and
> only invoked on a single HttpApplication instance, the first instance
> in the pool. It will fire before the application domain unloads,
> although there is some evidence that this behavior is not 100.00%
> reliable.

Hmmm... thanks. The sdk documentation has some wrong links.

Anyway, the problem with Application_End is that the applicationstate
object is already destroyed, so I can't use it...

=/
Hi Scott!

Suddenly I had the brilliant idea of creating a destructor for my object
(duh... why didn't i thought about it before?), and applying a singleton
pattern for it, so there is only one instance of it and when it is
destroyed, no matter where he is, it serializes itself to the file. When
the application restarts it checks for the file and load the state again.

Thanks anyway!

Serializing Collections with Interface members

I have a collection class and in order to make it type safe etc , I only add
and retrive members of Interface types.
But during XMLSerialization I get errors.
Is there any workaround ?
public class OrgRatingCollection:CollectionBase
{
public void Add(IRating item)
{
this.List.Add(item);
}
public IRating this[int index]
{
get
{
return (IRating) this.List[index];
}
set
{
this.List[index] = value;
}
}
}
}to serialize a collection, all object in the collection must be
serializable. defining a interface has no impact.
-- bruce (sqlwork.com)
"Akshay Kumar" <akshay349@.hotmail.com> wrote in message
news:OkVn0Q6wFHA.3720@.TK2MSFTNGP11.phx.gbl...
>I have a collection class and in order to make it type safe etc , I only
>add
> and retrive members of Interface types.
> But during XMLSerialization I get errors.
> Is there any workaround ?
>
> public class OrgRatingCollection:CollectionBase
> {
> public void Add(IRating item)
> {
> this.List.Add(item);
> }
>
> public IRating this[int index]
> {
> get
> {
>
> return (IRating) this.List[index];
> }
> set
> {
>
> this.List[index] = value;
> }
> }
> }
> }
>

Serializing Collections with Interface members

I have a collection class and in order to make it type safe etc , I only add
and retrive members of Interface types.

But during XMLSerialization I get errors.

Is there any workaround ?

public class OrgRatingCollection:CollectionBase

{

public void Add(IRating item)

{

this.List.Add(item);

}

public IRating this[int index]

{

get

{

return (IRating) this.List[index];

}

set

{

this.List[index] = value;

}

}

}

}to serialize a collection, all object in the collection must be
serializable. defining a interface has no impact.

-- bruce (sqlwork.com)

"Akshay Kumar" <akshay349@.hotmail.com> wrote in message
news:OkVn0Q6wFHA.3720@.TK2MSFTNGP11.phx.gbl...
>I have a collection class and in order to make it type safe etc , I only
>add
> and retrive members of Interface types.
> But during XMLSerialization I get errors.
> Is there any workaround ?
>
> public class OrgRatingCollection:CollectionBase
> {
> public void Add(IRating item)
> {
> this.List.Add(item);
> }
>
> public IRating this[int index]
> {
> get
> {
>
> return (IRating) this.List[index];
> }
> set
> {
>
> this.List[index] = value;
> }
> }
> }
> }