本文整理汇总了C#中System.Web.Script.Serialization.JavaScriptSerializer.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Script.Serialization.JavaScriptSerializer.Contains方法的具体用法?C# Script.Serialization.JavaScriptSerializer.Contains怎么用?C# Script.Serialization.JavaScriptSerializer.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Script.Serialization.JavaScriptSerializer
的用法示例。
在下文中一共展示了Script.Serialization.JavaScriptSerializer.Contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMaterialsByCategory
public ActionResult GetMaterialsByCategory(string categories)
{
var selectedCategories = new JavaScriptSerializer().Deserialize<IEnumerable<string>>(categories);
var materials = GetMarketingMaterials();
var idsResult = materials.Select(a => new { a.Id, Visible = selectedCategories.Contains(a.Category) }).ToArray();
return Json(idsResult);
}
示例2: TestReturnValue
//Tests the value returned by the LoadVideoMgmt method
private void TestReturnValue(ActionResult result, string expectedMrdvrResult, string expectedDeviceActionResponse)
{
//Assert
Assert.IsTrue(result != null, "result is null");
//A partial view result is returned
var resultPartial = result as PartialViewResult;
Assert.IsTrue(resultPartial != null, "resultPartial is null");
//It was the right type of partial view result
Assert.IsTrue(resultPartial.ViewName.Equals("VideoManagement_Partial"),
"Expected resultPartial.ViewName to be VideoManagement_Partial. It was actually "
+ resultPartial.ViewName + ".");
//It has the correct information
//Model is not null
var model = resultPartial.Model;
Assert.IsNotNull(model);
//Model response is correct
var modelResponse = model.ToJSON();
string modelResponseString = new JavaScriptSerializer().Serialize(modelResponse);
modelResponseString = modelResponseString.Replace(@"\", " ");
modelResponseString = modelResponseString.Replace(@"""", @" ");
Assert.IsTrue(modelResponseString.Contains(expectedMrdvrResult), "MRDVR Service was not found");
//Compare the expected DeviceActionResponse
int startResponse = modelResponseString.IndexOf("DeviceActionResponse", System.StringComparison.Ordinal);
int endResponse = modelResponseString.IndexOf("NewDeviceSerial", System.StringComparison.Ordinal);
string actualDeviceResponse = modelResponseString.Substring(startResponse, (endResponse - startResponse) - 1);
Assert.IsTrue(modelResponseString.Contains(expectedDeviceActionResponse), "DeviceActionResponse had an unexpected value. Expected: " +
expectedDeviceActionResponse + ", Actual: " + actualDeviceResponse + ".");
//Model is correct type
Assert.IsTrue(model is VideoManagementModel, "Model is not a VideoManagementModel as expected");
}
示例3: ExecuteCommand
public override void ExecuteCommand()
{
int lastNhour = 24;
List<WorkInstanceDetail> jobDetail = new List<WorkInstanceDetail>();
List<WorkJobInstanceDetails> instanceDetails = getWorkjobInstance();
foreach (WorkJobInstanceDetails job in instanceDetails)
{
int invocationCount = 0;
double totalRunTime = 0;
int faultCount = 0;
int faultRate = 0;
int runtime = 0;
Dictionary<string, List<string>> ErrorList = new Dictionary<string, List<string>>();
string AdminKey = WorkServiceAdminKey;
if (job.url.Contains("api-work-1"))
{
AdminKey = WorkServiceFailoverAdminKey;
}
NetworkCredential nc = new NetworkCredential(WorkServiceUserName, AdminKey);
//get all invocations in last 24 hours or last 10 invocations
int no = (lastNhour * 60) / job.FrequencyInMinutes;
if (no < 10) no = 10;
WebRequest request = WebRequest.Create(string.Format("{0}/instances/{1}?limit={2}", job.url, job.JobInstanceName, no));
request.Credentials = nc;
request.PreAuthenticate = true;
request.Method = "GET";
WebResponse respose = request.GetResponse();
using (var reader = new StreamReader(respose.GetResponseStream()))
{
JavaScriptSerializer js = new JavaScriptSerializer();
js.MaxJsonLength = Int32.MaxValue;
var objects = js.Deserialize<List<WorkJobInvocation>>(reader.ReadToEnd());
WorkJobInvocation lastJob;
bool alert = false;
string lastCompleted = string.Empty;
if (objects.Any((item => item.status.Equals("Executed") && item.result.Equals("Completed"))))
{
lastJob = objects.Where(item => item.status.Equals("Executed") && item.result.Equals("Completed")).ToList().FirstOrDefault();
}
else
{
lastJob = objects.FirstOrDefault();
}
if (lastJob != null)
{
lastCompleted = string.Format("{0} mins ago", Convert.ToInt32(DateTime.Now.Subtract(lastJob.completedAt).TotalMinutes));
}
else
{
lastCompleted = "N/A";
}
foreach (WorkJobInvocation each in objects)
{
if (each.result.Equals("Incomplete", StringComparison.OrdinalIgnoreCase)) continue;
if (each.completedAt >= DateTime.Now.AddHours(-1)) alert = true; // check there is any failure happened in last one hour
invocationCount++;
totalRunTime += each.completedAt.Subtract(each.queuedAt).TotalSeconds;
if (each.result.Equals("Faulted"))
{
faultCount++;
string message = getResultMessage(each.resultMessage);
if (ErrorList.ContainsKey(message))
{
if (ErrorList[message].Count < 5) ErrorList[message].Add(each.logUrl);
}
else
{
List<string> LogUrl = new List<string>();
LogUrl.Add(each.logUrl);
ErrorList.Add(message, LogUrl);
}
}
}
if (invocationCount != 0)
{
faultRate = (faultCount * 100 / invocationCount);
runtime = ((int)(totalRunTime / invocationCount));
}
jobDetail.Add(new WorkInstanceDetail(job.JobInstanceName, job.FrequencyInMinutes+ "mins",lastCompleted , runtime.ToString() + "s", invocationCount.ToString(), faultCount.ToString(), faultRate, ErrorList));
AlertThresholds thresholdValues = new JavaScriptSerializer().Deserialize<AlertThresholds>(ReportHelpers.Load(StorageAccount, "Configuration.AlertThresholds.json", ContainerName));
string[] Igonored = new JavaScriptSerializer().Deserialize<string[]>(ReportHelpers.Load(StorageAccount, "Configuration.WorkerJobToBeIgnored.json", ContainerName));
if (Igonored.Contains(job.JobInstanceName, StringComparer.OrdinalIgnoreCase)) continue;
if (faultRate > thresholdValues.WorkJobErrorThreshold && alert)
{
new SendAlertMailTask
{
AlertSubject = string.Format("Error: Alert for Nuget Work Service : {0} failure", job.JobInstanceName),
Details = string.Format("Rate of failure exceeded Error threshold for {0}. Threshold count : {1}%, failure in last 24 hour : {2}", job.JobInstanceName,thresholdValues.WorkJobErrorThreshold , faultCount),
AlertName = string.Format("Error: Nuget Work Service {0}", job.JobInstanceName),
Component = "Nuget Work Service",
Level = "Error"
}.ExecuteCommand();
}
else if (faultRate > thresholdValues.WorkJobWarningThreshold && alert)
//.........这里部分代码省略.........