private void LogToOrigin(ParserEventRecord record)
        {
            DynamicResult dr = record.SourceData as DynamicResult;

            if (dr != null)
            {
                if (dr.ContainsKey("$origin"))
                {
                    string origin = dr["$origin"];
                    int    id     = origin.LastIndexOf("::", StringComparison.Ordinal);
                    if (id != -1)
                    {
                        string sheetName = origin.Substring(0, id);
                        int    line      = int.Parse(origin.Substring(id + 2));
                        var    sheet     = GetSheet(sheetName, false);
                        try
                        {
                            sheet.AddMessage(line, record.Message);
                        }
                        catch (Exception ex)
                        {
                            LogEnvironment.LogEvent(ex.OutlineException(), LogSeverity.Error);
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the modelResult from a specific dynamicResult object
        /// </summary>
        /// <typeparam name="T">the target model in which to convert the dynamicResult</typeparam>
        /// <typeparam name="TM">the Meta-Type used for the mapping</typeparam>
        /// <param name="item">the DynamicResult that contains the original data</param>
        /// <returns>an instance of the desired type</returns>
        public static T GetModelResult <T, TM>(this DynamicResult item) where T : new()
        {
            T retVal = new T();

            item.ToModel <T, TM>(retVal);
            return(retVal);
        }
Пример #3
0
        /// <summary>
        /// Processes all configurations in the provided configuration collection
        /// </summary>
        /// <param name="configuration">the current configuration collection</param>
        /// <param name="data">the data that came out of the last query</param>
        private void ProcessConfig(QueryConfigurationCollection configuration, DynamicResult[] data = null)
        {
            QueryConfigurationCollection tmp = currentConfiguration.Value;
            DynamicResult currentTmpItem     = currentItem.Value;

            try
            {
                if (currentTmpItem != null)
                {
                    Parents.Insert(0, currentTmpItem);
                }
                currentConfiguration.Value = configuration;
                if (data != null)
                {
                    foreach (DynamicResult result in data)
                    {
                        currentItem.Value = result;
                        ProcessQueries(configuration);
                    }
                }
                else
                {
                    ProcessQueries(configuration);
                }
            }
            finally
            {
                currentConfiguration.Value = tmp;
                currentItem.Value          = currentTmpItem;
                if (currentTmpItem != null)
                {
                    Parents.RemoveAt(0);
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Maps the data of the dynamicResult instance into the T - Instance
 /// </summary>
 /// <param name="item">the item that contains the original data</param>
 /// <param name="target">the target instance into which the data is mapped</param>
 /// <param name="modelType">the meta-type used to identify mapped columns</param>
 public static void ToModel(this DynamicResult item, object target, Type modelType)
 {
     string[]  fieldNames = item.GetDynamicMemberNames().ToArray();
     MapRule[] rules      = DbColumnAttribute.GetRules(modelType).Clone() as MapRule[];
     for (int i = 0; i < rules.Length; i++)
     {
         MapRule r = rules[i];
         if (r != null && fieldNames.Any(n => n.Equals(r.FieldName, StringComparison.OrdinalIgnoreCase)))//Array.IndexOf(fieldNames, r.FieldName.ToLower()) != -1))))
         {
             try
             {
                 object val = item[r.FieldName];
                 if (!r.UseExpression)
                 {
                     r[target] = val;
                 }
                 else
                 {
                     r[target] = ProcessResolveExpression(r.ValueResolveExpression, val);
                 }
             }
             catch (Exception ex)
             {
                 LogEnvironment.LogEvent(string.Format("Failed to set value{1}{0}", ex.OutlineException(), Environment.NewLine), LogSeverity.Warning, "DataAccess");
             }
         }
         else if (r != null)
         {
             LogEnvironment.LogDebugEvent($"No Value found for MapRule {r.FieldName} ({r.UseExpression};{r.ValueResolveExpression}", LogSeverity.Report);
         }
     }
 }
Пример #5
0
        /// <summary>
        /// Converts a list of DynamicResult records into a DataTable
        /// </summary>
        /// <param name="data">the list of dynamicresult that is being converted into a datatable</param>
        /// <param name="extensionForRowInResult">when provided adds a new field in the DynamicResult and maps back the generated data-row to each Record</param>
        /// <returns>the datatable containing the items</returns>
        public static DataTable ToDataTable(this IEnumerable <DynamicResult> data, string extensionForRowInResult = null)
        {
            DataTable     retVal = new DataTable();
            DynamicResult first  = data.FirstOrDefault();

            if (first != null)
            {
                string[] names = first.GetDynamicMemberNames().ToArray();
                foreach (string s in names)
                {
                    retVal.Columns.Add(s, GetTableType(first.GetType(s)));
                }

                foreach (DynamicResult res in data)
                {
                    DataRow row = retVal.NewRow();
                    foreach (string s in names)
                    {
                        row[s] = res[s] ?? DBNull.Value;
                    }

                    if (extensionForRowInResult != null)
                    {
                        res.Extendable = true;
                        res[extensionForRowInResult] = row;
                    }

                    retVal.Rows.Add(row);
                }
            }

            return(retVal);
        }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the AcceptanceCallbackParameter class
 /// </summary>
 /// <param name="success"></param>
 /// <param name="dataSetName">the name of the processed DataSet</param>
 /// <param name="data">the data that was recognized for the provided DataSet-name</param>
 public AcceptanceCallbackParameter(bool success, string dataSetName, DynamicResult data, T sourceData)
 {
     Success     = success;
     DataSetName = dataSetName;
     Data        = data;
     SourceData  = sourceData;
 }
Пример #7
0
        /// <summary>
        /// Dumps data into the given row
        /// </summary>
        /// <param name="targetRow">the target row into which to dump the provided data</param>
        /// <param name="keys">the keys that are used for output</param>
        /// <param name="data">the source data. if null is provided, the keys are dumped into the row</param>
        private void DumpRow(IRow targetRow, string[] keys, DynamicResult data)
        {
            object[] res = (from t in keys select(object) data?[t] ?? t).ToArray();
            int      i   = 0;

            res.ForEach(r => SetCellValue(targetRow.CreateCell(i++), r)); //targetRow.CreateCell(i++).SetCellValue(r.ToString()));
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the ImportDiagnosticDataSet class
 /// </summary>
 /// <param name="sourceData">the source-data that was provided by an ImportSource</param>
 /// <param name="message">the Message of this Event</param>
 /// <param name="severity">the Severity of this event</param>
 /// <param name="resultData">the ResultData that was created by the parser</param>
 public ParserEventRecord(object sourceData, string message, ParserEventSeverity severity, DynamicResult resultData)
 {
     SourceData = sourceData;
     Message    = message;
     Severity   = severity;
     ResultData = resultData;
 }
Пример #9
0
        /// <summary>
        /// Registers the open data to the list of data for this consumer
        /// </summary>
        protected void AddCurrentRecord()
        {
            currentValues.Add(KeyName, results.Count);
            if (VirtualColumns.Count != 0)
            {
                Scope scope =
                    new Scope(new Dictionary <string, object>
                {
                    { "current", currentValues },
                    { "context", ImportContext.Current }
                });
                using (var session = ExpressionParser.BeginRepl(scope, a => { DefaultCallbacks.PrepareDefaultCallbacks(a.Scope, a.ReplSession); }))
                {
                    foreach (ConstConfiguration constConfiguration in VirtualColumns)
                    {
                        currentValues.Add(constConfiguration.Name,
                                          constConfiguration.ConstType == ConstType.SingleExpression
                                ? ExpressionParser.Parse(constConfiguration.ValueExpression, session)
                                : ExpressionParser.ParseBlock(constConfiguration.ValueExpression, session));
                    }
                }
            }

            DynamicResult record = new DynamicResult(currentValues);

            newData.Value = record;
            results.Add(record);
            currentValues.Clear();
        }
Пример #10
0
        public static ExpandoObject ToExpando(this DynamicResult item, bool extendWithUppercase)
        {
            ExpandoObject eob = new ExpandoObject();
            IDictionary <string, object> eoc = eob;

            CopyToDictionary(item, eoc, extendWithUppercase);

            return(eob);
        }
Пример #11
0
        public ObjectBuilder()
        {
            d = new DynamicResult(new Dictionary <string, object>());

            d.values.Add("Clear", new Action(Clear));
            d.values.Add("Add", new Action <string, string>(Add));
            d.values.Add("Remove", new Action <string>(Remove));
            d.values.Add("Clone", new Func <dynamic>(() => { return(d); }));
        }
Пример #12
0
        /// <summary>
        /// Tries to load content from an xml file. If the file does not exists, an empty array is returned
        /// </summary>
        /// <param name="fileName">the filename from which to load data</param>
        /// <returns>the list of retreived objects or an empty array if the file does not exist</returns>
        public DynamicResult[] TryLoadData(string fileName)
        {
            DynamicResult[] retVal = new DynamicResult[0];
            if (File.Exists(string.Format(@"{0}\{1}", dataDumpDirectory, fileName)))
            {
                retVal = LoadData(fileName);
            }

            return(retVal);
        }
Пример #13
0
        public static IDictionary <string, object> ToDictionary(this DynamicResult item, bool caseInsensitive)
        {
            var retVal =
                new Dictionary <string, object>(caseInsensitive
                    ? StringComparer.OrdinalIgnoreCase
                    : StringComparer.CurrentCulture);

            CopyToDictionary(item, retVal, false);
            return(retVal);
        }
Пример #14
0
        /// <summary>
        /// Gets the first item's specific column of a recordset or returns the provided default value
        /// </summary>
        /// <typeparam name="T">the type that is expected</typeparam>
        /// <param name="items">the array from which to get the first item</param>
        /// <param name="columnName">the columnname to retreive from the first item</param>
        /// <param name="defaultValue">the default value in case that the array does not contain any items</param>
        /// <returns>the demanded value or the default value</returns>
        public static T FirstValueOrDefault <T>(this dynamic[] items, string columnName, T defaultValue)
        {
            T retVal = defaultValue;

            if (items.Length != 0)
            {
                DynamicResult r = items[0];
                retVal = r[columnName];
            }

            return(retVal);
        }
Пример #15
0
 private static void CopyToDictionary(DynamicResult item, IDictionary <string, object> target, bool extendWithUppercase)
 {
     string[] fieldNames = item.GetDynamicMemberNames().ToArray();
     foreach (var fieldName in fieldNames)
     {
         target.Add(fieldName, item[fieldName]);
         if (extendWithUppercase && fieldName.ToUpper() != fieldName)
         {
             target.Add(fieldName.ToUpper(), item[fieldName]);
         }
     }
 }
Пример #16
0
        /// <summary>
        /// Gets the current data of a specific resultset-name
        /// </summary>
        /// <param name="name">the name for which to get the current value</param>
        /// <returns>a dynamicresult object containing the importer-data for a specific resultset</returns>
        public DynamicResult this[string name]
        {
            get
            {
                DynamicResult retVal = null;
                if (importingData.ContainsKey(name))
                {
                    retVal = importingData[name];
                }

                return(retVal);
            }
        }
Пример #17
0
        public List <dynamic> GetAllWithPartBySchedule(int scheduleID)
        {
            using (GymcimContext context = new GymcimContext())
            {
                string fields = "ExerciseID, ExerciseName, ExerciseSet, ExerciseRep, ExerciseDay, ExerciseDesc, " +
                                "e.PartID, ScheduleID, PartName";

                string query = "SELECT " + fields + " FROM Exercises e JOIN Parts p" +
                               " ON e.PartID = p.PartID" +
                               " WHERE ScheduleID = @id";

                return(DynamicResult.DynamicListFromSql(context, query, new Dictionary <string, object> {
                    { "id", scheduleID }
                }).ToList());
            }
        }
Пример #18
0
        /// <summary>
        /// Inserts a record into the specified table with the specified values
        /// </summary>
        /// <param name="value">the result containing the items inserted into the table</param>
        /// <param name="tableName">the tablename in which to insert the data</param>
        /// <param name="hardcodedValues">values that are hardcoded</param>
        public void InsertRecord(DynamicResult value, string tableName, Dictionary <string, string> hardcodedValues)
        {
            List <string> fields = new List <string>(hardcodedValues.Keys);
            List <string> values = new List <string>((from t in fields select hardcodedValues[t]));

            IDbDataParameter[] parameters = (from t in value.GetDynamicMemberNames() select GetParameter(t, value[t]) as IDbDataParameter).ToArray();
            (from t in value.GetDynamicMemberNames() select t).ToList().ForEach(fields.Add);
            (from t in value.GetDynamicMemberNames() select $"@{t}").ToList().ForEach(values.Add);
            string cmd = string.Format(SqlCommands.InsertWithGetIdentity, tableName, string.Join(",", fields), string.Join(",", values));
            int    id  = ExecuteCommandScalar <int>(cmd, parameters);

            if (value.Controller != null)
            {
                value.Controller.SetIndex(value, id);
            }
        }
Пример #19
0
        private static IEnumerable<T> MatchesDynamic<T>(Regex regex, string input, ICustomConverter<T> converter = null)
            where T : class, new()
        {
            string[] groupNames = regex.GetGroupNames();

            foreach (Match m in regex.Matches(input).OfType<Match>().Where(f => f.Success))
            {
                dynamic itm = new DynamicResult(m, groupNames);

                for (int i = 1; i < m.Groups.Count; ++i)
                {
                    string groupName = regex.GroupNameFromNumber(i);

                    if (converter != null)
                        converter.Convert(groupName, m.Groups[i], itm);
                }

                yield return itm;
            }
        }
Пример #20
0
        /// <summary>
        /// Inserts a record into the specified table with the specified values
        /// </summary>
        /// <param name="value">the result containing the items inserted into the table</param>
        /// <param name="tableName">the tablename in which to insert the data</param>
        /// <param name="hardcodedValues">values that are hardcoded</param>
        public void InsertRecord(DynamicResult value, string tableName, Dictionary <string, string> hardcodedValues)
        {
            List <string> fields     = new List <string>(hardcodedValues.Keys);
            List <string> values     = new List <string>((from t in fields select hardcodedValues[t]));
            var           parameters = (from t in value.GetDynamicMemberNames()
                                        select new { Field = t, Param = GetParameter(t, value[t]) as IDbDataParameter }).ToArray();
            var par = new List <IDbDataParameter>();

            parameters.ForEach(p =>
            {
                fields.Add(p.Field);
                values.Add(p.Param.ParameterName);
                par.Add(p.Param);
            });

            string cmd = string.Format(SqlCommands.InsertWithGetIdentity, tableName, string.Join(",", fields), string.Join(",", values));
            int    id  = ExecuteCommandScalar <int>(cmd, par.ToArray());

            if (value.Controller != null)
            {
                value.Controller.SetIndex(value, id);
            }
        }
 /// <summary>
 /// Initializes a new instance of the TextAcceptanceCallbackParameter class
 /// </summary>
 /// <param name="success">indicates whether the provided text was imported successfully</param>
 /// <param name="dataSetName">the name of the dataset the imported data is associated with</param>
 /// <param name="data">the recognized data</param>
 /// <param name="sourceData">the sourceData that was provided by a string-source</param>
 /// <param name="acceptedKeys">the data-keys that were accepted by the processing reader</param>
 public DictionaryAcceptanceCallbackParameter(bool success, string dataSetName, DynamicResult data, IDictionary <string, TValue> sourceData, string[] acceptedKeys) : base(success, dataSetName, data, sourceData)
 {
     AcceptedKeys = acceptedKeys;
 }
Пример #22
0
 /// <summary>
 /// Checks the index-columns with the ones of this sheet
 /// </summary>
 /// <param name="sourceData"></param>
 private void CheckIndexColumns(DynamicResult sourceData)
 {
     sourceData?.Keys.Where(n => !columns.Contains(n, StringComparer.OrdinalIgnoreCase)).ForEach(PushColumn);
     PushColumn("Message");
 }
Пример #23
0
 /// <summary>
 /// Logs an event on all Event-listeners of this ImportSource
 /// </summary>
 /// <param name="sourceData">the sourceData that was generated from this instance</param>
 /// <param name="eventText">the event-text for the parser-event</param>
 /// <param name="severity">the severity of the parser event</param>
 /// <param name="resultingData">the data that was recognized from one of the parsers or from this ImportSource</param>
 protected void LogParserEvent(T sourceData, string eventText, ParserEventSeverity severity,
                               DynamicResult resultingData = null)
 {
     listeners.ForEach(
         n => n?.ReportEvent(sourceData, eventText, severity, resultingData));
 }
Пример #24
0
 /// <summary>
 /// Sets the current importdata
 /// </summary>
 /// <param name="name">the name of the dataset that</param>
 /// <param name="data">the last result of a parser</param>
 internal void SetCurrent(string name, DynamicResult data)
 {
     importingData[name] = data;
 }
 /// <summary>
 /// Initializes a new instance of the TextAcceptanceCallbackParameter class
 /// </summary>
 /// <param name="success">indicates whether the provided text was imported successfully</param>
 /// <param name="firstAcceptedCharacter">the first character of the provided data</param>
 /// <param name="acceptedLength">the length that was processed by the consumer</param>
 /// <param name="dataSetName">the name of the dataset the imported data is associated with</param>
 /// <param name="data">the recognized data</param>
 /// <param name="sourceData">the sourceData that was provided by a string-source</param>
 public TextAcceptanceCallbackParameter(bool success, int firstAcceptedCharacter, int acceptedLength, string dataSetName, DynamicResult data, string sourceData) : base(success, dataSetName, data, sourceData)
 {
     FirstAcceptedCharacter = firstAcceptedCharacter;
     AcceptedLength         = acceptedLength;
 }
 /// <summary>
 /// Offers the possibility to process filtered Events that match the configured Severity
 /// </summary>
 /// <param name="data">the data that leads to this event</param>
 /// <param name="message">the generated message by a parser or a data-provider</param>
 /// <param name="severity">the severity of the event</param>
 /// <param name="result">the result that was generated by the parser</param>
 protected override void AddEvent(object data, string message, ParserEventSeverity severity, DynamicResult result)
 {
     events.Add(new ParserEventRecord(data, message, severity, result));
 }
Пример #27
0
 /// <summary>
 /// Offers the possibility to process filtered Events that match the configured Severity
 /// </summary>
 /// <param name="data">the data that leads to this event</param>
 /// <param name="message">the generated message by a parser or a data-provider</param>
 /// <param name="severity">the severity of the event</param>
 /// <param name="result">the result that was generated by the parser</param>
 protected abstract void AddEvent(object data, string message, ParserEventSeverity severity, DynamicResult result);
Пример #28
0
 /// <summary>
 /// Reports an event for a specific input-dataset
 /// </summary>
 /// <param name="data">the data that was generated by a specific source</param>
 /// <param name="message">the message that was generated by the parser or the source</param>
 /// <param name="severity">the severity of the event</param>
 /// <param name="result">the result that was generated by the parser</param>
 public void ReportEvent(object data, string message, ParserEventSeverity severity, DynamicResult result = null)
 {
     if ((severity & targetSeverity) != 0)
     {
         AddEvent(data, message, severity, result);
     }
 }
Пример #29
0
 /// <summary>
 /// Initializes a new instance of the TextAcceptanceCallbackParameter class
 /// </summary>
 /// <param name="success">indicates whether the provided text was imported successfully</param>
 /// <param name="dataSetName">the name of the dataset the imported data is associated with</param>
 /// <param name="data">the recognized data</param>
 /// <param name="sourceData">the sourceData that was provided by a string-source</param>
 /// <param name="acceptedKeys">the data-keys that were accepted by the processing reader</param>
 public KeyValueAcceptanceCallbackParameter(bool success, string dataSetName, DynamicResult data, IBasicKeyValueProvider sourceData, string[] acceptedKeys) : base(success, dataSetName, data, sourceData)
 {
     AcceptedKeys = acceptedKeys;
 }
Пример #30
0
 public void InsertRecord(DynamicResult value, string tableName, Dictionary <string, string> hardcodedValues)
 {
     throw new NotImplementedException();
 }