コード例 #1
0
 public afgeleide_functies()
 {
     InitializeComponent();
     // bvfta.Connection.ConnectionString = zeebregtsCs.Global.ConnectionString_fileserver;
     updatePbDelegate = new UpdateProgressBarDelegate(pro_bar.SetValue);
     updateLDelegate  = new UpdateLayoutDelegate(dg_nieuw.SetValue);
 }
コード例 #2
0
 public override void Draw()
 {
     if (CheckInputs())
     {
         WatchValue = InPortData[0].Object.ToString();
         UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
         Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
     }
 }
コード例 #3
0
        public dynWatch()
        {
            //add a list box
            System.Windows.Controls.TextBox tb = new System.Windows.Controls.TextBox();
            tb.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;
            tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

            //turn off the border
            SolidColorBrush backgroundBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0));

            tb.Background      = backgroundBrush;
            tb.BorderThickness = new Thickness(0);

            WatchValue = "Ready to watch!";

            //http://learnwpf.com/post/2006/06/12/How-can-I-create-a-data-binding-in-code-using-WPF.aspx

            System.Windows.Data.Binding b = new System.Windows.Data.Binding("WatchValue");
            b.Source = this;

            tb.SetBinding(System.Windows.Controls.TextBox.TextProperty, b);

            this.inputGrid.Children.Add(tb);
            tb.TextWrapping = System.Windows.TextWrapping.Wrap;
            tb.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;

            InPortData.Add(new PortData(null, "", "The Element to watch", typeof(dynElement)));

            base.RegisterInputsAndOutputs();

            //resize the panel
            this.topControl.Height = 100;
            this.topControl.Width  = 300;
            UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);

            Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
        }
