//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Microsoft.SqlTools.EditorServices.Session
{
///
/// Provides profile path resolution behavior relative to the name
/// of a particular SqlTools host.
///
public class ProfilePaths
{
#region Constants
///
/// The file name for the "all hosts" profile. Also used as the
/// suffix for the host-specific profile filenames.
///
public const string AllHostsProfileName = "profile.ps1";
#endregion
#region Properties
///
/// Gets the profile path for all users, all hosts.
///
public string AllUsersAllHosts { get; private set; }
///
/// Gets the profile path for all users, current host.
///
public string AllUsersCurrentHost { get; private set; }
///
/// Gets the profile path for the current user, all hosts.
///
public string CurrentUserAllHosts { get; private set; }
///
/// Gets the profile path for the current user and host.
///
public string CurrentUserCurrentHost { get; private set; }
#endregion
#region Public Methods
///
/// Creates a new instance of the ProfilePaths class.
///
///
/// The identifier of the host used in the host-specific X_profile.ps1 filename.
///
/// The base path to use for constructing AllUsers profile paths.
/// The base path to use for constructing CurrentUser profile paths.
public ProfilePaths(
string hostProfileId,
string baseAllUsersPath,
string baseCurrentUserPath)
{
this.Initialize(hostProfileId, baseAllUsersPath, baseCurrentUserPath);
}
private void Initialize(
string hostProfileId,
string baseAllUsersPath,
string baseCurrentUserPath)
{
string currentHostProfileName =
string.Format(
"{0}_{1}",
hostProfileId,
AllHostsProfileName);
this.AllUsersCurrentHost = Path.Combine(baseAllUsersPath, currentHostProfileName);
this.CurrentUserCurrentHost = Path.Combine(baseCurrentUserPath, currentHostProfileName);
this.AllUsersAllHosts = Path.Combine(baseAllUsersPath, AllHostsProfileName);
this.CurrentUserAllHosts = Path.Combine(baseCurrentUserPath, AllHostsProfileName);
}
///
/// Gets the list of profile paths that exist on the filesystem.
///
/// An IEnumerable of profile path strings to be loaded.
public IEnumerable GetLoadableProfilePaths()
{
var profilePaths =
new string[]
{
this.AllUsersAllHosts,
this.AllUsersCurrentHost,
this.CurrentUserAllHosts,
this.CurrentUserCurrentHost
};
return profilePaths.Where(p => File.Exists(p));
}
#endregion
}
}