public void TryEnableCooker_NotKnown_False()
        {
            var sut    = Engine.Create();
            var cooker = new DataCookerPath("not-there-id");

            Assert.IsFalse(sut.TryEnableCooker(cooker));
        }
        public ISourceDataCooker <T, TContext, TKey> GetSourceDataCooker(DataCookerPath cookerPath)
        {
            Guard.NotNull(cookerPath, nameof(cookerPath));

            this.cookerById.TryGetValue(cookerPath, out var cooker);
            return(cooker);
        }
示例#3
0
 public Source3DataCooker(DataCookerPath dataCookerPath)
     : base(dataCookerPath)
 {
     this.Objects        = new List <Source3DataObject>();
     this.Source1Objects = new List <Source1DataObject>();
     this.Source2Objects = new List <Source2DataObject>();
 }
示例#4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="CookedDataReflector"/>
        ///     class with the given path.
        /// </summary>
        /// <param name="dataCookerPath">
        ///     The path to this cooker.
        /// </param>
        protected CookedDataReflector(DataCookerPath dataCookerPath)
        {
            var dataExtensionType = this.GetType();
            var properties        = dataExtensionType.GetProperties();

            foreach (var property in properties)
            {
                var dataAttribute = property.GetCustomAttribute <DataOutputAttribute>();
                if (dataAttribute == null)
                {
                    continue;
                }

                string dataIdentifier = dataAttribute.DataIdentifier;

                if (string.IsNullOrWhiteSpace(dataIdentifier))
                {
                    dataIdentifier = property.Name;
                }

                this.publicDataProperties.Add(new DataOutputPath(dataCookerPath, dataIdentifier), property);
            }

            this.OutputIdentifiers = new ReadOnlyCollection <DataOutputPath>(this.publicDataProperties.Keys.ToList());
        }
        /// <summary>
        ///     A composite cooker has access to source data cookers, as well as other composite data cookers.
        /// </summary>
        /// <param name="dataCookerPath">
        ///     Identifies the composite data cooker.
        /// </param>
        /// <returns>
        ///     A set of data uniquely tailored to this composite data cooker.
        /// </returns>
        public IDataExtensionRetrieval CreateDataRetrievalForCompositeDataCooker(
            DataCookerPath dataCookerPath)
        {
            var filteredData = this.dataRetrievalCache.GetCompositeDataCookerFilteredData(dataCookerPath);

            if (filteredData != null)
            {
                return(filteredData);
            }

            var compositeDataCookerReference = this.DataExtensionRepository.GetCompositeDataCookerReference(dataCookerPath);

            if (compositeDataCookerReference == null)
            {
                throw new ArgumentException("Data retrieval requested for data cooker not found in repository.");
            }

            if (compositeDataCookerReference.Availability != DataExtensionAvailability.Available)
            {
                throw new ArgumentException("Data retrieval requested for data cooker that is not available.");
            }

            filteredData = new FilteredDataRetrieval(this, compositeDataCookerReference.DependencyReferences);

            this.dataRetrievalCache.AddCompositeDataCookerFilteredData(dataCookerPath, filteredData);

            return(filteredData);
        }
        public void EnableCooker_NotKnown_Throws()
        {
            var sut    = Engine.Create();
            var cooker = new DataCookerPath("not-there-id");

            var e = Assert.ThrowsException <CookerNotFoundException>(() => sut.EnableCooker(cooker));

            Assert.AreEqual(cooker, e.DataCookerPath);
        }
        public ISourceDataCookerReference GetSourceDataCookerReference(DataCookerPath dataCookerPath)
        {
            if (this.sourceCookersByPath.TryGetValue(dataCookerPath, out var sourceCookerReference))
            {
                return(sourceCookerReference);
            }

            return(this.getSourceDataCooker?.Invoke(dataCookerPath));
        }
        internal void AddCompositeDataCookerFilteredData(DataCookerPath dataCookerPath, IDataExtensionRetrieval data)
        {
            Debug.Assert(data != null, nameof(data));

            lock (this.compositeCacheLock)
            {
                this.compositeDataCookerCache[dataCookerPath] = new System.WeakReference <IDataExtensionRetrieval>(data);
            }
        }
        /// <summary>
        ///     Enables the given cooker for processing when <see cref="Process"/>
        ///     is called.
        /// </summary>
        /// <param name="dataCookerPath">
        ///     The cooker to enable.
        /// </param>
        /// <exception cref="CookerNotFoundException">
        ///     <paramref name="dataCookerPath"/> is not known by this instance.
        ///     See <see cref="AllCookers"/>.
        /// </exception>
        /// <exception cref="InstanceAlreadyProcessedException">
        ///     This instance has already been processed.
        /// </exception>
        public void EnableCooker(DataCookerPath dataCookerPath)
        {
            this.ThrowIfProcessed();

            if (!this.TryEnableCooker(dataCookerPath))
            {
                throw new CookerNotFoundException(dataCookerPath);
            }
        }
            protected override void RunCore()
            {
                var expectedSourceCookerPath = new DataCookerPath("SourceId", "CookerId");

                var engine = Engine.Create();

                Assert.IsTrue(engine.CustomDataSources.Any());
                Assert.IsTrue(engine.CustomDataSources.Any(x => x is Source123DataSource));
                Assert.IsTrue(engine.SourceDataCookers.Any(x => x == expectedSourceCookerPath));
            }
        public void CreateDataRetrievalForCompositeDataCooker_MissingCookerThrows()
        {
            var cookedDataRetrieval     = new TestCookedDataRetrieval();
            var dataExtensionRepository = new TestDataExtensionRepository();

            var cookerPath = new DataCookerPath("CompositeCooker1");

            var dataExtensionRetrievalFactory =
                new DataExtensionRetrievalFactory(cookedDataRetrieval, dataExtensionRepository);

            Assert.ThrowsException <ArgumentException>(() =>
                                                       dataExtensionRetrievalFactory.CreateDataRetrievalForCompositeDataCooker(cookerPath));
        }
        public ISourceDataCookerReference GetSourceDataCookerReference(DataCookerPath dataCookerPath)
        {
            if (!this.sourceDataCookerReferencesByPath.TryGetValue(dataCookerPath, out var reference))
            {
                return(null);
            }
            if (!this.sourceDataCookerReferencesByPath.ContainsKey(dataCookerPath))
            {
                return(null);
            }

            return(this.sourceDataCookerReferencesByPath[dataCookerPath]);
        }
 /// <summary>
 ///     Attempts to get the direct cooker retrieval for the specified
 ///     cooker.
 /// </summary>
 /// <param name="cookerPath">
 ///     The path to the cooker to retrieve.
 /// </param>
 /// <param name="retrieval">
 ///     The found retrieval, if any.
 /// </param>
 /// <returns>
 ///     <c>true</c> if the cooker can be queried;
 ///     <c>false</c> otherwise.
 /// </returns>
 public bool TryGetCookedData(DataCookerPath cookerPath, out ICookedDataRetrieval retrieval)
 {
     try
     {
         retrieval = this.GetCookedData(cookerPath);
         return(true);
     }
     catch
     {
         retrieval = null;
         return(false);
     }
 }
        /// <summary>
        /// Constructor that takes a data cooker path.
        /// </summary>
        /// <param name="dataCookerPath">Identifies the required data cooker</param>
        public RequiresCookerAttribute(string dataCookerPath)
        {
            Guard.NotNullOrWhiteSpace(dataCookerPath, nameof(dataCookerPath));

            if (!DataCookerPath.IsWellFormed(dataCookerPath))
            {
                throw new ArgumentException($"{nameof(dataCookerPath)} is not a valid identifier.");
            }

            this.RequiredDataCookerPath = new DataCookerPath(
                DataCookerPath.GetSourceParserId(dataCookerPath),
                DataCookerPath.GetDataCookerId(dataCookerPath));
        }
