none
Project.Server.Library : How to use the Filter.ReadXml Method ? RRS feed

  • Question

  • Hello,

    How can I make use of the ReadXml method ? What is the format expected ?I'm developing under Project Server 2010, and I'd like to have some insight about this.

    Once again, no documentation on this subject... http://msdn.microsoft.com/en-us/library/microsoft.office.project.server.library.filter.readxml%28v=office.12%29.aspx

    Does someone in the Project Server microcosm know about this ??

    Friday, April 12, 2013 8:39 AM

Answers

  • Hi there,

    This part of the "API" is not documented at all. People at Microsoft think it's not relevant to release some documentation on the subject. Well, let's hope they change their mind. In the meantime, I could finally achieve what I wanted in the first place: read the filter data stored as XML in the database (quite dirty) and convert this to a nice Filter object.

    Here's how to do so:

            private Filter _projectFilter = null;
            private Filter ProjectFilter
            {
                get
                {
                    if (this._projectFilter == null)
                    {
                        // Retrieve all views.
                        PSSchema.PWAViewReportsDataSet viewSummaries = PJContext.Current.PSI.ViewWebService.ReadViewSummaries();
    
                        // Retrieve the viewUID matching the following conditions.
                        Guid viewUID = (from v in viewSummaries.ViewReports.AsEnumerable().Cast<PSSchema.PWAViewReportsDataSet.ViewReportsRow>()
                                        where v.WVIEW_TYPE == 1 && v.IsWTABLE_UIDNull() && v.WVIEW_NAME == this.RequestView
                                        select v.WVIEW_UID).FirstOrDefault();
    
                        if (viewUID != Guid.Empty)
                        {
                            // Retrieve the view fields matching the viewUID guid.
                            PSSchema.PWAViewReportsDataSet pwaRptDs = PJContext.Current.PSI.ViewWebService.ReadView(viewUID);
                            if (pwaRptDs != null && pwaRptDs.ViewReportFields != null && pwaRptDs.ViewReportFields.Count > 0)
                            {
                                // retrieve filter(s)...
                                PSSchema.PWAViewReportsDataSet.ViewReportsRow reportRow = pwaRptDs.ViewReports
                                    .AsEnumerable()
                                    .Cast<PSSchema.PWAViewReportsDataSet.ViewReportsRow>()
                                    .FirstOrDefault();
                                if (reportRow != null && !reportRow.IsWVIEW_FILTERNull() && !string.IsNullOrEmpty(reportRow.WVIEW_FILTER))
                                {
                                    // Add an XML header and replace the Filter tag.
                                    string xmlstring = string.Concat(
                                        "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
                                        reportRow.WVIEW_FILTER
                                    ).Replace(
                                        @"<Filter xmlns:pwa=""http://microsoft.com/ProjectServer/FilterSchema.xsd"">",
                                        @"<Filter xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://microsoft.com/ProjectServer/FilterSchema.xsd"">"
                                    );
                                    XmlReader reader = XmlReader.Create(new StringReader(xmlstring));
                                    Filter f = new Filter();
                                    f.ReadXml(reader);
                                    this._projectFilter = f;
                                }
                            }
                        }
                    }
                    return this._projectFilter;
                }
            }



    Voilà!

    Hope that helps !
    • Marked as answer by Quentin V Tuesday, April 23, 2013 8:36 AM
    Tuesday, April 23, 2013 8:36 AM

