/// <summary>
        /// Gets the user manual for table.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="output">The output.</param>
        /// <param name="directInfo">The direct information.</param>
        /// <param name="skipUnDescribed">if set to <c>true</c> [skip un described].</param>
        public static void GetUserManualForTable(this DataTable dataObject, ITextRender output, String directInfo = "", Boolean skipUnDescribed = true)
        {
            output.AppendHeading("DataTable: " + dataObject.GetTitle(), 1);

            AppendIf(output, directInfo, "Comment: ");
            AppendIf(output, dataObject.GetDescription(), "Table description: ");

            output.AppendLine("This is automatically generated description of columns of DataTable [" + dataObject.TableName + "]");
            output.AppendHorizontalLine();

            AppendIf(output, dataObject.GetClassName(), "Table shema source: ");
            //output.AppendIf(dataObject.Rows.Count, "Table shema source: ");

            foreach (DataColumn dc in dataObject.Columns)
            {
                //output.AppendHeading("DataColumn -> [" + dc.ColumnName + "]", 2);

                var spe = dc.ExtendedProperties[templateFieldDataTable.col_spe] as settingsPropertyEntry;
                if (spe == null)
                {
                    spe = new settingsPropertyEntry(dc);
                    //spe.displayName = dc.Caption;
                    //spe.name = dc.ColumnName;
                    //spe.description = dc.GetDesc();
                    //spe.type = dc.DataType;
                    //spe.categoryName = dc.GetGroup();
                    //spe.format = dc.GetFormat();
                    //spe.letter = dc.GetLetter();
                    //spe.aggregation = dc.GetAggregation();
                    ////spe.index = dc.Ordinal;
                    //spe.importance = dc.GetImportance();
                    //spe.expression = dc.Expression;
                    //spe.unit = dc.GetUnit();
                    //spe.priority = dc.Ordinal;
                    //spe.width = dc.GetWidth();
                }

                GetUserManualSPE(spe, output);

                // dc.GetSPE().GetUserManual(output);
            }

            output.AppendHorizontalLine();

            var addInfo = dataObject.GetAdditionalInfo();

            output.AppendPairs(addInfo, false, " => ");

            var extraLines = dataObject.GetExtraDesc();

            if (Enumerable.Any <string>(extraLines))
            {
                output.AppendHorizontalLine();

                output.AppendList(extraLines, true);
            }

            //dataObject.GetDescription();
        }
        public static Object AskFor(settingsPropertyEntry prop, Object propValue)
        {
            Object propNewValue = null;

            String prompt = "";

            if (!prop.prompt.isNullOrEmptyString())
            {
                prompt = prop.prompt;
            }

            if (prop.type.IsEnum)
            {
                propNewValue = askForOption(prompt.or("Select value from list below"), propValue);
            }
            else
            {
                switch (prop.type.Name.ToLower())
                {
                case "string":
                    propNewValue = askForStringInline(prompt.or("Insert new value"), propValue as String);
                    break;

                case "decimal":
                    String  tmpString = askForStringInline(prompt.or("Insert new value"), propValue.ToString());
                    Decimal decimalResult;
                    if (Decimal.TryParse(tmpString, out decimalResult))
                    {
                        propNewValue = decimalResult;
                    }
                    else
                    {
                        Console.WriteLine("Invalid input - default value set: " + propValue.ToString());
                        propNewValue = propValue;
                    }
                    break;

                case "int32":
                    String tmpStringInt = askForStringInline(prompt.or("Insert new value"), propValue.ToString());
                    Int32  intResult;
                    if (Int32.TryParse(tmpStringInt, out intResult))
                    {
                        propNewValue = intResult;
                    }
                    else
                    {
                        Console.WriteLine("Invalid input - default value set: " + propValue.ToString());
                        propNewValue = propValue;
                    }
                    break;

                case "bool":
                case "boolean":
                    propNewValue = askYesNo(prompt.or("Select new value"), (Boolean)propValue);
                    break;
                }
            }
            return(propNewValue);
        }
 /// <summary>
 /// Spes the specified default col spe.
 /// </summary>
 /// <param name="dc">The dc.</param>
 /// <param name="default_col_spe">The default col spe.</param>
 /// <returns></returns>
 public static settingsPropertyEntry SPE(this DataColumn dc, settingsPropertyEntry default_col_spe)
 {
     if (!dc.ExtendedProperties.ContainsKey(templateFieldDataTable.col_spe))
     {
         dc.ExtendedProperties.add(templateFieldDataTable.col_spe, default_col_spe);
         dc.ExtendedProperties.add(templateFieldDataTable.col_pe, default_col_spe.pe);
         dc.ExtendedProperties.add(templateFieldDataTable.col_propertyInfo, default_col_spe.pi);
     }
     return(dc.ExtendedProperties[templateFieldDataTable.col_spe] as settingsPropertyEntry);
 }
        /// <summary>
        /// Sets data annotation from the column
        /// </summary>
        public void SetFrom(settingsPropertyEntry sPE, Boolean skipExisting = true)
        {
            name = sPE.name;
            PropertyCollection pce = sPE.exportPropertyCollection(definitions);

            foreach (var p in pce.Keys)
            {
                definitions.Add(p, pce[p]);
            }
        }
        /// <summary>
        /// Builds a <see cref="settingsPropertyEntry"/> from contained data
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="skipExisting">if set to <c>true</c> [skip existing].</param>
        /// <param name="log">The log.</param>
        /// <returns></returns>
        public settingsPropertyEntry BuildPCE(DataColumn column, Boolean skipExisting = true, ILogBuilder log = null)
        {
            settingsPropertyEntry pce = new settingsPropertyEntry(column);

            PropertyCollection pc = pce.exportPropertyCollection();

            foreach (var pair in definitions.keyValuePairs)
            {
                if (skipExisting)
                {
                    if (pc.ContainsKey(pair.resolvedKey))
                    {
                        if (!pc[pair.resolvedKey].toStringSafe().isNullOrEmpty())
                        {
                            if (log != null)
                            {
                                log.log(" Deploy [" + pair.key + "] = false, because destination is not empty (skipExisting=" + skipExisting.ToString() + ")");
                            }
                            continue;
                        }
                    }
                }

                switch (pair.resolvedKey)
                {
                default:
                    if (pair.resolvedKey is imbAttributeName attName)
                    {
                        pce.deploy(attName, pair.value);
                        if (log != null)
                        {
                            log.log("Set[" + pair.key + "] = " + pair.value.toStringSafe());
                        }
                    }
                    else if (pair.resolvedKey is templateFieldDataTable tfdt)
                    {
                        pce.deploy(tfdt, pair.value);
                        if (log != null)
                        {
                            log.log("Set[" + pair.key + "] = " + pair.value.toStringSafe());
                        }
                    }
                    else
                    {
                        if (log != null)
                        {
                            log.log(column.Table.GetTitle() + "." + column.ColumnName + " <- entry not recognized [" + pair.key + "]");
                        }
                    }
                    break;
                }
            }

            return(pce);
        }
        /// <summary>
        /// Deploys contained definitions onto DataColumn
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="skipExisting">if set to <c>true</c> [skip existing].</param>
        public void DeployTo(DataColumn column, Boolean skipExisting = true, ILogBuilder log = null)
        {
            if (log != null)
            {
                log.log(column.Table.GetTitle() + "." + column.ColumnName + " <- deploying preset [" + name + "]");
            }

            settingsPropertyEntry pce = BuildPCE(column, skipExisting, log);

            column.SetSPE(pce);
        }
        /// <summary>
        /// Generates content for <see cref="settingsPropertyEntry"/>
        /// </summary>
        /// <param name="spec">The spec.</param>
        /// <param name="output">The output.</param>
        public static void GetUserManualSPE(this settingsPropertyEntry spec, ITextRender output)
        {
            output.AppendHeading(imbSciStringExtensions.add(spec.categoryName, spec.displayName, ": "), 3);
            output.AppendPair("Property name: ", spec.name);
            output.AppendPair("Type: ", spec.type.Name);

            if (!spec.description.isNullOrEmpty())
            {
                output.AppendParagraph(spec.description);
            }

            if (!spec.letter.isNullOrEmpty())
            {
                output.AppendPair("Annotation: ", spec.letter);
            }
            if (!spec.unit.isNullOrEmpty())
            {
                output.AppendPair("Unit: ", spec.unit);
            }
            if (spec.aggregation != null)
            {
                output.AppendPair("Aggregation: ", spec.aggregation.multiTableType.ToString());
            }

            //if (showValue)
            //{
            //    if (spec.value != null)
            //    {
            //        output.AppendPair("Value: ", spec.value.toStringSafe(spec.format));
            //    }
            //}

            if (spec.type.IsEnum)
            {
                output.AppendPair("Possible values: ", spec.type.GetEnumNames().toCsvInLine());
            }
            else if (spec.type == typeof(Int32))
            {
            }

            if (!spec.info_helpTitle.isNullOrEmpty())
            {
                output.AppendLabel(spec.info_helpTitle);
                output.AppendQuote(spec.info_helpTips);
            }

            if (!spec.info_link.isNullOrEmpty())
            {
                output.AppendLink(spec.info_link, "More", "More");
            }

            output.AppendHorizontalLine();
        }
