Beispiel #1
0
 /// <summary>
 /// Merges the passed in GroupedRemoteSettings from buckets into this instance.
 /// Identical settings in this instance will be overwritten by those in buckets.
 /// </summary>
 /// <param name="buckets"></param>
 /// <param name="logger"></param>
 public void Merge(GroupedRemoteSettings buckets, IRemoteSettingsLogger logger)
 {
     foreach (string key in buckets.Keys)
     {
         RemoteSettingPossibilities remoteSettingPossibilities = buckets[key];
         if (!TryGetValue(key, out RemoteSettingPossibilities value))
         {
             value = (base[key] = new RemoteSettingPossibilities());
         }
         foreach (string key2 in remoteSettingPossibilities.Keys)
         {
             List <RemoteSetting> list = remoteSettingPossibilities[key2];
             if (!value.TryGetValue(key2, out List <RemoteSetting> value2))
             {
                 value2 = (value[key2] = new List <RemoteSetting>());
             }
             for (int num = list.Count - 1; num >= 0; num--)
             {
                 RemoteSetting remoteSetting = list[num];
                 int           num2          = value2.FindIndex((RemoteSetting s) => s.Name == remoteSetting.Name && s.ScopeString == remoteSetting.ScopeString);
                 if (num2 != -1)
                 {
                     logger.LogVerbose($"Overwriting RemoteSetting during merge: Old value from {value2[num2]}");
                     logger.LogVerbose($"Overwriting RemoteSetting during merge: New value from {remoteSetting}");
                     value2[num2] = remoteSetting;
                 }
                 else
                 {
                     value2.Insert(0, remoteSetting);
                 }
             }
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// Starts a background operation to check for new Remote Settings and apply them.
 /// </summary>
 public void Start()
 {
     RequiresNotDisposed();
     if (!isStarted)
     {
         if (isUpdateDisabled())
         {
             StartTask = Task.FromResult(false);
         }
         else
         {
             List <Task <GroupedRemoteSettings> > tasks = new List <Task <GroupedRemoteSettings> >();
             foreach (IRemoteSettingsProvider allRemoteSettingsProvider in AllRemoteSettingsProviders)
             {
                 tasks.Add(allRemoteSettingsProvider.Start());
             }
             StartTask = Task.Run(async delegate
             {
                 await logger.Start().ConfigureAwait(false);
                 IEnumerable <GroupedRemoteSettings> source = (await Task.WhenAll(tasks).ConfigureAwait(false)).Where((GroupedRemoteSettings x) => x != null);
                 if ((nonScopedStorageHandler != null || logger.LoggingEnabled) && source.Any())
                 {
                     GroupedRemoteSettings groupedRemoteSettings = source.Reverse().Aggregate(delegate(GroupedRemoteSettings a, GroupedRemoteSettings b)
                     {
                         a.Merge(b, logger);
                         return(a);
                     });
                     logger.LogVerbose("Merged settings", groupedRemoteSettings);
                     if (nonScopedStorageHandler != null)
                     {
                         using (Mutex mutex = new Mutex(false, "Global\\A7B8B64E-AEB3-4053-BC8C-C187F5320352"))
                         {
                             try
                             {
                                 mutex.WaitOne(-1, false);
                             }
                             catch (AbandonedMutexException)
                             {
                             }
                             try
                             {
                                 nonScopedStorageHandler.DeleteAllSettings();
                                 nonScopedStorageHandler.SaveNonScopedSettings(groupedRemoteSettings);
                             }
                             catch
                             {
                             }
                             finally
                             {
                                 mutex.ReleaseMutex();
                             }
                         }
                     }
                 }
                 OnRemoteSettingsApplied();
             });
         }
         isStarted = true;
     }
 }
Beispiel #3
0
        public IEnumerable <DirectoryReaderContext> ReadAllFiles()
        {
            logger.LogInfo("Reading all files from " + path);
            List <DirectoryReaderContext> list = new List <DirectoryReaderContext>();

            try
            {
                if (!Directory.Exists(path))
                {
                    return(list);
                }
                string[] files = Directory.GetFiles(path, "*.json");
                foreach (string text in files)
                {
                    logger.LogVerbose("Opening file for reading: " + text);
                    try
                    {
                        string text2 = text;
                        if (markProcessed)
                        {
                            logger.LogVerbose("Renaming file to .processed: " + text);
                            string text3 = text + ".processed";
                            File.Move(text, text3);
                            text2 = text3;
                        }
                        DirectoryReaderContext item = new DirectoryReaderContext
                        {
                            DirectoryName = directoryName,
                            FileName      = Path.GetFileNameWithoutExtension(text),
                            Stream        = File.OpenRead(text2)
                        };
                        list.Add(item);
                    }
                    catch (Exception exception)
                    {
                        logger.LogError("Processing file failed", exception);
                    }
                }
                return(list);
            }
            catch (Exception exception2)
            {
                logger.LogError("Checking directory failed", exception2);
                return(list);
            }
        }
        private IEnumerable <SplitKey> GetPossibleRemoteSettingKeys(string collectionPath, string key)
        {
            string str = collectionPath + " $" + key;
            string fullCollectionPath        = Path.Combine(CurrentCollectionPath, collectionPath);
            string fullCollectionPathWithKey = Path.Combine(fullCollectionPath, key + "*");

            if (remoteSettingsStorage.CollectionExists(fullCollectionPathWithKey))
            {
                logger.LogVerbose(str + " has multiple possible values");
                foreach (string item in from s in remoteSettingsStorage.GetPropertyNames(fullCollectionPathWithKey)
                         orderby s
                         select s)
                {
                    yield return(SplitKey.CreateFromStorageName(fullCollectionPathWithKey, item));
                }
            }
            yield return(new SplitKey(fullCollectionPath, key));
        }