示例#1
0
 /// <summary>
 /// Creates a new RemapWriter
 /// </summary>
 public RemapWriter(Stream stream, PipExecutionContext context, PipGraphFragmentContext pipGraphFragmentContext, bool debug = false, bool leaveOpen = true, bool logStats = false)
     : base(debug, stream, leaveOpen, logStats)
 {
     m_inliningWriter = new InnerInliningWriter(stream, context.PathTable, debug, leaveOpen, logStats);
     m_symbolTable    = context.SymbolTable;
     m_context        = pipGraphFragmentContext;
 }
示例#2
0
 /// <summary>
 /// Create a new RemapReader
 /// </summary>
 public RemapReader(PipGraphFragmentContext fragmentContext, Stream stream, PipExecutionContext context, bool debug = false, bool leaveOpen = true)
     : base(debug, context.StringTable, stream, leaveOpen)
 {
     Context            = fragmentContext;
     m_executionContext = context;
     m_inliningReader   = new InnerInliningReader(stream, context.PathTable, debug, leaveOpen);
     m_symbolTable      = context.SymbolTable;
 }
示例#3
0
        /// <summary>
        /// Creates an instance of <see cref="PipGraphFragmentSerializer"/>.
        /// </summary>
        public PipGraphFragmentSerializer(PipExecutionContext pipExecutionContext, PipGraphFragmentContext pipGraphFragmentContext)
        {
            Contract.Requires(pipExecutionContext != null);
            Contract.Requires(pipGraphFragmentContext != null);

            m_pipExecutionContext     = pipExecutionContext;
            m_pipGraphFragmentContext = pipGraphFragmentContext;
        }
示例#4
0
        /// <summary>
        /// Create a new RemapReader
        /// </summary>
        public PipRemapReader(PipExecutionContext pipExecutionContext, PipGraphFragmentContext pipGraphFragmentContext, Stream stream, bool debug = false, bool leaveOpen = true)
            : base(debug, pipExecutionContext.StringTable, stream, leaveOpen)
        {
            Contract.Requires(pipExecutionContext != null);
            Contract.Requires(pipGraphFragmentContext != null);
            Contract.Requires(stream != null);

            m_pipExecutionContext               = pipExecutionContext;
            m_pipGraphFragmentContext           = pipGraphFragmentContext;
            m_inliningReader                    = new InliningReader(stream, pipExecutionContext.PathTable, debug, leaveOpen);
            m_pipDataEntriesPointerInlineReader = new PipDataEntriesPointerInlineReader(this, stream, pipExecutionContext.PathTable, debug, leaveOpen);
        }
示例#5
0
        /// <summary>
        /// Creates an instance of <see cref="PipRemapWriter"/>.
        /// </summary>
        public PipRemapWriter(PipExecutionContext pipExecutionContext, PipGraphFragmentContext pipGraphFragmentContext, Stream stream, bool debug = false, bool leaveOpen = true, bool logStats = false)
            : base(debug, stream, leaveOpen, logStats)
        {
            Contract.Requires(pipExecutionContext != null);
            Contract.Requires(pipGraphFragmentContext != null);
            Contract.Requires(stream != null);

            m_pipExecutionContext               = pipExecutionContext;
            m_pipGraphFragmentContext           = pipGraphFragmentContext;
            m_inliningWriter                    = new InliningWriter(stream, pipExecutionContext.PathTable, debug, leaveOpen, logStats);
            m_pipDataEntriesPointerInlineWriter = new PipDataEntriesPointerInlineWriter(m_inliningWriter, stream, pipExecutionContext.PathTable, debug, leaveOpen, logStats);
        }
示例#6
0
        /// <summary>
        /// Creates an instance of <see cref="PipRemapWriter"/>.
        /// </summary>
        public PipRemapWriter(PipExecutionContext pipExecutionContext, PipGraphFragmentContext pipGraphFragmentContext, Stream stream, bool leaveOpen = true, char alternateSymbolSeparator = default)
            : base(debug: false, stream, leaveOpen, logStats: false)
        {
            Contract.Requires(pipExecutionContext != null);
            Contract.Requires(pipGraphFragmentContext != null);
            Contract.Requires(stream != null);

            m_pipExecutionContext               = pipExecutionContext;
            m_pipGraphFragmentContext           = pipGraphFragmentContext;
            m_inliningWriter                    = new InliningWriter(stream, pipExecutionContext.PathTable, debug: false, leaveOpen, logStats: false);
            m_pipDataEntriesPointerInlineWriter = new PipDataEntriesPointerInlineWriter(this, stream, pipExecutionContext.PathTable, debug: false, leaveOpen, logStats: false);

            m_alternateSymbolSeparatorAsArray  = alternateSymbolSeparator != default ? new char[] { alternateSymbolSeparator } : new char[0];
            m_alternateSymbolSeparatorAsString = alternateSymbolSeparator != default ? alternateSymbolSeparator.ToString() : string.Empty;
        }
        /// <summary>
        /// Serialize list of pips to a file
        /// </summary>
        public void Serialize(string fragmentDescription, PipExecutionContext context, PipGraphFragmentContext pipFragmentContext, AbsolutePath filePath, IReadOnlyCollection <Pip> pipsToSerialize)
        {
            FragmentDescription = fragmentDescription;
            PipsSerialized      = 0;
            string fileName = filePath.ToString(context.PathTable);

            using (FileStream stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None))
                using (RemapWriter writer = new RemapWriter(stream, context, pipFragmentContext))
                {
                    writer.Write(pipsToSerialize.Count);
                    foreach (var pip in pipsToSerialize)
                    {
                        pip.Serialize(writer);
                        PipsSerialized++;
                    }
                }
        }
        /// <summary>
        /// Deserialize a pip graph fragment and call the given handleDeserializedPip function on each pip deserialized
        /// Returns true if successfully handled all pips.
        /// </summary>
        public bool Deserialize(string fragmentDescription, PipExecutionContext context, PipGraphFragmentContext pipFragmentContext, AbsolutePath filePath, Func <Pip, bool> handleDeserializedPip)
        {
            FragmentDescription = fragmentDescription;
            PipsDeserialized    = 0;
            string fileName = filePath.ToString(context.PathTable);

            using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (RemapReader reader = new RemapReader(pipFragmentContext, stream, context))
                {
                    TotalPips = reader.ReadInt32();
                    for (int i = 0; i < TotalPips; i++)
                    {
                        var pip     = Pip.Deserialize(reader);
                        var success = handleDeserializedPip?.Invoke(pip);
                        if (success.HasValue & !success.Value)
                        {
                            return(false);
                        }

                        PipsDeserialized++;
                    }
                }

            return(true);
        }