コード例 #4
0
ファイル: dynNode.xaml.cs プロジェクト: Tadwork/Dynamo
        protected internal Value evaluateNode(FSharpList<Value> args)
        {
            //For convenience, store the bench.
            var bench = dynElementSettings.SharedInstance.Bench;

            if (SaveResult)
            {
                //Store the port mappings for this evaluate. We will compare later to see if it is dirty;
                foreach (dynPort p in InPorts)
                {
                    previousEvalPortMappings[p] = p.Connectors.Any()
                       ? p.Connectors[0].Start.Owner
                       : null;
                }
            }

            object[] rtAttribs = GetType().GetCustomAttributes(typeof(RequiresTransactionAttribute), false);
            bool useTransaction = rtAttribs.Length > 0 && ((RequiresTransactionAttribute)rtAttribs[0]).RequiresTransaction;

            object[] iaAttribs = GetType().GetCustomAttributes(typeof(IsInteractiveAttribute), false);
            bool isInteractive = iaAttribs.Length > 0 && ((IsInteractiveAttribute)iaAttribs[0]).IsInteractive;

            Value result = null;

            Action evaluation = delegate
            {
                if (bench.RunCancelled)
                    throw new CancelEvaluationException(false);

                bool debug = bench.RunInDebug;

                OnEvaluate();

                if (useTransaction)
                {
                    #region using transaction

                    if (!debug)
                    {
                        #region no debug

                        try
                        {
                            if (bench.TransMode == TransactionMode.Manual && !bench.IsTransactionActive())
                            {
                                var msg = "A Revit transaction is required in order evaluate this element.";
                                Error(msg);
                                throw new Exception(msg);
                            }

                            bench.InitTransaction();

                            result = Evaluate(args);

                            foreach (ElementId eid in deletedIds)
                            {
                                Bench.RegisterSuccessfulDeleteHook(
                                   eid,
                                   onSuccessfulDelete
                                );
                            }
                            deletedIds.Clear();

                            UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                            Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });

                            elementsHaveBeenDeleted = false;
                            ValidateConnections();
                        }
                        catch (CancelEvaluationException ex)
                        {
                            OnRunCancelled();
                            throw ex;
                        }
                        catch (Exception ex)
                        {
                            Dispatcher.Invoke(new Action(
                               delegate
                               {
                                   Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
                                   bench.Log(ex);
                                   bench.ShowElement(this);

                                   dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                                   dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                               }
                            ));

                            Error(ex.Message);
                        }

                        #endregion
                    }
                    else
                    {
                        #region debug

                        Dispatcher.Invoke(new Action(
                           () =>
                              bench.Log("Starting a debug transaction for element: " + NickName)
                        ));

                        result = IdlePromise<Value>.ExecuteOnIdle(
                           delegate
                           {
                               bench.InitTransaction();

                               try
                               {
                                   var exp = Evaluate(args);

                                   foreach (ElementId eid in deletedIds)
                                   {
                                       Bench.RegisterSuccessfulDeleteHook(
                                          eid,
                                          onSuccessfulDelete
                                       );
                                   }
                                   deletedIds.Clear();

                                   UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                                   Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });

                                   elementsHaveBeenDeleted = false;

                                   bench.EndTransaction();

                                   Dispatcher.BeginInvoke(new Action(
                                       () => ValidateConnections()
                                   ));

                                   return exp;
                               }
                               catch (CancelEvaluationException ex)
                               {
                                   OnRunCancelled();
                                   throw ex;
                               }
                               catch (Exception ex)
                               {
                                   Dispatcher.Invoke(new Action(
                                      delegate
                                      {
                                          Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
                                          bench.Log(ex);
                                          bench.ShowElement(this);
                                      }
                                   ));

                                   Error(ex.Message);

                                   bench.CancelTransaction();

                                   Dispatcher.Invoke(new Action(
                                      delegate
                                      {
                                          dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                                          dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                                      }
                                   ));

                                   return null;
                               }
                           }
                        );

                        #endregion
                    }

                    #endregion
                }
                else
                {
                    #region no transaction

                    try
                    {
                        result = Evaluate(args);

                        UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                        Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });

                        elementsHaveBeenDeleted = false;

                        Dispatcher.BeginInvoke(new Action(
                            () => ValidateConnections()
                        ));
                    }
                    catch (CancelEvaluationException ex)
                    {
                        OnRunCancelled();
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        Dispatcher.Invoke(new Action(
                           delegate
                           {
                               Debug.WriteLine(ex.Message + " : " + ex.StackTrace);

                               bench.Log(ex);
                               bench.ShowElement(this);

                               dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                               dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                           }
                        ));

                        Error(ex.Message);
                    }

                    #endregion
                }

                #region Register Elements w/ DMU

                var del = new DynElementUpdateDelegate(onDeleted);

                foreach (ElementId id in Elements)
                    Bench.RegisterDeleteHook(id, del);

                #endregion

                //Increment the run counter
                runCount++;

                IsDirty = false;
            };

            if (isInteractive)
                Dispatcher.Invoke(evaluation);
            else
                evaluation();

            if (result != null)
                return result;
            else
                throw new Exception("");
        }
