Exemple #1
0
        static void Main(string[] args)
        {
resetMark:
            int count = 0;

            try
            {
                Console.Write("Input TV`s count: ");
                count = Convert.ToInt32(Console.ReadLine());
            }
            catch
            {
                ErrorCatcher.Error("(devices count)");
                Thread.Sleep(2500);
                Console.Clear();
                goto resetMark;
            }

            List <TV> TVList = new List <TV>();

            for (int i = 0; i < count; i++)
            {
                TV.s_TV_Desc deviceDesc = new TV.s_TV_Desc();
                TV.ParamsInputRequest(ref deviceDesc);
                TVList.Add(new TV(deviceDesc));
            }

            foreach (TV device in TVList)
            {
                Console.WriteLine('\n' + device.ToString());
            }

            Console.ReadKey();
        }
Exemple #2
0
        private void LoadKompas3D_Click(object sender, EventArgs e)
        {
            if (LoadKompas3D.Enabled)
            {
                var errorCatcher = new ErrorCatcher();

                _kompasApp = new KompasApplication();
                if (_kompasApp == null)
                {
                    errorCatcher.CatchError(
                        ErrorCodes.KompasObjectCreatingError);
                }
                if (_kompasApp.LastErrorCode != ErrorCodes.OK)
                {
                    errorCatcher.CatchError(_kompasApp.LastErrorCode);
                    return;
                }

                SetAllInputsEnabledState(true);

                RunButton.Enabled = true;
                Defaults.Enabled  = true;

                WithoutHoleRadioButton.Enabled               = true;
                CrossheadScrewdriverRadioButton.Enabled      = true;
                FlatheadScrewdriverRadioButton.Enabled       = true;
                RegularPolygonScrewdriverRadioButton.Enabled = true;

                LoadKompas3D.Enabled  = false;
                CloseKompas3D.Enabled = true;
            }
        }
Exemple #3
0
        private void LoadKompas3D_Click(object sender, EventArgs e)
        {
            if (LoadKompas3D.Enabled)
            {
                var errorCatcher = new ErrorCatcher();

                // Создать образец приложения Kompas
                _kompasApp = new KompasApplication();
                if (_kompasApp == null)
                {
                    errorCatcher.CatchError(ErrorCodes.KompasObjectCreatingError);
                }
                if (_kompasApp.LastErrorCode != ErrorCodes.OK)
                {
                    errorCatcher.CatchError(_kompasApp.LastErrorCode);
                    return;
                }

                SetAllInputsEnabledState(true);

                RunButton.Enabled = true;

                LoadKompas3D.Enabled  = false;
                CloseKompas3D.Enabled = true;
            }
        }
Exemple #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //in your app you should run this func in  Main.cs
            ErrorCatcher.InitCathcer();

            ErrorCatcher.ErrorAction += (error) => {
                var alert = new NSAlert()
                {
                    MessageText     = "Exception",
                    InformativeText = error,
                    AlertStyle      = NSAlertStyle.Critical,
                };

                alert.RunModal();
            };

            btn_exception.Activated += (sender, e) => {
                throw new System.Exception("Test Exception");
            };

            btn_nsException.Activated += (sender, e) => {
                var d = new NSException("NSException", "Test NSException", null);
            };
        }
 public TaskSpecific()
 {
     ActionErrorCatcher      = new ErrorCatcher();
     EventErrorCatcher       = new ErrorCatcher();
     CombinationErrorCatcher = new ErrorCatcher();
     TaskParamErrorCatcher   = new ErrorCatcher();
 }
