public static void WritePSDataCollectionProfile(IAzureSession session, AzurePSDataCollectionProfile profile) { try { var store = session.DataStore; string dataPath = Path.Combine(session.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName); if (!store.DirectoryExists(session.ProfileDirectory)) { store.CreateDirectory(session.ProfileDirectory); } string contents = JsonConvert.SerializeObject(profile); store.WriteFile(dataPath, contents); } catch { // do not throw for i/o or serialization errors } }
static AzurePSDataCollectionProfile Initialize(IAzureSession session) { AzurePSDataCollectionProfile result = new AzurePSDataCollectionProfile(true); try { var environmentValue = Environment.GetEnvironmentVariable(AzurePSDataCollectionProfile.EnvironmentVariableName); bool enabled = true; if (!string.IsNullOrWhiteSpace(environmentValue) && bool.TryParse(environmentValue, out enabled)) { result.EnableAzureDataCollection = enabled; } else { var store = session.DataStore; string dataPath = Path.Combine(session.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName); if (store.FileExists(dataPath)) { string contents = store.ReadFileAsText(dataPath); var localResult = JsonConvert.DeserializeObject <AzurePSDataCollectionProfile>(contents); if (localResult != null && localResult.EnableAzureDataCollection.HasValue) { result = localResult; } } else { WritePSDataCollectionProfile(session, new AzurePSDataCollectionProfile(true)); } } } catch { // do not throw for i/o or serialization errors } return(result); }
public static DataCollectionController Create(AzurePSDataCollectionProfile profile) { return(new MemoryDataCollectionController(profile)); }
public MemoryDataCollectionController(AzurePSDataCollectionProfile enabled) { _lock = new object(); _enabled = enabled?.EnableAzureDataCollection; }
/// <summary> /// Initialize the data collection profile /// </summary> protected static void InitializeDataCollectionProfile() { if (_dataCollectionProfile != null && _dataCollectionProfile.EnableAzureDataCollection.HasValue) { return; } // Get the value of the environment variable for Azure PS data collection setting. string value = Environment.GetEnvironmentVariable(AzurePSDataCollectionProfile.EnvironmentVariableName); if (!string.IsNullOrWhiteSpace(value)) { if (string.Equals(value, bool.FalseString, StringComparison.OrdinalIgnoreCase)) { // Disable data collection only if it is explicitly set to 'false'. _dataCollectionProfile = new AzurePSDataCollectionProfile(true); } else if (string.Equals(value, bool.TrueString, StringComparison.OrdinalIgnoreCase)) { // Enable data collection only if it is explicitly set to 'true'. _dataCollectionProfile = new AzurePSDataCollectionProfile(false); } } // If the environment value is null or empty, or not correctly set, try to read the setting from default file location. if (_dataCollectionProfile == null) { string fileFullPath = Path.Combine(AzurePowerShell.ProfileDirectory, AzurePSDataCollectionProfile.DefaultFileName); if (File.Exists(fileFullPath)) { string contents = File.ReadAllText(fileFullPath); _dataCollectionProfile = JsonConvert.DeserializeObject<AzurePSDataCollectionProfile>(contents); } } // If the environment variable or file content is not set, create a new profile object. if (_dataCollectionProfile == null) { _dataCollectionProfile = new AzurePSDataCollectionProfile(); } }
public MetricHelper(AzurePSDataCollectionProfile profile) : this(new NetworkHelper()) { _profile = profile; }