Beispiel #1
0
        /// <summary>
        /// Serializes the specified writer.
        /// </summary>
        /// <param name="writer">
        /// The writer.
        /// </param>
        public void Serialize(UPSerializer writer)
        {
            int count = this.NumberOfRecordIds();

            writer.WriteElementStart("Row");
            writer.WriteAttributeValue("record", this.RecordIdentificationAtIndex(0));
            var serializationInfo = this.Result?.SerializationInfo;

            for (int i = 1; i < count; i++)
            {
                var recordIdentification = this.RecordIdentificationAtIndex(i);
                if (!string.IsNullOrEmpty(recordIdentification))
                {
                    writer.WriteAttributeValue(serializationInfo?.RecordIdAttributeAtIndex(i), recordIdentification);
                }
            }

            count = serializationInfo?.NumberOfColumns ?? 0;
            for (int i = 0; i < count; i++)
            {
                var value = this.ReportValueAtIndex(i);
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                var columnInfo          = serializationInfo?.ColumnInfoAtIndex(i);
                var attributeDictionary = columnInfo?.HasAttributes ?? false ? new Dictionary <string, string>(3) : null;
                var functionName        = columnInfo?.FunctionName;
                if (string.IsNullOrEmpty(functionName))
                {
                    attributeDictionary.SetObjectForKey(columnInfo?.IndexAttributeName, "idx");
                }

                if (columnInfo?.ReportRawValue ?? false)
                {
                    var rawValue = this.RawValueAtIndex(i);
                    attributeDictionary.SetObjectForKey(rawValue, "value");
                    if (columnInfo.ReportExternalKey)
                    {
                        var extKeyValue = columnInfo.ExternalKeyForRawValue(rawValue);
                        if (!string.IsNullOrEmpty(extKeyValue))
                        {
                            attributeDictionary.SetObjectForKey(extKeyValue, "extKey");
                        }
                    }
                }

                writer.WriteElementValueAttributes(
                    !string.IsNullOrEmpty(functionName) ? functionName : "Value",
                    value,
                    attributeDictionary);
            }

            writer.WriteElementEnd();
        }
        /// <summary>
        /// Serializes the name of the root element.
        /// </summary>
        /// <param name="writer">
        /// The writer.
        /// </param>
        /// <param name="rootElementName">
        /// Name of the root element.
        /// </param>
        public void SerializeRootElementName(UPSerializer writer, string rootElementName)
        {
            int count = this.RowCount;

            writer.WriteElementStart(rootElementName);
            writer.WriteAttributeValue("online", this.IsServer ? "true" : "false");
            writer.WriteElementStart("Rows");
            for (int i = 0; i < count; i++)
            {
                writer.WriteObject(this.ResultRowAtIndex(i) as UPSerializable);
            }

            writer.WriteElementEnd();
            if (this.MetaInfo != null)
            {
                var _serializationInfo = this.SerializationInfo;
                writer.WriteElementStart("Columns");
                count = _serializationInfo.NumberOfColumns;

                for (int i = 0; i < count; i++)
                {
                    var columnInfo = _serializationInfo.ColumnInfoAtIndex(i);
                    var label      = columnInfo.Label;
                    if (!string.IsNullOrEmpty(columnInfo.FunctionName))
                    {
                        writer.WriteElementValue(columnInfo.FunctionName, label);
                    }
                    else
                    {
                        var attributes = new Dictionary <string, string> {
                            { "idx", columnInfo.IndexAttributeName }
                        };
                        writer.WriteElementValueAttributes("Column", label, attributes);
                    }
                }

                writer.WriteElementEnd();
            }

            writer.WriteElementEnd();
        }