示例#15
0
        public static void ProcessTrace()
        {
            lock (IsTraceProcessedLock)
            {
                if (!IsTraceProcessed)
                {
                    // Input data
                    string[] lttngData     = { @"..\..\..\..\TestData\LTTng\lttng-kernel-trace.ctf" };
                    var      lttngDataPath = new FileInfo(lttngData[0]);
                    Assert.IsTrue(lttngDataPath.Exists);

                    // Approach #1 - Engine - Doesn't test tables UI but tests processing
                    var runtime = Engine.Create();

                    runtime.AddFile(lttngDataPath.FullName);

                    // Enable our various types of data
                    var lttngGenericEventDataCooker = new LTTngGenericEventDataCooker();
                    LTTngGenericEventDataCookerPath = lttngGenericEventDataCooker.Path;
                    runtime.EnableCooker(LTTngGenericEventDataCookerPath);

                    var lttngSyscallDataCooker = new LTTngSyscallDataCooker();
                    LTTngSyscallDataCookerPath = lttngSyscallDataCooker.Path;
                    runtime.EnableCooker(LTTngSyscallDataCookerPath);

                    var lttngThreadDataCooker = new LTTngThreadDataCooker();
                    LTTngThreadDataCookerPath = lttngThreadDataCooker.Path;
                    runtime.EnableCooker(LTTngThreadDataCookerPath);

                    var lttngDmesgDataCooker = new LTTngDmesgDataCooker();
                    LTTngDmesgDataCookerPath = lttngDmesgDataCooker.Path;
                    runtime.EnableCooker(LTTngDmesgDataCookerPath);

                    var lttngModuleDataCooker = new LTTngModuleDataCooker();
                    LTTngModuleDataCookerPath = lttngModuleDataCooker.Path;
                    runtime.EnableCooker(LTTngModuleDataCookerPath);

                    var lttngDiskDataCooker = new LTTngDiskDataCooker();
                    LTTngDiskDataCookerPath = lttngDiskDataCooker.Path;
                    runtime.EnableCooker(LTTngDiskDataCookerPath);

                    //
                    // Process our data.
                    //

                    RuntimeExecutionResults = runtime.Process();

                    IsTraceProcessed = true;
                }
            }
        }
        public ICompositeDataCookerReference GetCompositeDataCookerReference(DataCookerPath dataCookerPath)
        {
            if (this.compositeCookersByPath.TryGetValue(dataCookerPath, out var cookerReference))
            {
                return(cookerReference);
            }

            if (this.getCompositeDataCooker != null)
            {
                return(this.getCompositeDataCooker.Invoke(dataCookerPath));
            }

            return(null);
        }
        /// <summary>
        ///     Attempts to get a data cooker reference given a data cooker path.
        /// </summary>
        /// <param name="self">
        ///     A data extension repository to search.
        /// </param>
        /// <param name="dataCookerPath">
        ///     A path to a data cooker.
        /// </param>
        /// <param name="cooker">
        ///     Receives the result: a data cooker reference, or <c>null</c> if not found.
        /// </param>
        /// <returns>
        ///     true if the path resulted in a data cooker reference; false otherwise.
        /// </returns>
        public static bool TryGetDataCookerReference(
            this IDataExtensionRepository self,
            DataCookerPath dataCookerPath,
            out IDataCookerReference cooker)
        {
            Guard.NotNull(self, nameof(self));

            cooker = self.GetSourceDataCookerReference(dataCookerPath);
            if (cooker is null)
            {
                cooker = self.GetCompositeDataCookerReference(dataCookerPath);
            }

            return(!(cooker is null));
        }
        /// <summary>
        ///     Attempts to enable the given cooker for processing when <see cref="Process"/>
        ///     is called.
        /// </summary>
        /// <param name="dataCookerPath">
        ///     The cooker to enable.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the cooker exists and can be enabled;
        ///     <c>false</c> otherwise. Note that <c>false</c> is
        ///     always returned when <see cref="IsProcessed"/> is <c>true</c>.
        /// </returns>
        public bool TryEnableCooker(DataCookerPath dataCookerPath)
        {
            if (this.IsProcessed)
            {
                return(false);
            }

            if (!this.AllCookers.Contains(dataCookerPath))
            {
                return(false);
            }

            this.enabledCookers.Add(dataCookerPath);
            return(true);
        }
        public DataCookerSchedulingNode GetSchedulingNode(
            DataCookerPath dataCookerPath)
        {
            if (this.dataCookerPathsToDataCookers.TryGetValue(dataCookerPath, out var dataCooker))
            {
                if (this.cookersToNodes.TryGetValue(dataCooker, out var schedulingNode))
                {
                    return(schedulingNode);
                }
            }

            // it's a bug if we've reached this
            // cookers that don't have all their requirements met shouldn't be enabled on a source session.
            //
            throw new InvalidOperationException(
                      $"A required cooker is not available for {dataCookerPath}");
        }
        internal IDataExtensionRetrieval GetCompositeDataCookerFilteredData(DataCookerPath dataCookerPath)
        {
            Debug.Assert(dataCookerPath != null, nameof(dataCookerPath));

            lock (this.compositeCacheLock)
            {
                if (this.compositeDataCookerCache.TryGetValue(dataCookerPath, out var filteredDataReference))
                {
                    if (filteredDataReference.TryGetTarget(out var filteredData))
                    {
                        return(filteredData);
                    }
                }
            }

            return(null);
        }
        /// <summary>
        ///     Gets the direct cooker retrieval for the specified
        ///     cooker.
        /// </summary>
        /// <param name="cookerPath">
        ///     The path to the cooker to retrieve.
        /// </param>
        /// <returns>
        ///     The interface to query for cooked data from said cooker.
        /// </returns>
        /// <exception cref="CookerNotFoundException">
        ///     <paramref name="cookerPath"/> does not represent a known cooker.
        /// </exception>
        public ICookedDataRetrieval GetCookedData(DataCookerPath cookerPath)
        {
            if (this.sourceCookers.Contains(cookerPath))
            {
                return(this.cookedDataRetrieval);
            }

            try
            {
                var cooker    = this.repository.GetCompositeDataCookerReference(cookerPath);
                var retrieval = this.retrievalFactory.CreateDataRetrievalForCompositeDataCooker(cookerPath);
                return(cooker.GetOrCreateInstance(retrieval));
            }
            catch (Exception e)
            {
                throw new CookerNotFoundException(cookerPath, e);
            }
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="BaseSourceDataCooker{T, TContext, TKey}"/>
 ///     class for the given cooker.
 /// </summary>
 /// </param>
 /// <param name="dataCookerPath">
 ///     This cooker's path.
 /// </param>
 protected BaseSourceDataCooker(DataCookerPath dataCookerPath)
     : base(dataCookerPath)
 {
     this.Path = dataCookerPath;
 }
示例#23
0
 public void AddRequiredCompositeDataCookerPath(DataCookerPath dataCookerPath)
 {
     this.requiredCompositeDataCookerPaths.Add(dataCookerPath);
 }
示例#24
0
 public void AddRequiredSourceDataCookerPath(DataCookerPath dataCookerPath)
 {
     this.requiredSourceDataCookerPaths.Add(dataCookerPath);
 }
 private WaLinuxAgentDataCooker(DataCookerPath dataCookerPath) : base(dataCookerPath)
 {
     Path = dataCookerPath;
 }
示例#26
0
 public ISourceDataCooker <T, TContext, TKey> GetSourceDataCooker(DataCookerPath cookerPath)
 {
     return(this.GetSourceDataCookerFunc?.Invoke(cookerPath));
 }
示例#27
0
 private DmesgIsoDataCooker(DataCookerPath dataCookerPath) : base(dataCookerPath)
 {
     Path = dataCookerPath;
 }
示例#28
0
 public Source4DataCooker(DataCookerPath dataCookerPath)
     : base(dataCookerPath)
 {
     this.Objects = new List <Source4DataObject>();
 }
示例#29
0
 /// <summary>
 ///     Specifies the given
 ///     cooker as required for this extension.
 /// </summary>
 /// <param name="cookerPath">
 ///     The cooker path.
 /// </param>
 protected void AddRequiredDataCooker(DataCookerPath cookerPath)
 {
     this.requiredDataCookers.Add(cookerPath);
 }
示例#30
0
 private AndroidLogcatDataCooker(DataCookerPath dataCookerPath) : base(dataCookerPath)
 {
     Path = dataCookerPath;
 }