예제 #1
0
        public String Post([FromBody] NewSessionInfo input)
        {
            SessionController sessionController = new SessionController();

            List <Diagnoser> diagnosers = new List <Diagnoser>(sessionController.GetAllDiagnosers().Where(p => input.Diagnosers.Contains(p.Name)));

            String SessionId = "";

            if (input.RunLive)
            {
                TimeSpan ts;
                if (!TimeSpan.TryParse(input.TimeSpan, out ts))
                {
                    ts = TimeSpan.FromMinutes(5);
                }

                if (input.CollectLogsOnly)
                {
                    SessionId = sessionController.CollectLiveDataLogs(ts, diagnosers, null, input.Description).SessionId.ToString();
                }
                else
                {
                    SessionId = sessionController.TroubleshootLiveData(ts, diagnosers, null, input.Description).SessionId.ToString();
                }
            }
            else
            {
                DateTime startTime = DateTime.Parse(input.StartTime);
                DateTime endTime   = DateTime.Parse(input.EndTime);
                if (input.CollectLogsOnly)
                {
                    SessionId = sessionController.CollectLogs(startTime, endTime, diagnosers, null, input.Description).SessionId.ToString();
                }
                else
                {
                    SessionId = sessionController.Troubleshoot(startTime, endTime, diagnosers, null, input.Description).SessionId.ToString();
                }
            }

            return(SessionId);
        }
예제 #2
0
        public HttpResponseMessage Post([FromBody] NewSessionInfo input)
        {
            //Simulate Delay
            //System.Threading.Thread.Sleep(20000);

            //Simulate Failure
            //return "";

            String SessionId          = String.Empty;
            string InstancesSubmitted = "";

            try
            {
                SessionController sessionController = new SessionController();
                sessionController.StartSessionRunner();

                List <Diagnoser> diagnosers = new List <Diagnoser>(sessionController.GetAllDiagnosers().Where(p => input.Diagnosers.Contains(p.Name)));
                List <Instance>  instances  = new List <Instance>();

                instances = input.Instances.Any() ? new List <Instance>(sessionController.GetAllRunningSiteInstances().Where(p => input.Instances.Contains(p.Name)))
                                                  : new List <Instance>(sessionController.GetAllRunningSiteInstances());

                InstancesSubmitted = string.Join(",", instances.Select(x => x.Name));

                TimeSpan ts;
                if (!TimeSpan.TryParse(input.TimeSpan, out ts))
                {
                    ts = TimeSpan.FromMinutes(5);
                }

                if (input.RunLive)
                {
                    if (input.CollectLogsOnly)
                    {
                        SessionId = sessionController.CollectLiveDataLogs(ts, diagnosers, false, instances, input.Description, input.BlobSasUri).SessionId.ToString();
                    }
                    else
                    {
                        SessionId = sessionController.TroubleshootLiveData(ts, diagnosers, false, instances, input.Description, input.BlobSasUri).SessionId.ToString();
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(input.StartTime))
                    {
                        throw new ArgumentNullException("When RunLive is false or not specified, StartTime must be provided");
                    }

                    DateTime startTime = DateTime.Parse(input.StartTime);
                    //startTime = DateTime.SpecifyKind(startTime, DateTimeKind.Utc);
                    if (startTime > DateTime.UtcNow)
                    {
                        DateTime endTime = startTime + ts;
                        if (input.CollectLogsOnly)
                        {
                            SessionId = sessionController.CollectLogs(startTime, endTime, diagnosers, false, null, input.Description, input.BlobSasUri).SessionId.ToString();
                        }
                        else
                        {
                            SessionId = sessionController.Troubleshoot(startTime, endTime, diagnosers, false, null, input.Description, input.BlobSasUri).SessionId.ToString();
                        }
                    }
                    else
                    {
                        if (input.CollectLogsOnly)
                        {
                            SessionId = sessionController.CollectLiveDataLogs(ts, diagnosers, false, instances, input.Description, input.BlobSasUri).SessionId.ToString();
                        }
                        else
                        {
                            SessionId = sessionController.TroubleshootLiveData(ts, diagnosers, false, instances, input.Description, input.BlobSasUri).SessionId.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //log to Kusto and re-throw (it will be taken care in support API)
                Logger.LogErrorEvent("Encountered exception while submitting session", ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, $"Encountered exception {ex.Message} while submitting session"));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, SessionId));
        }