Exemplo n.º 1
0
 /// <summary>
 /// Invoked whenever there's a new settings object.
 /// </summary>
 public void Watch(Settings settings)
 {
     lock (syncLock)
     {
         if (Log.IsDebugEnabled)
             Log.Debug("Watch new settings");
         MonitorLocalChanges(settings);
         MonitorRemoteChanges(settings);
     }
 }
Exemplo n.º 2
0
 private static string AppendHost(this string relativeUrl, Settings settings)
 {
     var host = HttpContext.Current.Request.IsSecureConnection 
         ? (settings.SslHost ?? settings.Host)
         : settings.Host;
     if (host == null)
         return relativeUrl;
     return (host.EndsWith("/") ? host.Substring(0, host.Length - 1) : host) + relativeUrl;
 }
Exemplo n.º 3
0
        private void MonitorRemoteChanges(Settings settings)
        {
            var dynamicResourcesToWatch = (from rs in settings.ResourceSets
                                           where rs.IsAutoVersion
                                           from resource in rs.Resources
                                           where resource.Mode == ResourceMode.Dynamic
                                           select resource).Distinct().ToList();
            lock (currentMonitorInfo)
            {
                currentMonitorInfo.DynamicResourcesToWatch = dynamicResourcesToWatch;
                var localInterval = (settings.LocalChangeMonitorInterval == null ||
                                     settings.LocalChangeMonitorInterval <= 0)
                                        ? null
                                        : settings.LocalChangeMonitorInterval*1000L;
                currentMonitorInfo.LocalChangeMonitorInterval = localInterval;

                var remoteInterval = (settings.RemoteChangeMonitorInterval == null ||
                                      settings.RemoteChangeMonitorInterval <= 0)
                                         ? null
                                         : settings.RemoteChangeMonitorInterval*1000L;
                currentMonitorInfo.RemoteChangeMonitorInterval = remoteInterval;
            }
        }
Exemplo n.º 4
0
        private void MonitorLocalChanges(Settings settings)
        {
            watchers.ForEach(w => w.Dispose());
            watchers.Clear();

            var combresConfigPath = HostingEnvironment.MapPath(Configuration.Config.DefinitionUrl);
            var staticFilesToWatch = (from rs in settings.ResourceSets
                                      where rs.IsAutoVersion
                                      from resource in rs.Resources
                                      where resource.Mode == ResourceMode.Static
                                      select HostingEnvironment.MapPath(resource.Path))
                .Concat(new[] {combresConfigPath}).ToList();

            var directoriesToWatch = staticFilesToWatch
                .Select(Path.GetDirectoryName).Distinct();

            foreach (var directory in directoriesToWatch)
            {
                var watcher = new FileSystemWatcher
                                  {
                                      Path = directory,
                                      Filter = "*.*",
                                      NotifyFilter = NotifyFilters.LastWrite,
                                      IncludeSubdirectories = false
                                  };
                watcher.Changed += (sender, arg) =>
                                       {
                                           if (IsSamePath(arg.FullPath, combresConfigPath))
                                           {
                                               if (Log.IsDebugEnabled)
                                                   Log.Debug("OnConfigChanged");
                                               OnChange(ChangeType.Config, null);
                                           }
                                           else
                                           {
                                               var path =
                                                   staticFilesToWatch.FirstOrDefault(f => IsSamePath(arg.FullPath, f));
                                               if (path != null)
                                               {
                                                   var modifiedResourcePaths = (from rs in settings.ResourceSets
                                                                                where rs.IsAutoVersion
                                                                                from resource in rs.Resources
                                                                                where
                                                                                    resource.Mode == ResourceMode.Static &&
                                                                                    path.Equals(
                                                                                        HostingEnvironment.MapPath(
                                                                                            resource.Path),
                                                                                        StringComparison.
                                                                                            OrdinalIgnoreCase)
                                                                                select resource.Path).Distinct().ToList();
                                                   if (modifiedResourcePaths.Count > 0)
                                                   {
                                                       if (Log.IsDebugEnabled)
                                                           Log.Debug("Static resources change count: " +
                                                                     modifiedResourcePaths.Count);
                                                       OnChange(ChangeType.Resource, modifiedResourcePaths);
                                                   }
                                               }
                                           }
                                       };
                watcher.EnableRaisingEvents = true;
                watchers.Add(watcher);
            }
        }