public MruConnections Save(DbConnectionViewModel vm)
 {
     if (vm.MruConnections == null)
     {
         return(null);
     }
     MruDbConnectionParameterAdapter.SetMruDbConnectionParameter(vm.MruConnections, vm.ConnectionParameter);
     return(vm.MruConnections);
 }
Example #2
0
        /// <summary>
        /// Update the most recently used db connection parameter in the application data folder.
        /// </summary>
        /// <param name="dbConnectionParameter">The db connection parameter.</param>
        internal void SaveDbConnectionParameterInMruHistory(DbConnectionParameter dbConnectionParameter)
        {
            MruConnections mruConnections = MruDbConnectionParameters;

            if (mruConnections == null)
            {
                return;
            }

            bool parameterChanged = MruDbConnectionParameterAdapter.SetMruDbConnectionParameter(mruConnections, dbConnectionParameter);

            if (!parameterChanged)
            {
                return;
            }

            string mruConnectionsPath = GetGlobalFilePath(MruConnectionFileName);

            if (String.IsNullOrEmpty(mruConnectionsPath))
            {
                return;
            }


            try {
                string directory = Path.GetDirectoryName(mruConnectionsPath);
                Directory.CreateDirectory(directory);
                using (Stream stream = new FileStream(mruConnectionsPath, FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.SequentialScan)) {
                    XmlSchema     xmlSchema  = MruConnections.Schema;
                    XmlSerializer serializer = new XmlSerializer(typeof(MruConnections), xmlSchema.TargetNamespace);
                    serializer.Serialize(stream, mruConnections);
                    stream.Close();
                }
            }
            catch (Exception ex) {
                string context = MethodInfo.GetCurrentMethod().Name;
                string message = String.Format("{0}: Failed to save connection settings because [{1}].", context, ex.Message);
                Debug.WriteLine(message);
                var outputPane = Output.GetAndActivateOutputPane((EnvDTE80.DTE2)application);
                outputPane.OutputString(message);
            }
        }