Browse Source

主题订阅名称调整

zhouj1203@hotmail.com 4 years ago
parent
commit
f2223d5760
2 changed files with 38 additions and 19 deletions
  1. 36 17
      TEAMModelFunction/ServiceBusTopic.cs
  2. 2 2
      TEAMModelOS.SDK/Context/Constant/Constants.cs

+ 36 - 17
TEAMModelFunction/ServiceBusTopic.cs

@@ -19,16 +19,15 @@ namespace TEAMModelFunction
             _azureCosmos = azureCosmos;
         }
         [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>>();
             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("ExamInfo")) {
+            if (name.ToString().Equals("ExamInfo",StringComparison.OrdinalIgnoreCase)) {
                 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) {
                     exam.progress = "going";
@@ -36,18 +35,17 @@ namespace TEAMModelFunction
                     exam.progress = "finish";
                 }               
                 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;
                 var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"{code}"));
                 if (sresponse.Status == 200)
@@ -64,9 +62,30 @@ namespace TEAMModelFunction
                     }
                     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}"));
             }
-                
-
+            
         }
     }
 }

+ 2 - 2
TEAMModelOS.SDK/Context/Constant/Constants.cs

@@ -22,10 +22,10 @@ namespace TEAMModelOS.SDK.Context.Constant.Common
         /// <summary>
         /// 主题
         /// </summary>
-        public static   string TopicName = "test_topic_ActiveTask";
+        public static readonly string TopicName = "active-task";
         /// <summary>
         /// 订阅
         /// </summary>
-        public static   string SubName = "test_topic_ReciveTask";
+        public static readonly string SubName = "active-recive-task";
     }
 }