Пример #1
0
        private void _CreateSchemaFromFile(string filename)
        {
            string attributes;
            bool error;
            List<string> errors = new List<string>();
            string[] sides;
            string line;
            string[] lines = System.IO.File.ReadAllLines(filename);

            if (lines.Length > 0)
            {
                attributes = (new System.Text.RegularExpressions.Regex("[^a-zA-Z]")).Replace(lines[0], String.Empty);
                if (attributes.Length > 0)
                {
                    _schema = new Schema(attributes);

                    for (int i = 1; i < lines.Length; i++)
                    {
                        line = lines[i];
                        if (line.Contains(','))
                        {
                            sides = line.Split(',');
                            if (sides.Length == 2)
                            {
                                error = false;
                                for (int j = 0; j < 2; j++)
                                {
                                    for (int k = 0; k < sides[j].Length; k++)
                                    {
                                        if (!_schema.Attributes.Contains(sides[j][k]))
                                        {
                                            errors.Add("Line " + i + " does not have valid attributes on one of the sides ('" + line + "').");
                                            error = true;
                                            break;
                                        }
                                    }
                                }
                                if (!error) _schema.AddDependency(sides[0], sides[1]);
                            }
                            else
                            {
                                errors.Add("Line " + i + " does not have 2 sides ('" + line + "').");
                            }
                        }
                        else
                        {
                            errors.Add("Line " + i + " is not comma delimited ('" + line + "').");
                        }
                    }

                    if (errors.Count > 0)
                    {
                        MessageBox.Show(String.Join(Environment.NewLine, errors), "Schema Import Errors", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    if (errors.Count < lines.Length)
                    {
                        _CreateSchema();
                    }
                }
                else
                {
                    MessageBox.Show("No valid attributes found in the first line of the file.", "Schema Import Errors", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("No valid FD's found in the file.", "Schema Import Errors", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #2
0
 private void schemaCreateButton_Click(object sender, RoutedEventArgs e)
 {
     _schema = new Schema(Int32.Parse(this.schemaArityComboBox.SelectedItem.ToString()));
     _CreateSchema();
 }