Example #1
0
        /// <summary>
        /// Gets the complete data for serveral plugins of certain workstations and a certain timespan.
        /// </summary>
        /// <param name="macAndProperties"> A list containing tuples of:  MAC | PluginName | IndicatorName | LowerBound? | UpperBound? | Maximum numer of results?</param>
        /// <returns>A list containing tuples of: MAC | PluginName | IndicatorName | Value | Mapping | Time</returns>
        public List <Tuple <string, string, string, string, MappingState, DateTime> > GetDataOLDAPPROACH(List <Tuple <string, string, string, DateTime?, DateTime?, int?> > macAndProperties)
        {
            #region check arguments
            if (macAndProperties == null || macAndProperties.Count == 0)
            {
                throw new ArgumentException("macAndProperties list item false.", "macAndProperties");
            }
            #endregion

            List <Tuple <string, string, string, string, MappingState, DateTime> > result = new List <Tuple <string, string, string, string, MappingState, DateTime> >();


            using (var dataContext = DataContextFactory.CreateReadOnlyDataContext())
            {
                //current:  (MAC | PluginName | IndicatorName | LowerBound? | UpperBound? | Maximum numer of results?)
                foreach (var c in macAndProperties)
                {
                    try
                    {
                        // TODO Arno entfernen
                        //break;

                        #region check arguments
                        if (c.Item1 == null || c.Item1 == "")
                        {
                            throw new ArgumentException("macAndProperties list item false.", "macAdress (Item1)");
                        }
                        if (c.Item2 == null || c.Item2 == "")
                        {
                            throw new ArgumentException("macAndProperties list item false.", "pluginName (Item2)");
                        }
                        if (c.Item3 == null || c.Item3 == "")
                        {
                            throw new ArgumentException("macAndProperties list item false.", "IndicatorName (Item3)");
                        }

                        #endregion

                        //update mapping state
                        UpdateMappingState(c.Item1);

                        //set numbers of values
                        int  numbersOfValues = (c.Item6 != null && c.Item6 > 0) ? (int)c.Item6 : int.MaxValue;
                        long lowerTicks      = (c.Item4 != null) ? c.Item4.Value.Ticks : 0;
                        long upperTicks      = (c.Item5 != null) ? c.Item5.Value.Ticks : long.MaxValue;

                        #region caching for single results, continuing in loop
                        if (numbersOfValues == 1)
                        {
                            Tuple <string, string, string, string, MappingState, DateTime> value = GetCachedIndicator(c.Item1, c.Item2, c.Item3);
                            if (value != null)
                            {
                                result.Add(value);
                                continue;
                            }
                        }
                        #endregion

                        //get valueX type
                        var type = (from q in dataContext.Indicator
                                    where q.Name == c.Item3
                                    select q.ValueType).FirstOrDefault();

                        if (!(type == (byte)Core.DataType.Byte || type == (byte)Core.DataType.Float || type == (byte)Core.DataType.Int || type == (byte)Core.DataType.String))
                        {
                            continue;
                        }

                        //get valueX, create sub-results and add them to the result
                        #region byte
                        if (type == (byte)Core.DataType.Byte)
                        {
                            var byteResult = PrecompiledQueries.GetByteValues(dataContext, c.Item1, c.Item2, c.Item3, lowerTicks, upperTicks, numbersOfValues);
                            result.AddRange(byteResult);
                        }
                        #endregion

                        #region int
                        if (type == (byte)DataType.Int)
                        {
                            var intResult = PrecompiledQueries.GetIntValues(dataContext, c.Item1, c.Item2, c.Item3, lowerTicks, upperTicks, numbersOfValues);
                            result.AddRange(intResult);
                        }
                        #endregion

                        #region float
                        if (type == (byte)DataType.Float)
                        {
                            var floatResult = PrecompiledQueries.GetFloatValues(dataContext, c.Item1, c.Item2, c.Item3, lowerTicks, upperTicks, numbersOfValues);
                            result.AddRange(floatResult);
                        }
                        #endregion

                        #region string
                        if (type == (byte)DataType.String)
                        {
                            var stringResult = PrecompiledQueries.GetStringValues(dataContext, c.Item1, c.Item2, c.Item3, lowerTicks, upperTicks, numbersOfValues);
                            result.AddRange(stringResult);
                        }
                        #endregion

                        //cache first element
                        if (numbersOfValues == 1 && result.ElementAt(0) != null)
                        {
                            this.CacheIndicator(result.ElementAt(0));
                        }
                    }
                    catch (Exception e)
                    {
                        #region logging
                        //logging exception
                        var messageEx = new StringBuilder();
                        messageEx.Append("ValueManager_GetData: Can't create List of PluginDatas" + ". " + e.ToString() + " StackTrace: " + e.StackTrace);
                        MISD.Core.Logger.Instance.WriteEntry(messageEx.ToString(), LogType.Exception);
                        #endregion
                    }
                }
            }

            //TODO remove this log
            Logger.Instance.WriteEntry("ValueManager_GetData: Data createtd and returned: " + result.Count + " elements for " + macAndProperties.Count() + " mac/plugin/indicator combis starting with " + macAndProperties.First().Item1 + " and Plugin " + macAndProperties.First().Item2, LogType.Debug);

            return(result);
        }