|
@@ -19,16 +19,15 @@ namespace TEAMModelFunction
|
|
_azureCosmos = azureCosmos;
|
|
_azureCosmos = azureCosmos;
|
|
}
|
|
}
|
|
[FunctionName("ServiceBusTopic")]
|
|
[FunctionName("ServiceBusTopic")]
|
|
- public async Task Run([ServiceBusTrigger("test_topic_ActiveTask", "test_topic_ReciveTask", Connection = "ConnectionBusName")] string mySbMsg, ILogger log)
|
|
|
|
|
|
+ public async Task ExamBus([ServiceBusTrigger("active-task", "active-exam-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
|
|
{
|
|
{
|
|
- log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
|
|
|
|
Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
|
|
Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
keyValuePairs.TryGetValue("id", out object id);
|
|
keyValuePairs.TryGetValue("id", out object id);
|
|
keyValuePairs.TryGetValue("name", out object name);
|
|
keyValuePairs.TryGetValue("name", out object name);
|
|
keyValuePairs.TryGetValue("code", out object code);
|
|
keyValuePairs.TryGetValue("code", out object code);
|
|
//keyValuePairs.TryGetValue("status", out object progress);
|
|
//keyValuePairs.TryGetValue("status", out object progress);
|
|
- if (name.ToString().Equals("ExamInfo")) {
|
|
|
|
|
|
+ if (name.ToString().Equals("ExamInfo",StringComparison.OrdinalIgnoreCase)) {
|
|
ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
|
|
ExamInfo exam = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamInfo>(id.ToString(), new PartitionKey($"{code}"));
|
|
if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) < 0) {
|
|
if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(exam.endTime) < 0) {
|
|
exam.progress = "going";
|
|
exam.progress = "going";
|
|
@@ -36,18 +35,17 @@ namespace TEAMModelFunction
|
|
exam.progress = "finish";
|
|
exam.progress = "finish";
|
|
}
|
|
}
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(exam, id.ToString(), new PartitionKey($"{code}"));
|
|
- } else if (name.ToString().Equals("Survey")) {
|
|
|
|
- Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
|
- if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) < 0)
|
|
|
|
- {
|
|
|
|
- survey.progress = "going";
|
|
|
|
- }
|
|
|
|
- else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) > 0)
|
|
|
|
- {
|
|
|
|
- survey.progress = "finish";
|
|
|
|
- }
|
|
|
|
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
|
|
|
|
- } else if (name.ToString().Equals("Vote")) {
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public async Task VoteBus([ServiceBusTrigger("active-task", "active-vote-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ keyValuePairs.TryGetValue("id", out object id);
|
|
|
|
+ keyValuePairs.TryGetValue("name", out object name);
|
|
|
|
+ keyValuePairs.TryGetValue("code", out object code);
|
|
|
|
+ //keyValuePairs.TryGetValue("status", out object progress);
|
|
|
|
+ if (name.ToString().Equals("Vote",StringComparison.OrdinalIgnoreCase)) {
|
|
Vote vote;
|
|
Vote vote;
|
|
var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
|
|
if (sresponse.Status == 200)
|
|
if (sresponse.Status == 200)
|
|
@@ -64,9 +62,30 @@ namespace TEAMModelFunction
|
|
}
|
|
}
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(vote, id.ToString(), new PartitionKey($"{code}"));
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public async Task SurveyBus([ServiceBusTrigger("active-task", "active-survey-recive-task", Connection = "ConnectionBusName")] string mySbMsg)
|
|
|
|
+ {
|
|
|
|
+ Dictionary<string, object> keyValuePairs = mySbMsg.ToObject<Dictionary<string, object>>();
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ keyValuePairs.TryGetValue("id", out object id);
|
|
|
|
+ keyValuePairs.TryGetValue("name", out object name);
|
|
|
|
+ keyValuePairs.TryGetValue("code", out object code);
|
|
|
|
+ //keyValuePairs.TryGetValue("status", out object progress);
|
|
|
|
+ if (name.ToString().Equals("Survey",StringComparison.OrdinalIgnoreCase))
|
|
|
|
+ {
|
|
|
|
+ Survey survey = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Survey>(id.ToString(), new PartitionKey($"{code}"));
|
|
|
|
+ if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.startTime) > 0 && DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) < 0)
|
|
|
|
+ {
|
|
|
|
+ survey.progress = "going";
|
|
|
|
+ }
|
|
|
|
+ else if (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().CompareTo(survey.endTime) > 0)
|
|
|
|
+ {
|
|
|
|
+ survey.progress = "finish";
|
|
|
|
+ }
|
|
|
|
+ await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(survey, id.ToString(), new PartitionKey($"{code}"));
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|