Пример #1
0
        public bool CheckInputs()
        {
            MarkConnectionStateDelegate mcsd = new MarkConnectionStateDelegate(MarkConnectionState);

            foreach (PortData pd in InPortData)
            {
                //if the port data's object is null
                //or the port data's object type can not be matched
                if (pd.Object == null)  //|| pd.Object.GetType() != pd.PortType)
                {
                    Dispatcher.Invoke(mcsd, System.Windows.Threading.DispatcherPriority.Background,
                                      new object[] { true });

                    SetToolTipDelegate sttd = new SetToolTipDelegate(SetTooltip);
                    Dispatcher.Invoke(sttd, System.Windows.Threading.DispatcherPriority.Background,
                                      new object[] { "One or more connections is null." });

                    return(false);
                }
            }


            Dispatcher.Invoke(mcsd, System.Windows.Threading.DispatcherPriority.Background,
                              new object[] { false });

            return(true);
        }
        public static bool DownloadVersion(string URL, string outputPath,
                                           SetToolTipDelegate SetToolTip,
                                           SetProgressDelegate SetProgressMax,
                                           SetProgressDelegate AddProgressValue)
        {
            try
            {
                SetToolTip("Downloading " + URL);

                WebRequest  objRequest  = System.Net.HttpWebRequest.Create(URL);
                WebResponse objResponse = objRequest.GetResponse();

                SetProgressMax((int)objResponse.ContentLength);

                using (BinaryReader inputReader = new BinaryReader(objResponse.GetResponseStream()))
                {
                    using (FileStream outputStream = new FileStream(outputPath, FileMode.CreateNew))
                    {
                        byte[] buffer = new byte[32768];
                        int    read;
                        while ((read = inputReader.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            AddProgressValue(read);
                            outputStream.Write(buffer, 0, read);
                        }
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                SetToolTip("Unable to download " + URL + ": " + e.Message);
                SystemSounds.Beep.Play();

                return(false);
            }
        }
Пример #3
0
        public bool CheckInputs()
        {
            var mcsd = new MarkConnectionStateDelegate(MarkConnectionState);

            foreach (PortData pd in InPortData)
            {
                //if the port data's object is null
                //or the port data's object type can not be matched
                Dispatcher.Invoke(
                   mcsd,
                   System.Windows.Threading.DispatcherPriority.Background,
                   new object[] { true }
                );

                SetToolTipDelegate sttd = new SetToolTipDelegate(SetTooltip);
                Dispatcher.Invoke(
                   sttd, System.Windows.Threading.DispatcherPriority.Background,
                   new object[] { "One or more connections is null." }
                );

                return false;
            }

            Dispatcher.Invoke(mcsd, System.Windows.Threading.DispatcherPriority.Background,
               new object[] { false });

            return true;
        }
Пример #4
0
        internal void Error(string p)
        {
            MarkConnectionState(true);

            SetToolTipDelegate sttd = new SetToolTipDelegate(SetTooltip);
            Dispatcher.Invoke(sttd, System.Windows.Threading.DispatcherPriority.Background,
                new object[] { p });
        }
Пример #5
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
        }
        public static bool DownloadVersion(string URL, string outputPath, 
            SetToolTipDelegate SetToolTip,
            SetProgressDelegate SetProgressMax,
            SetProgressDelegate AddProgressValue)
        {
            try
            {
                SetToolTip("Downloading " + URL);

                WebRequest objRequest = System.Net.HttpWebRequest.Create(URL);
                WebResponse objResponse = objRequest.GetResponse();

                SetProgressMax((int)objResponse.ContentLength);

                using (BinaryReader inputReader = new BinaryReader(objResponse.GetResponseStream()))
                {
                    using (FileStream outputStream = new FileStream(outputPath, FileMode.CreateNew))
                    {

                        byte[] buffer = new byte[32768];
                        int read;
                        while ((read = inputReader.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            AddProgressValue(read);
                            outputStream.Write(buffer, 0, read);
                        }
                    }
                }

                return true;
            }
            catch (Exception e)
            {
                SetToolTip("Unable to download " + URL + ": " + e.Message);
                SystemSounds.Beep.Play();

                return false;
            }
        }
Пример #7
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
        }