using the web interface it will not work, but if I do it using my interface
it works.
The XML that is returned from my subscription reports:
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ScheduleDefinition
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n <StartDateTime
xmlns=\"http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</StartDateTime>\n
<EndDate
xmlns=\"http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</EndDate>\n
<MinuteRecurrence
xmlns=\"http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">\n
<MinutesInterval>900</MinutesInterval>\n
</MinuteRecurrence>\n</ScheduleDefinition>"
The XML that is returned from a report scheduled using the web app:
"<ScheduleDefinition><StartDateTime>2005-03-25T05:30:00.000-05:00</StartDateTime><MinuteRecurrence><MinutesInterval>105</MinutesInterval></MinuteRecurrence></ScheduleDefinition>"
private wsReportingServices.ScheduleDefinition
DeSerializeSchedule(string XMLString)
{
MemoryStream vStream = GetStreamFromString(XMLString);
XmlAttributes attrs=new XmlAttributes();
attrs.XmlElements.Add(new
XmlElementAttribute("MinuteRecurrence",typeof(wsReportingServices.MinuteRecurrence)));
attrs.XmlElements.Add(new
XmlElementAttribute("DailyRecurrence",typeof(wsReportingServices.DailyRecurrence)));
attrs.XmlElements.Add(new
XmlElementAttribute("WeeklyRecurrence",typeof(wsReportingServices.WeeklyRecurrence)));
attrs.XmlElements.Add(new
XmlElementAttribute("MonthlyRecurrence",typeof(wsReportingServices.MonthlyRecurrence)));
attrs.XmlElements.Add(new
XmlElementAttribute("MonthlyDOWRecurrence",typeof(wsReportingServices.MonthlyDOWRecurrence)));
XmlAttributeOverrides attrOver=new XmlAttributeOverrides();
attrOver.Add(typeof(wsReportingServices.ScheduleDefinition),"ScheduleDefinition",attrs);
XmlSerializer newSr=new
XmlSerializer(typeof(wsReportingServices.ScheduleDefinition),attrOver);
return
(wsReportingServices.ScheduleDefinition)newSr.Deserialize(vStream);
}Here is the code that works:
static public ScheduleDefinition GetScheduleDefinition(string
matchData)
{
ScheduleDefinition res = null;
if (!crgUtl.IsEmpty(matchData))
{
string endDateStart = "<EndDate>";
string endDateEnd = "</EndDate>";
string scheduleString = matchData;
string endDateString = string.Empty;
// 1. Find <EndDate> tag and parse it separately,
because it is not serialized correctly by Microsoft.
int posStart = matchData.IndexOf(endDateStart);
int posEnd = matchData.IndexOf(endDateEnd);
if (posStart != -1 && posEnd != -1)
{
endDateString = scheduleString.Substring(
posStart + endDateStart.Length,
posEnd - posStart - endDateStart.Length);
scheduleString =
scheduleString.Substring(0, posStart)
+ scheduleString.Substring(
posEnd + endDateEnd.Length,
scheduleString.Length - posEnd -
endDateEnd.Length);
}
// 2. Replace True/False on true/false.
scheduleString = scheduleString.Replace(">True</",
">true</");
scheduleString = scheduleString.Replace(">False</",
">false</");
// 2.1 Replace occurrences of which week item on
serialized correct value:
for (int i = 0; i < WHICH_WEEK_ENUM.Length; i++)
scheduleString =scheduleString.Replace(WHICH_WEEK_STRINGS[i], WHICH_WEEK_ENUM[i]);
// 3. Deserialize ScheduleDefinition.
Stream stream = null;
XmlReader xmlReader = null;
try
{
// set overrides options to pass namespace tag
during deserialization:
XmlAttributeOverrides overrides =GetScheduleOverrides();
stream = new
MemoryStream(System.Text.Encoding.Default.GetBytes(scheduleString));
xmlReader = new XmlTextReader(stream);
XmlSerializer ser = new
XmlSerializer(typeof(ScheduleDefinition), overrides);
res =(ScheduleDefinition)ser.Deserialize(xmlReader);
}
finally
{
if (xmlReader != null) xmlReader.Close();
if (stream != null) stream.Close();
}
if (res == null)
res = new ScheduleDefinition();
// 4. Parse EndDate.
DateTime endDate = DateTime.Today;
if (!crgUtl.IsEmpty(endDateString))
{
IFormatProvider culture = new
CultureInfo("en-US", true);
endDate = DateTime.Parse(endDateString,
culture);
res.EndDate = endDate;
res.EndDateSpecified = true;
}
else
{
res.EndDateSpecified = false;
}
}
if (res == null)
{
res = new ScheduleDefinition();
res.StartDateTime = DateTime.Today;
res.EndDateSpecified = false;
}
return res;
}
static private string [] WHICH_WEEK_STRINGS = new string [] {
"FIRST_WEEK",
"SECOND_WEEK",
"THIRD_WEEK",
"FOURTH_WEEK",
"LAST_WEEK"
};
static private string [] WHICH_WEEK_ENUM = new string [] {
WeekNumberEnum.FirstWeek.ToString(),
WeekNumberEnum.SecondWeek.ToString(),
WeekNumberEnum.ThirdWeek.ToString(),
WeekNumberEnum.FourthWeek.ToString(),
WeekNumberEnum.LastWeek.ToString()};
Dmitry Nechipor.
"SouthFLBoiler@.discussions.microsoft.com"
<SouthFLBoilerdiscussionsmicrosoftcom@.discussions.microsoft.com> wrote in
message news:83278D35-A056-4E12-91AF-67FA443CE248@.microsoft.com...
>I got deserializing to work, but the problem is; If I create the schedule
> using the web interface it will not work, but if I do it using my
> interface
> it works.
>
> The XML that is returned from my subscription reports:
>
> "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ScheduleDefinition
> xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
> xmlns:xsi=\"/n">http://www.w3.org/2001/XMLSchema-instance\">\n <StartDateTime
> xmlns=\"2005-03-25T13:24:26.4506144-05:00</StartDateTime>/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</StartDateTime>\n
> <EndDate
> xmlns=\"2005-03-25T13:24:26.4506144-05:00</EndDate>/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</EndDate>\n
> <MinuteRecurrence
> xmlns=\"/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">\n
> <MinutesInterval>900</MinutesInterval>\n
> </MinuteRecurrence>\n</ScheduleDefinition>"
>
> The XML that is returned from a report scheduled using the web app:
>
> "<ScheduleDefinition><StartDateTime>2005-03-25T05:30:00.000-05:00</StartDateTime><MinuteRecurrence><MinutesInterval>105</MinutesInterval></MinuteRecurrence></ScheduleDefinition>"
>
>
> private wsReportingServices.ScheduleDefinition
> DeSerializeSchedule(string XMLString)
> {
>
> MemoryStream vStream = GetStreamFromString(XMLString);
>
> XmlAttributes attrs=new XmlAttributes();
>
> attrs.XmlElements.Add(new
> XmlElementAttribute("MinuteRecurrence",typeof(wsReportingServices.MinuteRecurrence)));
> attrs.XmlElements.Add(new
> XmlElementAttribute("DailyRecurrence",typeof(wsReportingServices.DailyRecurrence)));
> attrs.XmlElements.Add(new
> XmlElementAttribute("WeeklyRecurrence",typeof(wsReportingServices.WeeklyRecurrence)));
> attrs.XmlElements.Add(new
> XmlElementAttribute("MonthlyRecurrence",typeof(wsReportingServices.MonthlyRecurrence)));
> attrs.XmlElements.Add(new
> XmlElementAttribute("MonthlyDOWRecurrence",typeof(wsReportingServices.MonthlyDOWRecurrence)));
>
> XmlAttributeOverrides attrOver=new
> XmlAttributeOverrides();
>
> attrOver.Add(typeof(wsReportingServices.ScheduleDefinition),"ScheduleDefinition",attrs);
>
> XmlSerializer newSr=new
> XmlSerializer(typeof(wsReportingServices.ScheduleDefinition),attrOver);
>
> return
> (wsReportingServices.ScheduleDefinition)newSr.Deserialize(vStream);
> }
>|||I tried the code, and it didnt seem to work.
You left out a couple of things though:
crgUtl. ' I repaced this to check if string was empty.
You also left out the code for GetScheduleOverrides();
I tried the following.. but didnt work: My item object was still null, and
the dates where 1/1/0001
private XmlAttributeOverrides GetScheduleOverrides()
{
XmlAttributes vXMLAtributes=new XmlAttributes();
vXMLAtributes.XmlElements.Add(new
XmlElementAttribute("MinuteRecurrence",typeof(MinuteRecurrence)));
vXMLAtributes.XmlElements.Add(new
XmlElementAttribute("DailyRecurrence",typeof(DailyRecurrence)));
vXMLAtributes.XmlElements.Add(new
XmlElementAttribute("WeeklyRecurrence",typeof(WeeklyRecurrence)));
vXMLAtributes.XmlElements.Add(new
XmlElementAttribute("MonthlyRecurrence",typeof(MonthlyRecurrence)));
vXMLAtributes.XmlElements.Add(new
XmlElementAttribute("MonthlyDOWRecurrence",typeof(MonthlyDOWRecurrence)));
vXMLAtributes.XmlElements.Add(new
XmlElementAttribute("RecurrencePattern",typeof(RecurrencePattern)));
XmlAttributeOverrides vAttrOverrides=new XmlAttributeOverrides();
vAttrOverrides.Add(typeof(ScheduleDefinition),"Item",vXMLAtributes);
return vAttrOverrides;
}
"msnews.microsoft.com" wrote:
> Here is the code that works:
>
> static public ScheduleDefinition GetScheduleDefinition(string
> matchData)
> {
> ScheduleDefinition res = null;
>
> if (!crgUtl.IsEmpty(matchData))
> {
> string endDateStart = "<EndDate>";
> string endDateEnd = "</EndDate>";
> string scheduleString = matchData;
> string endDateString = string.Empty;
> // 1. Find <EndDate> tag and parse it separately,
> because it is not serialized correctly by Microsoft.
> int posStart = matchData.IndexOf(endDateStart);
> int posEnd = matchData.IndexOf(endDateEnd);
> if (posStart != -1 && posEnd != -1)
> {
> endDateString = scheduleString.Substring(
> posStart + endDateStart.Length,
> posEnd - posStart - endDateStart.Length);
>
> scheduleString => scheduleString.Substring(0, posStart)
> + scheduleString.Substring(
> posEnd + endDateEnd.Length,
> scheduleString.Length - posEnd -
> endDateEnd.Length);
> }
>
> // 2. Replace True/False on true/false.
> scheduleString = scheduleString.Replace(">True</",
> ">true</");
> scheduleString = scheduleString.Replace(">False</",
> ">false</");
>
> // 2.1 Replace occurrences of which week item on
> serialized correct value:
> for (int i = 0; i < WHICH_WEEK_ENUM.Length; i++)
> scheduleString => scheduleString.Replace(WHICH_WEEK_STRINGS[i], WHICH_WEEK_ENUM[i]);
>
> // 3. Deserialize ScheduleDefinition.
> Stream stream = null;
> XmlReader xmlReader = null;
> try
> {
> // set overrides options to pass namespace tag
> during deserialization:
> XmlAttributeOverrides overrides => GetScheduleOverrides();
>
> stream = new
> MemoryStream(System.Text.Encoding.Default.GetBytes(scheduleString));
> xmlReader = new XmlTextReader(stream);
>
> XmlSerializer ser = new
> XmlSerializer(typeof(ScheduleDefinition), overrides);
> res => (ScheduleDefinition)ser.Deserialize(xmlReader);
> }
> finally
> {
> if (xmlReader != null) xmlReader.Close();
> if (stream != null) stream.Close();
> }
> if (res == null)
> res = new ScheduleDefinition();
>
> // 4. Parse EndDate.
> DateTime endDate = DateTime.Today;
> if (!crgUtl.IsEmpty(endDateString))
> {
> IFormatProvider culture = new
> CultureInfo("en-US", true);
> endDate = DateTime.Parse(endDateString,
> culture);
>
> res.EndDate = endDate;
> res.EndDateSpecified = true;
> }
> else
> {
> res.EndDateSpecified = false;
> }
> }
>
> if (res == null)
> {
> res = new ScheduleDefinition();
> res.StartDateTime = DateTime.Today;
> res.EndDateSpecified = false;
> }
>
> return res;
> }
>
> static private string [] WHICH_WEEK_STRINGS = new string [] {
> "FIRST_WEEK",
> "SECOND_WEEK",
> "THIRD_WEEK",
> "FOURTH_WEEK",
> "LAST_WEEK"
> };
> static private string [] WHICH_WEEK_ENUM = new string [] {
> WeekNumberEnum.FirstWeek.ToString(),
> WeekNumberEnum.SecondWeek.ToString(),
> WeekNumberEnum.ThirdWeek.ToString(),
> WeekNumberEnum.FourthWeek.ToString(),
> WeekNumberEnum.LastWeek.ToString()};
>
>
> Dmitry Nechipor.
> "SouthFLBoiler@.discussions.microsoft.com"
> <SouthFLBoilerdiscussionsmicrosoftcom@.discussions.microsoft.com> wrote in
> message news:83278D35-A056-4E12-91AF-67FA443CE248@.microsoft.com...
> >I got deserializing to work, but the problem is; If I create the schedule
> > using the web interface it will not work, but if I do it using my
> > interface
> > it works.
> >
> >
> > The XML that is returned from my subscription reports:
> >
> >
> >
> > "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ScheduleDefinition
> > xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
> > xmlns:xsi=\"/n">http://www.w3.org/2001/XMLSchema-instance\">\n <StartDateTime
> > xmlns=\"2005-03-25T13:24:26.4506144-05:00</StartDateTime>/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</StartDateTime>\n
> > <EndDate
> > xmlns=\"2005-03-25T13:24:26.4506144-05:00</EndDate>/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</EndDate>\n
> > <MinuteRecurrence
> > xmlns=\"/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">\n
> > <MinutesInterval>900</MinutesInterval>\n
> > </MinuteRecurrence>\n</ScheduleDefinition>"
> >
> >
> >
> > The XML that is returned from a report scheduled using the web app:
> >
> >
> >
> > "<ScheduleDefinition><StartDateTime>2005-03-25T05:30:00.000-05:00</StartDateTime><MinuteRecurrence><MinutesInterval>105</MinutesInterval></MinuteRecurrence></ScheduleDefinition>"
> >
> >
> >
> >
> >
> > private wsReportingServices.ScheduleDefinition
> > DeSerializeSchedule(string XMLString)
> >
> > {
> >
> >
> >
> > MemoryStream vStream = GetStreamFromString(XMLString);
> >
> >
> >
> > XmlAttributes attrs=new XmlAttributes();
> >
> >
> >
> > attrs.XmlElements.Add(new
> > XmlElementAttribute("MinuteRecurrence",typeof(wsReportingServices.MinuteRecurrence)));
> >
> > attrs.XmlElements.Add(new
> > XmlElementAttribute("DailyRecurrence",typeof(wsReportingServices.DailyRecurrence)));
> >
> > attrs.XmlElements.Add(new
> > XmlElementAttribute("WeeklyRecurrence",typeof(wsReportingServices.WeeklyRecurrence)));
> >
> > attrs.XmlElements.Add(new
> > XmlElementAttribute("MonthlyRecurrence",typeof(wsReportingServices.MonthlyRecurrence)));
> >
> > attrs.XmlElements.Add(new
> > XmlElementAttribute("MonthlyDOWRecurrence",typeof(wsReportingServices.MonthlyDOWRecurrence)));
> >
> >
> >
> > XmlAttributeOverrides attrOver=new
> > XmlAttributeOverrides();
> >
> >
> > attrOver.Add(typeof(wsReportingServices.ScheduleDefinition),"ScheduleDefinition",attrs);
> >
> >
> > XmlSerializer newSr=new
> > XmlSerializer(typeof(wsReportingServices.ScheduleDefinition),attrOver);
> >
> >
> >
> > return
> > (wsReportingServices.ScheduleDefinition)newSr.Deserialize(vStream);
> >
> > }
> >
>
>|||This is a multi-part message in MIME format.
--=_NextPart_000_0007_01C532E3.673356F0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable
1. static private XmlAttributeOverrides GetScheduleOverrides()
{
XmlAttributeOverrides overrides =3D new XmlAttributeOverrides();
XmlAttributes attrs =3D new XmlAttributes();
attrs.Xmlns =3D false;
overrides.Add(typeof(ScheduleDefinition), attrs);
overrides.Add(typeof(MinuteRecurrence), attrs);
overrides.Add(typeof(WeeklyRecurrence), attrs);
overrides.Add(typeof(MonthlyRecurrence), attrs);
overrides.Add(typeof(MonthlyDOWRecurrence), attrs);
overrides.Add(typeof(DaysOfWeekSelector), attrs);
overrides.Add(typeof(MonthsOfYearSelector), attrs);
return overrides;
}
2. static public bool IsEmpty(string s)
{
return (s =3D=3D null || s =3D=3D String.Empty);
}
I hope it will help you. I checked it with you string. It deserializes =correctly.
"SouthFLBoiler@.discussions.microsoft.com" =<SouthFLBoilerdiscussionsmicrosoftcom@.discussions.microsoft.com> wrote =in message news:8F51D612-BC59-4547-A4EC-6D6A39BDE532@.microsoft.com...
>I tried the code, and it didnt seem to work.
> > You left out a couple of things though:
> crgUtl. ' I repaced this to check if string was empty.
> > You also left out the code for GetScheduleOverrides();
> > I tried the following.. but didnt work: My item object was still null, =and > the dates where 1/1/0001
> > private XmlAttributeOverrides GetScheduleOverrides()
> {
> XmlAttributes vXMLAtributes=3Dnew XmlAttributes();
> vXMLAtributes.XmlElements.Add(new > XmlElementAttribute("MinuteRecurrence",typeof(MinuteRecurrence)));
> vXMLAtributes.XmlElements.Add(new > XmlElementAttribute("DailyRecurrence",typeof(DailyRecurrence)));
> vXMLAtributes.XmlElements.Add(new > XmlElementAttribute("WeeklyRecurrence",typeof(WeeklyRecurrence)));
> vXMLAtributes.XmlElements.Add(new > XmlElementAttribute("MonthlyRecurrence",typeof(MonthlyRecurrence)));
> vXMLAtributes.XmlElements.Add(new > =XmlElementAttribute("MonthlyDOWRecurrence",typeof(MonthlyDOWRecurrence)))=;
> vXMLAtributes.XmlElements.Add(new > XmlElementAttribute("RecurrencePattern",typeof(RecurrencePattern)));
> > XmlAttributeOverrides vAttrOverrides=3Dnew XmlAttributeOverrides();
> vAttrOverrides.Add(typeof(ScheduleDefinition),"Item",vXMLAtributes);
> return vAttrOverrides;
> }
> > "msnews.microsoft.com" wrote:
> >> Here is the code that works:
>> >> >> >> static public ScheduleDefinition =GetScheduleDefinition(string >> matchData)
>> >> {
>> >> ScheduleDefinition res =3D null;
>> >> >> >> if (!crgUtl.IsEmpty(matchData))
>> >> {
>> >> string endDateStart =3D "<EndDate>";
>> >> string endDateEnd =3D "</EndDate>";
>> >> string scheduleString =3D matchData;
>> >> string endDateString =3D string.Empty;
>> >> // 1. Find <EndDate> tag and parse it =separately, >> because it is not serialized correctly by Microsoft.
>> >> int posStart =3D =matchData.IndexOf(endDateStart);
>> >> int posEnd =3D matchData.IndexOf(endDateEnd);
>> >> if (posStart !=3D -1 && posEnd !=3D -1)
>> >> {
>> >> endDateString =3D =scheduleString.Substring(
>> >> posStart + endDateStart.Length,
>> >> posEnd - posStart - =endDateStart.Length);
>> >> >> >> scheduleString =3D
>> >> scheduleString.Substring(0, =posStart)
>> >> + scheduleString.Substring(
>> >> posEnd + endDateEnd.Length,
>> >> scheduleString.Length - posEnd - >> endDateEnd.Length);
>> >> }
>> >> >> >> // 2. Replace True/False on true/false.
>> >> scheduleString =3D =scheduleString.Replace(">True</", >> ">true</");
>> >> scheduleString =3D =scheduleString.Replace(">False</", >> ">false</");
>> >> >> >> // 2.1 Replace occurrences of which week item =on >> serialized correct value:
>> >> for (int i =3D 0; i < WHICH_WEEK_ENUM.Length; =i++)
>> >> scheduleString =3D >> scheduleString.Replace(WHICH_WEEK_STRINGS[i], WHICH_WEEK_ENUM[i]);
>> >> >> >> // 3. Deserialize ScheduleDefinition.
>> >> Stream stream =3D null;
>> >> XmlReader xmlReader =3D null;
>> >> try
>> >> {
>> >> // set overrides options to pass =namespace tag >> during deserialization:
>> >> XmlAttributeOverrides overrides =3D >> GetScheduleOverrides();
>> >> >> >> stream =3D new >> MemoryStream(System.Text.Encoding.Default.GetBytes(scheduleString));
>> >> xmlReader =3D new XmlTextReader(stream);
>> >> >> >> XmlSerializer ser =3D new >> XmlSerializer(typeof(ScheduleDefinition), overrides);
>> >> res =3D >> (ScheduleDefinition)ser.Deserialize(xmlReader);
>> >> }
>> >> finally
>> >> {
>> >> if (xmlReader !=3D null) =xmlReader.Close();
>> >> if (stream !=3D null) stream.Close();
>> >> }
>> >> if (res =3D=3D null)
>> >> res =3D new ScheduleDefinition();
>> >> >> >> // 4. Parse EndDate.
>> >> DateTime endDate =3D DateTime.Today;
>> >> if (!crgUtl.IsEmpty(endDateString))
>> >> {
>> >> IFormatProvider culture =3D new >> CultureInfo("en-US", true);
>> >> endDate =3D =DateTime.Parse(endDateString, >> culture);
>> >> >> >> res.EndDate =3D endDate;
>> >> res.EndDateSpecified =3D true;
>> >> }
>> >> else
>> >> {
>> >> res.EndDateSpecified =3D false;
>> >> }
>> >> }
>> >> >> >> if (res =3D=3D null)
>> >> {
>> >> res =3D new ScheduleDefinition();
>> >> res.StartDateTime =3D DateTime.Today;
>> >> res.EndDateSpecified =3D false;
>> >> }
>> >> >> >> return res;
>> >> }
>> >> >> >> static private string [] WHICH_WEEK_STRINGS =3D new =string [] {
>> >> "FIRST_WEEK",
>> >> "SECOND_WEEK",
>> >> "THIRD_WEEK",
>> >> "FOURTH_WEEK",
>> >> "LAST_WEEK"
>> >> };
>> >> static private string [] WHICH_WEEK_ENUM =3D new string =[] {
>> >> WeekNumberEnum.FirstWeek.ToString(),
>> >> WeekNumberEnum.SecondWeek.ToString(),
>> >> WeekNumberEnum.ThirdWeek.ToString(),
>> >> WeekNumberEnum.FourthWeek.ToString(),
>> >> WeekNumberEnum.LastWeek.ToString()};
>> >> >> >> >> Dmitry Nechipor.
>> >> "SouthFLBoiler@.discussions.microsoft.com" >> <SouthFLBoilerdiscussionsmicrosoftcom@.discussions.microsoft.com> =wrote in >> message news:83278D35-A056-4E12-91AF-67FA443CE248@.microsoft.com...
>> >I got deserializing to work, but the problem is; If I create the =schedule
>> > using the web interface it will not work, but if I do it using my >> > interface
>> > it works.
>> >
>> >
>> > The XML that is returned from my subscription reports:
>> >
>> >
>> >
>> > "<?xml version=3D\"1.0\" =encoding=3D\"utf-8\"?>\n<ScheduleDefinition
>> > xmlns:xsd=3D\"http://www.w3.org/2001/XMLSchema\"
>> > xmlns:xsi=3D\"/n">http://www.w3.org/2001/XMLSchema-instance\">\n =<StartDateTime
>> > =xmlns=3D\"http://schemas.microsoft.com/sqlserver/2003/12/reporting/report=
ingservices\">2005-03-25T13:24:26.4506144-05:00</StartDateTime>\n
>> > <EndDate
>> > =xmlns=3D\"http://schemas.microsoft.com/sqlserver/2003/12/reporting/report=
ingservices\">2005-03-25T13:24:26.4506144-05:00</EndDate>\n
>> > <MinuteRecurrence
>> > =xmlns=3D\"http://schemas.microsoft.com/sqlserver/2003/12/reporting/report=
ingservices\">\n
>> > <MinutesInterval>900</MinutesInterval>\n
>> > </MinuteRecurrence>\n</ScheduleDefinition>"
>> >
>> >
>> >
>> > The XML that is returned from a report scheduled using the web app:
>> >
>> >
>> >
>> > ="<ScheduleDefinition><StartDateTime>2005-03-25T05:30:00.000-05:00</StartD=ateTime><MinuteRecurrence><MinutesInterval>105</MinutesInterval></MinuteR=ecurrence></ScheduleDefinition>"
>> >
>> >
>> >
>> >
>> >
>> > private wsReportingServices.ScheduleDefinition
>> > DeSerializeSchedule(string XMLString)
>> >
>> > {
>> >
>> >
>> >
>> > MemoryStream vStream =3D =GetStreamFromString(XMLString);
>> >
>> >
>> >
>> > XmlAttributes attrs=3Dnew XmlAttributes();
>> >
>> >
>> >
>> > attrs.XmlElements.Add(new
>> > =XmlElementAttribute("MinuteRecurrence",typeof(wsReportingServices.MinuteR=ecurrence)));
>> >
>> > attrs.XmlElements.Add(new
>> > =XmlElementAttribute("DailyRecurrence",typeof(wsReportingServices.DailyRec=urrence)));
>> >
>> > attrs.XmlElements.Add(new
>> > =XmlElementAttribute("WeeklyRecurrence",typeof(wsReportingServices.WeeklyR=ecurrence)));
>> >
>> > attrs.XmlElements.Add(new
>> > =XmlElementAttribute("MonthlyRecurrence",typeof(wsReportingServices.Monthl=yRecurrence)));
>> >
>> > attrs.XmlElements.Add(new
>> > =XmlElementAttribute("MonthlyDOWRecurrence",typeof(wsReportingServices.Mon=thlyDOWRecurrence)));
>> >
>> >
>> >
>> > XmlAttributeOverrides attrOver=3Dnew >> > XmlAttributeOverrides();
>> >
>> >
>> > =attrOver.Add(typeof(wsReportingServices.ScheduleDefinition),"ScheduleDefi=nition",attrs);
>> >
>> >
>> > XmlSerializer newSr=3Dnew
>> > =XmlSerializer(typeof(wsReportingServices.ScheduleDefinition),attrOver);
>> >
>> >
>> >
>> > return
>> > (wsReportingServices.ScheduleDefinition)newSr.Deserialize(vStream);
>> >
>> > }
>> > >> >> --=_NextPart_000_0007_01C532E3.673356F0
Content-Type: text/html;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable
=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&
1.
static =private =XmlAttributeOverrides GetScheduleOverrides()
{
XmlAttributeOverrides overrides =3D new XmlAttributeOverrides();
XmlAttributes attrs =3D new XmlAttributes();
attrs.Xmlns =3D false;
overrides.Add(typeof(ScheduleDefinition), attrs);
overrides.Add(typeof(MinuteRecurrence), attrs);
overrides.Add(typeof(WeeklyRecurrence), attrs);
overrides.Add(typeof(MonthlyRecurrence), attrs);
overrides.Add(typeof(MonthlyDOWRecurrence), attrs);
overrides.Add(typeof(DaysOfWeekSelector), attrs);
overrides.Add(typeof(MonthsOfYearSelector), attrs);
return overrides;
}
2.
static public bool =IsEmpty(string s)
{
return (s =3D=3D null || s =3D=3D String.Empty);
}
I hope it will help you. I checked it with you =string. It deserializes correctly.
"SouthFLBoiler@.discussions.microsoft.com"
--=_NextPart_000_0007_01C532E3.673356F0--|||Ok.. that worked on the Schedules made by the web app, but it errors on the
schedules I make with my serialization.
So im check to see if the xml starts with <?xml .. if so, I use my original
deserializion, im not, I use the one you posted
Thanks
"Dmitry Nechipor. [MCDBA]" wrote:
> 1.
> static private XmlAttributeOverrides GetScheduleOverrides()
> {
> XmlAttributeOverrides overrides = new XmlAttributeOverrides();
> XmlAttributes attrs = new XmlAttributes();
> attrs.Xmlns = false;
> overrides.Add(typeof(ScheduleDefinition), attrs);
> overrides.Add(typeof(MinuteRecurrence), attrs);
> overrides.Add(typeof(WeeklyRecurrence), attrs);
> overrides.Add(typeof(MonthlyRecurrence), attrs);
> overrides.Add(typeof(MonthlyDOWRecurrence), attrs);
> overrides.Add(typeof(DaysOfWeekSelector), attrs);
> overrides.Add(typeof(MonthsOfYearSelector), attrs);
> return overrides;
> }
> 2.
> static public bool IsEmpty(string s)
> {
> return (s == null || s == String.Empty);
> }
> I hope it will help you. I checked it with you string. It deserializes correctly.
> "SouthFLBoiler@.discussions.microsoft.com" <SouthFLBoilerdiscussionsmicrosoftcom@.discussions.microsoft.com> wrote in message news:8F51D612-BC59-4547-A4EC-6D6A39BDE532@.microsoft.com...
> >I tried the code, and it didnt seem to work.
> >
> > You left out a couple of things though:
> > crgUtl. ' I repaced this to check if string was empty.
> >
> > You also left out the code for GetScheduleOverrides();
> >
> > I tried the following.. but didnt work: My item object was still null, and
> > the dates where 1/1/0001
> >
> > private XmlAttributeOverrides GetScheduleOverrides()
> > {
> > XmlAttributes vXMLAtributes=new XmlAttributes();
> > vXMLAtributes.XmlElements.Add(new
> > XmlElementAttribute("MinuteRecurrence",typeof(MinuteRecurrence)));
> > vXMLAtributes.XmlElements.Add(new
> > XmlElementAttribute("DailyRecurrence",typeof(DailyRecurrence)));
> > vXMLAtributes.XmlElements.Add(new
> > XmlElementAttribute("WeeklyRecurrence",typeof(WeeklyRecurrence)));
> > vXMLAtributes.XmlElements.Add(new
> > XmlElementAttribute("MonthlyRecurrence",typeof(MonthlyRecurrence)));
> > vXMLAtributes.XmlElements.Add(new
> > XmlElementAttribute("MonthlyDOWRecurrence",typeof(MonthlyDOWRecurrence)));
> > vXMLAtributes.XmlElements.Add(new
> > XmlElementAttribute("RecurrencePattern",typeof(RecurrencePattern)));
> >
> > XmlAttributeOverrides vAttrOverrides=new XmlAttributeOverrides();
> > vAttrOverrides.Add(typeof(ScheduleDefinition),"Item",vXMLAtributes);
> > return vAttrOverrides;
> > }
> >
> > "msnews.microsoft.com" wrote:
> >
> >> Here is the code that works:
> >>
> >>
> >>
> >> static public ScheduleDefinition GetScheduleDefinition(string
> >> matchData)
> >>
> >> {
> >>
> >> ScheduleDefinition res = null;
> >>
> >>
> >>
> >> if (!crgUtl.IsEmpty(matchData))
> >>
> >> {
> >>
> >> string endDateStart = "<EndDate>";
> >>
> >> string endDateEnd = "</EndDate>";
> >>
> >> string scheduleString = matchData;
> >>
> >> string endDateString = string.Empty;
> >>
> >> // 1. Find <EndDate> tag and parse it separately,
> >> because it is not serialized correctly by Microsoft.
> >>
> >> int posStart = matchData.IndexOf(endDateStart);
> >>
> >> int posEnd = matchData.IndexOf(endDateEnd);
> >>
> >> if (posStart != -1 && posEnd != -1)
> >>
> >> {
> >>
> >> endDateString = scheduleString.Substring(
> >>
> >> posStart + endDateStart.Length,
> >>
> >> posEnd - posStart - endDateStart.Length);
> >>
> >>
> >>
> >> scheduleString => >>
> >> scheduleString.Substring(0, posStart)
> >>
> >> + scheduleString.Substring(
> >>
> >> posEnd + endDateEnd.Length,
> >>
> >> scheduleString.Length - posEnd -
> >> endDateEnd.Length);
> >>
> >> }
> >>
> >>
> >>
> >> // 2. Replace True/False on true/false.
> >>
> >> scheduleString = scheduleString.Replace(">True</",
> >> ">true</");
> >>
> >> scheduleString = scheduleString.Replace(">False</",
> >> ">false</");
> >>
> >>
> >>
> >> // 2.1 Replace occurrences of which week item on
> >> serialized correct value:
> >>
> >> for (int i = 0; i < WHICH_WEEK_ENUM.Length; i++)
> >>
> >> scheduleString => >> scheduleString.Replace(WHICH_WEEK_STRINGS[i], WHICH_WEEK_ENUM[i]);
> >>
> >>
> >>
> >> // 3. Deserialize ScheduleDefinition.
> >>
> >> Stream stream = null;
> >>
> >> XmlReader xmlReader = null;
> >>
> >> try
> >>
> >> {
> >>
> >> // set overrides options to pass namespace tag
> >> during deserialization:
> >>
> >> XmlAttributeOverrides overrides => >> GetScheduleOverrides();
> >>
> >>
> >>
> >> stream = new
> >> MemoryStream(System.Text.Encoding.Default.GetBytes(scheduleString));
> >>
> >> xmlReader = new XmlTextReader(stream);
> >>
> >>
> >>
> >> XmlSerializer ser = new
> >> XmlSerializer(typeof(ScheduleDefinition), overrides);
> >>
> >> res => >> (ScheduleDefinition)ser.Deserialize(xmlReader);
> >>
> >> }
> >>
> >> finally
> >>
> >> {
> >>
> >> if (xmlReader != null) xmlReader.Close();
> >>
> >> if (stream != null) stream.Close();
> >>
> >> }
> >>
> >> if (res == null)
> >>
> >> res = new ScheduleDefinition();
> >>
> >>
> >>
> >> // 4. Parse EndDate.
> >>
> >> DateTime endDate = DateTime.Today;
> >>
> >> if (!crgUtl.IsEmpty(endDateString))
> >>
> >> {
> >>
> >> IFormatProvider culture = new
> >> CultureInfo("en-US", true);
> >>
> >> endDate = DateTime.Parse(endDateString,
> >> culture);
> >>
> >>
> >>
> >> res.EndDate = endDate;
> >>
> >> res.EndDateSpecified = true;
> >>
> >> }
> >>
> >> else
> >>
> >> {
> >>
> >> res.EndDateSpecified = false;
> >>
> >> }
> >>
> >> }
> >>
> >>
> >>
> >> if (res == null)
> >>
> >> {
> >>
> >> res = new ScheduleDefinition();
> >>
> >> res.StartDateTime = DateTime.Today;
> >>
> >> res.EndDateSpecified = false;
> >>
> >> }
> >>
> >>
> >>
> >> return res;
> >>
> >> }
> >>
> >>
> >>
> >> static private string [] WHICH_WEEK_STRINGS = new string [] {
> >>
> >> "FIRST_WEEK",
> >>
> >> "SECOND_WEEK",
> >>
> >> "THIRD_WEEK",
> >>
> >> "FOURTH_WEEK",
> >>
> >> "LAST_WEEK"
> >>
> >> };
> >>
> >> static private string [] WHICH_WEEK_ENUM = new string [] {
> >>
> >> WeekNumberEnum.FirstWeek.ToString(),
> >>
> >> WeekNumberEnum.SecondWeek.ToString(),
> >>
> >> WeekNumberEnum.ThirdWeek.ToString(),
> >>
> >> WeekNumberEnum.FourthWeek.ToString(),
> >>
> >> WeekNumberEnum.LastWeek.ToString()};
> >>
> >>
> >>
> >>
> >> Dmitry Nechipor.
> >>
> >> "SouthFLBoiler@.discussions.microsoft.com"
> >> <SouthFLBoilerdiscussionsmicrosoftcom@.discussions.microsoft.com> wrote in
> >> message news:83278D35-A056-4E12-91AF-67FA443CE248@.microsoft.com...
> >> >I got deserializing to work, but the problem is; If I create the schedule
> >> > using the web interface it will not work, but if I do it using my
> >> > interface
> >> > it works.
> >> >
> >> >
> >> > The XML that is returned from my subscription reports:
> >> >
> >> >
> >> >
> >> > "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ScheduleDefinition
> >> > xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
> >> > xmlns:xsi=\"/n">http://www.w3.org/2001/XMLSchema-instance\">\n <StartDateTime
> >> > xmlns=\"2005-03-25T13:24:26.4506144-05:00</StartDateTime>/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</StartDateTime>\n
> >> > <EndDate
> >> > xmlns=\"2005-03-25T13:24:26.4506144-05:00</EndDate>/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</EndDate>\n
> >> > <MinuteRecurrence
> >> > xmlns=\"/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">\n
> >> > <MinutesInterval>900</MinutesInterval>\n
> >> > </MinuteRecurrence>\n</ScheduleDefinition>"
> >> >
> >> >
> >> >
> >> > The XML that is returned from a report scheduled using the web app:
> >> >
> >> >
> >> >
> >> > "<ScheduleDefinition><StartDateTime>2005-03-25T05:30:00.000-05:00</StartDateTime><MinuteRecurrence><MinutesInterval>105</MinutesInterval></MinuteRecurrence></ScheduleDefinition>"
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > private wsReportingServices.ScheduleDefinition
> >> > DeSerializeSchedule(string XMLString)
> >> >
> >> > {
> >> >
> >> >
> >> >
> >> > MemoryStream vStream = GetStreamFromString(XMLString);
> >> >
> >> >
> >> >
> >> > XmlAttributes attrs=new XmlAttributes();
> >> >
> >> >
> >> >
> >> > attrs.XmlElements.Add(new
> >> > XmlElementAttribute("MinuteRecurrence",typeof(wsReportingServices.MinuteRecurrence)));
> >> >
> >> > attrs.XmlElements.Add(new
> >> > XmlElementAttribute("DailyRecurrence",typeof(wsReportingServices.DailyRecurrence)));
> >> >
> >> > attrs.XmlElements.Add(new
> >> > XmlElementAttribute("WeeklyRecurrence",typeof(wsReportingServices.WeeklyRecurrence)));
> >> >
> >> > attrs.XmlElements.Add(new
> >> > XmlElementAttribute("MonthlyRecurrence",typeof(wsReportingServices.MonthlyRecurrence)));
> >> >
> >> > attrs.XmlElements.Add(new
> >> > XmlElementAttribute("MonthlyDOWRecurrence",typeof(wsReportingServices.MonthlyDOWRecurrence)));
> >> >
> >> >
> >> >
> >> > XmlAttributeOverrides attrOver=new
> >> > XmlAttributeOverrides();
> >> >
> >> >
> >> > attrOver.Add(typeof(wsReportingServices.ScheduleDefinition),"ScheduleDefinition",attrs);
> >> >
> >> >
> >> > XmlSerializer newSr=new
> >> > XmlSerializer(typeof(wsReportingServices.ScheduleDefinition),attrOver);
> >> >
> >> >
> >> >
> >> > return
> >> > (wsReportingServices.ScheduleDefinition)newSr.Deserialize(vStream);
> >> >
> >> > }
> >> >
> >>
> >>
> >>|||Here's a nice example of serializing ScheduleDefinition:
http://www.odetocode.com/Articles/114.aspx
--
Adrian M.
MCP
"SouthFLBoiler@.discussions.microsoft.com"
<SouthFLBoilerdiscussionsmicrosoftcom@.discussions.microsoft.com> wrote in
message news:83278D35-A056-4E12-91AF-67FA443CE248@.microsoft.com...
>I got deserializing to work, but the problem is; If I create the schedule
> using the web interface it will not work, but if I do it using my
> interface
> it works.
>
> The XML that is returned from my subscription reports:
>
> "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ScheduleDefinition
> xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
> xmlns:xsi=\"/n">http://www.w3.org/2001/XMLSchema-instance\">\n <StartDateTime
> xmlns=\"2005-03-25T13:24:26.4506144-05:00</StartDateTime>/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</StartDateTime>\n
> <EndDate
> xmlns=\"2005-03-25T13:24:26.4506144-05:00</EndDate>/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">2005-03-25T13:24:26.4506144-05:00</EndDate>\n
> <MinuteRecurrence
> xmlns=\"/n">http://schemas.microsoft.com/sqlserver/2003/12/reporting/reportingservices\">\n
> <MinutesInterval>900</MinutesInterval>\n
> </MinuteRecurrence>\n</ScheduleDefinition>"
>
> The XML that is returned from a report scheduled using the web app:
>
> "<ScheduleDefinition><StartDateTime>2005-03-25T05:30:00.000-05:00</StartDateTime><MinuteRecurrence><MinutesInterval>105</MinutesInterval></MinuteRecurrence></ScheduleDefinition>"
>
>
> private wsReportingServices.ScheduleDefinition
> DeSerializeSchedule(string XMLString)
> {
>
> MemoryStream vStream = GetStreamFromString(XMLString);
>
> XmlAttributes attrs=new XmlAttributes();
>
> attrs.XmlElements.Add(new
> XmlElementAttribute("MinuteRecurrence",typeof(wsReportingServices.MinuteRecurrence)));
> attrs.XmlElements.Add(new
> XmlElementAttribute("DailyRecurrence",typeof(wsReportingServices.DailyRecurrence)));
> attrs.XmlElements.Add(new
> XmlElementAttribute("WeeklyRecurrence",typeof(wsReportingServices.WeeklyRecurrence)));
> attrs.XmlElements.Add(new
> XmlElementAttribute("MonthlyRecurrence",typeof(wsReportingServices.MonthlyRecurrence)));
> attrs.XmlElements.Add(new
> XmlElementAttribute("MonthlyDOWRecurrence",typeof(wsReportingServices.MonthlyDOWRecurrence)));
>
> XmlAttributeOverrides attrOver=new
> XmlAttributeOverrides();
>
> attrOver.Add(typeof(wsReportingServices.ScheduleDefinition),"ScheduleDefinition",attrs);
>
> XmlSerializer newSr=new
> XmlSerializer(typeof(wsReportingServices.ScheduleDefinition),attrOver);
>
> return
> (wsReportingServices.ScheduleDefinition)newSr.Deserialize(vStream);
> }
>
No comments:
Post a Comment