Ticket Q50133
Visible to All Users

Iterate through BO Types

created 17 years ago

I wish to build a new BO type similar in a way to ReportData but to hold the content of an MS Office Word Document. The purpose of this BO is to provide a mechamism to provide document templates for merging standard letters in Word. So, as a property of this Object I need to define which BO it will work with (just like a ReportData object). If we call this object 'WordTemplateData' then it will have a number of properties and capabilities which will include a) providing a list of 'merge fields' and b) merging an XPCollection of the specified type.
My appeal for help at this moment is a) how to iterate through the list of BOs in my application so that I can provide a drop down list of types just like the list of types provided when creating a new ReportData object, whilst doing so how do I check Attributes since I plan to add a new one 'VisibleInTemplate(Boolean)' and b) Given that I have a BO, how to iterate through it's properties so I can provide a list of merge fields to Word.
I know this can all be done using Reflection but since XAF is doing it already, I am hoping to hijack the XAF helpers to save me LOTS of time (in the genuine spirit of XAF development!!)
Many thanks
John

Comments (3)
Dennis Garavsky (DevExpress) 17 years ago

    Hi John,

    There are two approaches to iterate through BO types:

    1. iterate through classes, provided by the DevExpress.Xpo.Metadata.XPDictionary:
      <code lang="cs">
      public override void CustomizeXPDictionary(DevExpress.Xpo.Metadata.XPDictionary xpDictionary) {
          base.CustomizeXPDictionary(xpDictionary);
          foreach (DevExpress.Xpo.Metadata.XPClassInfo item in xpDictionary.Classes)
          {
              //…
          }
      }
      </code>
    2. iterate through items within the BOModel node in the application model:
      <code lang="cs">
                      foreach (DictionaryNode groupNode in Application.Model.RootNode.FindChildNode("NavigationItems").ChildNodes)
                      {
                          foreach (DictionaryNode itemNode in groupNode.ChildNodes)
                          {
                              if (itemNode.GetAttributeValue("ViewID") == objectTypeViewID)
                              {
                                  return groupNode;
                              }
                          }
                      }
      </code>

    >>provide a drop down list of types just like the list of types provided when creating a new ReportData object
    >>how do I check Attributes since I plan to add a new one 'VisibleInTemplate(Boolean)'
    I suggest you review the code, which illustrates how it is implemented in the case of the ReportData class:
    <code lang="cs">
                    [NonPersistent]
    public class NewReportParams {
    private string reportName;
    private Type dataType;
    public NewReportParams() { }
    public string ReportName {
    get { return reportName; }
    set { reportName = value; }
    }
                                    // pay your attention to the following line
    [TypeConverter(typeof(ReportDataTypeConverter))]
    public Type DataType {
    get { return dataType; }
    set { dataType = value; }
    }
    }
    </code>
    <code lang="cs>
                    public class ReportDataTypeConverter : LocalizedClassInfoTypeConverter {
    public ReportDataTypeConverter() : base() { }
    public ReportDataTypeConverter(XPDictionary dictionary) : base(dictionary) { }
    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
    StandardValuesCollection baseCollection = base.GetStandardValues(context);
    if (CaptionHelper.ApplicationNode == null) {
    return baseCollection;
    }
    DictionaryNode boModelNode = CaptionHelper.ApplicationNode.FindChildNode(BOModelNodeWrapper.NodeName);
    if (boModelNode == null) {
    return baseCollection;
    }
    List<Type> result = new List<Type>();
    foreach(Type type in baseCollection) {
    if(type == null) {
    result.Add(null);
    }
    else {
    DictionaryNode classNode = boModelNode.FindChildNode(ClassInfoNodeWrapper.NodeName, ClassInfoNodeWrapper.NameAttribute, type.FullName);
                                                                                    // pay your attention to the following line
    if(classNode != null && classNode.GetAttributeBoolValue(Module.VisibleInReportsAttributeName)) {
    result.Add(type);
    }
    }
    }
    return new StandardValuesCollection(result);
    }
    }
    </code>

    >>how to iterate through it's properties
    You can iterate through the properties, provided by your BO's ClassInfo property.

    Thanks
    Dennis

      Thanks Dennis
      This should set me well on my way.
      John

      Dennis Garavsky (DevExpress) 17 years ago

        Please feel free to contact us in case of any further difficulty.
        Thanks
        Dennis

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.