private static IEnumerable <string> GetPhysicalFilesForServer(SqlLocalDbInstance existingInstance)
        {
            if (!existingInstance.IsRunning)
            {
                existingInstance.Start();
            }

            List <string> filePaths = new List <string>();

            using (var connection = existingInstance.CreateConnection())
                using (var command = connection.CreateCommand())
                {
                    connection.Open();
                    command.CommandText = "SELECT physical_name AS physicalPath FROM sys.master_files";
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            filePaths.Add(reader["physicalPath"].ToString());
                        }
                    }
                }

            return(filePaths);
        }
Exemple #2
0
        /// <summary>
        /// Load all github tags in the background.
        /// </summary>
        private void LoadData()
        {
            //
            // Initialize the LocalDb service only once.
            //
            if (localDb == null)
            {
                var provider = new SqlLocalDbProvider();
                SqlLocalDbInstance instance;

                try
                {
                    //
                    // If we find an existing instance then shut it down and delete it.
                    //
                    instance = provider.GetInstance("RockLauncher");
                    if (instance.IsRunning)
                    {
                        instance.Stop();
                    }
                    SqlLocalDbInstance.Delete(instance);
                }
                finally
                {
                    //
                    // Create a new instance and keep a reference to it.
                    //
                    localDb = provider.CreateInstance("RockLauncher");
                    localDb.Start();
                }
            }

            //
            // Load all the instances from the file system.
            //
            var instances = Directory.GetDirectories(Support.GetInstancesPath())
                            .Select(d => Path.GetFileName(d)).ToList();

            //
            // Convert pre-1.0 instance folders to 1.0 instance folders, which contain a
            // RockWeb for the current instance data.
            //
            foreach (string instance in instances)
            {
                string instancePath = Path.Combine(Support.GetInstancesPath(), instance);
                string rockwebPath  = Path.Combine(instancePath, "RockWeb");

                if (!Directory.Exists(rockwebPath))
                {
                    Directory.CreateDirectory(rockwebPath);

                    foreach (var d in Directory.GetDirectories(instancePath))
                    {
                        if (!Path.GetFileName(d).Equals("RockWeb", StringComparison.CurrentCultureIgnoreCase))
                        {
                            Directory.Move(d, Path.Combine(rockwebPath, Path.GetFileName(d)));
                        }
                    }

                    foreach (var f in Directory.GetFiles(instancePath))
                    {
                        Directory.Move(f, Path.Combine(rockwebPath, Path.GetFileName(f)));
                    }
                }
            }

            //
            // Update the UI with the new list of instances.
            //
            Dispatcher.Invoke(() =>
            {
                cbInstances.ItemsSource = instances;
                if (instances.Count > 0)
                {
                    cbInstances.SelectedIndex = 0;
                }

                txtStatus.Text = "Idle";

                UpdateState();
            });
        }