예제 #1
0
 /// <summary>
 /// Internal constructor for unit testing
 /// </summary>
 /// <param name="textWriterFactory"></param>
 /// <param name="logFilePath"></param>
 internal LocalFileLogger(ITextWriterFactory textWriterFactory, string logFilePath)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(logFilePath, "logFilePath");
     CodeContract.RequiresArgumentNotNull <ITextWriterFactory>(textWriterFactory, "textWriterFactory");
     FullLogPath            = logFilePath;
     this.textWriterFactory = textWriterFactory;
 }
        public void SetValue <T>(string key, T value)
        {
            CodeContract.RequiresArgumentNotNullAndNotEmpty(key, "key");
            Tuple <string, string> pathComponents = GetPathComponents(key);

            SetValueInternal(pathComponents.Item1, pathComponents.Item2, value);
        }
예제 #3
0
 private bool IsCachedFlightEnabledInternal(string flight, bool sendTriggeredEvent)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(flight, "flight");
     RequiresNotDisposed();
     flight = flight.ToLowerInvariant();
     return(flightStatus.AddOrUpdate(flight, delegate(string key)
     {
         bool isEnabled = flightsProvider.Flights.Contains(key);
         if (sendTriggeredEvent)
         {
             PostFlightRequestTelemetry(flight, isEnabled);
         }
         return new FlightStatus
         {
             IsEnabled = isEnabled,
             WasTriggered = sendTriggeredEvent
         };
     }, delegate(string key, FlightStatus existingValue)
     {
         if (sendTriggeredEvent && !existingValue.WasTriggered)
         {
             PostFlightRequestTelemetry(flight, existingValue.IsEnabled);
             existingValue.WasTriggered = true;
         }
         return existingValue;
     }).IsEnabled);
 }
 public bool TryGetValue <T>(string collectionPath, string key, out T value)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(collectionPath, "collectionPath");
     collectionPath = collectionPath.NormalizePath();
     CodeContract.RequiresArgumentNotNullAndNotEmpty(key, "key");
     return(GetValueInternal(collectionPath, key, default(T), out value));
 }
예제 #5
0
        /// <summary>
        /// Get internal settings for the channel specified by its ID.
        /// There are 3 states could be:
        /// - explicitly enabled
        /// - explicitly disabled
        /// - undefined (no settings available)
        /// </summary>
        /// <param name="channelId"></param>
        /// <returns></returns>
        public virtual ChannelInternalSetting GetChannelSettings(string channelId)
        {
            CodeContract.RequiresArgumentNotNullAndNotEmpty(channelId, "channelId");
            if (!TypeTools.TryConvertToInt(registryTools.GetRegistryValueFromCurrentUserRoot("Software\\Coding4Fun\\VisualStudio\\Telemetry\\Channels", channelId, (object)(-1)), out int result))
            {
                result = -1;
            }
            ChannelInternalSetting channelInternalSetting = ChannelInternalSetting.Undefined;

            switch (result)
            {
            case 1:
                channelInternalSetting = ChannelInternalSetting.ExplicitlyEnabled;
                break;

            case 0:
                channelInternalSetting = ChannelInternalSetting.ExplicitlyDisabled;
                break;
            }
            if (channelInternalSetting != ChannelInternalSetting.Undefined)
            {
                diagnosticTelemetry.LogRegistrySettings(string.Format(CultureInfo.InvariantCulture, "Channel.{0}", new object[1]
                {
                    channelId
                }), channelInternalSetting.ToString());
            }
            return(channelInternalSetting);
        }
 public bool PropertyExists(string collectionPath, string key)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(collectionPath, "collectionPath");
     collectionPath = collectionPath.NormalizePath();
     CodeContract.RequiresArgumentNotNullAndNotEmpty(key, "key");
     return(((IRegistryTools)registryTools).GetRegistryValueFromCurrentUserRoot(collectionPath, key, (object)null) != null);
 }
 public void SetValue <T>(string collectionPath, string key, T value)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(collectionPath, "collectionPath");
     collectionPath = collectionPath.NormalizePath();
     CodeContract.RequiresArgumentNotNullAndNotEmpty(key, "key");
     SetValueInternal(collectionPath, key, value);
 }
예제 #8
0
 public LocalFlightsProvider(IKeyValueStorage keyValueStorage, string flightsKey)
 {
     CodeContract.RequiresArgumentNotNull <IKeyValueStorage>(keyValueStorage, "keyValueStorage");
     CodeContract.RequiresArgumentNotNullAndNotEmpty(flightsKey, "flightsKey");
     this.keyValueStorage = keyValueStorage;
     pathToSettings       = PathToSettingsPrefix + flightsKey;
 }
