Example #1
0
        /// <summary>
        ///     Attempts to get the default configuration from
        ///     the given collection of configurations.
        /// </summary>
        /// <param name="self">
        ///     The instance being operated upon.
        /// </param>
        /// <param name="configuration">
        ///     The default configuration in the collection, if
        ///     the default exists. <c>null</c> otherwise.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the default is retrieved;
        ///     <c>false</c> otherwise.
        /// </returns>
        public static bool TryGetDefaultConfiguration(
            this TableConfigurations self,
            out TableConfiguration configuration)
        {
            if (self is null)
            {
                configuration = null;
                return(false);
            }

            if (self.Configurations is null)
            {
                configuration = null;
                return(false);
            }

            var name = self.DefaultConfigurationName;

            configuration = null;
            foreach (var c in self.Configurations)
            {
                if (c is null)
                {
                    continue;
                }

                if (StringComparer.InvariantCulture.Equals(name, c.Name))
                {
                    configuration = c;
                    break;
                }
            }

            return(!(configuration is null));
        }
Example #2
0
        /// <summary>
        ///     Initializes a new Execution result for success case.
        /// </summary>
        /// <param name="context">
        ///     <see cref="ExecutionContext"/> from the processing state.
        /// </param>
        /// <param name="dataSourceInfo">
        ///     <see cref="DataSourceInfo"/> from the custom data source being processed.
        /// </param>
        /// <param name="dataSourceInfoFailure">
        ///     <see cref="Exception"/> for the processing state (if available).
        /// </param>
        /// <param name="processor">
        ///     <see cref="ICustomDataProcessor"/> associated to the processing state.
        /// </param>
        /// <param name="enableFailures">
        ///     Dictionary representing the failures for <see cref="TableDescriptor"/> (if any).
        /// </param>
        /// <param name="metadataName">
        ///     Name of the custom data source being processed.
        /// </param>
        /// <param name="builtMetadataTables">
        ///     Collection of <see cref="MetadataTableBuilder"/>.
        /// </param>
        /// <param name="metadataException">
        ///     <see cref="Exception"/> for creating metadata tables (if available).
        /// </param>
        public ExecutionResult(
            ExecutionContext context,
            DataSourceInfo dataSourceInfo,
            Exception dataSourceInfoFailure,
            ICustomDataProcessor processor,
            IDictionary <TableDescriptor, Exception> enableFailures,
            string metadataName,
            IEnumerable <MetadataTableBuilder> builtMetadataTables,
            Exception metadataException)
            : this(enableFailures, context.TablesToEnable)
        {
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(dataSourceInfo, nameof(dataSourceInfo));
            Guard.NotNull(processor, nameof(processor));
            Guard.NotNullOrWhiteSpace(metadataName, nameof(metadataName));
            Guard.NotNull(builtMetadataTables, nameof(builtMetadataTables));

            this.AssociatedWithCustomDataSource = true;

            // Exception may be null.

            this.Context               = context;
            this.Processor             = processor;
            this.DataSourceInfo        = dataSourceInfo;
            this.DataSourceInfoFailure = dataSourceInfoFailure;

            this.MetadataName         = metadataName;
            this.BuiltMetadataTables  = new ReadOnlyCollection <MetadataTableBuilder>(builtMetadataTables.ToList());
            this.MetadataTableFailure = metadataException;

            Debug.Assert(this.RequestedTables != null);

            // If the processor contains tables that were generated while processing the data source, then add them to our RequestedTables.
            // todo: RequestedTables - should we rename this? Just make it AvailableTables or something similar?
            if (processor is IDataDerivedTables postProcessTables &&
                postProcessTables.DataDerivedTables != null)
            {
                // do some extra validation on these table descriptors, as they might have been generated by hand
                // rather than our usual library
                //

                foreach (var tableDescriptor in postProcessTables.DataDerivedTables)
                {
                    if (tableDescriptor.PrebuiltTableConfigurations is null)
                    {
                        var tableConfigurations = new TableConfigurations(tableDescriptor.Guid)
                        {
                            Configurations = Enumerable.Empty <TableConfiguration>()
                        };

                        tableDescriptor.PrebuiltTableConfigurations = tableConfigurations;
                    }
                }

                // combine these new tables with any existing requested tables for this processor
                this.RequestedTables = this.RequestedTables.Concat(postProcessTables.DataDerivedTables);
            }
        }
        internal static void BuildMetadataTable(ITableBuilder tableBuilder, LTTngSourceParser sourceParser, ITableConfigurationsSerializer serializer)
        {
            ITableBuilderWithRowCount table = tableBuilder.SetRowCount(sourceParser.TraceStats.Count);

            IReadOnlyList <string> eventNames = sourceParser.TraceStats.Keys.ToList();

            var eventNameProjection       = Projection.CreateUsingFuncAdaptor(x => eventNames[x]);
            var traceStatsProjection      = eventNameProjection.Compose(eventName => sourceParser.TraceStats[eventName]);
            var eventCountProjection      = traceStatsProjection.Compose(traceStats => traceStats.EventCount);
            var payloadBitCountProjection = traceStatsProjection.Compose(traceStats => (double)traceStats.PayloadBitCount / 8);

            table.AddColumn(
                new DataColumn <string>(
                    EventNameConfiguration,
                    eventNameProjection));

            table.AddColumn(
                new DataColumn <ulong>(
                    CountConfiguration,
                    eventCountProjection));

            table.AddColumn(
                new DataColumn <double>(
                    TotalPayloadSizeConfiguration,
                    payloadBitCountProjection));

            var configurations = TableConfigurations.GetPrebuiltTableConfigurations(
                typeof(TraceStatsTable),
                TableDescriptor.Guid,
                serializer);

            foreach (var configuration in configurations)
            {
                tableBuilder.AddTableConfiguration(configuration);
                if (StringComparer.Ordinal.Equals(configuration.Name, configurations.DefaultConfigurationName))
                {
                    tableBuilder.SetDefaultTableConfiguration(configuration);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Parses the ledcontrol.ini file.
        /// </summary>
        /// <param name="LedControlIniFile">The ledcontrol.ini FileInfo object.</param>
        /// <param name="ThrowExceptions">if set to <c>true</c> [throw exceptions].</param>
        /// <exception cref="System.Exception">
        /// File {0} does not contain data.
        /// or
        /// Could not find {0} section in file {1}.
        /// or
        /// File {1} does not contain data in the {0} section.
        /// or
        /// Section {0} of file {1} does not have the same number of columns in all lines.
        /// </exception>
        private void ParseLedControlIni(FileInfo LedControlIniFile, bool ThrowExceptions = false)
        {
            string[] ColorStartStrings         = { "[Colors DOF]", "[Colors LedWiz]" };
            string[] OutStartStrings           = { "[Config DOF]", "[Config outs]" };
            string[] VariableStartStrings      = { "[Variables DOF]" };
            string[] VersionStartStrings       = { "[version]" };
            string[] TableVariableStartStrings = { "[TableVariables]" };;
            string   FileData = "";

            #region Read file
            try
            {
                FileData = General.FileReader.ReadFileToString(LedControlIniFile);
            }
            catch (Exception E)
            {
                Log.Exception("Could not read file {0}.".Build(LedControlIniFile), E);
                if (ThrowExceptions)
                {
                    throw new Exception("Could not read file {0}.".Build(LedControlIniFile), E);
                }
            }
            if (FileData.IsNullOrWhiteSpace())
            {
                Log.Warning("File {0} does not contain data.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("File {0} does not contain data.".Build(LedControlIniFile));
                }
            }
            #endregion

            Dictionary <string, List <string> > Sections = new Dictionary <string, List <String> >();

            #region Read sections

            List <string> SectionData   = new List <string>();
            String        SectionHeader = null;
            foreach (string RawIniLine in FileData.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string IniLine = RawIniLine.Trim();
                if (IniLine.Length > 0 && !IniLine.StartsWith("#"))
                {
                    if (IniLine.StartsWith("[") && IniLine.EndsWith("]") && IniLine.Length > 2)
                    {
                        //This is a section header
                        if (!SectionHeader.IsNullOrWhiteSpace())
                        {
                            if (Sections.ContainsKey(SectionHeader))
                            {
                                int Cnt = 2;
                                while (Sections.ContainsKey("{0} {1}".Build(SectionHeader, Cnt)))
                                {
                                    Cnt++;
                                    if (Cnt > 999)
                                    {
                                        throw new Exception("Section header {0} exists to many times.".Build(SectionHeader));
                                    }
                                }
                                SectionHeader = "{0} {1}".Build(SectionHeader, Cnt);
                            }
                            Sections.Add(SectionHeader, SectionData);
                            SectionData = new List <string>();
                        }
                        SectionHeader = IniLine;
                    }
                    else
                    {
                        //Its a data line
                        SectionData.Add(IniLine);
                    }
                }
            }

            if (!SectionHeader.IsNullOrWhiteSpace())
            {
                if (Sections.ContainsKey(SectionHeader))
                {
                    int Cnt = 2;
                    while (Sections.ContainsKey("{0} {1}".Build(SectionHeader, Cnt)))
                    {
                        Cnt++;
                        if (Cnt > 999)
                        {
                            throw new Exception("Section header {0} exists to many times.".Build(SectionHeader));
                        }
                    }
                    SectionHeader = "{0} {1}".Build(SectionHeader, Cnt);
                }
                Sections.Add(SectionHeader, SectionData);
                SectionData = new List <string>();
            }
            SectionData = null;
            #endregion

            FileData = null;

            List <string> ColorData         = GetSection(Sections, ColorStartStrings);
            List <string> OutData           = GetSection(Sections, OutStartStrings);
            List <string> VariableData      = GetSection(Sections, VariableStartStrings);
            List <string> VersionData       = GetSection(Sections, VersionStartStrings);
            List <string> TableVariableData = GetSection(Sections, TableVariableStartStrings);

            if (VersionData != null && VersionData.Count > 0)
            {
                MinDOFVersion = null;

                string MinDofVersionLine = VersionData.FirstOrDefault(S => S.ToLowerInvariant().StartsWith("mindofversion="));

                if (MinDofVersionLine != null)
                {
                    string MinDofVersionString = MinDofVersionLine.Substring("mindofversion=".Length);

                    try
                    {
                        MinDOFVersion = new Version(MinDofVersionString);
                    }
                    catch (Exception E)
                    {
                        Log.Exception("Could not parse line {1} from file {0}".Build(LedControlIniFile, MinDofVersionLine));
                        MinDOFVersion = null;
                    }
                    if (MinDOFVersion != null)
                    {
                        Log.Write("Min DOF Version is {0} for file {1}".Build(MinDOFVersion.ToString(), LedControlIniFile.Name));
                    }
                }
                else
                {
                    Log.Warning("No DOF version information found in file {0}.".Build(LedControlIniFile));
                }
            }
            else
            {
                Log.Warning("No version section found in file {0}.".Build(LedControlIniFile));
            }

            if (ColorData == null)
            {
                Log.Warning("Could not find color definition section in file {0}.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("Could not find  color definition section in file {0}.".Build(LedControlIniFile));
                }
                return;
            }
            else if (ColorData.Count < 1)
            {
                Log.Warning("File {0} does not contain data in the color definition section.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("File {0} does not contain data in the color definition section.".Build(LedControlIniFile));
                }
                return;
            }

            if (OutData == null)
            {
                Log.Warning("Could not find table config section in file {0}.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("Could not find table config section section in file {1}.".Build(LedControlIniFile));
                }
                return;
            }
            else if (OutData.Count < 1)
            {
                Log.Warning("File {0} does not contain data in the table config section.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("File {0} does not contain data in the table config section".Build(LedControlIniFile));
                }
                return;
            }

            if (VariableData != null)
            {
                ResolveVariables(OutData, VariableData);
            }

            if (TableVariableData != null)
            {
                ResolveTableVariables(OutData, TableVariableData);
            }



            ColorConfigurations.ParseLedControlData(ColorData, ThrowExceptions);

            TableConfigurations.ParseLedcontrolData(OutData, ThrowExceptions);

            //ResolveOutputNumbers();
            ResolveRGBColors();

            this.LedControlIniFile = LedControlIniFile;
        }
        /// <summary>
        /// Parses the ledcontrol.ini file.
        /// </summary>
        /// <param name="LedControlIniFile">The ledcontrol.ini FileInfo object.</param>
        /// <param name="ThrowExceptions">if set to <c>true</c> [throw exceptions].</param>
        /// <exception cref="System.Exception">
        /// File {0} does not contain data.
        /// or
        /// Could not find {0} section in file {1}.
        /// or
        /// File {1} does not contain data in the {0} section.
        /// or
        /// Section {0} of file {1} does not have the same number of columns in all lines.
        /// </exception>
        private void ParseLedControlIni(FileInfo LedControlIniFile, bool ThrowExceptions = false)
        {
            string[] ColorStartStrings = { "[Colors DOF]", "[Colors LedWiz]" };
            string[] OutStartStrings   = { "[Config DOF]", "[Config outs]" };

            //Read the file
            string Data = "";

            try
            {
                Data = General.FileReader.ReadFileToString(LedControlIniFile);
            }
            catch (Exception E)
            {
                Log.Exception("Could not read file {0}.".Build(LedControlIniFile), E);
                if (ThrowExceptions)
                {
                    throw new Exception("Could not read file {0}.".Build(LedControlIniFile), E);
                }
            }
            if (Data.IsNullOrWhiteSpace())
            {
                Log.Warning("File {0} does not contain data.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("File {0} does not contain data.".Build(LedControlIniFile));
                }
            }

            //Find starting positions of both sections
            int    ColorStart       = -1;
            string ColorStartString = "";

            foreach (string S in ColorStartStrings)
            {
                ColorStart       = Data.IndexOf(S, StringComparison.InvariantCultureIgnoreCase);
                ColorStartString = S;
                if (ColorStart >= 0)
                {
                    break;
                }
            }
            int    OutStart       = -1;
            string OutStartString = "";

            foreach (string S in OutStartStrings)
            {
                OutStart       = Data.IndexOf(S, StringComparison.InvariantCultureIgnoreCase);
                OutStartString = S;
                if (OutStart >= 0)
                {
                    break;
                }
            }

            if (ColorStart < 0)
            {
                Log.Exception("Could not find color definition section in file {0}.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("Could not find  color definition section in file {0}.".Build(LedControlIniFile));
                }
                return;
            }

            if (OutStart < 0)
            {
                Log.Exception("Could not find table config section in file {0}.".Build(LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("Could not find table config section section in file {1}.".Build(LedControlIniFile));
                }
                return;
            }

            string[] ColorData;
            string[] OutData;

            //Extract data of the sections, split into string arrays and remove empty lines
            if (ColorStart < OutStart)
            {
                ColorData = Data.Substring(ColorStart + ColorStartString.Length, OutStart - (ColorStart + ColorStartString.Length)).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                OutData   = Data.Substring(OutStart + OutStartString.Length).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                OutData   = Data.Substring(OutStart + OutStartString.Length, ColorStart - (OutStart + OutStartString.Length)).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                ColorData = Data.Substring(ColorStart + ColorStartString.Length).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            }


            if (OutData.Length == 0)
            {
                Log.Exception("File {1} does not contain data in the {0} section.".Build(OutStartString, LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("File {1} does not contain data in the {0} section.".Build(OutStartString, LedControlIniFile));
                }
                return;
            }

            if (ColorData.Length == 0)
            {
                Log.Exception("File {1} does not contain data in the {0} section.".Build(ColorStartString, LedControlIniFile));
                if (ThrowExceptions)
                {
                    throw new Exception("File {1} does not contain data in the {0} section.".Build(ColorStartString, LedControlIniFile));
                }
                return;
            }



            ColorConfigurations.ParseLedControlData(ColorData, ThrowExceptions);

            TableConfigurations.ParseLedcontrolData(OutData, ThrowExceptions);

            ResolveOutputNumbers();
            ResolveRGBColors();
        }