コード例 #5
0
ファイル: dynElement.xaml.cs プロジェクト: TCadorette/dynamo
        /// <summary>
        /// The build method is called back from the child class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Build(object sender, EventArgs e)
        {
            dynElement el = sender as dynElement;

            bool useTransaction = true;

            object[] attribs = el.GetType().GetCustomAttributes(typeof(RequiresTransactionAttribute), false);
            if (attribs.Length > 0)
            {
                if ((attribs[0] as RequiresTransactionAttribute).RequiresTransaction == false)
                {
                    useTransaction = false;
                }
            }

            #region using transaction
            if (useTransaction)
            {
                Transaction t = new Transaction(dynElementSettings.SharedInstance.Doc.Document, el.GetType().ToString() + " update.");
                TransactionStatus ts = t.Start();

                try
                {
                    FailureHandlingOptions failOpt = t.GetFailureHandlingOptions();
                    failOpt.SetFailuresPreprocessor(dynElementSettings.SharedInstance.WarningSwallower);
                    t.SetFailureHandlingOptions(failOpt);

                    el.Destroy();
                    el.Draw();

                    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                    Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { el });

                    elementsHaveBeenDeleted = false;

                    ts = t.Commit();

                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
                    dynElementSettings.SharedInstance.Bench.Log(ex.Message);

                    SetToolTipDelegate sttd = new SetToolTipDelegate(SetTooltip);
                    Dispatcher.Invoke(sttd, System.Windows.Threading.DispatcherPriority.Background,
                        new object[] { ex.Message});

                    MarkConnectionStateDelegate mcsd = new MarkConnectionStateDelegate(MarkConnectionState);
                    Dispatcher.Invoke(mcsd, System.Windows.Threading.DispatcherPriority.Background,
                        new object[] { true });

                    if (ts == TransactionStatus.Committed)
                    {
                        t.RollBack();
                    }

                    t.Dispose();

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                }

                try
                {
                    el.UpdateOutputs();
                }
                catch(Exception ex)
                {

                    //Debug.WriteLine("Outputs could not be updated.");
                    dynElementSettings.SharedInstance.Bench.Log("Outputs could not be updated.");
                    if (ts == TransactionStatus.Committed)
                    {
                        t.RollBack();
                    }

                    t.Dispose();

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                }
            }
            #endregion

            #region no transaction
            if (!useTransaction)
            {
                try
                {

                    el.Destroy();

                    el.Draw();

                    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                    Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { el });

                    elementsHaveBeenDeleted = false;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
                    dynElementSettings.SharedInstance.Bench.Log(ex.Message);

                    SetToolTipDelegate sttd = new SetToolTipDelegate(SetTooltip);
                    Dispatcher.Invoke(sttd, System.Windows.Threading.DispatcherPriority.Background,
                        new object[] { ex.Message });

                    MarkConnectionState(true);

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);

                }

                try
                {
                    el.UpdateOutputs();
                }
                catch(Exception ex)
                {

                    //Debug.WriteLine("Outputs could not be updated.");
                    dynElementSettings.SharedInstance.Bench.Log("Outputs could not be updated.");

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                }
            }
            #endregion
        }
コード例 #6
0
ファイル: dynTransactions.cs プロジェクト: Dewb/Dynamo
        protected internal override ProcedureCallNode Compile(IEnumerable<string> portNames)
        {
            ExternMacro m = new ExternMacro(
               delegate(FSharpList<Expression> args, ExecutionEnvironment environment)
               {
                   if (this.Bench.RunCancelled)
                       throw new CancelEvaluationException(false);

                   IdlePromiseDelegate<Expression> eval = delegate
                    {
                        this.Bench.InIdleThread = true;
                        dynElementSettings.SharedInstance.Bench.InitTransaction();

                        try
                        {
                            var exp = environment.Evaluate(args[0]);

                            UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                            Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });

                            dynElementSettings.SharedInstance.Bench.EndTransaction();

                            this.ValidateConnections();

                            return exp;
                        }
                        catch (CancelEvaluationException ex)
                        {
                            throw ex;
                        }
                        catch (Exception ex)
                        {
                            this.Dispatcher.Invoke(new Action(
                                delegate
                                {
                                    Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
                                    this.Bench.Log(ex);
                                    this.Bench.ShowElement(this);

                                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                                }
                            ));

                            this.Error(ex.Message);
                            return null;
                        }
                    };

                   if (dynElementSettings.SharedInstance.Bench.RunInDebug)
                   {
                       var val = environment.Evaluate(args[0]);
                       this._isDirty = false;
                       return val;
                   }

                   var result = IdlePromise<Expression>.ExecuteOnIdle(eval);

                   this.Bench.InIdleThread = false;

                   return result;
               }
            );

            return new ExternalMacroNode(m, portNames);
        }