예제 #9
0
 /// <summary>
 /// Move property from the excluded property list to the event properties list
 /// </summary>
 /// <param name="propertyName"></param>
 public void IncludePropertyToEvent(string propertyName)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(propertyName, "propertyName");
     if (excludedProperties != null && TelemetryEvent != null && excludedProperties.TryGetValue(propertyName, out object value))
     {
         TelemetryEvent.Properties[propertyName] = value;
     }
 }
예제 #10
0
 public RemoteFlightsProvider(IKeyValueStorage keyValueStorage, string flightsKey, IRemoteFileReaderFactory remoteFileFactory, IFlightsStreamParser flightsStreamParser)
     : base(keyValueStorage, flightsStreamParser, 1800000)
 {
     CodeContract.RequiresArgumentNotNull <IRemoteFileReaderFactory>(remoteFileFactory, "remoteFileFactory");
     CodeContract.RequiresArgumentNotNullAndNotEmpty(flightsKey, "flightsKey");
     remoteFileReader = new Lazy <IRemoteFileReader>(() => remoteFileFactory.Instance());
     this.flightsKey  = flightsKey;
 }
예제 #11
0
        private async Task <bool> IsFlightEnabledInternalAsync(string flight, CancellationToken token, bool sendTriggeredEvent)
        {
            CodeContract.RequiresArgumentNotNullAndNotEmpty(flight, "flight");
            RequiresNotDisposed();
            await flightsProvider.WaitForReady(token).ConfigureAwait(false);

            return(IsCachedFlightEnabledInternal(flight, sendTriggeredEvent));
        }
        public T GetValue <T>(string key, T defaultValue)
        {
            CodeContract.RequiresArgumentNotNullAndNotEmpty(key, "key");
            Tuple <string, string> pathComponents = GetPathComponents(key);

            GetValueInternal(pathComponents.Item1, pathComponents.Item2, defaultValue, out T value);
            return(value);
        }
예제 #13
0
 public AFDFlightsProvider(IKeyValueStorage keyValueStorage, string flightsKey, IFlightsStreamParser flightsStreamParser, IExperimentationFilterProvider filterProvider, IHttpWebRequestFactory httpWebRequestFactory)
     : base(keyValueStorage, flightsStreamParser, 1800000)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(flightsKey, "flightsKey");
     CodeContract.RequiresArgumentNotNull <IExperimentationFilterProvider>(filterProvider, "filterProvider");
     CodeContract.RequiresArgumentNotNull <IHttpWebRequestFactory>(httpWebRequestFactory, "httpWebRequestFactory");
     this.filterProvider        = filterProvider;
     this.flightsKey            = flightsKey;
     this.httpWebRequestFactory = httpWebRequestFactory;
 }
예제 #14
0
 /// <summary>
 /// Remove property from the property list of the event and move it to the
 /// excluded properties list
 /// </summary>
 /// <param name="propertyName"></param>
 public void ExcludePropertyFromEvent(string propertyName)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(propertyName, "propertyName");
     if (TelemetryEvent != null && TelemetryEvent.Properties.ContainsKey(propertyName))
     {
         if (excludedProperties == null)
         {
             excludedProperties = new Dictionary <string, object>();
         }
         excludedProperties[propertyName] = TelemetryEvent.Properties[propertyName];
         TelemetryEvent.Properties.Remove(propertyName);
     }
 }
예제 #15
0
        public bool ReadIsOptedInStatus(string productVersion)
        {
            CodeContract.RequiresArgumentNotNullAndNotEmpty(productVersion, "productVersion");
            bool result = false;

            if (TryGlobalPolicyOptedInStatus(out bool optedIn))
            {
                result = optedIn;
            }
            else
            {
                int?registryIntValueFromLocalMachineRoot = ((IRegistryTools)registryTools).GetRegistryIntValueFromLocalMachineRoot(string.Format(CultureInfo.InvariantCulture, "Software\\Microsoft\\VSCommon\\{0}\\SQM", new object[1]
                {
                    productVersion
                }), "OptIn", (int?)null);
                if (registryIntValueFromLocalMachineRoot.HasValue)
                {
                    result = (registryIntValueFromLocalMachineRoot.Value == 1);
                }
            }
            return(result);
        }
