/// <summary>
        /// Creates measurements
        /// </summary>
        /// <param name="consumer">Data consumer</param>
        /// <param name="argument">Argument</param>
        /// <param name="values">Names of values</param>
        /// <param name="series">series</param>
        /// <param name="functions">functions</param>
        /// <returns>Mesurements dictionary</returns>
        public static Dictionary <string, object> CreateMeasurements(this IDataConsumer consumer, string argument, string[] values, out ParametrizedSeries[] series,
                                                                     out Dictionary <DoubleArrayFunction, IMeasurement[]> functions)
        {
            Double a = 0;

            functions = new Dictionary <DoubleArrayFunction, IMeasurement[]>();
            series    = null;
            if (argument == null | values == null)
            {
                return(null);
            }
            IMeasurement arg = null;

            if (argument.Equals("Time"))
            {
                arg = DataPerformer.Portable.StaticExtensionDataPerformerPortable.Factory.TimeProvider.TimeMeasurement;
            }
            else
            {
                arg = consumer.FindMeasurement(argument, false);
            }
            Dictionary <string, object> d = new Dictionary <string, object>();
            List <ParametrizedSeries>   m = new List <ParametrizedSeries>();

            foreach (string key in values)
            {
                object       o   = null;
                IMeasurement val = consumer.FindMeasurement(key, false);
                object       t   = val.Type;
                if (t.Equals(a))
                {
                    ParametrizedSeries ps = new ParametrizedSeries(arg.ToValueHolder(), val.ToValueHolder());

                    m.Add(ps);
                    o = ps;
                }
                else
                {
                    DoubleArrayFunction f = new DoubleArrayFunction(t);
                    functions[f] = new IMeasurement[] { arg, val };
                    o            = f;
                }
                d[key] = o;
            }
            series = m.ToArray();
            Type type = consumer.GetType();

            System.Reflection.MethodInfo mi = type.GetMethod("Prepare", new Type[0]);
            if (mi != null)
            {
                mi.Invoke(consumer, new object[0]);
            }
            return(d);
        }
        /// <summary>
        /// Creates Xml document
        /// </summary>
        /// <param name="consumer">Data consumer</param>
        /// <param name="collection">Components</param>
        /// <param name="input">Input</param>
        /// <param name="start">Start</param>
        /// <param name="step">Step</param>
        /// <param name="count">Count</param>
        /// <returns>Result</returns>
        static public XmlDocument CreateXmlDocument(this IDataConsumer consumer,
                                                    XmlDocument input, double start, double step,
                                                    int count)
        {
            List <string> p    = new List <string>();
            IMeasurement  cond = null;
            string        arg  = null;
            Dictionary <string, Func <Func <object> > > d = new Dictionary <string, Func <Func <object> > >();
            XmlElement r = input.DocumentElement;

            foreach (XmlElement e in r.ChildNodes)
            {
                string name = e.Name;
                if (name.Equals("Condition"))
                {
                    cond = consumer.FindMeasurement(e.InnerText, true);
                    continue;
                }
                if (name.Equals("Argument"))
                {
                    arg = e.InnerText;
                    continue;
                }
                if (name.Equals("Parameters"))
                {
                    XmlNodeList nl = e.ChildNodes;
                    foreach (XmlElement xp in nl)
                    {
                        string pn = null;
                        string pv = null;
                        foreach (XmlElement xpp in xp.ChildNodes)
                        {
                            string npp = xpp.Name;
                            if (npp.Equals("Name"))
                            {
                                pn = xpp.InnerText;
                                continue;
                            }
                            pv = xpp.InnerText;
                        }
                        IMeasurement mcc = consumer.FindMeasurement(pn, false);
                        d[pv] = mcc.ToValueHolder();
                    }
                }
            }
            XmlParameterWriter xpv  = new XmlParameterWriter(null);
            IParameterWriter   pvv  = xpv;
            Action             acts = () =>
            {
                Dictionary <string, string> dpp = new Dictionary <string, string>();
                foreach (string k in d.Keys)
                {
                    object v = d[k]()();
                    FormulaMeasurement.CheckValue(v);
                    dpp[k] = v + "";
                }
                pvv.Write(dpp);
            };

            Action act = (cond == null) ? acts : () =>
            {
                foreach (string k in d.Keys)
                {
                    object v = d[k]()();
                    FormulaMeasurement.CheckValue(v);
                }
                if ((bool)cond.Parameter())
                {
                    acts();
                }
            };

            try
            {
                consumer.PerformFixed(start, step, count, StaticExtensionDataPerformerInterfaces.Calculation, 0, act);
            }
            catch (Exception e)
            {
                e.ShowError(10);
            }
            return(xpv.Document);
        }
示例#3
0
        /// <summary>
        /// Creates measurements
        /// </summary>
        /// <param name="argument">Argument</param>
        /// <param name="values">Names of values</param>
        /// <param name="series">series</param>
        /// <param name="functions">functions</param>
        /// <param name="disassembly">Disassembly</param>
        /// <returns>Mesurements dictionary</returns>
        public Dictionary <string, object> CreateMeasurements(string argument, string[] values, out ParametrizedSeries[] series,
                                                              out Dictionary <DoubleArrayFunction, IMeasurement[]> functions, Dictionary <IMeasurement, MeasurementsDisasseblyWrapper> disassembly = null)
        {
            Dictionary <IMeasurement, MeasurementsDisasseblyWrapper> dis = new Dictionary <IMeasurement, MeasurementsDisasseblyWrapper>();

            if (disassembly != null)
            {
                dis = disassembly;
            }
            double a = 0;

            functions = new Dictionary <DoubleArrayFunction, IMeasurement[]>();
            series    = null;
            if (argument == null | values == null)
            {
                return(null);
            }
            IMeasurement arg = null;

            if (argument.Equals("Time"))
            {
                arg = StaticExtensionDataPerformerPortable.Factory.TimeProvider.TimeMeasurement;
            }
            else
            {
                arg = this.FindMeasurement(argument, false);
            }
            Dictionary <string, object> d = new Dictionary <string, object>();
            List <ParametrizedSeries>   m = new List <ParametrizedSeries>();

            foreach (string key in values)
            {
                object       o   = null;
                IMeasurement val = this.FindMeasurement(key, false);
                if (val == null)
                {
                    continue;
                }
                object t = val.Type;
                if (t.Equals(a))
                {
                    ParametrizedSeries ps =
                        new ParametrizedSeries(arg.ToValueHolder(), val.ToValueHolder());
                    m.Add(ps);
                    o = ps;
                }
                else if (disassembly.ContainsKey(val))
                {
                    MeasurementsDisasseblyWrapper mv = disassembly[val];
                    string k = key.Substring(0, key.IndexOf('.') + 1);
                    foreach (IMeasurement mea in mv.Measurements)
                    {
                        ParametrizedSeries ps =
                            new ParametrizedSeries(arg.ToValueHolder(), mea.ToValueHolder());
                        m.Add(ps);
                        if (ps != null)
                        {
                            d[k + mea.Name] = ps;
                        }
                    }
                    continue;

                    /* TEMP DELETE   DoubleArrayFunction f = new DoubleArrayFunction(t);
                     * functions[f] = new IMeasurement[] { arg, val };
                     * o = f;
                     */
                }
                if (o != null)
                {
                    d[key] = o;
                }
            }
            series = m.ToArray();
            Prepare();
            return(d);
        }