Example #1
0
        private void LoadConfigExecute(object sender)
        {
            var fileDialog = new OpenFileDialog();

            fileDialog.Multiselect     = false;
            fileDialog.CheckFileExists = true;
            fileDialog.DefaultExt      = "*.msConfigStore";
            fileDialog.Filter          = "ConfigFile (*.msConfigStore)|*.msConfigStore";
            var result = fileDialog.ShowDialog();

            if (result.HasValue && result.Value && File.Exists(fileDialog.FileName))
            {
                Tables.Clear();
                Views.Clear();
                StoredProcs.Clear();
                SelectedTable = null;

                var         binFormatter = new BinaryFormatter();
                ConfigStore options;
                try
                {
                    using (var fs = fileDialog.OpenFile())
                    {
                        options = (ConfigStore)binFormatter.Deserialize(fs);
                    }
                }
                catch (Exception)
                {
                    Status = "File is an in invalid format";
                    return;
                }

                var version = typeof(SharedMethods).Assembly.GetName().Version;
                if (new Version(options.Version) != version)
                {
                    var messageBoxResult = MessageBox.Show(Application.Current.MainWindow,
                                                           "Warning Version missmatch",
                                                           string.Format("The current Entity Creator version ({0}) is not equals the version ({1}) you have provided.",
                                                                         version, options.Version),
                                                           MessageBoxButton.OKCancel);

                    if (messageBoxResult == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                }

                if (options.SourceConnectionString != null)
                {
                    ConnectionString = options.SourceConnectionString;
                    CreateEntrysAsync(ConnectionString, "", string.Empty).ContinueWith(task =>
                    {
                        foreach (var optionsAction in options.Actions)
                        {
                            optionsAction.Replay(this);
                        }
                    });
                }
            }
        }