Esempio n. 8
0
        /// <summary>
        /// Gets the cloned shema.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <returns></returns>

        /*   public static T GetClonedShema<T>(this DataTable table, bool disablePrimaryKey = true, String[] categories = null) where T : DataTable, new()
         * {
         *     DataTable clone = table.Clone();
         *     T output = new T();
         *
         *     ColumnGroups groupsOfColumns = clone.getGroupsOfColumns();
         *
         *     if (categories != null)
         *     {
         *         List<String> matched = new List<string>();
         *         foreach (String c in categories)
         *         {
         *             var cg = groupsOfColumns.FirstOrDefault(x => x.name.Equals(c, StringComparison.InvariantCultureIgnoreCase));
         *             if (cg == null)
         *             {
         *                 if (clone.Columns.Contains(c))
         *                 {
         *                     matched.Add(c);
         *                 }
         *             }
         *             else
         *             {
         *                 matched.AddRange(cg.Select(x => x.ColumnName));
         *             }
         *
         *         }
         *
         *         List<DataColumn> dcdel = new List<DataColumn>();
         *         foreach (DataColumn dc in clone.Columns)
         *         {
         *             if (!matched.Contains(dc.ColumnName))
         *             {
         *                 dcdel.Add(dc);
         *             }
         *             //String g = dc.GetGroup();
         *             //if (!matched.Any())
         *             //{
         *             //    if (!matched.Contains(dc.ColumnName))
         *             //    {
         *
         *             //    }
         *             //}
         *             //else
         *             //{
         *             //    if (!matched.Contains(g))
         *             //    {
         *             //        dcdel.Add(dc);
         *             //    }
         *             //}
         *         }
         *
         *         foreach (DataColumn dc in dcdel)
         *         {
         *             clone.Columns.Remove(dc);
         *         }
         *
         *     }
         *
         *     table.ExtendedProperties.copyInto(output.ExtendedProperties);
         *
         *     output.SetTitle(table.GetTitle());
         *     output.SetDescription(table.GetDescription());
         *     output.SetClassName(table.GetClassName());
         *     output.SetClassType(table.GetClassType());
         *     output.SetAggregationAspect(table.GetAggregationAspect());
         *     output.SetAggregationOriginCount(table.GetAggregationOriginCount());
         *     output.SetAdditionalInfo(table.GetAdditionalInfo());
         *     output.SetExtraDesc(table.GetExtraDesc());
         *
         *     output.SetCategoryPriority(table.GetCategoryPriority());
         *
         *     output.SetStyleSet(table.GetStyleSet());
         *     output.SetColumnMetaSet(table.GetColumnMetaSet());
         *     output.SetRowMetaSet(table.GetRowMetaSet());
         *     //output.SetClassType(table.Get)
         *
         *
         *
         *
         *
         *
         *     List<string> catPri = table.GetCategoryPriority();
         *
         *     if (disablePrimaryKey) output.PrimaryKey = new DataColumn[0];
         *
         *     foreach (DataColumn dc in clone.Columns)
         *     {
         *         dc.GetSPE();
         *     }
         *
         *     foreach (DataColumn dc in clone.Columns)
         *     {
         *         DataColumn dce = output.Add(dc.GetSPE());
         *        // dce.SetValueType(dc.GetValueType()); //<--------- ad hok hack --- da vidim
         *
         *         //clone.Columns.Remove(dc);
         *         //output.Columns.Add(dc);
         *
         *         // output.Columns[dc.ColumnName].ExtendedProperties.AppendData(dc.ExtendedProperties, existingDataMode.overwriteExisting);
         *     }
         *     if (catPri.Any())
         *     {
         *         output.Columns.OrderByCategoryPriority(catPri);
         *     }
         *
         *     if (output.TableName.isNullOrEmpty()) output.TableName = "datatable_" + imbStringGenerators.getRandomString(4);
         *
         *     return output;
         * }*/
        /*
         * public static void AddColumns(this DataTable table, Type type, params string[] columns)
         * {
         *  settingsEntriesForObject seo = new settingsEntriesForObject(type, false);
         *
         *  foreach (string col in columns)
         *  {
         *      if (seo.spes.ContainsKey(col))
         *      {
         *          table.Add(col, seo.spes[col].description, "", seo.pis[col].PropertyType, seo.spes[col].importance, seo.spes[col].format, seo.spes[col].displayName);
         *      }
         *      else
         *      {
         *      }
         *  }
         * }*/

        /// <summary>
        /// Adds column using meta information of <see cref="imbSCI.Core.data.settingsPropertyEntry"/>
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="spe">The spe.</param>
        /// <returns>newly added column</returns>
        public static DataColumn Add(this DataTable table, settingsPropertyEntry spe)
        {
            DataColumn output = Add(table, (string)spe.name, spe.description, spe.letter, spe.type, spe.importance, spe.format, spe.displayName);

            output.SetClassName(spe.type.Name);

            // output.SetPriority(spe.priority);
            output.SetSPE(spe);
            // output.SetGroup(spe.categoryName);
            output.SetHasLinks(spe.attributes.containsAnyOfKeys(templateFieldDataTable.col_hasLinks));
            output.SetHasTemplate(spe.attributes.containsAnyOfKeys(templateFieldDataTable.col_hasTemplate));

            return(output);
        }
        /// <summary>
        /// Gets <see cref="settingsMemberInfoEntry"/>
        /// </summary>
        /// <param name="dc">The dc.</param>
        /// <returns></returns>
        public static settingsPropertyEntry GetSPE(this DataColumn dc)
        {
            if (!dc.ExtendedProperties.ContainsKey(templateFieldDataTable.col_spe))
            {
                settingsPropertyEntry spe = new settingsPropertyEntry(dc);
                // if (col_spe.isHiddenInReport) dc.ExtendedProperties.add(imbAttributeName.reporting_hide, true, false);

                if (dc.Table.Rows.Count == 0)
                {
                    dc.SetSPE(spe);
                }

                return(spe);
            }
            return(dc.ExtendedProperties[templateFieldDataTable.col_spe] as settingsPropertyEntry);
        }
