void updateDaemon()
        {
            while (true)
            {
                System.Threading.Thread.Sleep(10);
                if (InvokeRequired)
                {
                    Invoke(new MethodInvoker(() =>
                    {
                        m_currentPreferenceData[m_currentModule] = m_openPreference.GetValues();
                    }));
                }
                else
                {
                    m_currentPreferenceData[m_currentModule] = m_openPreference.GetValues();
                }


                string currentModule = m_currentModule;
                Dictionary <string, object> cachedValues  = m_cachedPreferenceData[currentModule];
                Dictionary <string, object> currentValues = m_currentPreferenceData[currentModule];
                bool thisIsDirty = false;
                foreach (KeyValuePair <string, object> kvPair in currentValues)
                {
                    if (!currentValues[kvPair.Key].Equals(cachedValues[kvPair.Key]))
                    {
                        if (InvokeRequired)
                        {
                            Invoke(new MethodInvoker(() =>
                            {
                                Dirty = true;
                            }));
                        }
                        else
                        {
                            Dirty = true;
                        }
                        m_dirtyModules.Add(m_currentModule);
                        thisIsDirty = true;
                        break;
                    }
                }
                if (!thisIsDirty)
                {
                    m_dirtyModules.Remove(m_currentModule);

                    if (m_dirtyModules.Count == 0)
                    {
                        if (InvokeRequired)
                        {
                            Invoke(new MethodInvoker(() =>
                            {
                                Dirty = false;
                            }));
                        }
                        else
                        {
                            Dirty = false;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public static Dictionary <string, object> getPreferenceData(string tag)
        {
            Dictionary <string, object> values = new Dictionary <string, object>();

            if (tag == "General")
            {
                IEnumerator                 iterator   = DataSetManager.Manager.getData(DataSets.Config, DataSetManager.GENERIC_TABLE_NAME);
                GeneralPreferences          gp         = new GeneralPreferences();
                Dictionary <string, object> dataValues = gp.GetValues();
                if (iterator.MoveNext())
                {
                    DataRow dr = ((DataRow)iterator.Current);
                    foreach (KeyValuePair <string, object> kv in dataValues)
                    {
                        values[kv.Key] = dr[kv.Key];
                    }
                }
                else
                {
                    foreach (KeyValuePair <string, object> kv in dataValues)
                    {
                        values[kv.Key] = kv.Value;
                    }
                }
            }
            else
            {
                Dictionary <string, Type> modules = getModules();

                Type[]  types = new Type[0]; object[] parameters = new object[0];
                IModule moduleObject = (modules[tag]).GetConstructor(types).Invoke(parameters) as IModule;

                if (moduleObject.preferencesAvailable()) // Previous Data Never Stored
                {
                    IEnumerator iterator = DataSetManager.Manager.getData(DataSets.Config, tag);
                    if (iterator == null || !iterator.MoveNext()) // No Table or Empty Table
                    {
                        PreferenceControl preferenceControl = moduleObject.getPreferenceControl();

                        Dictionary <string, object> mappings = preferenceControl.GetValues();
                        Dictionary <string, Type>   columns  = new Dictionary <string, Type>();
                        foreach (KeyValuePair <string, object> mapping in mappings)
                        {
                            values.Add(mapping.Key, mapping.Value);
                            columns.Add(mapping.Key, mapping.Value.GetType());
                        }
                        if (iterator == null)
                        {
                            DataSetManager.Manager.addTable(DataSets.Config, tag, columns);
                        }
                    }
                    else// Should only have 1 data element
                    {
                        DataRow dr = iterator.Current as DataRow;
                        foreach (DataColumn column in dr.Table.Columns)
                        {
                            values.Add(column.ColumnName, dr[column]);
                        }
                    }
                }
            }

            return(values);
        }