Esempio n. 1
0
        private async Task <bool> DeserializeTopSortAsync(Func <PipId, Pip, Task <bool> > handleDeserializedPip, PipRemapReader reader)
        {
            bool successful = true;

            m_totalPipsToDeserialize = reader.ReadInt32();
            var numberOfLayers = reader.ReadInt32();
            int totalPips      = 0;

            for (int layer = 0; layer < numberOfLayers; ++layer)
            {
                var deserializedPips = reader.ReadReadOnlyList((deserializer) => DeserializePipAndPipId(reader));

                totalPips += deserializedPips.Count;

                Task <bool>[] tasks = new Task <bool> [deserializedPips.Count];

                for (int i = 0; i < deserializedPips.Count; i++)
                {
                    var(pip, pipId) = deserializedPips[i];
                    tasks[i]        = HandleAndReportDeserializedPipAsync(handleDeserializedPip, pipId, pip);
                }

                successful &= (await Task.WhenAll(tasks)).All(x => x);
            }

            Contract.Assert(totalPips == m_totalPipsToDeserialize, "Unexpected number of deserialized pips");

            return(successful);
        }
Esempio n. 2
0
        private async Task <bool> DeserializeSeriallyAsync(Func <PipId, Pip, Task <bool> > handleDeserializedPip, PipRemapReader reader)
        {
            bool successful = true;

            m_totalPipsToDeserialize = reader.ReadInt32();
            for (int totalPipsRead = 0; totalPipsRead < m_totalPipsToDeserialize; totalPipsRead++)
            {
                var pip   = Pip.Deserialize(reader);
                var pipId = new PipId(reader.ReadUInt32());
                if (!await(handleDeserializedPip?.Invoke(pipId, pip)))
                {
                    successful = false;
                }

                Stats.Increment(pip, serialize: false);
            }

            return(successful);
        }
Esempio n. 3
0
        /// <summary>
        /// Deserializes a pip graph fragment and call the given handleDeserializedPip function on each pip deserialized.
        /// </summary>
        public bool Deserialize(
            AbsolutePath filePath,
            Func <PipGraphFragmentContext, PipGraphFragmentProvenance, PipId, Pip, bool> handleDeserializedPip = null,
            string fragmentDescriptionOverride = null)
        {
            Contract.Requires(filePath.IsValid);

            string fileName = filePath.ToString(m_pipExecutionContext.PathTable);

            using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (var reader = new PipRemapReader(m_pipExecutionContext, m_pipGraphFragmentContext, stream))
                {
                    string serializedDescription = reader.ReadNullableString();
                    FragmentDescription = (fragmentDescriptionOverride ?? serializedDescription) ?? filePath.ToString(m_pipExecutionContext.PathTable);
                    var provenance = new PipGraphFragmentProvenance(filePath, FragmentDescription);

                    m_totalPipsToDeserialize = reader.ReadInt32();

                    for (int i = 0; i < m_totalPipsToDeserialize; i++)
                    {
                        var pip = Pip.Deserialize(reader);

                        // Pip id is not deserialized when pip is deserialized.
                        // Pip id must be read separately. To be able to add a pip to the graph, the pip id of the pip
                        // is assumed to be unset, and is set when the pip gets inserted into the pip table.
                        // Thus, one should not assign the pip id of the deserialized pip with the deserialized pip id.
                        // Do not use reader.ReadPipId() for reading the deserialized pip id. The method reader.ReadPipId()
                        // remaps the pip id to a new pip id.
                        var pipId = new PipId(reader.ReadUInt32());

                        var success = handleDeserializedPip?.Invoke(m_pipGraphFragmentContext, provenance, pipId, pip);

                        if (success.HasValue & !success.Value)
                        {
                            return(false);
                        }

                        Stats.Increment(pip, serialize: false);
                    }
                }

            return(true);
        }
Esempio n. 4
0
        private async Task <bool> DeserializeSeriallyAsync(Func <PipId, Pip, Task <bool> > handleDeserializedPip, PipRemapReader reader)
        {
            bool successful = true;

            m_totalPipsToDeserialize = reader.ReadInt32();
            for (int totalPipsRead = 0; totalPipsRead < m_totalPipsToDeserialize; totalPipsRead++)
            {
                (Pip pip, PipId pipId) = DeserializePipAndPipId(reader);

                if (!await handleDeserializedPip(pipId, pip))
                {
                    successful = false;
                }

                Stats.Increment(pip, serialize: false);
            }

            return(successful);
        }
Esempio n. 5
0
        private async Task <bool> DeserializeTopSortAsync(Func <PipId, Pip, Task <bool> > handleDeserializedPip, PipRemapReader reader)
        {
            bool successful = true;

            m_totalPipsToDeserialize = reader.ReadInt32();
            int totalPipsRead = 0;

            while (totalPipsRead < m_totalPipsToDeserialize)
            {
                var deserializedPips = reader.ReadReadOnlyList <(Pip pip, PipId pipId)>((deserializer) =>
                {
                    var pip = Pip.Deserialize(reader);

                    // Pip id is not deserialized when pip is deserialized.
                    // Pip id must be read separately. To be able to add a pip to the graph, the pip id of the pip
                    // is assumed to be unset, and is set when the pip gets inserted into the pip table.
                    // Thus, one should not assign the pip id of the deserialized pip with the deserialized pip id.
                    // Do not use reader.ReadPipId() for reading the deserialized pip id. The method reader.ReadPipId()
                    // remaps the pip id to a new pip id.
                    var pipId = new PipId(reader.ReadUInt32());
                    return(pip, pipId);
                });

                totalPipsRead += deserializedPips.Count;
                Task <bool>[] tasks = new Task <bool> [deserializedPips.Count];

                for (int i = 0; i < deserializedPips.Count; i++)
                {
                    var deserializedPip = deserializedPips[i];
                    tasks[i] = HandleAndReportDeserializedPipAsync(handleDeserializedPip, deserializedPip.pipId, deserializedPip.pip);
                }

                successful &= (await Task.WhenAll(tasks)).All(x => x);
            }

            return(successful);
        }
Esempio n. 6
0
        private bool DeserializeTopSort(Func <PipId, Pip, bool> handleDeserializedPip, PipRemapReader reader)
        {
            bool successful = true;

            m_totalPipsToDeserialize = reader.ReadInt32();
            int totalPipsRead = 0;

            while (totalPipsRead < m_totalPipsToDeserialize)
            {
                var deserializedPips = reader.ReadReadOnlyList <(Pip, PipId)>((deserializer) =>
                {
                    var pip = Pip.Deserialize(reader);

                    // Pip id is not deserialized when pip is deserialized.
                    // Pip id must be read separately. To be able to add a pip to the graph, the pip id of the pip
                    // is assumed to be unset, and is set when the pip gets inserted into the pip table.
                    // Thus, one should not assign the pip id of the deserialized pip with the deserialized pip id.
                    // Do not use reader.ReadPipId() for reading the deserialized pip id. The method reader.ReadPipId()
                    // remaps the pip id to a new pip id.
                    var pipId = new PipId(reader.ReadUInt32());
                    return(pip, pipId);
                });
                totalPipsRead += deserializedPips.Count;

                Parallel.ForEach(deserializedPips, new ParallelOptions(), deserializedPip =>
                {
                    if (!(handleDeserializedPip?.Invoke(deserializedPip.Item2, deserializedPip.Item1)).Value)
                    {
                        successful = false;
                    }

                    Stats.Increment(deserializedPip.Item1, serialize: false);
                });
            }

            return(successful);
        }