Esempio n. 10
0
        //public void RegisterProperties(settingsEntriesForObject seo)
        //{
        //    if (SEOs.Contains(seo)) return
        //}

        public Property RegisterProperty(settingsPropertyEntry sme)
        {
            String UID = sme.memberInfo.DeclaringType.Name + "." + sme.memberInfo.Name;

            Property p = this.FirstOrDefault(x => x.Id == UID);

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

            p = new Property(UID, sme.displayName, sme.pi.PropertyType);

            Add(p);

            return(p);
        }
        /// <summary>
        /// Sets or creates new preset item, with data annotations taken from the specified column
        /// </summary>
        /// <param name="property">The property entry to learn from.</param>
        /// <param name="skipExistingAnnotations">if set to <c>true</c> [skip existing annotations].</param>
        /// <returns>Created or updated preset item</returns>
        public propertyAnnotationPresetItem SetFrom(settingsPropertyEntry property, Boolean skipExistingAnnotations = true)
        {
            var item = GetAnnotationPresetItem(property.name);

            if (item == defaultItem)
            {
                item = new propertyAnnotationPresetItem();
                item.SetFrom(property, skipExistingAnnotations);
                items.Add(item);

                return(item);
            }
            else
            {
                item.SetFrom(property, skipExistingAnnotations);
                return(item);
            }
        }
        /// <summary>
        /// Sets and deploys SPE
        /// </summary>
        /// <param name="dc">The dc.</param>
        /// <param name="col_spe">The col spe.</param>
        /// <returns></returns>
        public static DataColumn SetSPE(this DataColumn dc, settingsPropertyEntry col_spe)
        {
            dc.SetWidth(col_spe.width);
            dc.SetUnit(col_spe.unit);
            dc.SetDesc(col_spe.description);
            dc.SetGroup(col_spe.categoryName);
            dc.SetDefaultBackground(col_spe.color);
            dc.SetTextColor(col_spe.textColor);
            dc.SetHeading(col_spe.displayName);
            dc.ColumnName = col_spe.name;
            dc.SetAligment(col_spe.Alignment);

            //templateFieldDataTable.col_alignment
            if (col_spe.type.isNullable())
            {
                dc.DataType = typeof(Object);
            }
            else
            {
                dc.DataType = col_spe.type;
            }
            dc.SetValueType(col_spe.type);

            dc.SetFormat(col_spe.format);
            dc.SetLetter(col_spe.letter);
            dc.SetAggregation(col_spe.aggregation);
            dc.SetPriority(col_spe.priority); //<--- prioritet
            dc.SetImportance(col_spe.importance);
            dc.Expression = col_spe.expression;

            dc.ExtendedProperties.add(templateFieldDataTable.col_spe, col_spe);
            dc.ExtendedProperties.add(templateFieldDataTable.col_pe, col_spe.pe);
            dc.ExtendedProperties.add(templateFieldDataTable.col_propertyInfo, col_spe.pi);
            if (col_spe.isHiddenInReport)
            {
                dc.ExtendedProperties.add(imbAttributeName.reporting_hide, true, false);
            }
            //dc.ExtendedProperties.add(imbAttributeName.reporting_hide);
            return(dc);
        }
 public typedParamInfo(ParameterInfo paramInfo)
 {
     name = paramInfo.Name;
     type = paramInfo.ParameterType;
     sPE  = new settingsPropertyEntry(paramInfo);
 }
        public static DataTable GetParallelAggregates <T>(this List <IEnumerable <T> > sources, string column_snap, string column_prefix, dataPointAggregationType column_sideAggregates, params string[] column_toInclude)
        {
            settingsEntriesForObject sEO        = new settingsEntriesForObject(typeof(T));
            settingsPropertyEntry    sPE_snap   = sEO.spes[column_snap];
            settingsPropertyEntry    sPE_prefix = sEO.spes[column_prefix];

            List <settingsPropertyEntry> sPE_toInclude = new List <settingsPropertyEntry>();

            foreach (string toInclude in column_toInclude)
            {
                sPE_toInclude.Add(sEO.spes[toInclude]);
            }

            List <dataPointAggregationType> side_aggregates = column_sideAggregates.getEnumListFromFlags <dataPointAggregationType>();

            Dictionary <dataPointAggregationType, settingsPropertyEntry> sPE_sideAggregates = new Dictionary <dataPointAggregationType, settingsPropertyEntry>();

            Dictionary <settingsPropertyEntry, dataPointAggregationType> sPE_sideAggregatesContra = new Dictionary <settingsPropertyEntry, dataPointAggregationType>();

            foreach (settingsPropertyEntry toInclude in sPE_toInclude)
            {
                foreach (dataPointAggregationType sideType in side_aggregates)
                {
                    settingsPropertyEntry sPE = new settingsPropertyEntry(toInclude.pi);
                    sPE.type = typeof(double);
                    sPE.name = sPE.name + "_" + sideType.ToString();
                    sPE_sideAggregates.Add(sideType, sPE);
                    sPE_sideAggregatesContra.Add(sPE, sideType);
                }
            }

            // <---------------------------- preparing data

            Dictionary <string, IEnumerable <T> > dataByPrefix = new Dictionary <string, IEnumerable <T> >();
            int c = 0;

            foreach (IEnumerable <T> s in sources)
            {
                T firstItem = s.FirstOrDefault <T>();
                if (firstItem != null)
                {
                    string prefix = firstItem.imbGetPropertySafe(sPE_prefix.pi).toStringSafe(c.ToString("D3"));
                    dataByPrefix.Add(prefix, s);
                }
                c++;
            }

            // <----- DataColumn Index

            aceDictionarySet <string, DataColumn> columnsByPrefix = new aceDictionarySet <string, DataColumn>();

            aceDictionarySet <string, DataColumn> columnsSideAggregationByPrefix = new aceDictionarySet <string, DataColumn>();

            // <------------------------- building Shema
            DataTable output = new DataTable();

            output.TableName = "ParallelAggregate_by_" + column_snap;

            DataColumn            col_recordID = output.Add("ID", "Row ordinal number", "ID", typeof(int), dataPointImportance.normal, "D3").SetUnit("#");
            settingsPropertyEntry sPE_recID    = col_recordID.GetSPE();

            DataColumn col_snap = output.Add(sPE_snap);

            aceDictionary2D <settingsPropertyEntry, dataPointAggregationType, DataColumn> columnsByAggregationType = new aceDictionary2D <settingsPropertyEntry, dataPointAggregationType, DataColumn>();
            aceDictionarySet <settingsPropertyEntry, DataColumn> columnsBySource = new aceDictionarySet <settingsPropertyEntry, DataColumn>();

            foreach (settingsPropertyEntry toInclude in sPE_toInclude)
            {
                foreach (var pair in dataByPrefix)
                {
                    DataColumn nColumn = output.Add(toInclude);
                    nColumn.ColumnName = pair.Key + "_" + nColumn.ColumnName;
                    nColumn.SetGroup(pair.Key);

                    columnsByPrefix.Add(pair.Key, nColumn);

                    columnsBySource.Add(toInclude, nColumn);
                }

                foreach (var pair2 in sPE_sideAggregatesContra)
                {
                    DataColumn nColumn2 = output.Add(toInclude);
                    nColumn2.SetGroup("Aggregate");

                    //                    columnsSideAggregationByPrefix.Add(pair.Key, nColumn);
                }
            }

            // <----------------------------------------------------------- collecting rows

            aceDictionary2D <string, settingsPropertyEntry, object> dataRowBySnapValue = new aceDictionary2D <string, settingsPropertyEntry, object>();

            int riMax = 0;

            foreach (string prefix in dataByPrefix.Keys)
            {
                IEnumerable <T> s  = dataByPrefix[prefix];
                int             ri = 0;
                foreach (T si in s)
                {
                    ri++;
                    string snapValue = si.imbGetPropertySafe(sPE_snap.pi).toStringSafe();

                    dataRowBySnapValue[snapValue, sPE_snap]  = snapValue;
                    dataRowBySnapValue[snapValue, sPE_recID] = ri;

                    foreach (settingsPropertyEntry toInclude in sPE_toInclude)
                    {
                        foreach (var pair in columnsByPrefix[prefix])
                        {
                            var spe = dataColumnRenderingSetup.GetSPE(pair);

                            dataRowBySnapValue[snapValue, spe] = si.imbGetPropertySafe(spe.pi);
                        }
                    }
                    riMax = Math.Max(ri, riMax);
                }
            }

            foreach (string prefix in dataByPrefix.Keys)
            {
            }

            //List<Double> data = new List<Double>();
            //foreach (var pair2 in columnsSideAggregationByPrefix[prefix])
            //{
            //    var spe2 = pair.GetSPE();

            //    dataRowBySnapValue[snapValue, spe2] = si.imbGetPropertySafe(spe2.pi);
            //}

            return(output);
        }
        /// <summary>
        /// Gets aggregated version of the objects
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">The source.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static collectionAggregationResult <T> GetAggregates <T>(this IEnumerable <T> source, dataPointAggregationType type = dataPointAggregationType.avg, bool stringKeepLastEntry = true) where T : class, new()
        {
            //if (type == dataPointAggregationType.none)
            //{
            //}

            var aggList = type.getEnumListFromFlags <dataPointAggregationType>();

            collectionAggregationResult <T> output = new collectionAggregationResult <T>();

            output.aspect = dataPointAggregationAspect.subSetOfRows;

            aceDictionary2D <dataPointAggregationType, PropertyInfo, double> outputData = new aceDictionary2D <dataPointAggregationType, PropertyInfo, double>();

            aceDictionary2D <dataPointAggregationType, PropertyInfo, List <double> > datatCollections = new aceDictionary2D <dataPointAggregationType, PropertyInfo, List <double> >();

            Type t = typeof(T);

            List <PropertyInfo> nominalList = new List <PropertyInfo>();
            List <PropertyInfo> piList      = new List <PropertyInfo>();

            Dictionary <PropertyInfo, settingsPropertyEntry> sPEDict = new Dictionary <PropertyInfo, settingsPropertyEntry>();

            foreach (PropertyInfo pi in t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty | BindingFlags.GetProperty))
            {
                settingsPropertyEntry sPE = new settingsPropertyEntry(pi);

                bool ok = true;

                if (!pi.CanWrite)
                {
                    ok = false;
                }

                if (ok && pi.PropertyType == typeof(string))
                {
                    nominalList.Add(pi);
                    ok = false;
                }
                else if (ok && pi.PropertyType == typeof(Enum))
                {
                    ok = false;
                }

                if (ok && sPE.aggregation[dataPointAggregationAspect.subSetOfRows].HasFlag(dataPointAggregationType.hidden))
                {
                    ok = false;
                }
                if (ok && sPE.attributes.ContainsKey(imbAttributeName.reporting_hide))
                {
                    ok = false;
                }

                if (ok)
                {
                    sPEDict.Add(pi, sPE);
                    piList.Add(pi);
                }
            }

            if (aggList.Contains(dataPointAggregationType.avg))
            {
                aggList.AddUnique(dataPointAggregationType.sum);
            }

            if (aggList.Contains(dataPointAggregationType.range))
            {
                aggList.AddUnique(dataPointAggregationType.min);
                aggList.AddUnique(dataPointAggregationType.max);
            }

            foreach (dataPointAggregationType aggType in aggList)
            {
                output.Add(aggType, new T());

                switch (aggType)
                {
                case dataPointAggregationType.var:
                case dataPointAggregationType.stdev:
                case dataPointAggregationType.entropy:
                    foreach (PropertyInfo pi in piList)
                    {
                        datatCollections[aggType, pi] = new List <double>();    //.Add(item.imbGetPropertySafe<Double>(pi));
                    }
                    break;
                }

                // outputData.Add(aggType, 0);
            }

            int count = 0;

            // <------------ first pass
            foreach (T item in source)
            {
                if (output.firstItem == null)
                {
                    output.firstItem = item;
                }
                output.lastItem = item;
                foreach (dataPointAggregationType aggType in aggList)
                {
                    foreach (PropertyInfo pi in piList)
                    {
                        double vl = outputData[aggType, pi];

                        switch (aggType)
                        {
                        case dataPointAggregationType.sum:
                            vl = vl + item.imbGetPropertySafe <double>(pi);
                            break;

                        case dataPointAggregationType.min:
                            vl = Math.Min(item.imbGetPropertySafe <double>(pi), vl);
                            break;

                        case dataPointAggregationType.max:
                            vl = Math.Max(item.imbGetPropertySafe <double>(pi), vl);
                            break;

                        case dataPointAggregationType.var:
                        case dataPointAggregationType.stdev:
                        case dataPointAggregationType.entropy:
                            datatCollections[aggType, pi].Add(item.imbGetPropertySafe <double>(pi));
                            break;
                        }
                        outputData[aggType, pi] = vl;
                    }
                }

                count++;
            }

            foreach (dataPointAggregationType aggType in aggList)
            {
                foreach (PropertyInfo pi in piList)
                {
                    switch (aggType)
                    {
                    case dataPointAggregationType.count:
                        outputData[aggType, pi] = count;
                        break;

                    case dataPointAggregationType.avg:
                        outputData[aggType, pi] = outputData[dataPointAggregationType.sum, pi] / (double)count;
                        break;

                    case dataPointAggregationType.range:
                        outputData[aggType, pi] = outputData[dataPointAggregationType.max, pi] - outputData[dataPointAggregationType.min, pi];
                        break;

                    case dataPointAggregationType.firstEntry:
                        outputData[aggType, pi] = output.firstItem.imbGetPropertySafe <double>(pi);
                        break;

                    case dataPointAggregationType.lastEntry:
                        outputData[aggType, pi] = output.lastItem.imbGetPropertySafe <double>(pi);
                        break;

                    case dataPointAggregationType.var:
                        outputData[aggType, pi] = datatCollections[aggType, pi].GetVariance();
                        break;

                    case dataPointAggregationType.stdev:
                        outputData[aggType, pi] = datatCollections[aggType, pi].GetStdDeviation();
                        break;

                    case dataPointAggregationType.entropy:
                        outputData[aggType, pi] = datatCollections[aggType, pi].GetEntropy();
                        break;
                    }
                }
            }

            foreach (dataPointAggregationType aggType in aggList)
            {
                foreach (PropertyInfo pi in piList)
                {
                    output[aggType].imbSetPropertyConvertSafe(pi, outputData[aggType, pi]);
                }

                if (stringKeepLastEntry)
                {
                    foreach (PropertyInfo pi in nominalList)
                    {
                        output[aggType].imbSetPropertyConvertSafe(pi, output.lastItem.imbGetPropertySafe(pi));
                    }
                }
            }
            output.Count = count;
            return(output);
        }
        public void AppendProperty(settingsPropertyEntry property, PropertyAppendType type, PropertyAppendFlags flags)
        {
            String def_value = "";

            if (flags.HasFlag(PropertyAppendFlags.setDefaultValue))
            {
                if (property.type.IsValueType)
                {
                    def_value = " = default(" + property.type + ");";
                }
                else
                {
                    if (property.type.GetConstructor(new Type[] { }) != null)
                    {
                        def_value = " = new " + property.type + "();";
                    }
                    else
                    {
                        def_value = " = default(" + property.type + ");";
                    }
                }

                def_value = def_value.Replace("  ", " ").Trim();
            }
            else
            {
            }

            List <String> inserts = property.GetPropertyCodeInsertLines(flags);

            switch (type)
            {
            case PropertyAppendType.autoproperty:

                foreach (var l in inserts)
                {
                    AppendLine(l);
                }

                String apl = "public " + property.name + " {get;set;} " + def_value;
                if (def_value != "")
                {
                    apl = apl.ensureEndsWith(";");
                }
                apl = apl.Replace("  ", " ");

                AppendLine(apl);
                break;

            case PropertyAppendType.backingField:

                AppendLine("protected " + property.relevantTypeName + " _" + property.name + "  " + def_value.ensureEndsWith(";"));

                foreach (var l in inserts)
                {
                    AppendLine(l);
                }

                AppendLine("public " + property.relevantTypeName + " " + property.name + "");

                open(CodeBlockType.codeBlock);

                AppendGetSetBlock(property.name, true, true);

                close(CodeBlockType.codeBlock);
                break;
            }
        }
        /// <summary>
        /// Sets data annotation from the column
        /// </summary>
        public void SetFrom(PropertyInfo property, Boolean skipExisting = true)
        {
            settingsPropertyEntry sPE = new settingsPropertyEntry(property);

            SetFrom(sPE, skipExisting);
        }
        /// <summary>
        /// Sets data annotation from the column
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="skipExisting">if set to <c>true</c> [skip existing].</param>
        public void SetFrom(DataColumn column, Boolean skipExisting = true)
        {
            settingsPropertyEntry sPE = column.GetSPE();

            SetFrom(sPE, skipExisting);
        }
