static void CreateNotRespondingTask() { try { using (TaskService ts = new TaskService()) { string appName = "GMA_SA_AEME_CheckNotRespondingService"; SAServiceFolder[] folders; SAServiceFolder location = new SAServiceFolder(); TaskDefinition tdNotResponding = ts.NewTask(); tdNotResponding.RegistrationInfo.Description = ""; tdNotResponding.RegistrationInfo.Date = DateTime.Now; Trigger tr1 = Trigger.CreateTrigger(TaskTriggerType.Time); tr1.StartBoundary = DateTime.Now; tr1.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero, false); tdNotResponding.Triggers.Add(tr1); Trigger tr2 = Trigger.CreateTrigger(TaskTriggerType.Time); tr2.StartBoundary = DateTime.Now; tr2.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero, false); tdNotResponding.Triggers.Add(tr2); Trigger tr3 = Trigger.CreateTrigger(TaskTriggerType.Time); tr3.StartBoundary = DateTime.Now; tr3.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero, false); tdNotResponding.Triggers.Add(tr3); // folders = Configuration.Info.StandAloneInfo.SAServicePaths; location = folders.FirstOrDefault(m => m.Path.Contains(appName)); if (location != null) { // Create an action that will launch Notepad whenever the trigger fires tdNotResponding.Actions.Add(new ExecAction(string.Format(@"{0}\Deploy\{1}.exe", location.Path, appName), string.Format(@"{0}\Logs\{1}.txt", location.Path, appName), null)); // Register the task in the root folder ts.RootFolder.RegisterTaskDefinition(appName, tdNotResponding); } else { Console.WriteLine("Service: " + appName); Console.WriteLine("URL setup file not found"); } } Console.WriteLine("Create Not-Responding check jobs done"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void SaveCheckNotRespondingService(int aeID, int meID) { string appName = "GMA_SA_AEME_CheckNotRespondingService"; Console.WriteLine("Update xml file in {0} service", appName); string path = Path.Combine(Environment.CurrentDirectory, string.Format(@"WindowsService\{0}\Deploy\{1}.exe.config", appName, appName)); try { if (!File.Exists(path)) { Console.WriteLine("xml file not found"); return; } XmlDocument doc = new XmlDocument(); doc.Load(path); //Connectionstring XmlNodeList nodeConnectionString = doc.SelectNodes("/configuration/connectionStrings/add"); foreach (XmlNode n in nodeConnectionString) { var attr = n.Attributes[0]; switch (attr.Value) { case "StandardDataLibraryEntities": n.Attributes[1].Value = Configuration.Info.ServerInfo.SQLServer.ConnectionStringStandardDataLibraryEntities; break; case "TemplateEntities": n.Attributes[1].Value = Configuration.Info.ServerInfo.SQLServer.ConnectionStringTemplateEntities; break; case "UserEntities": n.Attributes[1].Value = Configuration.Info.ServerInfo.SQLServer.ConnectionString; break; case "EmailConfigEntities": n.Attributes[1].Value = Configuration.Info.ServerInfo.SQLServer.ConnectionStringEmailConfigEntities; break; } } //Appsetting XmlNodeList nodeAppSetting = doc.SelectNodes("/configuration/appSettings/add"); foreach (XmlNode n in nodeAppSetting) { var attr = n.Attributes[0]; switch (attr.Value) { case "AEPath": n.Attributes[1].Value = Configuration.Info.StandAloneInfo.SAMachine.AEPathExe; break; case "AEInstanceId": n.Attributes[1].Value = aeID.ToString(); break; case "AEProcessName": n.Attributes[1].Value = Configuration.Info.StandAloneInfo.SAMachine.AEProcessName; break; case "MEPath": n.Attributes[1].Value = Configuration.Info.StandAloneInfo.SAMachine.MEPathExe; break; case "MEInstanceId": n.Attributes[1].Value = meID.ToString(); break; case "MEProcessName": n.Attributes[1].Value = Configuration.Info.StandAloneInfo.SAMachine.MEProcessName; break; case "lblDataConnection": n.Attributes[1].Value = Configuration.Info.ServerInfo.SQLServer.AppSettingValue; break; case "ServicePath": SAServiceFolder[] folders = Configuration.Info.StandAloneInfo.SAServicePaths; SAServiceFolder f = folders.FirstOrDefault(m => m.Path.Contains(appName)); n.Attributes[1].Value = (f != null ? f.Path : ""); break; } } //doc.Save(path); // Common.HotFixSaveRawXml(doc, path); // Console.WriteLine("Update {0} xml file success", appName); } catch (Exception ex) { Console.WriteLine("Error when update {0} xml check not-responsding congif file", appName); Console.WriteLine(ex.Message); } finally { Console.WriteLine(""); } }
static void CreateAETask() { try { using (TaskService ts = new TaskService()) { string appName = ""; SAServiceFolder[] folders; SAServiceFolder location = new SAServiceFolder(); #region " Export services " TaskDefinition tdExport = ts.NewTask(); tdExport.RegistrationInfo.Description = ""; tdExport.RegistrationInfo.Date = DateTime.Now; Trigger tr1 = Trigger.CreateTrigger(TaskTriggerType.Time); tr1.StartBoundary = DateTime.Now; tr1.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero, false); tdExport.Triggers.Add(tr1); Trigger tr2 = Trigger.CreateTrigger(TaskTriggerType.Time); tr2.StartBoundary = DateTime.Now; tr2.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero, false); tdExport.Triggers.Add(tr2); Trigger tr3 = Trigger.CreateTrigger(TaskTriggerType.Time); tr3.StartBoundary = DateTime.Now; tr3.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero, false); tdExport.Triggers.Add(tr3); // appName = "GMA_SA_AE_ExportTemplateService"; folders = Configuration.Info.StandAloneInfo.SAServicePaths; location = folders.FirstOrDefault(m => m.Path.Contains(appName)); if (location != null) { // Create an action that will launch Notepad whenever the trigger fires tdExport.Actions.Add(new ExecAction(string.Format(@"{0}\Deploy\{1}.exe", location.Path, appName), string.Format(@"{0}\Deploy\{1}.txt", location.Path, appName), null)); // Register the task in the root folder ts.RootFolder.RegisterTaskDefinition(appName, tdExport); } else { Console.WriteLine("Service: " + appName); Console.WriteLine("URL setup file not found"); } #endregion #region " Export services " TaskDefinition tdAEService = ts.NewTask(); tdAEService.RegistrationInfo.Description = ""; tdAEService.RegistrationInfo.Date = DateTime.Now; Trigger tr4 = Trigger.CreateTrigger(TaskTriggerType.Time); tr4.StartBoundary = DateTime.Now; tr4.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero, false); tdAEService.Triggers.Add(tr4); Trigger tr5 = Trigger.CreateTrigger(TaskTriggerType.Time); tr5.StartBoundary = DateTime.Now; tr5.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero, false); tdAEService.Triggers.Add(tr5); Trigger tr6 = Trigger.CreateTrigger(TaskTriggerType.Time); tr6.StartBoundary = DateTime.Now; tr6.Repetition = new RepetitionPattern(new TimeSpan(0, 1, 0), TimeSpan.Zero, false); tdAEService.Triggers.Add(tr6); // appName = "GMA_SA_AfterEffectService"; folders = Configuration.Info.StandAloneInfo.SAServicePaths; location = folders.FirstOrDefault(m => m.Path.Contains(appName)); if (location != null) { // Create an action that will launch Notepad whenever the trigger fires tdAEService.Actions.Add(new ExecAction(string.Format(@"{0}\Deploy\{1}.exe", location.Path, appName), string.Format(@"{0}\Deploy\{1}.txt", location.Path, appName), null)); // Register the task in the root folder ts.RootFolder.RegisterTaskDefinition(appName, tdAEService); } else { Console.WriteLine("Service: " + appName); Console.WriteLine("URL setup file not found"); } #endregion } Console.WriteLine("Create AE jobs done"); }catch (Exception ex) { Console.WriteLine(ex.Message); } }