/// <summary>
        /// Event handler for the 'Copy' context menu option <c>Click</c> event. Copies an existing workset.
        /// </summary>
        /// <param name="sender">Reference to the object that raised the event.</param>
        /// <param name="e">Parameter passed from the object that raised the event.</param>
        private void m_ContextMenuItemCopy_Click(object sender, EventArgs e)
        {
            // Skip, if the Dispose() method has been called.
            if (IsDisposed)
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            // Local reference to the selected item.
            WorksetItem selectedItem = new WorksetItem();

            // The index value of the selected workset.
            int selectedIndex;

            try
            {
                selectedItem = (WorksetItem)m_ListView.SelectedItems[0];
                selectedIndex = m_ListView.SelectedIndices[0];
            }
            catch (Exception)
            {
                selectedItem = null;
                selectedIndex = 0;
            }
            finally
            {
                Cursor = Cursors.Default;
            }

            // Check that an item has been selected.
            if (selectedItem == null)
            {
                MessageBox.Show(Resources.MBTInstructionSelectWorkset, Resources.MBCaptionWarning, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Cursor = Cursors.WaitCursor;

            // Create a temporary workset.
            Workset_t copyOfWorkset = new Workset_t();
            copyOfWorkset.Replicate(selectedItem.Workset);
            
            // Override the security level to be the security level of the current user.
            copyOfWorkset.SecurityLevel = Security.SecurityLevelCurrent;

            // Override the name of the workset.
            copyOfWorkset.Name = selectedItem.Workset.Name + CommonConstants.BindingMessage + Resources.TextCopy;
            m_WorksetCollection.Add(copyOfWorkset);
            Cursor = Cursors.Default;

            // Save the modified object to disk.
            Save();
            UpdateListView();
        }
示例#2
0
        /// <summary>
        /// For the specified workset file update: (a) the baseline workset; (b) the WatchItems, WatchElementList and CountMax properties of all other worksets and (c) 
        /// the EntryCountMax field to be compatible with the new data dictionary. Also report any worksets that: (a) contain more watch values than are permitted 
        /// or (b) include one or more invalid old identifier references.
        /// </summary>
        /// <param name="worksetCollectionFile">The structure containing the de-serialized workset file.</param>
        private void Update(ref WorksetCollectionFile_t worksetCollectionFile)
        {
            // Get the number of watch variables and the number of oldIdentifiers associated with the current data dictionary and the data dictionary associated with 
            // the workset.
            int dataDictionaryOldIdentifierCount = Lookup.WatchVariableTableByOldIdentifier.RecordList.Count;
            int dataDictionaryWatchIdentifierCount = Lookup.WatchVariableTable.RecordList.Count;
            int worksetOldIdentifierCount = worksetCollectionFile.WorksetList[0].WatchItems.Length;
            int worksetWatchIdentifierCount = 0;
            for (int elementIndex = 0; elementIndex < worksetOldIdentifierCount; elementIndex++)
            {
                if (worksetCollectionFile.WorksetList[0].WatchItems[elementIndex].Exists == true)
                {
                    worksetWatchIdentifierCount++;
                }
            }

            int watchVariablesAddedTo = 0;
            int watchVariablesDeletedFrom = 0;
            if (dataDictionaryOldIdentifierCount > worksetOldIdentifierCount)
            {
                watchVariablesAddedTo = dataDictionaryOldIdentifierCount - worksetOldIdentifierCount;
                watchVariablesDeletedFrom = watchVariablesAddedTo - (dataDictionaryWatchIdentifierCount - worksetWatchIdentifierCount);
            }
            else if (worksetOldIdentifierCount > dataDictionaryOldIdentifierCount)
            {
                watchVariablesDeletedFrom = worksetOldIdentifierCount - dataDictionaryOldIdentifierCount;
                watchVariablesAddedTo = watchVariablesDeletedFrom - (worksetWatchIdentifierCount - dataDictionaryWatchIdentifierCount);
            }

            // Check whether the WatchItems property of the worksets in the specified workset collection need be updated i.e. check whether any watch variables have been 
            // added to or deleted from the the data dictionary since the workset was created.
            List<short> invalidOldIdentifierList;
            List<Workset_t> invalidOldIdentifierWorksetList, invalidWatchSizeWorksetList;
            if ((dataDictionaryOldIdentifierCount != worksetOldIdentifierCount) ||
                (dataDictionaryWatchIdentifierCount != worksetWatchIdentifierCount))
            {
                #region - [Error Reporting] -
                // Check whether any watch variables have been deleted from the current data dictionary since the worksets were defined.
                if (watchVariablesDeletedFrom > 0)
                {
                    // Yes - Get a list of any old identifiers in the workset file that are incompatible with the current data dictionary.
                    invalidOldIdentifierList = GetIncompatibleOldIdentifierList(worksetCollectionFile);
                    if (invalidOldIdentifierList.Count > 0)
                    {
                        // Get the list of worksets that are effected.
                        invalidOldIdentifierWorksetList = GetIncompatibleWorksetList(worksetCollectionFile, invalidOldIdentifierList);

                        if (invalidOldIdentifierWorksetList.Count > 0)
                        {
                            ReportIncompatibleWorksets(invalidOldIdentifierWorksetList, invalidOldIdentifierList, worksetCollectionFile.WorksetCollectionType); 
                        }
                    }
                }
                #endregion - [Error Reporting] -

                #region - [WatchItems/WatchElementList Update] -
                // ------------------------------------------------------------------------------------
                // Update the WatchItems and WatchElementList fields of all of the workset in the file.
                // ------------------------------------------------------------------------------------
                for (short worksetIndex = 0; worksetIndex < worksetCollectionFile.WorksetList.Count; worksetIndex++)
                {
                    // Replicate the workset.
                    Workset_t workset = new Workset_t();
                    workset.Replicate(worksetCollectionFile.WorksetList[worksetIndex]);

                    //Create a new WatchItems propery for the current workset based upon the current data dictionary with the Added property of all elements set to false.
                    workset.WatchItems = new WatchItem_t[dataDictionaryOldIdentifierCount];
                    WatchItem_t watchItem;
                    for (short watchItemIndex = 0; watchItemIndex < dataDictionaryOldIdentifierCount; watchItemIndex++)
                    {
                        watchItem = new WatchItem_t();
                        watchItem.OldIdentifier = watchItemIndex;
                        watchItem.Added = false;

                        try
                        {
                            // Check whether the watch variable exists and set the Exists property of the watch item appropriately.
                            WatchVariable watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[watchItemIndex];
                            watchItem.Exists = (watchVariable == null) ? false : true;
                        }
                        catch (Exception)
                        {
                            watchItem.Exists = false;
                        }

                        workset.WatchItems[watchItemIndex] = watchItem;
                    }

                    // Update the WatchElementList and the WatchItems properties of the workset using the old identifier values stored in each column of the workset.
                    workset.WatchElementList = new List<short>();
                    short oldIdentifier;
                    for (int columnIndex = 0; columnIndex < workset.Column.Length; columnIndex++)
                    {
                        for (int rowIndex = 0; rowIndex < workset.Column[columnIndex].OldIdentifierList.Count; rowIndex++)
                        {
                            // Get the old identifier value.
                            oldIdentifier = workset.Column[columnIndex].OldIdentifierList[rowIndex];

                            // Check whether the watch variable associated with the old identifier value exists in the current workset.
                            try
                            {
                                WatchVariable watchVariable = Lookup.WatchVariableTableByOldIdentifier.Items[oldIdentifier];
                                if (watchVariable == null)
                                {
                                    // No, add the watch identifier value used to represent the watch variable not being defined in the current data dictionary.
                                    workset.WatchElementList.Add(CommonConstants.WatchIdentifierNotDefined);
                                }
                                else
                                {
                                    // Add the watch identifier of the watch variable corresponding to the specified old identifier to the list of watch identifiers.
                                    workset.WatchElementList.Add(watchVariable.Identifier);

                                    // Update the Exists and Added properties of the WatchItem element corresponding to the specified old identifier.
                                    workset.WatchItems[oldIdentifier].Added = true;
                                    workset.WatchItems[oldIdentifier].Exists = true;
                                }
                            }
                            catch (Exception)
                            {
                                // No, add the watch identifier value used to represent the watch variable not being defined in the current data dictionary.
                                workset.WatchElementList.Add(CommonConstants.WatchIdentifierNotDefined);
                            }
                        }
                    }

                    workset.WatchElementList.Sort();

                    // Replace the workset.
                    worksetCollectionFile.WorksetList[worksetIndex] = workset;
                    #endregion - [WatchItems/WatchElementList Update] -
                }
            }

            // Only carry out watch size processing if the workset collection corresponds to a watch window workset.
            if (worksetCollectionFile.WorksetCollectionType == Configuration.WorksetCollectionType.RecordedWatch)
            {
                #region - [Error Reporting] -
                invalidWatchSizeWorksetList = GetIncompatibleWorksetList(worksetCollectionFile, Parameter.WatchSize);
                if (invalidWatchSizeWorksetList.Count > 0)
                {
                    ReportIncompatibleWorksets(invalidWatchSizeWorksetList);
                }
                #endregion - [Error Reporting] -

                #region - [WatchSize Update] -
                // Update the EntryCountMax field of the workset file, if required.
                if (worksetCollectionFile.EntryCountMax != Parameter.WatchSize)
                {
                    worksetCollectionFile.EntryCountMax = Parameter.WatchSize;
                }

                // Update the baseline workset and the EntryCount max field of individual worksets, if required.
                for (int worksetIndex = 0; worksetIndex < worksetCollectionFile.WorksetList.Count; worksetIndex++)
                {
                    Workset_t workset;
                    if (worksetCollectionFile.WorksetList[worksetIndex].CountMax != Parameter.WatchSize)
                    {
                        // If the workset is the baseline workset, update it.
                        if (worksetIndex == 0)
                        {
                            workset = CreateBaselineWorkset();

                        }
                        else
                        {
                            workset = worksetCollectionFile.WorksetList[worksetIndex];
                            workset.CountMax = Parameter.WatchSize;
                        }

                        worksetCollectionFile.WorksetList[worksetIndex] = workset;
                    }
                }
                #endregion - [WatchSize Update] -
            }
        }
示例#3
0
        /// <summary>
        /// Convert the current user setting to a workset.
        /// </summary>
        /// <param name="worksetName">The name of the workset.</param>
        /// <returns>The user settings converted to a workset.</returns>
        private Workset_t ConvertToWorkset(string worksetName)
        {
            Workset_t workset = new Workset_t();
            workset.Replicate(m_Workset);

            // This attribute is used to define the plot screen layout and is defined by the user when displaying the saved data file.
            workset.PlotTabPages = new PlotTabPage_t[workset.Column.Length];
            for (int tabPageindex = 0; tabPageindex < workset.Column.Length; tabPageindex++)
            {
                workset.PlotTabPages[tabPageindex].HeaderText = m_TextBoxHeaders[tabPageindex].Text;
                workset.PlotTabPages[tabPageindex].OldIdentifierList = new List<short>();
                workset.PlotTabPages[tabPageindex].DisplayMaskList = new List<uint>();

                for (int index = 0; index < m_ListBoxes[tabPageindex].Items.Count; index++)
                {
                    workset.PlotTabPages[tabPageindex].OldIdentifierList.Add(((WatchItem_t)m_ListBoxes[tabPageindex].Items[index]).OldIdentifier);
                    workset.PlotTabPages[tabPageindex].DisplayMaskList.Add(((WatchItem_t)m_ListBoxes[tabPageindex].Items[index]).DisplayMask);
                }
            }

            return workset;
        }