コード例 #7
0
ファイル: dynBaseTypes.cs プロジェクト: TCadorette/dynamo
        public override void Draw()
        {
            try
            {

                //bool boolWatch = Convert.ToBoolean(InPortData[0].Object);

                if ( CheckInputs() && (File.Exists(FilePath))) // (boolWatch == true)
                {

                    readFile(FilePath);
                }

                // OutPortData[0].Object = this.Tree;//Hack - seems like overkill to put in the draw loop
                //OnDynElementUpdated(EventArgs.Empty);
                //OnDynElementReadyToBuild(EventArgs.Empty);

                //this.UpdateOutputs();
                //OnDynElementReadyToBuild(EventArgs.Empty);

                UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
            }
            catch (Exception e)
            {
                TaskDialog.Show("Exception", e.ToString());

            }
        }
コード例 #8
0
ファイル: dynBaseTypes.cs プロジェクト: TCadorette/dynamo
        public dynDataFromFile()
        {
            StackPanel myStackPanel;

            //Define a StackPanel
            myStackPanel = new StackPanel();
            myStackPanel.Orientation = System.Windows.Controls.Orientation.Vertical;
            System.Windows.Controls.Grid.SetRow(myStackPanel, 1);

            this.inputGrid.Children.Add(myStackPanel);

            //add a button to the inputGrid on the dynElement
            System.Windows.Controls.Button readFileButton = new System.Windows.Controls.Button();

            System.Windows.Controls.Grid.SetColumn(readFileButton, 0); // trying to get this button to be on top... grrr.
            System.Windows.Controls.Grid.SetRow(readFileButton, 0);
            readFileButton.Margin = new System.Windows.Thickness(0, 0, 0, 0);
            readFileButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            readFileButton.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            readFileButton.Click += new System.Windows.RoutedEventHandler(readFileButton_Click);
            readFileButton.Content = "Read File";
            readFileButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            readFileButton.VerticalAlignment = System.Windows.VerticalAlignment.Center;

            myStackPanel.Children.Add(readFileButton);

            //add a list box
            //label = new System.Windows.Controls.Label();
            System.Windows.Controls.TextBox tb = new System.Windows.Controls.TextBox();
            //tb.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            //tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

            DataFromFileString = "Ready to read file!";

            //http://learnwpf.com/post/2006/06/12/How-can-I-create-a-data-binding-in-code-using-WPF.aspx

            //this.inputGrid.Children.Add(label);
            //this.inputGrid.Children.Add(tb);
            //tb.Visibility = System.Windows.Visibility.Hidden;
            //System.Windows.Controls.Grid.SetColumn(tb, 0);
            //System.Windows.Controls.Grid.SetRow(tb, 1);
            tb.TextWrapping = System.Windows.TextWrapping.Wrap;
            tb.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            tb.Height = 100;
            //tb.AcceptsReturn = true;

            System.Windows.Data.Binding b = new System.Windows.Data.Binding("DataFromFileString");
            b.Source = this;
            tb.SetBinding(System.Windows.Controls.TextBox.TextProperty, b);

            myStackPanel.Children.Add(tb);
            myStackPanel.Height = 200;

            //InPortData.Add(new PortData(null, "", "The Element to watch", typeof(dynElement)));
            InPortData.Add(new PortData(null, "F", "Watch File?", typeof(dynElement)));
            //InPortData.Add(new PortData(null, "tim", "How often to receive updates.", typeof(dynTimer)));

            OutPortData.Add(new PortData(null, "", "downstream data", typeof(dynDataFromFile)));
            this.Tree.Trunk.Branches.Add(new DataTreeBranch());
            this.Tree.Trunk.Branches[0].Leaves.Add(DataFromFileString);
            OutPortData[0].Object = this.Tree;

            base.RegisterInputsAndOutputs();

            //resize the panel
            this.topControl.Height = 200;
            this.topControl.Width = 300;
            UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
            Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
            //this.UpdateLayout();
        }
