コード例 #1
0
        /// <summary>
        /// Serialize blocks with entities with given serialization type
        /// </summary>
        /// <param name="container"></param>
        /// <param name="blocks"></param>
        /// <param name="type"></param>
        /// <param name="delimeter">Optional, only required for SerializationType: Text</param>
        /// <returns></returns>
        public XmlDocument Serialize(IExecutionContainer container, ShuffleBlocks blocks, SerializationType type, char delimeter)
        {
            container.StartSection("Serialize");
            XmlDocument xml = null;

            if (blocks.Count > 0)
            {
                SendLine(container, "Serializing {0} blocks with type {1}", blocks.Count, type);
                xml = new XmlDocument();
                XmlNode root = xml.CreateElement("ShuffleData");
                xml.AppendChild(root);
                XML.AppendAttribute(root, "Type", type.ToString());
                XML.AppendAttribute(root, "ExportTime", DateTime.Now.ToString("s"));
                switch (type)
                {
                case SerializationType.Full:
                case SerializationType.Simple:
                case SerializationType.SimpleWithValue:
                case SerializationType.SimpleNoId:
                case SerializationType.Explicit:
                    foreach (var block in blocks.Keys)
                    {
                        SendLine(container, $"Serializing {blocks[block].Count()} records in block {block}");
                        XmlNode xBlock = xml.CreateElement("Block");
                        root.AppendChild(xBlock);
                        XML.AppendAttribute(xBlock, "Name", block);
                        XML.AppendAttribute(xBlock, "Count", blocks[block].Count().ToString());

                        var xSerialized = blocks[block].Serialize(container, (SerializationStyle)type);
                        xBlock.AppendChild(xml.ImportNode(xSerialized.ChildNodes[0], true));
                    }
                    break;

                case SerializationType.Text:
                    XML.AppendAttribute(root, "Delimeter", delimeter.ToString());
                    var text = new StringBuilder();
                    foreach (var block in blocks.Keys)
                    {
                        SendLine(container, $"Serializing {blocks[block].Count()} records in block {block}");
                        text.AppendLine("<<<" + block + ">>>");
                        var serializedblock = blocks[block].ToTextFile(container, delimeter);
                        text.Append(serializedblock);
                    }
                    XML.AddCDATANode(root, "Text", text.ToString());
                    break;
                }
            }
            container.EndSection();
            return(xml);
        }
コード例 #2
0
 /// <summary>
 /// Specifies the <see cref="SerializationType"/> in the app.config.
 /// </summary>
 /// <param name="serializationType"></param>
 public static void SpecifySerializationType(SerializationType serializationType)
 {
     // TODO: Add exception.
     SetValue("serializationType", serializationType.ToString());
 }