Exemplo n.º 1
0
        /// <summary>
        /// Executes the script. If no instance of the script object exists, a error message will be stored and the return value is false.
        /// If the script object exists, the data change notifications will be switched of (for all tables).
        /// Then the Execute function of this script object is called. Afterwards, the data changed notifications are switched on again.
        /// </summary>
        /// <param name="myTable">The data table this script is working on.</param>
        /// <param name="reporter">Progress reporter that can be used by the script to report the progress of its work.</param>
        /// <returns>True if executed without exceptions, otherwise false.</returns>
        /// <remarks>If exceptions were thrown during execution, the exception messages are stored
        /// inside the column script and can be recalled by the Errors property.</remarks>
        public bool ExecuteWithSuspendedNotifications(Altaxo.Data.DataTable myTable, Altaxo.IProgressReporter reporter)
        {
            bool bSucceeded = true;

            Altaxo.Data.DataTableCollection myDataSet = null;

            if (null == _scriptObject && !_wasTriedToCompile)
            {
                Compile();
            }

            // first, test some preconditions
            if (null == _scriptObject)
            {
                _errors = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, "Script Object is null"));
                return(false);
            }

            myDataSet = Altaxo.Data.DataTableCollection.GetParentDataTableCollectionOf(myTable);

            IDisposable suspendToken = null;

            if (null != myDataSet)
            {
                suspendToken = myDataSet.SuspendGetToken();
            }
            else if (null != myTable)
            {
                suspendToken = myTable.SuspendGetToken();
            }

            try
            {
                ((Altaxo.Calc.TableScriptExeBase)_scriptObject).Execute(myTable, reporter);
            }
            catch (Exception ex)
            {
                bSucceeded = false;
                _errors    = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, ex.ToString()));
            }
            finally
            {
                if (null != suspendToken)
                {
                    suspendToken.Dispose();
                }
            }

            return(bSucceeded);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shows a dialog to add columns to a table.
        /// </summary>
        /// <param name="table">The table where to add the columns.</param>
        /// <param name="bAddToPropertyColumns">If true, the columns are added to the property columns instead of the data columns collection.</param>
        public static void ShowAddColumnsDialog(Altaxo.Data.DataTable table, bool bAddToPropertyColumns)
        {
            var lbitems = new Altaxo.Collections.SelectableListNodeList
            {
                new Altaxo.Collections.SelectableListNode("Numeric", typeof(Altaxo.Data.DoubleColumn), true),
                new Altaxo.Collections.SelectableListNode("Date/Time", typeof(Altaxo.Data.DateTimeColumn), false),
                new Altaxo.Collections.SelectableListNode("Text", typeof(Altaxo.Data.TextColumn), false)
            };

            var ct = new IntegerAndComboBoxController(
                "Number of colums to add:", 1, int.MaxValue, 1,
                "Type of columns to add:", lbitems, 0);

            Current.Gui.FindAndAttachControlTo(ct);

            if (true == Current.Gui.ShowDialog(ct, "Add new column(s)", false))
            {
                var columntype = (System.Type)ct.SelectedItem.Tag;

                using (var suspendToken = table.SuspendGetToken())
                {
                    if (bAddToPropertyColumns)
                    {
                        for (int i = 0; i < ct.IntegerValue; i++)
                        {
                            table.PropCols.Add((Altaxo.Data.DataColumn)System.Activator.CreateInstance(columntype));
                        }
                    }
                    else
                    {
                        for (int i = 0; i < ct.IntegerValue; i++)
                        {
                            table.DataColumns.Add((Altaxo.Data.DataColumn)System.Activator.CreateInstance(columntype));
                        }
                    }

                    suspendToken.Dispose();
                }
            }
        }