Example #1
0
        public string Encode() => this.Encode(WorkflowSymbol.DefaultEncodingFormat); // default format

        /// <summary>
        /// Encodes the specified encoding format.
        /// </summary>
        /// <param name="encodingFormat">The encoding format.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="SerializationException"></exception>
        internal string Encode(EncodingFormat encodingFormat)
        {
            using var ms     = new MemoryStream();
            using var writer = new BinaryWriter(ms);
            if (this.checksum != null)
            {
                writer.Write((byte)(encodingFormat | EncodingFormat.Checksum));
                SymbolHelper.WriteEncodedInt32(writer, this.checksum.Length);
                writer.Write(this.checksum);
            }
            else
            {
                writer.Write((byte)encodingFormat);
            }
            switch (encodingFormat)
            {
            case EncodingFormat.Binary:
                this.Write(writer);
                break;

            case EncodingFormat.String:
                writer.Write(this.ToString());
                break;

            default:
                throw FxTrace.Exception.AsError(new SerializationException());
            }

            // Need to copy to a buffer to trim excess capacity.
            var buffer = new byte[ms.Length];

            Array.Copy(ms.GetBuffer(), buffer, ms.Length);
            return(Convert.ToBase64String(buffer));
        }
Example #2
0
 // Binary serializer
 void Write(BinaryWriter writer)
 {
     writer.Write(this.FileName ?? string.Empty);
     if (this.Symbols != null)
     {
         SymbolHelper.WriteEncodedInt32(writer, this.Symbols.Count);
         foreach (ActivitySymbol actSym in this.Symbols)
         {
             actSym.Write(writer);
         }
     }
     else
     {
         SymbolHelper.WriteEncodedInt32(writer, 0);
     }
 }
Example #3
0
 // Binary serializer.
 internal void Write(BinaryWriter writer)
 {
     SymbolHelper.WriteEncodedInt32(writer, this.StartLine);
     SymbolHelper.WriteEncodedInt32(writer, this.StartColumn);
     SymbolHelper.WriteEncodedInt32(writer, this.EndLine);
     SymbolHelper.WriteEncodedInt32(writer, this.EndColumn);
     if (this.QualifiedId != null)
     {
         SymbolHelper.WriteEncodedInt32(writer, this.QualifiedId.Length);
         writer.Write(this.QualifiedId, 0, this.QualifiedId.Length);
     }
     else
     {
         SymbolHelper.WriteEncodedInt32(writer, 0);
     }
 }