Esempio n. 19
0
        public void process(IEnumerable <DataTable> tables, dataPointAggregationAspect __aspect = dataPointAggregationAspect.overlapMultiTable)
        {
            aspect = __aspect;

            string __desc = "This table is result of summary operation (" + aspect.ToString() + ") over tables: ";
            int    tc     = 0;

            int rcMin  = int.MaxValue;
            int rcMax  = int.MinValue;
            int rcProc = 0;

            DataTable shemaProvider = null;

            foreach (DataTable dt in tables)
            {
                if (shemaProvider == null)
                {
                    shemaProvider = dt;
                }

                tc++;
                if (tc < 5)
                {
                    __desc = __desc.add(dt.GetTitle(), ", ");
                }
                rcMin   = Math.Min(dt.Rows.Count, rcMin);
                rcMax   = Math.Max(dt.Rows.Count, rcMax);
                rcProc += dt.Rows.Count;
            }

            additionalProps.AddRange(shemaProvider.GetAdditionalInfo(), false, false, false);

            categoriesPriority = shemaProvider.GetCategoryPriority();
            if (categoriesPriority.Any())
            {
            }

            if (tc > 4)
            {
                __desc = __desc.add("... in total: " + tc + " tables", ", ");
            }
            sources       = tc;
            rowsMax       = rcMax;
            rowsCommon    = rcMin;
            rowsProcessed = rcProc;

            additionalProps.Add(ADDPROPS_ROWSMAX, rcMax, ADDPROPS_ROWSMAX, "Highest row count in the table set");
            additionalProps.Add(ADDPROPS_ROWSCOMMON, rcMin, ADDPROPS_ROWSCOMMON, "Lowest row count in the table set");
            additionalProps.Add(ADDPROPS_ROWSPROCESSED, rcProc, ADDPROPS_ROWSPROCESSED, "Total count of rows processed");
            additionalProps.Add("Category", categoriesPriority.toCsvInLine());

            extraDescriptions.Add("[" + sources + "] source tables had at least [" + rowsCommon + "] rows. Maximum rows per source table: [" + rowsMax + "]");

            shemaColumns = new DataColumnMetaDictionary();

            foreach (DataColumn dc in shemaProvider.Columns)
            {
                /* FINDING AGGREGATION SETTINGS */
                settingsPropertyEntry          spe = dc.GetSPE();
                dataPointAggregationDefinition agg = null;
                if (spe.aggregation == null)
                {
                    PropertyInfo pi = dc.ExtendedProperties.getProperObject <PropertyInfo>(templateFieldDataTable.col_propertyInfo); //, col_spe.pi);
                    if (pi != null)
                    {
                        spe = new settingsPropertyEntry(pi);
                    }
                }
                if (spe.aggregation == null)
                {
                    spe.aggregation = new dataPointAggregationDefinition();
                }
                agg = spe.aggregation;
                /* ----------------------------- */

                if (agg[aspect] != dataPointAggregationType.none)
                {
                    List <dataPointAggregationType> aggTypes = agg[aspect].getEnumListFromFlags <dataPointAggregationType>();

                    foreach (dataPointAggregationType a in aggTypes)
                    {
                        if (a != dataPointAggregationType.hidden)
                        {
                            shemaColumns.Add(DataColumnInReportTypeEnum.dataSummed, dc, a, dc.GetUnit());
                        }
                    }
                }
            }

            desc = __desc;
        }