Exemplo n.º 1
0
        /// <summary>
        /// Prepares a pip to be serialized.
        /// </summary>
        /// <param name="pip"></param>
        /// <param name="pathTable"></param>
        /// <param name="stringTable"></param>
        /// <param name="symbolTable"></param>
        /// <param name="pipGraph"></param>
        /// <returns>Serialized Pip object.</returns>
        public static SerializedPip CreateObjectForSerialization(Pip pip, PathTable pathTable, StringTable stringTable, SymbolTable symbolTable, PipGraph pipGraph)
        {
            SerializedPip serializedPip = new SerializedPip
            {
                PipMetaData = CreatePipMetadata(pip, pathTable, stringTable, pipGraph, symbolTable)
            };

            switch (pip.PipType)
            {
            case PipType.CopyFile:
                serializedPip.CopyFileSpecificDetails = CreateCopyFileSpecificDetails((CopyFile)pip, pathTable);
                break;

            case PipType.Process:
                serializedPip.ProcessSpecificDetails = CreateProcessSpecificDetails((Process)pip, pathTable, stringTable);
                break;

            case PipType.Ipc:
                serializedPip.IpcSpecificDetails = CreateIpcSpecificDetails((IpcPip)pip, pathTable, stringTable);
                break;

            case PipType.Value:
                serializedPip.ValueSpecificDetails = CreateValueSpecificDetails((ValuePip)pip, pathTable, symbolTable);
                break;

            case PipType.SpecFile:
                serializedPip.SpecFileSpecificDetails = CreateSpecFileSpecificDetails((SpecFilePip)pip, pathTable);
                break;

            case PipType.Module:
                serializedPip.ModuleSpecificDetails = CreateModuleSpecificDetails((ModulePip)pip, pathTable, stringTable);
                break;

            case PipType.HashSourceFile:
                serializedPip.HashSourceFileSpecificDetails = CreateHashSourceFileSpecificDetails((HashSourceFile)pip, pathTable);
                break;

            case PipType.SealDirectory:
                serializedPip.SealDirectorySpecificDetails = CreateSealDirectorySpecificDetails((SealDirectory)pip, pathTable);
                break;

            case PipType.WriteFile:
                serializedPip.WriteFileSpecificDetails = CreateWriteFileSpecificDetails((WriteFile)pip, pathTable);
                break;

            default:
                Contract.Assert(false, $"Specified pip type '{pip.PipType}' does not match any known pip types.");
                break;
            }

            return(serializedPip);
        }
        /// <summary>
        /// Prepares a pip to be serialized.
        /// </summary>
        /// <param name="pip"></param>
        /// <param name="dynamicData"></param>
        /// <param name="pathTable"></param>
        /// <param name="stringTable"></param>
        /// <param name="symbolTable"></param>
        /// <param name="pipGraph"></param>
        /// <returns>Serialized Pip object.</returns>
        public static SerializedPip CreateObjectForSerialization(Pip pip, ProcessExecutionMonitoringReportedEventData?dynamicData, PathTable pathTable, StringTable stringTable, SymbolTable symbolTable, PipGraph pipGraph)
        {
            SerializedPip serializedPip = new SerializedPip
            {
                PipMetaData = CreatePipMetadata(pip, pathTable, stringTable, pipGraph, symbolTable)
            };

            switch (pip.PipType)
            {
            case PipType.CopyFile:
                serializedPip.CopyFileSpecificDetails = CreateCopyFileSpecificDetails((CopyFile)pip, pathTable);
                break;

            case PipType.Process:
                serializedPip.ProcessSpecificDetails = CreateProcessSpecificDetails((Process)pip, pathTable, stringTable, pipGraph);
                break;

            case PipType.Ipc:
                serializedPip.IpcSpecificDetails = CreateIpcSpecificDetails((IpcPip)pip, pathTable, stringTable);
                break;

            case PipType.Value:
                serializedPip.ValueSpecificDetails = CreateValueSpecificDetails((ValuePip)pip, pathTable, symbolTable);
                break;

            case PipType.SpecFile:
                serializedPip.SpecFileSpecificDetails = CreateSpecFileSpecificDetails((SpecFilePip)pip, pathTable);
                break;

            case PipType.Module:
                serializedPip.ModuleSpecificDetails = CreateModuleSpecificDetails((ModulePip)pip, pathTable, stringTable);
                break;

            case PipType.HashSourceFile:
                serializedPip.HashSourceFileSpecificDetails = CreateHashSourceFileSpecificDetails((HashSourceFile)pip, pathTable);
                break;

            case PipType.SealDirectory:
                serializedPip.SealDirectorySpecificDetails = CreateSealDirectorySpecificDetails((SealDirectory)pip, pathTable);
                break;

            case PipType.WriteFile:
                serializedPip.WriteFileSpecificDetails = CreateWriteFileSpecificDetails((WriteFile)pip, pathTable);
                break;

            default:
                Contract.Assert(false, $"Specified pip type '{pip.PipType}' does not match any known pip types.");
                break;
            }

            if (dynamicData.HasValue)
            {
                if (dynamicData.Value.ReportedProcesses != null && dynamicData.Value.ReportedProcesses.Count > 0)
                {
                    serializedPip.ReportedProcesses = new List <ReportedProcessData>();
                    foreach (var reportedProcess in dynamicData.Value.ReportedProcesses)
                    {
                        serializedPip.ReportedProcesses.Add(CreateReportedProcessData(reportedProcess));
                    }
                }

                if (dynamicData.Value.ReportedFileAccesses != null && dynamicData.Value.ReportedFileAccesses.Count > 0)
                {
                    serializedPip.ReportedFileAccesses = new List <ReportedFileAccessData>();
                    foreach (var reportedFileAccess in dynamicData.Value.ReportedFileAccesses)
                    {
                        serializedPip.ReportedFileAccesses.Add(CreateReportedFileAccessData(reportedFileAccess, pathTable));
                    }
                }
            }

            return(serializedPip);
        }