コード例 #9
0
ファイル: dynBaseTypes.cs プロジェクト: TCadorette/dynamo
        public override void Draw()
        {
            if (CheckInputs())
            {
                DataTree tree = InPortData[0].Object as DataTree;

                if (tree != null)
                {
                    SumValue = 0.0; // reset to ensue we don't count on refresh
                    Process(tree.Trunk.Branches[0]); // add em back up
                    WatchValue = "Computed Sum of SR Values: " + SumValue.ToString() + "\n";
                    //WatchValue = WatchValue + tree.ToString(); // MDJ presume data is in a data tree, one line in each datatree leaf
                    //this.Tree.Clear();
                   // this.Tree.Trunk.Branches[0].Leaves.Add(SumValue);
                    try
                    {
                        OutPortData[0].Object = SumValue;
                    }
                    catch (Exception e)
                    {
                        TaskDialog.Show("Error", e.ToString());
                    }

                    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                    Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
                }
                else
                {
                    TaskDialog.Show("Error", "Please use this element for computing and showing solar radiation data");
                    //find the object as a string
                    WatchValue = InPortData[0].Object.ToString();
                    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                    Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
                }
            }
        }
コード例 #10
0
ファイル: dynBaseTypes.cs プロジェクト: TCadorette/dynamo
        public dynComputeSolarRadiationValue()
        {
            //add a list box
            //label = new System.Windows.Controls.Label();
            System.Windows.Controls.TextBox tb = new System.Windows.Controls.TextBox();
            tb.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

            WatchValue = "Ready to compute solar radiation value!";

            //http://learnwpf.com/post/2006/06/12/How-can-I-create-a-data-binding-in-code-using-WPF.aspx

            System.Windows.Data.Binding b = new System.Windows.Data.Binding("WatchValue");
            b.Source = this;
            //label.SetBinding(System.Windows.Controls.Label.ContentProperty, b);
            tb.SetBinding(System.Windows.Controls.TextBox.TextProperty, b);

            this.inputGrid.Children.Add(tb);
            tb.TextWrapping = System.Windows.TextWrapping.Wrap;
            tb.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            //tb.AcceptsReturn = true;

            InPortData.Add(new PortData(null, "", "The solar radiation data file", typeof(dynElement)));

            OutPortData.Add(new PortData(null, "", "The solar radiation computed data", typeof(dynDouble)));
            this.Tree.Trunk.Branches.Add(new DataTreeBranch());
            this.Tree.Trunk.Branches[0].Leaves.Add(SumValue); //MDJ TODO - cleanup input tree and output tree
            //OutPortData[0].Object = this.Tree;
            OutPortData[0].Object = SumValue;

            base.RegisterInputsAndOutputs();

            //resize the panel
            this.topControl.Height = 100;
            this.topControl.Width = 300;
            UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
            Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
            //this.UpdateLayout();
        }
コード例 #11
0
ファイル: dynBaseTypes.cs プロジェクト: TCadorette/dynamo
        public override void Draw()
        {
            if (CheckInputs())
            {
                WatchValue = InPortData[0].Object.ToString();
                UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });

                //DataTree tree = InPortData[0].Object as DataTree;

                //if (tree != null)
                //{
                //    WatchValue = tree.ToString();

                //    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                //    Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
                //}
                //else
                //{
                //    //find the object as a string
                //    WatchValue = InPortData[0].Object.ToString();
                //    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                //    Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
                //}
            }
        }
コード例 #12
0
ファイル: dynBaseTypes.cs プロジェクト: TCadorette/dynamo
        public dynWatch()
        {
            //add a list box
            System.Windows.Controls.TextBox tb = new System.Windows.Controls.TextBox();
            tb.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

            //turn off the border
            SolidColorBrush backgroundBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0));
            tb.Background = backgroundBrush;
            tb.BorderThickness = new Thickness(0);

            WatchValue = "Ready to watch!";

            //http://learnwpf.com/post/2006/06/12/How-can-I-create-a-data-binding-in-code-using-WPF.aspx

            System.Windows.Data.Binding b = new System.Windows.Data.Binding("WatchValue");
            b.Source = this;
            //label.SetBinding(System.Windows.Controls.Label.ContentProperty, b);
            tb.SetBinding(System.Windows.Controls.TextBox.TextProperty, b);

            //this.inputGrid.Children.Add(label);
            this.inputGrid.Children.Add(tb);
            tb.TextWrapping = System.Windows.TextWrapping.Wrap;
            tb.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            //tb.AcceptsReturn = true;

            InPortData.Add(new PortData(null, "", "The Element to watch", typeof(dynElement)));

            base.RegisterInputsAndOutputs();

            //resize the panel
            this.topControl.Height = 100;
            this.topControl.Width = 300;
            UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
            Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });
            //this.UpdateLayout();
        }
