public static void Run([QueueTrigger("salsaqueue", Connection = "AzureWebJobsStorage")] string myQueueItem, ILogger log) { try { var currentDir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var salsaPath = Path.Combine(Directory.GetParent(currentDir).FullName, @"SALsA_Exe\SALsA_Exe.exe"); var logManager = new LogManager(log); var process = new Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.OutputDataReceived += logManager.p_OutputDataReceived; process.ErrorDataReceived += logManager.p_ErrorDataReceived; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = salsaPath; process.StartInfo.Arguments = myQueueItem; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception("SALSA_Exe exit with error code : " + process.ExitCode.ToString()); } } catch (Exception ex) { TableStorage.AppendEntity(myQueueItem.Split(" ").First(), SALsA.General.SALsAState.UnknownException, "Not available", ex.Message); throw ex; } }
internal static void AddRunToSALsA(int icm, object manual = null) { var client = new QueueClient(Authentication.Instance.GenevaAutomationConnectionString, Constants.QueueName); string queueMessage; if (manual != null) { queueMessage = String.Format("{0} {1} {2}", icm, manual.GetType(), Utility.Base64Encode(Utility.ObjectToJson(manual))); } else { queueMessage = icm.ToString(); } TableStorage.AppendEntity(icm, SALsAState.Queued); client.SendMessage(Utility.Base64Encode(queueMessage)); }
public static async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "status")] HttpRequestMessage req, ILogger log, System.Security.Claims.ClaimsPrincipal claimsPrincipal) { if (Auth.CheckIdentity(req, log, claimsPrincipal, out HttpResponseMessage err) == false) { return(err); } ; var watch = new System.Diagnostics.Stopwatch(); watch.Start(); var icmsDic = new Dictionary <int, StatusLine>(); var icms = SALsA.LivesiteAutomation.TableStorage.ListAllEntity(); var incidents = ICM.GetIncidentsWithId(icms.Select(x => x.PartitionKey).ToList()); var lst = new List <string[]>(); lst.Add(StatusLine.Headers); if (icms != null) { foreach (var run in icms) { if (run.SALsAState == SALsA.General.SALsAState.Ignore.ToString()) { continue; } StatusLine tuple; if (icmsDic.ContainsKey(int.Parse(run.PartitionKey))) { tuple = icmsDic[int.Parse(run.PartitionKey)]; } else { try { var currentIcm = incidents[run.PartitionKey]; tuple = new StatusLine(currentIcm.Id, FunctionUtility.ColorICMStatus(currentIcm.OwningTeamId, currentIcm.Status), DateTime.Parse(currentIcm.CreateDate)); } catch { tuple = new StatusLine(); } } var status = run.SALsAState; var logPath = run.Log; if (run.Log != null && run.Log.StartsWith("http")) { if (tuple.IcmStatus == "Unknown" && tuple.IcmCreation.HasValue == false) { run.SALsAState = SALsAState.ICMNotAccessible.ToString(); tuple.IcmStatus = FunctionUtility.ColorICMStatus("Request for assistance", Color.Blue); TableStorage.AppendEntity(tuple.IcmId, SALsAState.ICMNotAccessible); } } else { logPath = run.SALsAState == SALsAState.Running.ToString() || run.SALsAState == SALsAState.Queued.ToString() ? "Wait..." : "Unavailable"; } status = Utility.UrlToHml(run.SALsAState, run.SALsALog, 20); tuple.Update(run.PartitionKey, status, logPath, run.Timestamp.UtcDateTime); icmsDic[int.Parse(run.PartitionKey)] = tuple; } } var values = icmsDic.Values.ToList(); values.Sort((y, x) => { int ret = DateTime.Compare(x._SalsaInternalIngestion.HasValue ? x._SalsaInternalIngestion.Value : new DateTime(0), y._SalsaInternalIngestion.HasValue ? y._SalsaInternalIngestion.Value : new DateTime(0)); return(ret != 0 ? ret : DateTime.Compare(x.IcmCreation.HasValue ? x.IcmCreation.Value : new DateTime(0), y.IcmCreation.HasValue ? y.IcmCreation.Value : new DateTime(0))); }); foreach (var value in values) { if (value.SalsaLogIngestion == "N/A") { try { FunctionUtility.AddRunToSALsA(int.Parse(value._icm)); } catch { }; } } lst.AddRange(values.Select(x => x.ToArray()).ToList()); var response = new HttpResponseMessage(HttpStatusCode.OK); response.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true, MustRevalidate = true }; watch.Stop(); string result = Utility.List2DToHTML(lst, true) + String.Format("<p style=\"text-align: right\">Page generated at : {0}Z (in {1} seconds)</p>", DateTime.UtcNow.ToString("s"), watch.Elapsed.TotalSeconds); response.Content = new StringContent(result, System.Text.Encoding.UTF8, "text/html"); return(response); }