Ejemplo n.º 1
0
        /// <summary>
        /// Generates the class that transforms a data model into a human read-able document.
        /// </summary>
        /// <param name="dataTransform">Describes how to transform abstract data into a document.</param>
        public DataTransformClass(DataTransform dataTransform)
        {
            //	/// <summary>
            //	/// Transforms a data model into a document.
            //	/// </summary>
            //	public class PrototypeView : DocumentView
            //	{
            this.Comments.Add(new CodeCommentStatement("<summary>", true));
            this.Comments.Add(new CodeCommentStatement("Transforms a data model into a document.", true));
            this.Comments.Add(new CodeCommentStatement("</summary>", true));
            this.Name = dataTransform.DataTransformId;
            this.BaseTypes.Add("DocumentView");

            // The Column Index (Absolute Order) Constants
            //		// Constant Column Indices
            //		internal const int workingStatusImageIndex = 0;
            //		internal const int submittedStatusImageIndex = 1;
            //		internal const int recordIdIndex = 2;
            bool isFirstColumnIndexConstant = true;

            for (int columnIndex = 0; columnIndex < dataTransform.Columns.Count; columnIndex++)
            {
                DataTransform.ColumnNode columnNode = dataTransform.Columns[columnIndex];
                string          constantName        = CamelCase.Convert(columnNode.ColumnId) + "Index";
                CodeMemberField codeMemberField     = new CodeMemberField(typeof(Int32), constantName);
                if (isFirstColumnIndexConstant)
                {
                    isFirstColumnIndexConstant = false;
                    codeMemberField.Comments.Add(new CodeCommentStatement("Constant Column Indices (Column Order)"));
                }
                codeMemberField.Attributes     = MemberAttributes.Const | MemberAttributes.Assembly;
                codeMemberField.InitExpression = new CodePrimitiveExpression(columnIndex);
                this.Members.Add(codeMemberField);
            }

            // The Column Ordinal (Viewer Order) Constants
            //		// Constant Column Indices
            //		internal const int workingStatusImageOrdinal = 0;
            //		internal const int submittedStatusImageOrdinal = 1;
            //		internal const int recordIdOrdinal = 2;
            bool isFirstColumnOrdinalConstant = true;

            for (int columnOrdinal = 0; columnOrdinal < dataTransform.View.Count; columnOrdinal++)
            {
                DataTransform.ColumnNode columnNode = dataTransform.View[columnOrdinal].Column;
                string          constantName        = CamelCase.Convert(columnNode.ColumnId) + "Ordinal";
                CodeMemberField codeMemberField     = new CodeMemberField(typeof(Int32), constantName);
                if (isFirstColumnOrdinalConstant)
                {
                    isFirstColumnOrdinalConstant = false;
                    codeMemberField.Comments.Add(new CodeCommentStatement("Constant Column Ordinals (Viewer Order)"));
                }
                codeMemberField.Attributes     = MemberAttributes.Const | MemberAttributes.Assembly;
                codeMemberField.InitExpression = new CodePrimitiveExpression(columnOrdinal);
                this.Members.Add(codeMemberField);
            }

            // The Row Height Constants.
            //		// Constant Row Heights
            //		private const float headerRowHeight = 40F;
            //		private const float workingOrderRowHeight = 20F;
            //		private const float sourceOrderRowHeight = 20F;
            //		private const float destinationOrderRowHeight = 20F;
            //		private const float executionRowHeight = 20F;
            bool isFirstRowHeightConstant = true;

            foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates)
            {
                foreach (DataTransform.RowNode rowNode in templateNode.Rows)
                {
                    string          constantName    = CamelCase.Convert(rowNode.RowId) + "Height";
                    CodeMemberField codeMemberField = new CodeMemberField(typeof(Single), constantName);
                    if (isFirstRowHeightConstant)
                    {
                        isFirstRowHeightConstant = false;
                        codeMemberField.Comments.Add(new CodeCommentStatement("Constant Row Heights"));
                    }
                    codeMemberField.Attributes     = MemberAttributes.Const | MemberAttributes.Private;
                    codeMemberField.InitExpression = new CodePrimitiveExpression(rowNode.Height);
                    this.Members.Add(codeMemberField);
                }
            }

            // The Row Width Constants.
            //		// Constant Row Widths
            //		private const float headerRowHeight = 745F;
            //		private const float workingOrderRowHeight = 745F;
            //		private const float sourceOrderRowHeight = 745F;
            //		private const float destinationOrderRowHeight = 745F;
            //		private const float executionRowHeight = 745F;
            bool isFirstRowWidthConstant = true;

            foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates)
            {
                foreach (DataTransform.RowNode rowNode in templateNode.Rows)
                {
                    string          constantName    = CamelCase.Convert(rowNode.RowId) + "Width";
                    CodeMemberField codeMemberField = new CodeMemberField(typeof(Single), constantName);
                    if (isFirstRowWidthConstant)
                    {
                        isFirstRowWidthConstant = false;
                        codeMemberField.Comments.Add(new CodeCommentStatement("Constant Row Widths"));
                    }
                    codeMemberField.Attributes = MemberAttributes.Const | MemberAttributes.Private;
                    float rowWidth = 0.0f;
                    foreach (DataTransform.ColumnReferenceNode columnReferenceNode in dataTransform.View)
                    {
                        rowWidth += columnReferenceNode.Column.Width;
                    }
                    codeMemberField.InitExpression = new CodePrimitiveExpression(rowWidth);
                    this.Members.Add(codeMemberField);
                }
            }

            // The Column Width Constants.
            //		// Constant Column Widths
            //		private const float askPriceWidth = 53F;
            //		private const float availableQuantityWidth = 56F;
            //		private const float bidPriceWidth = 53F;
            //		private const float destinationOrderQuantityWidth = 56F;
            bool isFirstColumnWidthConstant = true;

            foreach (DataTransform.ColumnNode columnNode in dataTransform.Columns)
            {
                string          constantName    = CamelCase.Convert(columnNode.ColumnId) + "Width";
                CodeMemberField codeMemberField = new CodeMemberField(typeof(Single), constantName);
                if (isFirstColumnWidthConstant)
                {
                    isFirstColumnWidthConstant = false;
                    codeMemberField.Comments.Add(new CodeCommentStatement("Constant Column Widths"));
                }
                codeMemberField.Attributes     = MemberAttributes.Const | MemberAttributes.Private;
                codeMemberField.InitExpression = new CodePrimitiveExpression(columnNode.Width);
                this.Members.Add(codeMemberField);
            }

            // The Comparers
            //		// Comparers
            //		private System.Collections.Generic.IComparer<MarkThree.Forms.ViewerRow> workingOrderRowComparer;
            //		private System.Collections.Generic.IComparer<MarkThree.Forms.ViewerRow> sourceOrderRowComparer;
            //		private System.Collections.Generic.IComparer<MarkThree.Forms.ViewerRow> destinationOrderRowComparer;
            bool isFirstComparer = true;

            foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates)
            {
                foreach (DataTransform.RowNode rowNode in templateNode.Rows)
                {
                    foreach (DataTransform.ApplyTemplateNode applyTemplateNode in rowNode.ApplyTemplates)
                    {
                        if (applyTemplateNode.Sorts.Count != 0)
                        {
                            string          comparerName    = CamelCase.Convert(applyTemplateNode.Select) + "RowComparer";
                            CodeMemberField codeMemberField = new CodeMemberField(typeof(IComparer <ViewerRow>), comparerName);
                            if (isFirstComparer)
                            {
                                isFirstComparer = false;
                                codeMemberField.Comments.Add(new CodeCommentStatement("Comparers"));
                            }
                            codeMemberField.Attributes = MemberAttributes.Private;
                            this.Members.Add(codeMemberField);
                        }
                    }
                }
            }


            // Add the constructor to the namespace.
            this.Members.Add(new DataTransformConstructor(dataTransform));

            // Add the Build method used to construct the styles.
            this.Members.Add(new DataTransformInitializeViewMethod(dataTransform));

            // Add the Build method used to construct the document.
            this.Members.Add(new DataTransformBuildViewMethod(dataTransform));

            // Add the code for all the template handlers.
            foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates)
            {
                this.Members.Add(new DataTransformTemplateMethod(templateNode));
            }
        }
        /// <summary>
        /// Creates the method that is the starting point for the document creation.
        /// </summary>
        /// <param name="dataTransform">Describes how to create a document from an abstract data model.</param>
        public DataTransformInitializeViewMethod(DataTransform dataTransform)
        {
            //			/// <summary>
            //			/// Builds the styles used to display data in the document.
            //			/// </summary>
            //			public override void InitializeView(List<ViewerCommand> viewerCommands)
            //			{
            this.Comments.Add(new CodeCommentStatement("<summary>", true));
            this.Comments.Add(new CodeCommentStatement("Builds the styles used to display data in the document.", true));
            this.Comments.Add(new CodeCommentStatement("</summary>", true));
            this.Attributes = MemberAttributes.Public | MemberAttributes.Override;
            this.ReturnType = new CodeTypeReference(typeof(void));
            this.Name       = "InitializeView";

            //			// Split the screen into quadrants.
            //			this.documentViewer.ViewerCommandQueue.Enqueue(new MarkThree.Forms.ViewerCommand(new MarkThree.Forms.ViewerSplit(new System.Drawing.SizeF(54F, 55F)), new MarkThree.Forms.ViewerCommandDelegate(this.documentViewer.SetSplit)));
            SizeF splitSize = dataTransform.SplitSize;

            if (splitSize != SizeF.Empty)
            {
                this.Statements.Add(new CodeCommentStatement("Split the screen into quadrants."));
                this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "ViewerCommandQueue"), "Enqueue",
                                                                   new CodeObjectCreateExpression(typeof(ViewerCommand), new CodeObjectCreateExpression(typeof(ViewerSplit), new CodeObjectCreateExpression(typeof(SizeF), new CodePrimitiveExpression(splitSize.Width), new CodePrimitiveExpression(splitSize.Height))),
                                                                                                  new CodeObjectCreateExpression(typeof(ViewerCommandDelegate), new CodeMethodReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "SetSplit")))));
            }

            //			// Set the magnification factor.
            //			this.documentViewer.ViewerCommandQueue.Enqueue(new MarkThree.Forms.ViewerCommand(new MarkThree.Forms.ViewerScale(1.25F), new MarkThree.Forms.ViewerCommandDelegate(this.documentViewer.SetScale)));
            float scaleFactor = dataTransform.ScaleFactor;

            if (scaleFactor != DefaultDocument.ScaleFactor)
            {
                this.Statements.Add(new CodeCommentStatement("Set the magnification factor."));
                this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "ViewerCommandQueue"), "Enqueue",
                                                                   new CodeObjectCreateExpression(typeof(ViewerCommand), new CodeObjectCreateExpression(typeof(ViewerScale), new CodePrimitiveExpression(scaleFactor)),
                                                                                                  new CodeObjectCreateExpression(typeof(ViewerCommandDelegate), new CodeMethodReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "SetScale")))));
            }

            // This will generate each of the styles in turn and add them to the range of styles that is sent to the viewer.
            // The viewer will then use these styles to match up the incoming tiles to instructions to present them in the
            // document.
            foreach (DataTransform.StyleNode styleNode in dataTransform.Styles)
            {
                //					// Header Style
                //					MarkThree.Forms.ViewerStyle headerStyle = this.documentViewer.GetStyle("Default");
                //					if (("Default" != headerStyle.ParentId))
                //					{
                //						headerStyle.ParentId = "Default";
                //						headerStyle.IsModified = true;
                //					}
                //					headerStyle.Attributes.Add(new MarkThree.Forms.ViewerBottomBorder(System.Drawing.Color.DarkGray, 1F));
                //					headerStyle.Attributes.Add(new MarkThree.Forms.ViewerRightBorder(System.Drawing.Color.DarkGray, 1F));
                //					headerStyle.Attributes.Add(new MarkThree.Forms.ViewerInteriorBrush(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.Control)));
                //					headerStyle.Attributes.Add(new MarkThree.Forms.ViewerImage(this.documentViewer.Variables["GreenCheckImage"]));
                this.Statements.Add(new CodeCommentStatement(string.Format("{0} Style", styleNode.StyleId)));
                string variableName = string.Format("{0}Style", CamelCase.Convert(styleNode.StyleId));
                this.Statements.Add(new CodeVariableDeclarationStatement(typeof(ViewerStyle), variableName, new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "GetStyle", new CodePrimitiveExpression(styleNode.StyleId))));
                if (styleNode.ParentStyle != null)
                {
                    CodeStatement[] trueStatements0 = new CodeStatement[2];
                    trueStatements0[0] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "ParentId"), new CodePrimitiveExpression(styleNode.ParentStyle.StyleId));
                    trueStatements0[1] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "IsModified"), new CodePrimitiveExpression(true));
                    this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodePrimitiveExpression(styleNode.ParentStyle.StyleId), CodeBinaryOperatorType.IdentityInequality, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "ParentId")), trueStatements0));
                }
                if (styleNode.HasAnimation)
                {
                    if (styleNode.Animation.Effect == Effect.Fade)
                    {
                        this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFadeAnimation), CodeSnippet.Convert(styleNode.Animation.Up), CodeSnippet.Convert(styleNode.Animation.Down), CodeSnippet.Convert(styleNode.Animation.Same), new CodePrimitiveExpression(styleNode.Animation.Steps))));
                    }
                    if (styleNode.Animation.Effect == Effect.Flash)
                    {
                        this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFlashAnimation), CodeSnippet.Convert(styleNode.Animation.Foreground), CodeSnippet.Convert(styleNode.Animation.Background), new CodePrimitiveExpression(styleNode.Animation.On), new CodePrimitiveExpression(styleNode.Animation.Off), new CodePrimitiveExpression(styleNode.Animation.Repeat))));
                    }
                }
                if (styleNode.HasBottomBorder)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerBottomBorder), CodeSnippet.Convert(styleNode.BottomBorder.Color), new CodePrimitiveExpression(styleNode.BottomBorder.Width))));
                }
                if (styleNode.HasLeftBorder)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerLeftBorder), CodeSnippet.Convert(styleNode.LeftBorder.Color), new CodePrimitiveExpression(styleNode.LeftBorder.Width))));
                }
                if (styleNode.HasRightBorder)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerRightBorder), CodeSnippet.Convert(styleNode.RightBorder.Color), new CodePrimitiveExpression(styleNode.RightBorder.Width))));
                }
                if (styleNode.HasTopBorder)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerTopBorder), CodeSnippet.Convert(styleNode.TopBorder.Color), new CodePrimitiveExpression(styleNode.TopBorder.Width))));
                }
                if (styleNode.HasFont)
                {
                    if (styleNode.Font.Style == FontStyle.Regular)
                    {
                        this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFont), CodeSnippet.Convert(styleNode.Font.FontFamily), new CodePrimitiveExpression(styleNode.Font.Size))));
                    }
                    else
                    {
                        this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFont), CodeSnippet.Convert(styleNode.Font.FontFamily), new CodePrimitiveExpression(styleNode.Font.Size), CodeSnippet.Convert(styleNode.Font.Style))));
                    }
                }
                if (styleNode.HasFontBrush)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerFontBrush), CodeSnippet.Convert(styleNode.ForeColor))));
                }
                if (styleNode.HasStringFormat)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerStringFormat), CodeSnippet.Convert(styleNode.StringFormat.Alignment), CodeSnippet.Convert(styleNode.StringFormat.LineAlignment))));
                }
                if (styleNode.HasNumberFormat)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerNumberFormat), new CodePrimitiveExpression(styleNode.NumberFormat))));
                }
                if (styleNode.HasInterior)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerInteriorBrush), CodeSnippet.Convert(styleNode.BackColor))));
                }
                if (styleNode.HasImage)
                {
                    this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(variableName), "Attributes"), "Add", new CodeObjectCreateExpression(typeof(ViewerImage), new CodeCastExpression(typeof(Image), new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "Variables"), new CodePrimitiveExpression(styleNode.Image))))));
                }
            }
        }
        /// <summary>
        /// Constructs the CodeDOM method used to transform abstract data into a readable document.
        /// </summary>
        /// <param name="templateNode">Contains the specification for the template.</param>
        public DataTransformTemplateMethod(DataTransform.TemplateNode templateNode)
        {
            // This is a rudimentary test for the start of the document.  The idea is to follow the XSL language where possible
            // but the rigours of an XPATH parser are beyond the scope of this function at the time of this writing.  In the future
            // it should be expanded to follow an XPATH like specification into the data model.
            bool isRootTemplate = templateNode.Match.StartsWith("/");

            // Some top-level information will be needed to construct the template, such as the class name to reference constants.
            DataTransform dataTransform = templateNode.TopLevelNode as DataTransform;

            //		/// <summary>
            //		/// Transforms a row of data into screen instructions.
            //		/// </summary>
            //		/// <param name="viewerTable">The current outline level of the document.</param>
            //		/// <param name="dataRow">The source of the data for this template.</param>
            //		public virtual void SlashTemplate(MarkThree.Forms.ViewerTable viewerTable, System.Data.DataRow dataRow)
            //		{
            this.Comments.Add(new CodeCommentStatement(@"<summary>", true));
            this.Comments.Add(new CodeCommentStatement(@"Transforms a row of data into screen instructions.", true));
            this.Comments.Add(new CodeCommentStatement(@"</summary>", true));
            this.Comments.Add(new CodeCommentStatement(@"<param name=""viewerTable"">The current outline level of the document.</param>", true));
            this.Comments.Add(new CodeCommentStatement(@"<param name=""dataRow"">The source of the data for this template.</param>", true));
            this.Name       = string.Format("{0}Template", templateNode.Match.Replace("/", "Slash"));
            this.Attributes = MemberAttributes.Public;
            this.Parameters.Add(new CodeParameterDeclarationExpression(typeof(ViewerTable), "viewerTable"));
            string rowType         = isRootTemplate ? "DataRow" : string.Format(string.Format("{0}Row", templateNode.Match));
            string rowNamespace    = isRootTemplate ? "System.Data" : dataTransform.Source;
            string rowVariableName = CamelCase.Convert(rowType);

            this.Parameters.Add(new CodeParameterDeclarationExpression(string.Format("{0}.{1}", rowNamespace, rowType), rowVariableName));

            // This will create the instructions for generating each row that appears in the template.
            int rowIndex = 0;

            foreach (DataTransform.RowNode rowNode in templateNode.Rows)
            {
                //				// Execution
                //				MarkThree.Forms.ViewerRow viewerRow0 = new MarkThree.Forms.ViewerRow();
                //				viewerRow0.Data = new object[17];
                //				viewerRow0.Tiles = new ViewerTile[17];
                //				viewerRow0.Children = new ViewerTable[2];

                string viewerRowVariableName = string.Format("viewerRow{0}", rowIndex++);
                this.Statements.Add(new CodeCommentStatement(rowNode.RowId));
                this.Statements.Add(new CodeVariableDeclarationStatement(typeof(ViewerRow), viewerRowVariableName, new CodeObjectCreateExpression(typeof(ViewerRow))));
                this.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(viewerRowVariableName), "Data"),
                                                            new CodeArrayCreateExpression(typeof(object), new CodePrimitiveExpression(dataTransform.Columns.Count))));
                this.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(viewerRowVariableName), "Tiles"),
                                                            new CodeArrayCreateExpression(typeof(ViewerTile), new CodePrimitiveExpression(dataTransform.View.Count))));
                int childTableCount = 0;
                foreach (DataTransform.ApplyTemplateNode applyTemplateNode in rowNode.ApplyTemplates)
                {
                    if (applyTemplateNode.RowFilter.ToLower() != bool.FalseString.ToLower())
                    {
                        childTableCount++;
                    }
                }
                if (childTableCount != 0)
                {
                    this.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(viewerRowVariableName), "Children"),
                                                                new CodeArrayCreateExpression(typeof(ViewerTable), new CodePrimitiveExpression(childTableCount))));
                }

                // Add in any temporary variables that need to be calculated.
                if (rowNode.ScratchList.Count != 0)
                {
                    // This will add any temporary variables needed to compute the data in a column.
                    this.Statements.Add(new CodeCommentStatement("This will calculate intermediate values used in the row."));
                    foreach (DataTransform.ScratchNode scratchNode in rowNode.ScratchList)
                    {
                        this.Statements.Add(new CodeSnippetExpression(scratchNode.Text.Trim().Trim(';')));
                    }
                }

                // This will create instructions for generating each of the tiles that appear in the row.
                this.Statements.Add(new CodeCommentStatement("Populate the data image of the row."));
                foreach (DataTransform.ColumnNode columnNode in dataTransform.Columns)
                {
                    // The 'View' describes the order of the columns.  Attempt to find the corresponding column in the row
                    // definition.  If it doesn't exist in the row, it will likely screw up the spacing of the document, but it
                    // won't crash with this check.
                    DataTransform.TileNode tileNode;
                    if (!rowNode.Tiles.TryGetValue(columnNode.ColumnId, out tileNode))
                    {
                        continue;
                    }

                    //					viewerRow0.Data[PrototypeViewer.workingStatusImageIndex] = this.variables["WorkingStatusHeaderImage"];
                    CodeExpression dataReferenceExpression = tileNode.Data != string.Empty ? (CodeExpression) new CodeSnippetExpression(tileNode.Data) :
                                                             tileNode.VariableName != string.Empty ? (CodeExpression) new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "Variables"), new CodePrimitiveExpression(tileNode.VariableName)) :
                                                             (CodeExpression) new CodePrimitiveExpression(DBNull.Value);
                    this.Statements.Add(new CodeAssignStatement(new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(viewerRowVariableName), "Data"),
                                                                                          new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), string.Format("{0}Index", CamelCase.Convert(columnNode.ColumnId)))),
                                                                dataReferenceExpression));
                }

                // This is a common value for all tiles in the row.
                CodeFieldReferenceExpression heightExpression = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), string.Format("{0}Height", CamelCase.Convert(rowNode.RowId)));

                // This will create instructions for generating each of the tiles that appear in the row.
                int tileIndex = 0;
                foreach (DataTransform.ColumnReferenceNode columnReferenceNode in dataTransform.View)
                {
                    // The 'View' describes the order of the columns.  Attempt to find the corresponding column in the row
                    // definition.  If it doesn't exist in the row, it will likely screw up the spacing of the document, but it
                    // won't crash with this check.
                    DataTransform.TileNode tileNode;
                    if (!rowNode.Tiles.TryGetValue(columnReferenceNode.ColumnId, out tileNode))
                    {
                        continue;
                    }

                    //					// WorkingStatusImage
                    //					MarkThree.Forms.ViewerTile viewerTile0 = this.documentViewer.GetTile(executionRow, PrototypeView.workingStatusImageIndex);
                    this.Statements.Add(new CodeCommentStatement(columnReferenceNode.ColumnId));
                    string tileVariableName = string.Format("viewerTile{0}", tileIndex);
                    string constantName     = CamelCase.Convert(columnReferenceNode.ColumnId) + "Index";
                    this.Statements.Add(new CodeVariableDeclarationStatement(typeof(ViewerTile), tileVariableName, new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "GetTile"), new CodeVariableReferenceExpression(rowVariableName), new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), constantName))));

                    //					string viewerStyleId0 = "HeaderImage";
                    //					if (viewerStyleId0 != viewerTile0.ViewerStyleId)
                    //					{
                    //						viewerTile0.ViewerStyleId = viewerStyleId0;
                    //						viewerTile0.IsModified = true;
                    //					}
                    if (tileNode.StyleId != string.Empty)
                    {
                        string styleIdVariableName = string.Format("viewerStyleId{0}", tileIndex);
                        this.Statements.Add(new CodeVariableDeclarationStatement(typeof(string), styleIdVariableName, new CodeSnippetExpression(tileNode.StyleId)));
                        CodeStatement[] trueStatements0 = new CodeStatement[2];
                        trueStatements0[0] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "ViewerStyleId"), new CodeVariableReferenceExpression(styleIdVariableName));
                        trueStatements0[1] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "IsModified"), new CodePrimitiveExpression(true));
                        this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression(styleIdVariableName), CodeBinaryOperatorType.IdentityInequality, new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "ViewerStyleId")), trueStatements0));
                    }

                    //					if ((viewerRow0.Data[PrototypeView.workingStatusImageOrdinal].Equals(viewerTile0.Data) != true))
                    //					{
                    //						viewerTile0.Data = viewerRow0.Data[PrototypeView.workingStatusImageOrdinal];
                    //						viewerTile0.IsModified = true;
                    //					}
                    CodeStatement[] trueStatements = new CodeStatement[2];
                    trueStatements[0] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "Data"), new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(viewerRowVariableName), "Data"),
                                                                                                                                                                                           new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), string.Format("{0}Index", CamelCase.Convert(columnReferenceNode.ColumnId)))));
                    trueStatements[1] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "IsModified"), new CodePrimitiveExpression(true));
                    this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeMethodInvokeExpression(new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(viewerRowVariableName), "Data"),
                                                                                                                                                             new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), string.Format("{0}Index", CamelCase.Convert(columnReferenceNode.ColumnId)))), "Equals",
                                                                                                                                   new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "Data")), CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(true)), trueStatements));

                    //					SizeF sizeF0 = new SizeF(PrototypeView.workingStatusImageWidth, PrototypeView.headerHeight);
                    //					if ((sizeF0 != viewerTile0.RectangleF.Size))
                    //					{
                    //						viewerTile0.RectangleF.Size = sizeF0;
                    //						viewerTile0.IsModified = true;
                    //					}
                    //CodeFieldReferenceExpression widthExpression = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), string.Format("{0}Width", CamelCase.Convert(columnReferenceNode.ColumnId)));
                    //string sizeVariableName = string.Format("sizeF{0}", tileIndex);
                    //this.Statements.Add(new CodeVariableDeclarationStatement(typeof(SizeF), sizeVariableName, new CodeObjectCreateExpression(typeof(SizeF), widthExpression, heightExpression)));
                    //CodeStatement[] trueStatements1 = new CodeStatement[2];
                    //trueStatements1[0] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "RectangleF"), "Size"), new CodeVariableReferenceExpression(sizeVariableName));
                    //trueStatements1[1] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "IsModified"), new CodePrimitiveExpression(true));
                    //this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression(sizeVariableName), CodeBinaryOperatorType.IdentityInequality, new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "RectangleF"), "Size")), trueStatements1));

                    //					if ((PrototypeView.workingStatusImageWidth != viewerTile0.RectangleF.Width))
                    //					{
                    //						viewerTile0.RectangleF.Width = PrototypeView.workingStatusImageWidth;
                    //						viewerTile0.IsModified = true;
                    //					}
                    CodeFieldReferenceExpression widthExpression = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), string.Format("{0}Width", CamelCase.Convert(columnReferenceNode.ColumnId)));
                    CodeStatement[] trueStatements1 = new CodeStatement[2];
                    trueStatements1[0] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "RectangleF"), "Width"), widthExpression);
                    trueStatements1[1] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "IsModified"), new CodePrimitiveExpression(true));
                    this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(widthExpression, CodeBinaryOperatorType.IdentityInequality, new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "RectangleF"), "Width")), trueStatements1));

                    //					if ((PrototypeView.headerHeight != viewerTile0.RectangleF.Height))
                    //					{
                    //						viewerTile0.RectangleF.Height = PrototypeView.headerHeight;
                    //						viewerTile0.IsModified = true;
                    //					}
                    CodeStatement[] trueStatements2 = new CodeStatement[2];
                    trueStatements2[0] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "RectangleF"), "Height"), heightExpression);
                    trueStatements2[1] = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "IsModified"), new CodePrimitiveExpression(true));
                    this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(heightExpression, CodeBinaryOperatorType.IdentityInequality, new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "RectangleF"), "Height")), trueStatements2));

                    //					viewerTile0.Cursor.Width = PrototypeView.workingStatusImageWidth;
                    //					viewerTile0.Cursor.Height = 0;
                    if (tileIndex < dataTransform.View.Count - 1)
                    {
                        this.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "Cursor"), "Width"), widthExpression));
                        this.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "Cursor"), "Height"), new CodePrimitiveExpression(0.0f)));
                    }
                    else
                    {
                        CodeExpression columnWidthExpression = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), string.Format("{0}Width", CamelCase.Convert(dataTransform.View[tileIndex].Column.ColumnId)));
                        CodeExpression rowWidthExpression    = new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), string.Format("{0}Width", CamelCase.Convert(rowNode.RowId)));
                        this.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "Cursor"), "Width"), new CodeBinaryOperatorExpression(columnWidthExpression, CodeBinaryOperatorType.Subtract, rowWidthExpression)));
                        this.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tileVariableName), "Cursor"), "Height"), heightExpression));
                    }

                    //					viewerRow0.Tiles[PrototypeViewer.statusImageOrdinal] = viewerTile0;
                    this.Statements.Add(new CodeAssignStatement(new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(viewerRowVariableName), "Tiles"),
                                                                                          new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), string.Format("{0}Ordinal", CamelCase.Convert(columnReferenceNode.ColumnId)))),
                                                                new CodeVariableReferenceExpression(tileVariableName)));

                    // This indexer will keep the variable names distinct for each column.
                    tileIndex++;
                }

                // Each row can have one or more relationship to child rows that are specified in the 'ApplyTemplate' node.  This
                // specification works very similar to the XSL analog in that it traces through the child nodes seeing if there are
                // any templates that can be applied.
                int childIndex = 0;
                foreach (DataTransform.ApplyTemplateNode applyTemplateNode in rowNode.ApplyTemplates)
                {
                    // It's possible for debugging to include a 'False' row filter, which would remove all the children from the
                    // applied templates.  Unfortunately, an expression that always evaluates to 'False' will result in a warning
                    // about unreachable code.  This will remove the entire reference to the children when the row filter
                    // expression is 'False'.
                    if (applyTemplateNode.RowFilter.ToLower() != bool.FalseString.ToLower())
                    {
                        //						// This will add the child relations for this row to the document.
                        //						MarkThree.Forms.ViewerTable workingOrderTable = new MarkThree.Forms.ViewerTable();
                        //						for (int rowIndex = 0; (rowIndex < SimulatedDatabase.WorkingOrder.Count); rowIndex = (rowIndex + 1))
                        //						{
                        //							SimulatedDatabase.WorkingOrderRow workingOrderRow = SimulatedDatabase.WorkingOrder[rowIndex];
                        //							if (workingOrderRow.StatusCode != 6)
                        //							{
                        //								this.WorkingOrderTemplate(workingOrderTable, workingOrderRow);
                        //							}
                        //						}
                        this.Statements.Add(new CodeCommentStatement("This will add the child relations for this row to the document."));
                        string tableVariableName = string.Format("{0}Table", CamelCase.Convert(applyTemplateNode.Select));
                        this.Statements.Add(new CodeVariableDeclarationStatement(typeof(ViewerTable), tableVariableName, new CodeObjectCreateExpression(typeof(ViewerTable))));
                        CodeExpression childRows = isRootTemplate ?
                                                   (CodeExpression) new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.Source), applyTemplateNode.Select) :
                                                   (CodeExpression) new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeArgumentReferenceExpression(rowVariableName), string.Format("Get{0}Rows", applyTemplateNode.Select)));
                        string                  countingMember          = isRootTemplate ? "Count" : "Length";
                        CodeStatement           initializationStatement = new CodeVariableDeclarationStatement(typeof(int), "rowIndex", new CodePrimitiveExpression(0));
                        CodeExpression          testExpression          = new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("rowIndex"), CodeBinaryOperatorType.LessThan, new CodeFieldReferenceExpression(childRows, countingMember));
                        CodeStatement           incrementStatement      = new CodeAssignStatement(new CodeVariableReferenceExpression("rowIndex"), new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression("rowIndex"), CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1)));
                        CodeStatementCollection iterationBody           = new CodeStatementCollection();
                        string                  childRowName            = CamelCase.Convert(string.Format("{0}Row", applyTemplateNode.Select));
                        iterationBody.Add(new CodeVariableDeclarationStatement(new CodeTypeReference(string.Format("{0}.{1}Row", dataTransform.Source, applyTemplateNode.Select)), childRowName, new CodeIndexerExpression(childRows, new CodeVariableReferenceExpression("rowIndex"))));
                        if (applyTemplateNode.RowFilter == string.Empty)
                        {
                            iterationBody.Add(new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), string.Format("{0}Template", applyTemplateNode.Select), new CodeVariableReferenceExpression(tableVariableName), new CodeVariableReferenceExpression(childRowName))));
                        }
                        else
                        {
                            iterationBody.Add(new CodeConditionStatement(new CodeSnippetExpression(applyTemplateNode.RowFilter), new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), string.Format("{0}Template", applyTemplateNode.Select), new CodeVariableReferenceExpression(tableVariableName), new CodeVariableReferenceExpression(childRowName)))));
                        }
                        CodeStatement[] iterationArray = new CodeStatement[iterationBody.Count];
                        iterationBody.CopyTo(iterationArray, 0);
                        this.Statements.Add(new CodeIterationStatement(initializationStatement, testExpression, incrementStatement, iterationArray));
                        if (applyTemplateNode.Sorts.Count > 0)
                        {
                            this.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression(tableVariableName), "Sort", new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), string.Format("{0}RowComparer", CamelCase.Convert(applyTemplateNode.Select)))));
                        }

                        //						// The child table is associated to the parent row here.
                        //						viewerRow0.Children[0] = workingOrderTable;
                        this.Statements.Add(new CodeCommentStatement("The child table is associated to the parent row here."));
                        this.Statements.Add(new CodeAssignStatement(new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(viewerRowVariableName), "Children"), new CodePrimitiveExpression(childIndex)), new CodeVariableReferenceExpression(tableVariableName)));
                    }
                }

                //				// The child rows are added to the parent tables when they've been built.  In this way the hierarchical document is
                //				// built.
                //				viewerTable.Add(viewerRow0);
                this.Statements.Add(new CodeCommentStatement("The child rows are added to the parent tables when they've been built.  In this way the hierarchical document is"));
                this.Statements.Add(new CodeCommentStatement("built."));
                this.Statements.Add(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression("viewerTable"), "Add", new CodeVariableReferenceExpression(viewerRowVariableName)));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a CodeDOM method to compare two rows of a document for the purpose of sorting.
        /// </summary>
        /// <param name="templateNode">Contains the specification for the template.</param>
        public SortCompareMethod(DataTransform.ApplyTemplateNode applyTemplateNode)
        {
            // The sort works very efficiently by examining the tiles using the column ordinals as indices into the row.  The View
            // class defines these ordinals as public constants.
            DataTransform dataTransform = applyTemplateNode.TopLevelNode as DataTransform;

            //			#region IComparer<ViewerRow> Members
            this.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "IComparer<ViewerRow> Members"));

            //		// <summary>
            //		// Compares a row with another row using the column values to determine the order.
            //		// </summary>
            //		// <param name="x">The first row to be compared.</param>
            //		// <param name="y">The second row to be compared.</param>
            //		// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
            //		public virtual int Compare(MarkThree.Forms.ViewerRow x, MarkThree.Forms.ViewerRow y)
            //		{
            this.Comments.Add(new CodeCommentStatement(@"<summary>"));
            this.Comments.Add(new CodeCommentStatement(@"Compares a row with another row using the column values to determine the order."));
            this.Comments.Add(new CodeCommentStatement(@"</summary>"));
            this.Comments.Add(new CodeCommentStatement(@"<param name=""x"">The first row to be compared.</param>"));
            this.Comments.Add(new CodeCommentStatement(@"<param name=""y"">The second row to be compared.</param>"));
            this.Comments.Add(new CodeCommentStatement(@"<returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>"));
            this.Attributes = MemberAttributes.Public;
            this.ReturnType = new CodeTypeReference(typeof(int));
            this.Name       = "Compare";
            this.Parameters.Add(new CodeParameterDeclarationExpression(typeof(ViewerRow), "x"));
            this.Parameters.Add(new CodeParameterDeclarationExpression(typeof(ViewerRow), "y"));

            //			// The order of the comparison determines whether the rows are sorted in ascending order or descending.  If the values
            //			// compared in one set of tiles is equal, then the next set of tiles in the sort order will be compared.
            //			MarkThree.Forms.ViewerTile xTile0 = ((MarkThree.Forms.ViewerTile)(x.Tile[PrototypeView.symbolIndex]));
            //			MarkThree.Forms.ViewerTile yTile0 = ((MarkThree.Forms.ViewerTile)(y.Tile[PrototypeView.symbolIndex]));
            //			int compare0 = xTile0.CompareTo(yTile0);
            //			if ((compare0 != 0))
            //			{
            //				return compare0;
            //			}
            //			return ((IComparable)y.Data[PrototypeView.sourceOrderQuantityIndex]).CompareTo(x.Data[PrototypeView.sourceOrderQuantityIndex]);
            this.Statements.Add(new CodeCommentStatement("The order of the comparison determines whether the rows are sorted in ascending order or descending.  If the values"));
            this.Statements.Add(new CodeCommentStatement("compared in one set of tiles is equal, then the next set of tiles in the sort order will be compared."));
            for (int index = 0; index < applyTemplateNode.Sorts.Count; index++)
            {
                DataTransform.SortNode sortNode = applyTemplateNode.Sorts[index];
                string columnReference          = string.Format("{0}Index", CamelCase.Convert(sortNode.Column.ColumnId));
                string operand1 = sortNode.Direction == SortOrder.Ascending ? "x" : "y";
                string operand2 = sortNode.Direction == SortOrder.Ascending ? "y" : "x";
                if (index != applyTemplateNode.Sorts.Count - 1)
                {
                    string compareVariableName = string.Format("compare{0}", index);
                    this.Statements.Add(new CodeVariableDeclarationStatement(typeof(int), compareVariableName, new CodeMethodInvokeExpression(new CodeCastExpression(typeof(IComparable),
                                                                                                                                                                     new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(operand1), "Data"),
                                                                                                                                                                                               new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), columnReference))), "CompareTo",
                                                                                                                                              new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(operand2), "Data"),
                                                                                                                                                                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), columnReference)))));
                    this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression(compareVariableName), CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(0)), new CodeMethodReturnStatement(new CodeVariableReferenceExpression(compareVariableName))));
                }
                else
                {
                    this.Statements.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression(new CodeCastExpression(typeof(IComparable),
                                                                                                                            new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(operand1), "Data"),
                                                                                                                                                      new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), columnReference))), "CompareTo",
                                                                                                     new CodeIndexerExpression(new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(operand2), "Data"),
                                                                                                                               new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(dataTransform.DataTransformId), columnReference)))));
                }
            }

            //		#endregion
            this.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a constructor for a class that transforms abstract data into a human read-able document.
        /// </summary>
        public DataTransformConstructor(DataTransform dataTransform)
        {
            //		/// <summary>
            //		/// Create a view of the data.
            //		/// </summary>
            //		public PrototypeView(MarkThree.Forms.DocumentViewer documentViewer) :
            //				base(documentViewer)
            //		{
            this.Comments.Add(new CodeCommentStatement("<summary>", true));
            this.Comments.Add(new CodeCommentStatement("Create a view of the data.", true));
            this.Comments.Add(new CodeCommentStatement("</summary>", true));
            this.Attributes = MemberAttributes.Public;
            this.Parameters.Add(new CodeParameterDeclarationExpression(typeof(MarkThree.Forms.DocumentViewer), "documentViewer"));
            this.BaseConstructorArgs.Add(new CodeArgumentReferenceExpression("documentViewer"));

            // Initialize the comparers with instances of the comparison classes.
            //			// These objects are used to sort the rows.
            //			this.workingOrderRowComparer = new WorkingOrderRowComparer();
            //			this.sourceOrderRowComparer = new SourceOrderRowComparer();
            //			this.destinationOrderRowComparer = new DestinationOrderRowComparer();
            //			this.executionRowComparer = new ExecutionRowComparer();
            bool isFirstComparer = true;

            foreach (DataTransform.TemplateNode templateNode in dataTransform.Templates)
            {
                foreach (DataTransform.RowNode rowNode in templateNode.Rows)
                {
                    foreach (DataTransform.ApplyTemplateNode applyTemplateNode in rowNode.ApplyTemplates)
                    {
                        if (applyTemplateNode.Sorts.Count != 0)
                        {
                            string comparerName = CamelCase.Convert(applyTemplateNode.Select) + "RowComparer";
                            CodeAssignStatement codeAssignmentStatement = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), comparerName), new CodeObjectCreateExpression(applyTemplateNode.Select + "RowComparer", new CodeExpression[] { }));
                            if (isFirstComparer)
                            {
                                isFirstComparer = false;
                                this.Statements.Add(new CodeCommentStatement("These objects are used to sort the rows."));
                            }
                            this.Statements.Add(codeAssignmentStatement);
                        }
                    }
                }
            }

            // The 'Variable' table is a cache where objects that require significan resources (e.g. Bitmaps) can be kept.  The
            // idea is to generate them once and store them in the variable table.  Any reference to the variable after that will
            // pick up the copy stored in the hash table instead of generating the object at the time it is referenced.
            //			// Initialize the global variables
            //			if (!this.variables.ContainsKey("WorkingStatusHeaderImage"))
            //				this.variables.Add("WorkingStatusHeaderImage", new Bitmap(new MemoryStream(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALEQAACxEBf2RfkQAAAelJREFUOE+t0t9PUmEYB3C778/of2htuTBZZ24ao5GWKMrRA5wDIqCw+JEdDCkMGd20+GUoDQ+r7ALxQoaLETdsLBZ3navGRRPWYnLvtyNObl6nY/O9eS/e5/28z/O8z8DAda1IJMLHE5tHoVCwYzVrM4FV49hLDyNbeUaPuO3ad163XvQ46CPX8qxo5SY+Ee9ms9k/nU4H2x93sWSdQWjdguArM/w8B6+HxQvnHIJrJoQ3LFhenPxHAIIg/Gg2mwi/jYLVT3QDw28sWFvRw76o7gLrvjPAzI7/JoBEIrHfbrfxPrINHfOkB/ie6wiAnVP+JIBoNLrZarWQ3BLAzD+9FKCnRr8TQCwW8zcaDezsfJEAtdQDc7eE8wx413yvB5OqB/sEkEwmF0RRxO7XPakEDTYCC70eOCxTcNtn4FrS4LWPg+rhfYEAUqnU43q9jr3cATgDDb/XgIDPCOkbYdKpQKtHt6bHRyi1ijJI++2LMhisVqs4PPwGhmGgHBv+zNGPOEajMLBa5ZB04calM5fJZG6VSiWUy2VwRhPu3B3i+xrSXC53s1AonFQqFdhsNshksnBfwGlwsVg8rtVqcDqdkMvlH/oG8vn8L2mB53lQFEXO+1ViOp12xOPxv1IJdYVCce+q+Gs5/w/Ocy+mFPCPZQAAAABJRU5ErkJggg=="))));
            //			if (!this.variables.ContainsKey("SubmittedStatusHeaderImage"))
            //				this.variables.Add("SubmittedStatusHeaderImage", new Bitmap(new MemoryStream(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAAK7wAACu8BfXaKSAAAAf5JREFUOE+1UzmLmkEY3qQNKdKnTLN/ImkEtxAVb/G+L7wPVFDBY1HwBFHRKCooaiGiVmJj9j+ks0iRcgkEwrIu2SczU4TAZ8AU+WAY+Gae433ed66u/sfndrvfmc3m7mAwODqdztLFGqlUSjwejz/tdrufBPwsl8shkUiMfxC8+CuZ3W5/tdlsvubzefD5fNzc3EAgEEAoFH5Uq9Xvs9lsJRqNHj0ez9uzJCaTybrdbk88Hg8ikQhUXSaTIRQKodVqYTKZoNPpgJR3r9frrzkkuVzuczweZyCVSgWfz4dut4v5fI7RaIR2u41arQbihJ5/5xAkk8mnu7s7rNdrFAoFGAwGHA4HNBoNNJtNVCoVBAIB9l+pVD5xCIj6IykBy+USi8WCEZFMsN/vEQ6HYbPZ2CLdoQ64BLFY7HG1WmE2m2E4HLK6q9UqSHAMSEJmO8nqvINIJPIwnU4ZuNfrMduUIJFIMDBdFosFRqMRCoWC68Dv9z/0+32WNAXTwEqlEogzWK3W32CdTkc7xCXwer0/qO16vY5yuYxisQg6E8FgkAVHFwVrNBraqRMnRKKydblcp0wmw5Rpu9LpNMjgMJBWq2XtJfa/kP3D2WEiIb0hF29J0keHw/FM6ydvgYZGgd/ImZmM9suL3gZRuZZKpUMCvBeLxbeE5PVFwH+99Auih0hpPDuhBAAAAABJRU5ErkJggg=="))));
            //			if (!this.variables.ContainsKey("IsInstitutionMatchHeaderImage"))
            //				this.variables.Add("IsInstitutionMatchHeaderImage", new Bitmap(new MemoryStream(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALEQAACxEBf2RfkQAAAlxJREFUOE+tU91L2lEYbu2DYH9EN7v1avcTwQoaSqCQmmL5XZafCyWFNMWPQFekDrZyhmYUjSDoIvFGhl7oxcb0ShAm1uVw93M8e8+BJHGX/eBwfpxz3ud9n+d534mJx/rsdvtzlUr14h7P6XS+XF9fr6+trW0/zLG4uPg0EAg8GclrNBqfuVyuKj3+oVQqp9jl1tbWe4vFgpWVlT8mk+k1O6PAKYfD8c1sNt+IRKLJIQgdbttsNvYYGo0mbbVa1QQ4cLvd0Ov1kMvl3zc2Nt5sbm6m7t8tLS29GwLQ5W0sFgPt0Gq1oErg8/n4YmfLy8ugrGAVhUIhEDXIZLKfQ4BIJFJMp9O4urrCYDDA2dkZut0uTk9PEY1GIRQKodPpsLCwgMvLS5BemJub+zAEODg4+MgADg8P0e/3kcvl0Ov1sL+/zzNKpVK+Ez0cHR2BUSPQ2BAgmUya2MXx8THu7u7QbrfRarXQaDRA1YGE5RUwCsFgEOQESETFQwqT4XD4S71eR6fTQbPZ5MGlUgkkMMglrgv7Z6LOzs5+ouBRK3d3dwOVSgXVahWZTAa1Wg3n5+fcGXKFB3s8Hi7mzMyMdaz/CMBbLpfB3FCr1SgWi1zE1dVVkKU82O/3cxpisVg3BhCPx+3X19dIJBI86OTkBPl8nmf2er18MRrsjvgrxwAos/ni4gJ7e3tc5UKhgGw2ywOpA/liYKw6Ang7BkBWvtrZ2alQwG9qlF+pVIpbxpqJ+U5z8nd+fv6G/HcLBILhzPx3FonztMFg+EwdeKtQKL5S1zkkEsn0Yw3uCM4/B7t+5RBCaBIAAAAASUVORK5CYII="))));
            //			if (!this.variables.ContainsKey("IsBrokerMatchHeaderImage"))
            //				this.variables.Add("IsBrokerMatchHeaderImage", new Bitmap(new MemoryStream(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALEQAACxEBf2RfkQAAAd9JREFUOE/NUrur0mEYPhGnPfoXWs4gR0xFRLzkAf0hKnjFW97FRXTQwRsI4eAVQRAX0RBxCYMwBMstxHQQN4eWGmoIaqkzHOo8vd8PklryTNEHH9/yvs/33E5O/uuTTqe5fD7/mu7nVCr1IxKJXDmdzo8Gg+GVUqm8OJAPBAK3m82mtN1u3/9d0WAw+LDdbjGdTtHr9VCpVJDJZODz+aDRaL4cZovF4svFYoHhcHjdaDTmhUKBK5VKt4jBi263i1wuh2AwCJvNBo7j2DIUCsXTA0AoFLqs1+uYzWbY7XZgYK1W6y1RfpxMJj91Oh34/X4QdajVaqhUqq1QKDw9ALhcrpLdbr/2er2IxWKo1WqYz+dYLpfY7/dYr9eoVquIRqOwWq08A6lU+uiPAD0ezwWBFMikvtvtfkOgl/F4HKvVimfEpJCRcDgc0Gq1EIvFob82QKfT3SG9TyaTCfr9PsgnkCRYLBZehkgkMh6tEKVzzn5mCWSzWZBXMJvNzEAG8OAoAMm6m0gkvpbLZf73X/qJ/jeBQHDvJgD2zWaD8XiMcDgMo9HI65fJZIxB4CgAZX9Gffg+Go1AL98F1gOJRHIll8vPjwKwAZPJ9JDyf6bX699Rfd/T8nO6yhst/5Ohn3dZ+oOFdumLAAAAAElFTkSuQmCC"))));
            //			if (!this.variables.ContainsKey("IsHedgeMatchHeaderImage"))
            //				this.variables.Add("IsHedgeMatchHeaderImage", new Bitmap(new MemoryStream(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAAK7wAACu8BfXaKSAAAAklJREFUOE+tUzlPclEQ9RfSU7mEYEGDkJAQqCwgoTZIVISwKKtLYWiFAuKnEKQg7AGCIJDHvis538zNJ3z0vmTy7n3vzjkz59zZ2/uNx+FwdAOBwMrn8829Xu/U7XaPKQYul0vif06n8/P6+rp5dXXVsNvtNVpXbDbbnw233+9v4d+zWq3QaDSwXq9FFItF8Lflcol8Po/FYoGzszMQ2HwDQMyfnP/9/S0O1Go1kfD19SWS5vM5RqMRCoUCgsEg5HI5Li8vtwAej6dTLpdRrVbx/v4OhUIBg8GAer0OjUaDaDSKXq+HSCSCg4MDce7+/n61qYBQu1wB9QWZTIZQKASj0QjSAMfHx7BYLHh8fBTMr6+vGA6HXMkWgDSQDg8PodPpRKkfHx+YTqc4OTkRYFqtFiqVCuFwGP1+X/x7eHjYAejF43FRcqvVQi6XE+IxwP7+PqxWK05PT3FzcyM0YDCqcKsBWddn4UqlEiqVCrLZLMxmM1KpFF5eXtBsNpFIJHB0dASyl9lxfn4+/d+F4Ww2w2AwQLvdFokmkwmTyQSZTEYIyPH29ibe3AZVstgA3N7ejhmAE5hNrVbj6elJ7NPpNLrdLjqdjgDmFpmEcrYAZOOE7WPBlEol9Ho9np+fBXssFhPWMhDbyW/eUys7AFP2nstmj1kLSZIEczKZFIzMzBayQ7zeqYBsnLN4XCa3wLfvp1dmZDDe8/rnDAm/rYDvNV2aFQ3NjAZlTAMzoJDoe+fi4qJJ0aBLViXlKxQFsjVJ83D3G4O89xeGEXGAvz4xDAAAAABJRU5ErkJggg=="))));
            bool isFirstVariable = true;

            foreach (DataTransform.VariableNode variableNode in dataTransform.Variables)
            {
                if (isFirstVariable)
                {
                    isFirstVariable = false;
                    this.Statements.Add(new CodeCommentStatement("Initialize the global variables"));
                }
                this.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "Variables"), "ContainsKey", new CodePrimitiveExpression(variableNode.Name)), CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(false)),
                                                               new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeFieldReferenceExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "documentViewer"), "Variables"), "Add"), new CodePrimitiveExpression(variableNode.Name), new CodeSnippetExpression(variableNode.Select)))));
            }
        }