Пример #1
0
        void PerformExternal(IBufferData data)
        {
            string reason                   = StaticExtensionDataPerformerInterfaces.Calculation;
            IEnumerable <object> en         = PureEnumerable(data);
            IEnumerator <object> enumerator = en.GetEnumerator();

            using (TimeProviderBackup backup = new TimeProviderBackup(externalComponentCollection, this, 0, reason))
            {
                enumerator.MoveNext();
                IDataRuntime runtime = backup.Runtime;
                IStep        st      = null;
                if (runtime is IStep)
                {
                    st      = runtime as IStep;
                    st.Step = 0;
                }
                externalComponentCollection.ForEach((IStarted started) => { started.Start(time); });
                double last = time;
                Action <double, double, long> act = runtime.Step(null,
                                                                 (double timer) => { }, reason, null);
                int i = 0;
                while (enumerator.MoveNext())
                {
                    act(last, time, i);
                    ++i;
                    if (st != null)
                    {
                        st.Step = i;
                    }
                    last = time;
                }
            }
        }
        public static bool PerformIterator(this IDataConsumer consumer, IIterator iterator,
                                           ITimeMeasureProvider timeProvider, string reason, Func <bool> stop)
        {
            try
            {
                using (TimeProviderBackup backup = new TimeProviderBackup(consumer, timeProvider, null, reason, 0))
                {
                    IDataRuntime runtime = backup.Runtime;
                    IStep        st      = null;
                    IMeasurement time    = timeProvider.TimeMeasurement;
                    if (runtime is IStep)
                    {
                        st      = runtime as IStep;
                        st.Step = 0;
                    }
                    iterator.Reset();
                    double t    = (double)time.Parameter();
                    double last = t;
                    Action <double, double, long> act = runtime.Step(null,
                                                                     (double timer) => { }, reason, null);
                    int i = 0;
                    IEnumerable <object> enu = runtime.AllComponents;

                    while (iterator.Next())
                    {
                        t = (double)time.Parameter();
                        act(last, t, i);
                        ++i;
                        if (st != null)
                        {
                            st.Step = i;
                        }
                        last = t;
                        if (stop())
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                ex.ShowError(10);
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Performs ation with array of arguments
        /// </summary>
        /// <param name="consumer">Data consumer</param>
        /// <param name="array">Array of arguments</param>
        /// <param name="collection">Desktop</param>
        /// <param name="provider">Provider of time measure</param>
        /// <param name="processor">Differential equation processor</param>
        /// <param name="priority">Priority</param>
        /// <param name="action">Additional action</param>
        /// <param name="reason">Reason</param>
        static public void PerformArray(this IDataConsumer consumer, Array array, IComponentCollection collection, ITimeMeasureProvider provider,
                                        IDifferentialEquationProcessor processor, int priority, Action action, string reason)
        {
            using (TimeProviderBackup backup = new TimeProviderBackup(collection, provider, processor, priority, reason))
            {
                IDataRuntime         runtime = backup.Runtime;
                ITimeMeasureProvider old     = processor.TimeProvider;
                processor.TimeProvider = provider;
                IStep st = null;
                if (runtime is IStep)
                {
                    st = runtime as IStep;
                }
                int    n    = array.Length;
                double t    = (double)array.GetValue(0);
                double last = t;
                Action <double, double, long> act =
                    runtime.Step(processor, (double time) =>
                                 { provider.Time = time; }, reason);
                for (int i = 0; i < n; i++)
                {
                    t = (double)array.GetValue(i);
                    act(last, t, (long)i);

                    /* last = t;
                     * if (i == 0)
                     * {
                     *   runtime.StartAll((double)array.GetValue(0));
                     * }
                     * if (st != null)
                     * {
                     *   st.Step = i;
                     * }
                     * runtime.UpdateAll();
                     * provider.Time = (double)array.GetValue(i);
                     * if (i > 0 & processor != null)
                     * {
                     *   processor.Step((double)array.GetValue(i - 1), (double)array.GetValue(i));
                     * }
                     * provider.Time = (double)array.GetValue(i);*/
                    action();
                    //collection.ResetUpdatedMeasurements();
                }
                processor.TimeProvider = old;
            }
        }
Пример #4
0
 /// <summary>
 /// Performs action with fixed step
 /// </summary>
 /// <param name="consumer">Data consumer</param>
 /// <param name="start">Start</param>
 /// <param name="step">Step</param>
 /// <param name="count">Count of steps</param>
 /// <param name="provider">Provider of time measure</param>
 /// <param name="processor">Differential equation processor</param>
 /// <param name="reason">Reason</param>
 /// <param name="priority">Priority</param>
 /// <param name="action">Additional action</param>
 /// <param name="errorHandler">Error handler</param>
 /// <param name="asynchronousCalculation">Asynchronous calculation</param>
 static public void PerformFixed(this IDataConsumer consumer, double start, double step, int count,
                                 ITimeMeasureProvider provider,
                                 IDifferentialEquationProcessor processor, string reason,
                                 int priority, Action action, IAsynchronousCalculation asynchronousCalculation = null,
                                 IErrorHandler errorHandler = null)
 {
     try
     {
         using (TimeProviderBackup backup = new TimeProviderBackup(consumer, provider, processor, reason, priority))
         {
             IDataRuntime         runtime = backup.Runtime;
             ITimeMeasureProvider old     = processor.TimeProvider;
             processor.TimeProvider = provider;
             IStep st = null;
             if (runtime is IStep)
             {
                 st = runtime as IStep;
             }
             provider.Time = start;
             double t    = start;
             double last = t;
             Action <double, double, long> act = runtime.Step(processor,
                                                              (double time) => { provider.Time = time; }, reason, asynchronousCalculation);
             for (int i = 0; i < count; i++)
             {
                 t = start + i * step;
                 act(last, t, i);
                 last = t;
                 action();
             }
             processor.TimeProvider = old;
         }
     }
     catch (Exception ex)
     {
         if (errorHandler != null)
         {
             errorHandler.ShowError(ex, 10);
         }
         else
         {
             ex.ShowError(10);
         }
     }
 }
Пример #5
0
        IEnumerable <byte[]> Transform(IIterator iterator, Func <bool> stop)
        {
            string reason = StaticExtensionEventInterfaces.RealtimeLogAnalysis;

            using (TimeProviderBackup backup = new TimeProviderBackup(consumer, iterator as ITimeMeasureProvider, null, reason, 0))
            {
                IDataRuntime runtime = backup.Runtime;
                IStep        st      = null;
                IMeasurement time    = (iterator as ITimeMeasureProvider).TimeMeasurement;
                if (runtime is IStep)
                {
                    st      = runtime as IStep;
                    st.Step = 0;
                }
                iterator.Reset();
                double t    = (double)time.Parameter();
                double last = t;
                Action <double, double, long> act = runtime.Step(null,
                                                                 (double timer) =>
                {
                }, reason, null);
                int i = 0;
                while (iterator.Next()) //!!! Unifinished?
                {
                    t = (double)time.Parameter();
                    act(last, t, i);
                    ++i;
                    DateTime dt = new DateTime();
                    dt += TimeSpan.FromSeconds(t);
                    object tuple =
                        new Tuple <DateTime, Dictionary <string, object> >(dt,
                                                                           measurementsWrite.WriteParameters());
                    yield return(objectToBytes(tuple));

                    if (stop())
                    {
                        break;
                    }
                }
            }
        }
Пример #6
0
 /// <summary>
 /// Performs action with fixed step
 /// </summary>
 /// <param name="collection">Desktop</param>
 /// <param name="start">Start</param>
 /// <param name="step">Step</param>
 /// <param name="count">Count of steps</param>
 /// <param name="provider">Provider of time measure</param>
 /// <param name="processor">Differential equation processor</param>
 /// <param name="priority">Priority</param>
 /// <param name="action">Additional action</param>
 /// <param name="reason">Reason</param>
 static public void PerformFixed(this IComponentCollection collection, double start, double step, int count, ITimeMeasureProvider provider,
                                 IDifferentialEquationProcessor processor, int priority, Action action, string reason)
 {
     using (TimeProviderBackup backup = new TimeProviderBackup(collection, provider, processor, priority, reason))
     {
         List <IMeasurements> measurements = backup.Measurements;
         IDataRuntime         runtime      = backup.Runtime;
         ITimeMeasureProvider old          = processor.TimeProvider;
         processor.TimeProvider = provider;
         Action <double, double, long> act = runtime.Step(processor,
                                                          (double time) => { provider.Time = time; }, reason);
         double last = start;
         double t    = start;
         for (int i = 0; i < count; i++)
         {
             t = start + i * step;
             act(last, t, (long)i);
             last = t;
             action();
         }
         processor.TimeProvider = old;
     }
 }
Пример #7
0
        /// <summary>
        /// Creates action
        /// </summary>
        /// <param name="runtime">Runtime</param>
        /// <param name="time">Time</param>
        /// <param name="processor">processor</param>
        /// <param name="action">Action</param>
        /// <param name="update">Update objects</param>
        /// <returns>Action</returns>
        protected virtual Action CreateAction(IDataRuntime runtime, double[] time,
                                              IDifferentialEquationProcessor processor, Action action, IRealtimeUpdate[] update)
        {
            ITimeMeasureProvider rt = realtime;

            double[]        t                 = new double[1];
            Action <double> setTime           = (double a) => { };
            Action <double, double, long> act = runtime.Step(processor, setTime,
                                                             StaticExtensionEventInterfaces.Realtime, null);

            long[] st = new long[] { 0 };

            Action updList = null;

            foreach (IRealtimeUpdate upd in update)
            {
                Action actp = upd.Update;
                if (actp == null)
                {
                    continue;
                }
                if (act != null)
                {
                    if (updList == null)
                    {
                        updList = actp;
                        continue;
                    }
                    updList = updList + actp;
                }
            }
            if (action != null)
            {
                updList = updList + action;
            }
            if (updList == null)
            {
                updList = action;
            }
            if (updList == null)
            {
                updList = () => { };
            }

            //  Action[] updateActions = updlist.ToArray();
            object loc = new object();

            if (realtimeStep == null)
            {
                return(() =>
                {
                    // !!! REPLACED WITH GLOBAL LOCKER  lock(locker)
                    // {
                    realtime.Update();
                    t[0] = rt.Time;
                    if (time[0] == t[0])
                    {
                        return;
                    }
                    act(time[0], t[0], st[0]);
                    time[0] = t[0];
                    st[0] += 1;
                    updList();
                    //}
                });
            }
            else
            {
                Action <double> acti;

                acti = (double arg) =>
                {
                    realtimeStep.Start(arg);
                    acti = realtimeStep.Step;
                };


                return(() =>
                {
                    lock (realtime)
                    {
                        realtime.Update();
                        t[0] = rt.Time;
                        act(time[0], t[0], st[0]);
                        time[0] = t[0];
                        st[0] += 1;
                        updList();
                        acti(t[0]);
                    }
                });
            }
        }