예제 #1
0
 private static void UpdateSite(Site site, IEnumerable<Type> tasks)
 {
     foreach (var t in tasks)
     {
         ConstructorInfo constructor = t.GetConstructors(BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod).FirstOrDefault();
         var task = (Task)constructor.Invoke(new object[]{site});
         task.Run();
     }
 }
예제 #2
0
        public void RunTasks()
        {
            var site = new Site(ConfigurationSettings.AppSettings[Constants.SiteConfigurationKey]);
            var versions = ConfigurationSettings.AppSettings[Constants.VersionsConfigurationKey].Split(new[] { ';' }).Select(v => new Version(v)).OrderBy(v => v.Major).ToList();
            var firstVersion = versions.Where(v => v.Major == site.CurrentVersion.Major).First();
            int index = versions.IndexOf(firstVersion);
            var types = Assembly.GetExecutingAssembly().GetTypes();

            for (int i = index; i < versions.Count; i++)
            {
                int minorIndex = (i == index) ? site.CurrentVersion.Minor + 1 : 0;
                for(int j = minorIndex; j <= versions[i].Minor; j++)
                {
                    String taskNamespace = String.Format("v{0}_{1}", i, j);
                    var tasks = types.Where(t => t.Namespace == String.Format(NamespaceTemplate, taskNamespace)).
                                      Where(t => t.IsSubclassOf(typeof(Task))).
                                      ToList();
                    UpdateSite(site, tasks);
                }
            }

            UpdateSiteVersion(site, versions.Last());
        }
예제 #3
0
 private static void UpdateSiteVersion(Site site, Version lastVersion)
 {
     site.CurrentVersion = lastVersion;
     site.Update();
 }
예제 #4
0
 protected Task(Site site)
 {
     Site = site;
 }