aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs
blob: 807b959350225f5323f0d464c898e9c020ad6c62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Tango.BL.Entities;
using Tango.Core;
using System.Data.Entity;
using Tango.Core.Threading;

namespace Tango.BL
{
    public partial class ObservablesStaticCollections : ExtendedObject
    {
        private ObservablesContext db;

        private bool _initialized;
        public bool IsInitialized
        {
            get { return _initialized; }
            private set { _initialized = value; }
        }

        private static ObservablesStaticCollections _instance;
        /// <summary>
        /// Gets the singleton instance.
        /// </summary>
        public static ObservablesStaticCollections Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new ObservablesStaticCollections();
                }
                return _instance;
            }
        }

        private ObservablesStaticCollections()
        {

        }

        public ObservablesStaticCollections(ObservablesContext context)
        {
            db = context;
        }

        public ObservablesContext Context
        {
            get { return db; }
        }

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        public void Initialize(Action<String> progressLog = null)
        {
            if (!_initialized)
            {
                progressLog?.Invoke("Loading static collections...");
                db = ObservablesContext.CreateDefault();

                WindingMethods = db.WindingMethods.ToObservableCollection();

                progressLog?.Invoke("Loading color spaces...");
                ColorSpaces = db.ColorSpaces.ToObservableCollection();

                progressLog?.Invoke("Loading spools...");
                SpoolTypes = db.SpoolTypes.ToObservableCollection();

                progressLog?.Invoke("Loading events...");
                EventTypes = db.EventTypes.ToObservableCollection();

                progressLog?.Invoke("Loading blowers...");
                HardwareBlowerTypes = db.HardwareBlowerTypes.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();
                //HardwareBlowers = db.HardwareBlowers.ToObservableCollection();

                progressLog?.Invoke("Loading break sensors...");
                HardwareBreakSensorTypes = db.HardwareBreakSensorTypes.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();
                //HardwareBreakSensors = db.HardwareBreakSensors.ToObservableCollection();

                progressLog?.Invoke("Loading dancers...");
                HardwareDancerTypes = db.HardwareDancerTypes.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();
                //HardwareDancers = db.HardwareDancers.ToObservableCollection();

                progressLog?.Invoke("Loading motors...");
                HardwareMotorTypes = db.HardwareMotorTypes.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();
                //HardwareMotors = db.HardwareMotors.ToObservableCollection();

                progressLog?.Invoke("Loading pid controls...");
                HardwarePidControlTypes = db.HardwarePidControlTypes.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();
                //HardwarePidControls = db.HardwarePidControls.ToObservableCollection();

                progressLog?.Invoke("Loading speed sensors...");
                HardwareSpeedSensorTypes = db.HardwareSpeedSensorTypes.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();
                //HardwareSpeedSensors = db.HardwareSpeedSensors.ToObservableCollection();

                progressLog?.Invoke("Loading winders...");
                HardwareWinderTypes = db.HardwareWinderTypes.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();
                //HardwareWinders = db.HardwareWinders.ToObservableCollection();

                progressLog?.Invoke("Loading tech controllers...");
                TechControllers = db.TechControllers.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();

                progressLog?.Invoke("Loading tech dispensers...");
                TechDispensers = db.TechDispensers.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();

                progressLog?.Invoke("Loading tech io's...");
                TechIos = db.TechIos.ToObservableCollection();

                progressLog?.Invoke("Loading tech monitors...");
                TechMonitors = db.TechMonitors.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();

                progressLog?.Invoke("Loading tech valves...");
                TechValves = db.TechValves.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();

                progressLog?.Invoke("Loading tech heaters...");
                TechHeaters = db.TechHeaters.ToList().OrderByAlphaNumeric(x => x.Description).ToObservableCollection();

                progressLog?.Invoke("Loading machines...");
                Machines = db.Machines.Include(x => x.Organization).ToObservableCollection();

                progressLog?.Invoke("Loading users...");
                Users = db.Users.Where(x => !x.Deleted).Include(x => x.Contact).ToObservableCollection();

                progressLog?.Invoke("Loading machine versions...");
                MachineVersions = db.MachineVersions.ToObservableCollection();

                //Load later...
                Task.Factory.StartNew(() =>
                {
                    LiquidTypes = db.LiquidTypes.ToObservableCollection();
                    DispenserTypes = db.DispenserTypes.ToObservableCollection();
                    MidTankTypes = db.MidTankTypes.ToObservableCollection();
                    CartridgeTypes = db.CartridgeTypes.ToObservableCollection();
                    IdsPackFormulas = db.IdsPackFormulas.ToObservableCollection();


                    Rmls = db.Rmls.ToObservableCollection();
                    LiquidTypesRmls = db.LiquidTypesRmls.ToObservableCollection();

                    foreach (var machine in Machines)
                    {
                        ObservablesContextAdapter adapter = new ObservablesContextAdapter(db);

                        adapter.GetConfiguration(x => x.Guid == machine.ConfigurationGuid);
                    }
                });

                _initialized = true;
            }

            //InitCollectionSources();
        }

        /// <summary>
        /// Creates a collection view from the specified observable collection.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection">The collection.</param>
        /// <returns></returns>
        private ICollectionView CreateCollectionView<T>(ObservableCollection<T> collection)
        {
            var view = CollectionViewSource.GetDefaultView(collection);
            return view;
        }
    }
}
span> IdleTaskGetLoadTable (uint32_t *aBuffer) { memcpy (aBuffer,idle_load_table,sizeof(idle_load_table)); } uint32_t MillisecCounter = 0; uint32_t ControlCounter = 0; Void mySwitchFxn(Task_Handle from, Task_Handle to) { if (to == Control_Task_Handle) ControlCounter++; if (to == Millisecond_Task_Handle) MillisecCounter++; //idle_counter // System_printf("mySwitchFxn: from = 0x%x, to = 0x%x", from, to); } /********************************************************** Name : calculate_system_load Function : calculate the average system load Parameters : current load (int) Return value : None Note : the average resets when the number_of_load_samples = 0 Description : The function calculate and change the system load variable ***********************************************************/ static void calculate_system_load (int current_load) { static int sum_of_previous_load=0; static uint32_t number_of_load_samples; if (first_time_after_init) { first_time_after_init = FALSE; system_load = current_load; max_system_load = system_load; max_load = Load; number_of_load_samples = 1; sum_of_previous_load = current_load; } else { sum_of_previous_load = sum_of_previous_load + current_load; number_of_load_samples = number_of_load_samples + 1; system_load = ( sum_of_previous_load / number_of_load_samples); if(system_load > max_system_load) max_system_load = system_load; } } /*********************************************************** Name : IDLE_change_parameters Function : starts new statistic with new time interval Parameters : new time interval Return value : None Note : None Description : sets the new interval and reset the samples number. ***********************************************************/ extern void IDLE_change_parameters(uint32_t new_interval) { next_interval = new_interval; memset(idle_load_table,0,sizeof(idle_load_table)); memset(idle_max_sequence_table,0,sizeof(idle_max_sequence_table)); memset(idle_sequence_table,0,sizeof(idle_sequence_table)); first_time_after_init=TRUE; /* reset the avarage calculation */ } /********************************************************** Name : IDEL_get_load Function : returns the system load Parameters : None Return value : system load Note : External function Description : Trivial ***********************************************************/ extern int IDLE_TASK_get_load(void) { return system_load; } /***********************************************************/ extern int IDLE_TASK_get_current_load(void) { return Load; } /***********************************************************/ /*export MN_uint32_t mn_get_load(char *pParams) { int i; MN_printf("\n\r\n\rSystem load\n\r-------------"); for(i=0;i<10;i++) MN_printf("\n\r %3d-%-3d Max Continuous Load is %4d intervals = %5d mSec", i*10, (i * 10 + 9),idle_max_sequence_table[i], 10*next_interval*idle_max_sequence_table[i]); MN_printf("\n\r %3d Max Continuous Load is %4d intervals = %5d mSec", (i * 10),idle_max_sequence_table[i], 10*next_interval*idle_max_sequence_table[i]); MN_printf("\n\r\n\rSystem avarege load=%d , max avarege load = %d",system_load, max_system_load); return(RET_OK); }*/ /***********************************************************/ /*export MN_uint32_t mn_get_curent_load(char *pParams) { MN_printf("\n\rload=%d,max Load=%d", Load, max_load); return(RET_OK); } */ /***********************************************************/ /*export MN_uint32_t mn_get_load_table(char *pParams) { int i; uint32_t interval_count; uint32_t avarege; int total_avarege; interval_count = 0; total_avarege = 0; MN_printf("\n\ridle_load_table\n\r---------------\n\r"); for ( i=0;i<=100;i++) { interval_count+=idle_load_table[i]; } for ( i=0;i<=100;i++) { avarege = (100*idle_load_table[i])/interval_count; MN_printf("|%3d-%-7d(%-2d)", i, idle_load_table[i], avarege); total_avarege+=(idle_load_table[i]*i); taskDelay(2); } total_avarege = total_avarege/interval_count; MN_printf("\n\rTotal avarege = %ld",total_avarege); return(RET_OK); } */ /***********************************************************/ /*export MN_uint32_t mn_change_interval(char *pParams) { MN_uint32_t rc; MN_WORD new_interval; MN_WORD index; index = 0; rc = MN_ParseWord(pParams ,&index ,&new_interval); if(rc == RET_OK) { IDLE_change_parameters((long)new_interval); } else { MN_printf("\r\nrc = %d Illegal parameter" ,rc); } return(RET_OK); }*/ /***********************************************************/ /*extern uint32_t IDLE_TASK_monitor_init(void) { MN_uint32_t rc=RET_OK; MN_WORD idleMenuEntry; rc|=MN_BindMenu("Idle_task menu","Monitor system load",&idleMenuEntry); rc|=MN_BindCommand("GetCurLoad",idleMenuEntry,mn_get_curent_load,"GetCurLoad - Get Curent System CPU load\r\nGetCurLoad <cr>"); rc|=MN_BindCommand("GetLoad",idleMenuEntry,mn_get_load,"GetLoad - Get averege system load (since last time you changed interval or since initiation)\r\nGetLoad <cr>"); rc|=MN_BindCommand("IdleTbl",idleMenuEntry,mn_get_load_table,"IdleTbl - Get load table(since last time you changed interval or since initiation)\r\nGetLoad <cr>"); rc|=MN_BindCommand("ChangeInt",idleMenuEntry,mn_change_interval,"ChangeInt - change interval of system load chack\r\nChangeInterval <New Interval in Tics (~100 in second)>"); return(RET_OK); } */