コード例 #13
0
ファイル: dynBaseTypes.cs プロジェクト: pterelaos/dynamo
        public override void Draw()
        {
            if (CheckInputs())
            {
                WatchValue = InPortData[0].Object.ToString();
                UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { this });

            }
        }
コード例 #14
0
        /// <summary>
        /// The build method is called back from the child class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Build(object sender, EventArgs e)
        {
            dynElement el = sender as dynElement;

            bool useTransaction = true;

            object[] attribs = el.GetType().GetCustomAttributes(typeof(RequiresTransactionAttribute), false);
            if (attribs.Length > 0)
            {
                if ((attribs[0] as RequiresTransactionAttribute).RequiresTransaction == false)
                {
                    useTransaction = false;
                }
            }

            #region using transaction
            if (useTransaction)
            {
                Transaction       t  = new Transaction(dynElementSettings.SharedInstance.Doc.Document, el.GetType().ToString() + " update.");
                TransactionStatus ts = t.Start();

                try
                {
                    FailureHandlingOptions failOpt = t.GetFailureHandlingOptions();
                    failOpt.SetFailuresPreprocessor(dynElementSettings.SharedInstance.WarningSwallower);
                    t.SetFailureHandlingOptions(failOpt);

                    el.Destroy();
                    el.Draw();

                    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                    Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { el });

                    elementsHaveBeenDeleted = false;

                    ts = t.Commit();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
                    dynElementSettings.SharedInstance.Bench.Log(ex.Message);

                    SetToolTipDelegate sttd = new SetToolTipDelegate(SetTooltip);
                    Dispatcher.Invoke(sttd, System.Windows.Threading.DispatcherPriority.Background,
                                      new object[] { ex.Message });

                    MarkConnectionStateDelegate mcsd = new MarkConnectionStateDelegate(MarkConnectionState);
                    Dispatcher.Invoke(mcsd, System.Windows.Threading.DispatcherPriority.Background,
                                      new object[] { true });

                    if (ts == TransactionStatus.Committed)
                    {
                        t.RollBack();
                    }

                    t.Dispose();

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                }

                try
                {
                    el.UpdateOutputs();
                }
                catch (Exception ex)
                {
                    //Debug.WriteLine("Outputs could not be updated.");
                    dynElementSettings.SharedInstance.Bench.Log("Outputs could not be updated.");
                    if (ts == TransactionStatus.Committed)
                    {
                        t.RollBack();
                    }

                    t.Dispose();

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                }
            }
            #endregion

            #region no transaction
            if (!useTransaction)
            {
                try
                {
                    el.Destroy();

                    el.Draw();

                    UpdateLayoutDelegate uld = new UpdateLayoutDelegate(CallUpdateLayout);
                    Dispatcher.Invoke(uld, System.Windows.Threading.DispatcherPriority.Background, new object[] { el });

                    elementsHaveBeenDeleted = false;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message + " : " + ex.StackTrace);
                    dynElementSettings.SharedInstance.Bench.Log(ex.Message);

                    SetToolTipDelegate sttd = new SetToolTipDelegate(SetTooltip);
                    Dispatcher.Invoke(sttd, System.Windows.Threading.DispatcherPriority.Background,
                                      new object[] { ex.Message });

                    MarkConnectionState(true);

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                }

                try
                {
                    el.UpdateOutputs();
                }
                catch (Exception ex)
                {
                    //Debug.WriteLine("Outputs could not be updated.");
                    dynElementSettings.SharedInstance.Bench.Log("Outputs could not be updated.");

                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.Message);
                    dynElementSettings.SharedInstance.Writer.WriteLine(ex.StackTrace);
                }
            }
            #endregion
        }