Exemple #6
0
        /// <summary>
        ///Проверка пользовательских параметров ввода и построение фигуры после этого
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RunButton_Click_1(object sender, EventArgs e)
        {
            var errorCatcher = new ErrorCatcher();

            if (_kompasApp == null)
            {
                MessageBox.Show("Сначала загрузите KOMPAS 3D.", "Information",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }

            if (!SetFigureParameters())
            {
                return;
            }

            _kompasApp.Parameters = _figureParameters;

            // Create 3D document
            if (!_kompasApp.CreateDocument3D())
            {
                return;
            }

            // Create build manager
            BuildManager _buildManager = new BuildManager(_kompasApp);

            if (_buildManager == null)
            {
                errorCatcher.CatchError(ErrorCodes.ManagerCreatingError);
                return;
            }
            if (_buildManager.LastErrorCode != ErrorCodes.OK)
            {
                errorCatcher.CatchError(_buildManager.LastErrorCode);
                return;
            }

            _buildManager.CreateDetail();

            if (_buildManager.LastErrorCode != ErrorCodes.OK)
            {
                errorCatcher.CatchError(_buildManager.LastErrorCode);
            }
            else
            {
                errorCatcher.CatchSuccess();
            }
        }
Exemple #7
0
        public static Base FromStream(Stream stream)
        {
            // Check stream
            if (stream == null)
            {
                throw new ArgumentNullException();
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("Stream can not be read");
            }
            XmlReader reader = null;

            try
            {
                // Start reading XML header
                reader = XmlReader.Create(stream);
                if (reader.ReadToFollowing("Root") == false)
                {
                    throw new ArgumentException("Unable to locate root element");
                }
                // Determine the type of the XML file
                string name    = reader.GetAttribute("Name");
                string version = reader.GetAttribute("Version");
                reader.Close();
                // XML file doesn't meet our expected format
                if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(version))
                {
                    throw new ArgumentException("Unable to locate Name or Version attribute");
                }
                string type = name + "_" + version;

                // Load file as known type
                Registration registration = null;
                lock (_types)
                {
                    if (_types.ContainsKey(type))
                    {
                        registration = _types[type];
                    }
                }
                if (registration == null)
                {
                    throw new ArgumentException("No registered data class for type " + name + " v" + version);
                }
                // Verify document
                if (!string.IsNullOrEmpty(registration.Schema))
                {
                    stream.Seek(0, SeekOrigin.Begin);
                    XmlReaderSettings readerSettings = new XmlReaderSettings();
                    readerSettings.ConformanceLevel = ConformanceLevel.Document;
                    // Configure XSD validation
                    readerSettings.ValidationType = ValidationType.Schema;
                    readerSettings.Schemas.Add(registration.Namespace, registration.Schema);
                    readerSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
                    // Validate document
                    stream.Seek(0, SeekOrigin.Begin);
                    reader = XmlReader.Create(stream, readerSettings);
                    while (reader.Read())
                    {
                    }
                    reader.Close();
                }
                // Deserialize
                stream.Seek(0, SeekOrigin.Begin);
                reader = XmlReader.Create(stream);
                XmlSerializer serializer   = XML.GetSerializer(registration.Type);
                ErrorCatcher  errorCatcher = new ErrorCatcher();
                serializer.UnknownAttribute += new XmlAttributeEventHandler(errorCatcher.OnUnknownAttribute);
                serializer.UnknownElement   += new XmlElementEventHandler(errorCatcher.OnUnknownElement);
                serializer.UnknownNode      += new XmlNodeEventHandler(errorCatcher.OnUnknownNode);
                Base data = (Base)serializer.Deserialize(reader);
                // Verify output
                if (errorCatcher.Exceptions.Count > 0)
                {
                    throw errorCatcher.Exceptions[0];
                }
                if (data == null)
                {
                    return(null);
                }
                // Upgrade data if needed
                while (data.CanUpgrade)
                {
                    data = data.Upgrade();
                }
                // Apply XSD information
                if (!string.IsNullOrEmpty(registration.Namespace) && !string.IsNullOrEmpty(registration.Schema))
                {
                    // TODO: figure out a way to set the 'xmlns' attribute
                    data.XsiSchemaLocation = registration.Namespace + " " + registration.Schema;
                }
                else if (!string.IsNullOrEmpty(registration.Schema))
                {
                    data.XsiNoNamespaceSchemaLocation = registration.Schema;
                }
                // Everything went right, pfew
                return(data);
            }
            finally
            {
                // Close anything left open
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }