public void GetOneWebJob() { // Setup string jobName = "webJobName"; WebJobType type = WebJobType.Continuous; List <PSWebJob> output = new List <PSWebJob>() { new PSWebJob() { JobName = jobName, JobType = type } }; WebJobFilterOptions options = null; websitesClientMock.Setup(f => f.FilterWebJobs(It.IsAny <WebJobFilterOptions>())) .Returns(output) .Callback((WebJobFilterOptions actual) => options = actual) .Verifiable(); cmdlet.JobName = jobName; cmdlet.JobType = type.ToString(); // Test cmdlet.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.FilterWebJobs(options), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(output, true), Times.Once()); }
public void WriteProperties_InternalWebJobInstanceIsUpdated() { //Set up WebJobRun jobRun = new WebJobRun(); WebJob webJob = new WebJob() { Type = WebJobType.Triggered, }; string jobName = "My Job Name"; WebJobType jobType = WebJobType.Triggered; string detailedStatus = "some details"; string extraInfoUrl = "an extra info url"; string historyUrl = "a history url"; WebJobRun latestRun = new WebJobRun(); string logUrl = "a log url"; string status = "my web job status"; string runCommand = "my run command"; Uri url = new System.Uri("http://myWebJobUrl"); // Test PSWebJob wrapper = new PSWebJob(webJob); wrapper.JobType = jobType; wrapper.JobName = jobName; wrapper.DetailedStatus = detailedStatus; wrapper.ExtraInfoUrl = extraInfoUrl; wrapper.HistoryUrl = historyUrl; wrapper.LatestRun = latestRun; wrapper.LogUrl = logUrl; wrapper.Status = status; wrapper.RunCommand = runCommand; wrapper.Url = url; // Assert Assert.AreEqual(jobName, wrapper.JobName); Assert.AreEqual(jobType, wrapper.JobType); Assert.AreEqual(detailedStatus, wrapper.DetailedStatus); Assert.AreEqual(extraInfoUrl, wrapper.ExtraInfoUrl); Assert.AreEqual(historyUrl, wrapper.HistoryUrl); Assert.AreEqual(latestRun, wrapper.LatestRun); Assert.AreEqual(logUrl, wrapper.LogUrl); Assert.AreEqual(status, wrapper.Status); Assert.AreEqual(runCommand, wrapper.RunCommand); Assert.AreEqual(url, wrapper.Url); Assert.AreEqual(jobName, webJob.Name); Assert.AreEqual(jobType, webJob.Type); Assert.AreEqual(detailedStatus, webJob.DetailedStatus); Assert.AreEqual(extraInfoUrl, webJob.ExtraInfoUrl); Assert.AreEqual(historyUrl, webJob.HistoryUrl); Assert.AreEqual(latestRun, webJob.LatestRun); Assert.AreEqual(logUrl, webJob.LogUrl); Assert.AreEqual(status, webJob.Status); Assert.AreEqual(runCommand, webJob.RunCommand); Assert.AreEqual(url, webJob.Url); }
public WebJob(string webAppId, string name, WebJobType type, string detailsUrl, StatusLevel statusLevel, string statusDescription, DateTimeOffset statusTime) { this.WebAppId = webAppId; this.Name = name; this.Type = type; this.DetailsUrl = detailsUrl; this.StatusLevel = statusLevel; this.StatusDescription = statusDescription; this.StatusTime = statusTime; }
internal static string ToSerializedValue(this WebJobType value) { switch (value) { case WebJobType.Continuous: return("Continuous"); case WebJobType.Triggered: return("Triggered"); } return(null); }
/// <summary> /// Convert an enum of type WebJobType to a string. /// </summary> /// <param name='value'> /// The value to convert to a string. /// </param> /// <returns> /// The enum value as a string. /// </returns> internal static string WebJobTypeToString(WebJobType value) { if (value == WebJobType.Triggered) { return "triggered"; } if (value == WebJobType.Continuous) { return "continuous"; } throw new ArgumentOutOfRangeException("value"); }
public void StopsTriggeredWebJob() { // Setup string jobName = "myWebJob"; WebJobType jobType = WebJobType.Continuous; websitesClientMock.Setup(f => f.StopWebJob(websiteName, slot, jobName, jobType)).Verifiable(); cmdlet.JobName = jobName; // Test cmdlet.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.StopWebJob(websiteName, slot, jobName, jobType), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(true), Times.Once()); }
public void DeletesContinuousWebJob() { // Setup string jobName = "myWebJob"; WebJobType jobType = WebJobType.Continuous; websitesClientMock.Setup(f => f.DeleteWebJob(websiteName, slot, jobName, jobType)).Verifiable(); cmdlet.JobName = jobName; cmdlet.JobType = jobType; commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>())).Returns(true); // Test cmdlet.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.DeleteWebJob(websiteName, slot, jobName, jobType), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(true), Times.Once()); }
public void WriteProperties_InternalWebJobInstanceIsUpdated() { //Set up TriggeredWebJobRun jobRun = new TriggeredWebJobRun(); TriggeredWebJob webJob = new TriggeredWebJob() { Type = WebJobType.Triggered, }; string jobName = "My Job Name"; WebJobType jobType = WebJobType.Triggered; string extraInfoUrl = "an extra info url"; string historyUrl = "a history url"; TriggeredWebJobRun latestRun = new TriggeredWebJobRun(); string runCommand = "my run command"; Uri url = new System.Uri("http://myWebJobUrl"); // Test PSTriggeredWebJob wrapper = new PSTriggeredWebJob(webJob); wrapper.JobType = jobType; wrapper.JobName = jobName; wrapper.ExtraInfoUrl = extraInfoUrl; wrapper.HistoryUrl = historyUrl; wrapper.LatestRun = latestRun; wrapper.RunCommand = runCommand; wrapper.Url = url; // Assert Assert.Equal(jobName, wrapper.JobName); Assert.Equal(jobType, wrapper.JobType); Assert.Equal(extraInfoUrl, wrapper.ExtraInfoUrl); Assert.Equal(historyUrl, wrapper.HistoryUrl); Assert.Equal(new PSTriggeredWebJobRun(latestRun).ToString(), wrapper.LatestRun.ToString()); Assert.Equal(runCommand, wrapper.RunCommand); Assert.Equal(url, wrapper.Url); Assert.Equal(jobName, webJob.Name); Assert.Equal(jobType, webJob.Type); Assert.Equal(extraInfoUrl, webJob.ExtraInfoUrl); Assert.Equal(historyUrl, webJob.HistoryUrl); Assert.Equal(latestRun, webJob.LatestRun); Assert.Equal(runCommand, webJob.RunCommand); Assert.Equal(url, webJob.Url); }
public void SavesTriggeredWebJobLog() { // Setup string jobName = "myWebJob"; string output = ".\\myFile.zip"; string runId = "runId1"; WebJobType jobType = WebJobType.Triggered; websitesClientMock.Setup(f => f.SaveWebJobLog(websiteName, slot, jobName, jobType, output, runId)).Verifiable(); cmdlet.JobName = jobName; cmdlet.JobType = jobType; cmdlet.Output = output; cmdlet.RunId = runId; cmdlet.PassThru = false; // Test cmdlet.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.SaveWebJobLog(websiteName, slot, jobName, jobType, output, runId), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <bool>()), Times.Never()); }
public void GetsMultipleWebJobs() { // Setup string jobName1 = "webJobName1"; string jobName2 = "webJobName2"; string jobName3 = "webJobName3"; WebJobType type1 = WebJobType.Continuous; WebJobType type2 = WebJobType.Continuous; WebJobType type3 = WebJobType.Triggered; WebJobFilterOptions options = null; List <PSWebJob> output = new List <PSWebJob>() { new PSWebJob() { JobName = jobName1, JobType = type1 }, new PSWebJob() { JobName = jobName2, JobType = type2 }, new PSWebJob() { JobName = jobName3, JobType = type3 } }; websitesClientMock.Setup(f => f.FilterWebJobs(It.IsAny <WebJobFilterOptions>())) .Returns(output) .Callback((WebJobFilterOptions actual) => options = actual) .Verifiable(); // Test cmdlet.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.FilterWebJobs(options), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(output, true), Times.Once()); }
public void CreatesTriggeredWebJob() { // Setup string jobName = "myWebJob"; string jobFile = "job.bat"; WebJobType jobType = WebJobType.Triggered; PSWebJob output = new PSWebJob() { JobName = jobName, JobType = jobType }; websitesClientMock.Setup(f => f.CreateWebJob(websiteName, slot, jobName, jobType, jobFile)).Returns(output); cmdlet.JobName = jobName; cmdlet.JobType = jobType; cmdlet.JobFile = jobFile; // Test cmdlet.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.CreateWebJob(websiteName, slot, jobName, jobType, jobFile), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(output), Times.Once()); }
/// <summary> /// Creates new web job for a website /// </summary> /// <param name="name">The website name</param> /// <param name="slot">The website slot name</param> /// <param name="jobName">The web job name</param> /// <param name="jobType">The web job type</param> /// <param name="jobFile">The web job file name</param> public PSWebJob CreateWebJob(string name, string slot, string jobName, WebJobType jobType, string jobFile) { WebJobFilterOptions options = new WebJobFilterOptions() { Name = name, Slot = slot, JobName = jobName, JobType = jobType.ToString() }; name = SetWebsiteName(name, slot); IWebSiteExtensionsClient client = GetWebSiteExtensionsClient(name); if (Path.GetExtension(jobFile).ToLower() != ".zip") { throw new InvalidOperationException(Resources.InvalidWebJobFile); } switch (jobType) { case WebJobType.Continuous: client.WebJobs.UploadContinuous(jobName, File.OpenRead(jobFile)); break; case WebJobType.Triggered: client.WebJobs.UploadTriggered(jobName, File.OpenRead(jobFile)); break; default: break; } PSWebJob webjob = null; Thread.Sleep(UploadJobWaitTime); try { webjob = FilterWebJobs(options).FirstOrDefault(); } catch (CloudException e) { if (e.Response.StatusCode == HttpStatusCode.NotFound) { throw new ArgumentException(Resources.InvalidJobFile); } } return webjob; }
/// <summary> /// Saves a web job logs to file. /// </summary> /// <param name="name">The website name</param> /// <param name="slot">The slot name</param> /// <param name="jobName">The web job name</param> /// <param name="jobType">The web job type</param> /// <param name="output">The output file name</param> /// <param name="runId">The job run id</param> public void SaveWebJobLog(string name, string slot, string jobName, WebJobType jobType, string output, string runId) { if (jobType == WebJobType.Continuous && !string.IsNullOrEmpty(runId)) { throw new InvalidOperationException(); } name = SetWebsiteName(name, slot); IWebSiteExtensionsClient client = GetWebSiteExtensionsClient(name); throw new NotImplementedException(); }
/// <summary> /// Deletes a web job for a website. /// </summary> /// <param name="name">The website name</param> /// <param name="slot">The slot name</param> /// <param name="jobName">The web job name</param> /// <param name="jobType">The web job type</param> public void DeleteWebJob(string name, string slot, string jobName, WebJobType jobType) { name = SetWebsiteName(name, slot); IWebSiteExtensionsClient client = GetWebSiteExtensionsClient(name); if (jobType == WebJobType.Continuous) { client.ContinuousWebJobs.Delete(jobName); } else if (jobType == WebJobType.Triggered) { client.TriggeredWebJobs.Delete(jobName); } else { throw new ArgumentException("jobType"); } }
/// <summary> /// Creates new web job for a website /// </summary> /// <param name="name">The website name</param> /// <param name="slot">The website slot name</param> /// <param name="jobName">The web job name</param> /// <param name="jobType">The web job type</param> /// <param name="jobFile">The web job file name</param> /// <returns>The created web job instance</returns> public IPSWebJob CreateWebJob(string name, string slot, string jobName, WebJobType jobType, string jobFile) { name = SetWebsiteName(name, slot); IWebSiteExtensionsClient client = GetWebSiteExtensionsClient(name); string fileName = Path.GetFileName(jobFile); bool isZipFile = Path.GetExtension(jobFile).ToLower() == ".zip"; switch (jobType) { case WebJobType.Continuous: if (isZipFile) { client.ContinuousWebJobs.UploadZip(jobName, fileName, File.OpenRead(jobFile)); } else { client.ContinuousWebJobs.UploadFile(jobName, fileName, File.OpenRead(jobFile)); } break; case WebJobType.Triggered: if (isZipFile) { client.TriggeredWebJobs.UploadZip(jobName, fileName, File.OpenRead(jobFile)); } else { client.TriggeredWebJobs.UploadFile(jobName, fileName, File.OpenRead(jobFile)); } break; default: break; } //Thread.Sleep(UploadJobWaitTime); var options = new WebJobFilterOptions() { Name = name, Slot = slot, JobName = jobName, JobType = jobType.ToString() }; try { return FilterWebJobs(options).FirstOrDefault(); } catch (CloudException e) { if (e.Response.StatusCode == HttpStatusCode.NotFound) { throw new ArgumentException(Resources.InvalidJobFile); } throw; } }
/// <summary> /// Stops a web job in a website. /// </summary> /// <param name="name">The website name</param> /// <param name="slot">The slot name</param> /// <param name="jobName">The web job name</param> /// <param name="jobType">The web job type</param> public void StopWebJob(string name, string slot, string jobName, WebJobType jobType) { name = SetWebsiteName(name, slot); IWebSiteExtensionsClient client = GetWebSiteExtensionsClient(name); if (jobType == WebJobType.Continuous) { client.ContinuousWebJobs.Stop(jobName); } else { throw new InvalidOperationException(); } }
/// <summary> /// Starts a web job in a website. /// </summary> /// <param name="name">The website name</param> /// <param name="slot">The slot name</param> /// <param name="jobName">The web job name</param> /// <param name="jobType">The web job type</param> public void StartWebJob(string name, string slot, string jobName, WebJobType jobType) { name = SetWebsiteName(name, slot); IWebSiteExtensionsClient client = GetWebSiteExtensionsClient(name); if (jobType == WebJobType.Continuous) { client.ContinuousWebJobs.Start(jobName); } else { client.TriggeredWebJobs.Run(jobName); } }
/// <summary> /// Saves a web job logs to file. /// </summary> /// <param name="name">The website name</param> /// <param name="slot">The slot name</param> /// <param name="jobName">The web job name</param> /// <param name="jobType">The web job type</param> public void SaveWebJobLog(string name, string slot, string jobName, WebJobType jobType) { const string defaultLogFile = ".\\jobLog.zip"; SaveWebJobLog(name, slot, jobName, jobType, defaultLogFile, null); }
public ActionResult Add(WebJobType input) { _context.AddOneEntity <WebJobType>(input); return(RedirectToAction <WebJobTypeController>(d => d.Index(input.LanguageId))); }
public static string ToSerialString(this WebJobType value) => value switch {
internal WebJobRunIdentifierViewModel(WebJobType jobType, string jobName, string jobRunId) { JobType = jobType; JobName = jobName; RunId = jobRunId; }
/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param> /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param> /// <param name="formatProvider">not used by this TypeConverter.</param> /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param> /// <returns> /// an instance of <see cref="WebJobType" />, or <c>null</c> if there is no suitable conversion. /// </returns> public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => WebJobType.CreateFrom(sourceValue);