예제 #16
0
        public override ChannelInternalSetting GetChannelSettings(string channelId)
        {
            CodeContract.RequiresArgumentNotNullAndNotEmpty(channelId, "channelId");
            int num = -1;

            try
            {
                JToken val = default(JToken);
                if (channelSettingsJson != null && channelSettingsJson.TryGetValue(channelId, StringComparison.OrdinalIgnoreCase, out val))
                {
                    string a = ((object)val).ToString();
                    if (a == "enabled")
                    {
                        num = 1;
                    }
                    if (a == "disabled")
                    {
                        num = 0;
                    }
                }
            }
            catch
            {
                num = -1;
            }
            switch (num)
            {
            case 1:
                return(ChannelInternalSetting.ExplicitlyEnabled);

            case 0:
                return(ChannelInternalSetting.ExplicitlyDisabled);

            default:
                return(base.GetChannelSettings(channelId));
            }
        }
        public bool TryGetValueKind(string collectionPath, string key, out ValueKind kind)
        {
            CodeContract.RequiresArgumentNotNullAndNotEmpty(collectionPath, "collectionPath");
            collectionPath = collectionPath.NormalizePath();
            CodeContract.RequiresArgumentNotNullAndNotEmpty(key, "key");
            kind = ValueKind.Unknown;
            RegistryValueKind registryValueKind = default(RegistryValueKind);

            if (registryTools.TryGetRegistryValueKindFromCurrentUserRoot(collectionPath, key, out registryValueKind))
            {
                switch (registryValueKind)
                {
                case RegistryValueKind.DWord:
                    kind = ValueKind.DWord;
                    break;

                case RegistryValueKind.QWord:
                    kind = ValueKind.QWord;
                    break;

                case RegistryValueKind.MultiString:
                    kind = ValueKind.MultiString;
                    break;

                case RegistryValueKind.String:
                    kind = ValueKind.String;
                    break;

                default:
                    kind = ValueKind.Unknown;
                    break;
                }
                return(true);
            }
            return(false);
        }
 public bool DeleteProperty(string collectionPath, string propertyName)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(collectionPath, "collectionPath");
     CodeContract.RequiresArgumentNotNullAndNotEmpty(propertyName, "propertyName");
     return(((IRegistryTools2)registryTools).DeleteRegistryValueFromCurrentUserRoot(collectionPath, propertyName));
 }
 public IEnumerable <string> GetPropertyNames(string collectionPath)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(collectionPath, "collectionPath");
     collectionPath = collectionPath.NormalizePath();
     return(((IRegistryTools2)registryTools).GetRegistryValueNamesFromCurrentUserRoot(collectionPath));
 }
예제 #20
0
 public void AddPassthroughEventName(string eventName)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(eventName, "eventName");
     passthroughEvents.Add(eventName);
 }
예제 #21
0
 public SetFlightsProvider(IKeyValueStorage keyValueStorage, string flightsKey)
 {
     CodeContract.RequiresArgumentNotNull <IKeyValueStorage>(keyValueStorage, "keyValueStorage");
     CodeContract.RequiresArgumentNotNullAndNotEmpty(flightsKey, "flightsKey");
     cachedFlightsProvider = new Lazy <LocalFlightsProvider>(() => new LocalFlightsProvider(keyValueStorage, flightsKey));
 }
예제 #22
0
 /// <summary>
 /// Log registry settings using key/value pair.
 /// settingsName - suffix for the settings property.
 /// </summary>
 /// <param name="settingsName"></param>
 /// <param name="value"></param>
 public void LogRegistrySettings(string settingsName, string value)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(settingsName, "settingsName");
     CodeContract.RequiresArgumentNotNullAndNotEmpty(value, "value");
     registrySettings["VS.TelemetryApi.RegistrySettings." + settingsName] = value;
 }
예제 #23
0
 /// <summary>
 /// Reads and set VS OptIn status.
 /// </summary>
 /// <param name="productVersion">VS product version so it is possible to build settings path</param>
 public void UseVsIsOptedIn(string productVersion)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(productVersion, "productVersion");
     IsOptedIn = optinStatusReader.ReadIsOptedInStatus(productVersion);
 }
 public bool CollectionExists(string collectionPath)
 {
     CodeContract.RequiresArgumentNotNullAndNotEmpty(collectionPath, "collectionPath");
     collectionPath = collectionPath.NormalizePath();
     return(((IRegistryTools2)registryTools).DoesRegistryKeyExistInCurrentUserRoot(collectionPath));
 }