Пример #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This method will fill our list with the data sources from the specified project.
        /// The skipped values are saved before rebuilding the list so we can use them as the
        /// list is being built.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void InitializeFromProject(PaProject project)
        {
            SkippedDataSourceList tmpList = new SkippedDataSourceList();

            // Copy this list to a temp. list to save it's values before clearing this list.
            foreach (KeyValuePair <string, bool> kvp in this)
            {
                tmpList[kvp.Key] = kvp.Value;
            }

            Clear();

            // Go through the data sources, adding them to this list and setting each data
            // sources skip value to those found in the temp. list. If there is a data
            // source in the project that isn't in the temp. list, then don't skip it.
            foreach (PaDataSource ds in project.DataSources)
            {
                bool   fSkip;
                string dsName = ds.ToString(true);
                if (!tmpList.TryGetValue(dsName, out fSkip))
                {
                    fSkip = false;
                }

                this[dsName] = fSkip;
            }
        }
Пример #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static SkippedDataSourceList Load(PaProject project)
        {
            if (project != null)
            {
                SkippedDataSourceList sdsl = new SkippedDataSourceList();
                foreach (PaDataSource ds in project.DataSources)
                {
                    sdsl[ds.ToString(true)] = false;
                }

                string filename = project.ProjectPathFilePrefix + kDataSourceInfoFilePrefix;

                if (File.Exists(filename))
                {
                    InternalSkipList skipList = STUtils.DeserializeData(filename,
                                                                        typeof(InternalSkipList)) as InternalSkipList;

                    if (skipList != null)
                    {
                        foreach (string dsName in skipList)
                        {
                            if (sdsl.ContainsKey(dsName))
                            {
                                sdsl[dsName] = true;
                            }
                        }
                    }
                }

                return(sdsl);
            }

            return(new SkippedDataSourceList());
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This message (i.e. BeforeLoadingDataSources) gets called right before PA loads all
        /// the data sources in the current project. This specific version of the message
        /// handler will do is find all data sources that match the ones this add-on saves
        /// in the DataSourceLoadInfo list (saved in a file in the project folder) and remove
        /// them from the project's data source list. The data sources that are removed are
        /// stored in a temporary list so that they can be re-added to the project's list
        /// after the data sources are read.
        /// </summary>
        /// <remarks>
        /// Concerning the reason for setting the last modification date on each skipped
        /// data source to tomorrow (i.e. DateTime.Now.AddDays(1)), is so that every time
        /// PA gains focus and it determines if any of the data sources have been updated
        /// since it lost focus, PA will determine that all skipped data sources have not
        /// been updated. Normally, the last modification date on a data source is set when
        /// the data source is read. But if the data source is skipped, then the last
        /// modification date will not get set properly and will cause PA to keep re-reading
        /// data sources each time the program becomes active. Hence setting the data to
        /// tomorrow.
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        protected bool OnBeforeLoadingDataSources(object args)
        {
            PaProject project = args as PaProject;

            if (project == null)
            {
                return(false);
            }

            m_skippedDataSources = null;

            // Get the list of data sources that were marked for not loading.
            SkippedDataSourceList sdsl = SkippedDataSourceList.Load(project);

            if (sdsl == null || sdsl.Count == 0)
            {
                return(false);
            }

            // Create our list to temporarily store the skipped data sources. Make it
            // a sorted list so we can insert them back in the list in the same place
            // they were when we removed them. This is so they will appear in the
            // project settings dialog in the same order in which the user added them.
            m_skippedDataSources = new SortedDictionary <int, PaDataSource>();

            // Go through the project's data sources and remove any that are to be skipped.
            for (int i = project.DataSources.Count - 1; i >= 0; i--)
            {
                PaDataSource ds = project.DataSources[i];
                if (sdsl.SkipDataSource(ds.ToString(true)))
                {
                    // Set the skipped data sources date to tomorrow (see comment in
                    // header of this method), save it to our temp. list and remove
                    // it from the project's list of data sources.
                    ds.LastModification     = DateTime.Now.AddDays(1);
                    m_skippedDataSources[i] = ds;
                    project.DataSources.RemoveAt(i);
                }
            }

            if (m_skippedDataSources.Count == 0)
            {
                m_skippedDataSources = null;
            }

            return(false);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Use this event to initialize the Load? column when the grid is loaded for the
        /// first time as the dialog is being constructed.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void grid_RowsAddedOnLoad(object sender, DataGridViewRowsAddedEventArgs e)
        {
            if (m_project == null)
            {
                m_project = ReflectionHelper.GetField(m_dialog, "m_project") as PaProject;
            }

            // Get the list of the skipped data source that will be used to initialize
            // our column in the OnInitializeLoadColumn method.
            m_skippedList = SkippedDataSourceList.Load(m_project);

            // Post a message here to initialize the "Load?" column values in the grid
            // because the rows don't actually have any data in them yet.
            PaApp.MsgMediator.PostMessage("InitializeLoadColumn", null);

            m_grid.RowsAdded   -= grid_RowsAddedOnLoad;
            m_grid.RowsAdded   += grid_RowsAdded;
            m_grid.RowsRemoved += m_grid_RowsRemoved;
        }