All replies

  • Hello,

    I'm not sure about the usage that you want to do, but I can guess that you want to build a XML filter to read some data through PSI.

    Some methods are waiting for a Filter object, which is defined in XML:

    • ReadCalendars
    • ReadCustomFields
    • ReadLookupTables
    • ReadLookupTablesMultiLang
    • ReadResources
    • ReadResourceAssignments
    • ReadResourcePlan

    This filter help reducing the amount of data returned by the query (bandwidth, processing time...)

    If it is what you want to do, this page "How to: Use a Filter Parameter with PSI Methods" might help you : http://msdn.microsoft.com/en-us/library/office/ms453399(v=office.12).aspx

    As very often in the Project Server documentation, it includes some code examples easy to reuse.

    Good luck, and let us know if you need additionnal help.

    Sylvain

    Monday, April 15, 2013 1:42 PM
  • Hello,

    Maybe I was not accurate enough in my previous post. Let me explain it again.

    I am trying to read the filters stored as an XML string in a PWAViewReportsDataSet.ViewReportsRow object instance and load them into Filter objects. The big issue here is that there is no documentation on the subject, so I was hoping someone in the community might help me out on this.

    I have the following code :

    ... using PSSchema = Microsoft.Office.Project.Server.Schema; ...

            private List<PSFieldInfo> GetProjectFieldsForView(string viewText)
            {
                List<PSFieldInfo> fields = new List<PSFieldInfo>();
                PSSchema.PWAViewReportsDataSet viewSummaries = PJContext.Current.PSI.ViewWebService.ReadViewSummaries();
                Guid viewUID =
                    (from v in viewSummaries.ViewReports.AsEnumerable().Cast<PSSchema.PWAViewReportsDataSet.ViewReportsRow>()
                     where v.WVIEW_TYPE == 1 && v.IsWTABLE_UIDNull() && v.WVIEW_NAME == viewText
                     select v.WVIEW_UID).FirstOrDefault();

                if (viewUID != Guid.Empty)
                {
                    // Retrieve fields.
                    Microsoft.Office.Project.Server.Schema.PWAViewReportsDataSet pwaRptDs = PJContext.Current.PSI.ViewWebService.ReadView(viewUID);
                    if (pwaRptDs != null && pwaRptDs.ViewReportFields != null && pwaRptDs.ViewReportFields.Count > 0)
                    {
                        foreach (PSSchema.PWAViewReportsDataSet.ViewReportFieldsRow fieldRow in pwaRptDs.ViewReportFields)
                        {
                            fields.Add(new PSFieldInfo(fieldRow));
                        }
                    }
                }
                return fields;
            }



    And here's the XML in the WVIEW_FILTER field :

    <Filter xmlns:pwa="http://microsoft.com/ProjectServer/FilterSchema.xsd">
    	<Criteria>
    		<LogicalOperator logicalOperationType="Nop">
    			<FieldOperator fieldOperationType="LessThanEqual">
    				<Field fieldName="TASKOUTLINELEVEL"/>
    				<Operand>1</Operand>
    			</FieldOperator>
    		</LogicalOperator>
    	</Criteria>
    </Filter>



    Is there another specific method I should be using to load a Filter object ?


    • Edited by Quentin V Tuesday, April 16, 2013 1:00 PM
    Tuesday, April 16, 2013 12:59 PM
  • Hi there,

    This part of the "API" is not documented at all. People at Microsoft think it's not relevant to release some documentation on the subject. Well, let's hope they change their mind. In the meantime, I could finally achieve what I wanted in the first place: read the filter data stored as XML in the database (quite dirty) and convert this to a nice Filter object.

    Here's how to do so:

            private Filter _projectFilter = null;
            private Filter ProjectFilter
            {
                get
                {
                    if (this._projectFilter == null)
                    {
                        // Retrieve all views.
                        PSSchema.PWAViewReportsDataSet viewSummaries = PJContext.Current.PSI.ViewWebService.ReadViewSummaries();
    
                        // Retrieve the viewUID matching the following conditions.
                        Guid viewUID = (from v in viewSummaries.ViewReports.AsEnumerable().Cast<PSSchema.PWAViewReportsDataSet.ViewReportsRow>()
                                        where v.WVIEW_TYPE == 1 && v.IsWTABLE_UIDNull() && v.WVIEW_NAME == this.RequestView
                                        select v.WVIEW_UID).FirstOrDefault();
    
                        if (viewUID != Guid.Empty)
                        {
                            // Retrieve the view fields matching the viewUID guid.
                            PSSchema.PWAViewReportsDataSet pwaRptDs = PJContext.Current.PSI.ViewWebService.ReadView(viewUID);
                            if (pwaRptDs != null && pwaRptDs.ViewReportFields != null && pwaRptDs.ViewReportFields.Count > 0)
                            {
                                // retrieve filter(s)...
                                PSSchema.PWAViewReportsDataSet.ViewReportsRow reportRow = pwaRptDs.ViewReports
                                    .AsEnumerable()
                                    .Cast<PSSchema.PWAViewReportsDataSet.ViewReportsRow>()
                                    .FirstOrDefault();
                                if (reportRow != null && !reportRow.IsWVIEW_FILTERNull() && !string.IsNullOrEmpty(reportRow.WVIEW_FILTER))
                                {
                                    // Add an XML header and replace the Filter tag.
                                    string xmlstring = string.Concat(
                                        "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
                                        reportRow.WVIEW_FILTER
                                    ).Replace(
                                        @"<Filter xmlns:pwa=""http://microsoft.com/ProjectServer/FilterSchema.xsd"">",
                                        @"<Filter xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://microsoft.com/ProjectServer/FilterSchema.xsd"">"
                                    );
                                    XmlReader reader = XmlReader.Create(new StringReader(xmlstring));
                                    Filter f = new Filter();
                                    f.ReadXml(reader);
                                    this._projectFilter = f;
                                }
                            }
                        }
                    }
                    return this._projectFilter;
                }
            }



    Voilà!

    Hope that helps !
    • Marked as answer by Quentin V Tuesday, April 23, 2013 8:36 AM
    Tuesday, April 23, 2013 8:36 AM