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; }