From 008e6af6b56e81b6189a290d22fbcd39c05cf805 Mon Sep 17 00:00:00 2001
From: Bensong Liu <bensl@microsoft.com>
Date: Wed, 21 Oct 2020 12:59:51 +0800
Subject: [PATCH] add manual operation

---
 activity.hpp        | 39 ++++++++++++++++++++++++++++++---------
 xaml-template.hpp   |  2 +-
 xaml.gen.example.cc |  3 ++-
 3 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/activity.hpp b/activity.hpp
index b2439fc..0000ae5 100644
--- a/activity.hpp
+++ b/activity.hpp
@@ -25,16 +25,17 @@ namespace CIS {
     private:
         friend Flow;
         virtual rlib::string generateXaml() const = 0;
+    public:
+        Flow operator>>(const Flow &seqNext) const;
+        Flow operator|(const Flow &seqNext) const;
     };
 
-    class Activity : private ActivityBase {
+    class Activity : public ActivityBase {
     public:
         // All `Name` should not contain QuotationMark(")
         Activity(string displayName, string className, string entityName = "")
             : displayName(Utility::HtmlEscapeString(displayName)), className(className), entityName(entityName), taskId(Utility::GenUUID()) {}
         
-        Flow operator>>(const Flow &seqNext) const;
-        Flow operator|(const Flow &seqNext) const;
         void addInputSetting(string k, string v) {
             inputSettings[k] = v;
         }
@@ -55,7 +56,7 @@ namespace CIS {
             auto inputSettingsString = ",\n"_rs.join(inputSettingStrings);
             return rlib::string(templates::ACTIVITY_DICT_TEMPLATE_UNESCAPED).replace_once("__TEMPLATE_ARG_DictLines", inputSettingsString);
         }
-        virtual rlib::string generateXaml() const {
+        virtual rlib::string generateXaml() const override {
             rlib::string xamlCode;
 
             if(inputSettings.empty()) {
@@ -80,7 +81,27 @@ namespace CIS {
         }
     };
 
-    class ManualOperation : private ActivityBase {
+    class ManualOperation : public ActivityBase {
+    public:
+        explicit ManualOperation(string displayName, string message = "", string entityName = "")
+            : displayName(Utility::HtmlEscapeString(displayName)), messageInCSharp(Utility::HtmlEscapeString("\"" + message + "\"")), entityName(entityName) {}
+        
+        ManualOperation &explicitSetMessageInCSharp(string messageInCSharp) {
+            this->messageInCSharp = messageInCSharp;
+            return *this;
+        }
+
+    private:
+        string displayName, messageInCSharp, entityName;
+        virtual rlib::string generateXaml() const override {
+            rlib::string xamlCode = templates::MANUAL_OPERATION_XAML;
+            xamlCode.replace_once("__TEMPLATE_ARG_DisplayName", displayName);
+            xamlCode.replace_once("__TEMPLATE_ARG_CodeLines", messageInCSharp);
+
+            auto entityXaml = this->entityName == "" ? "" : rlib::string(templates::ENTITY_DEF_TEMPLATE).replace("__TEMPLATE_ARG_EntityName", this->entityName);
+            xamlCode.replace_once("__TEMPLATE_ARG_EntityDefPlaceholder", entityXaml);
+            return xamlCode;
+        }
 
     };
 
@@ -89,7 +110,7 @@ namespace CIS {
         Flow(const ActivityBase &activity) {
             xamlCode = activity.generateXaml();
         }
-        Flow(rlib::string xamlCode) : xamlCode(xamlCode) {}
+        explicit Flow(rlib::string xamlCode) : xamlCode(xamlCode) {}
         Flow(const Flow &another) : queued(another.queued), xamlCode(another.xamlCode), prevOperationIsSequential(another.prevOperationIsSequential) {}
 
         // Actually modify xamlCode on "OperationChange". 
@@ -131,10 +152,10 @@ namespace CIS {
         }
     };
 
-    inline Flow Activity::operator>>(const Flow &seqNext) const {
+    inline Flow ActivityBase::operator>>(const Flow &seqNext) const {
         return Flow(*this) >> seqNext;
     }
-    inline Flow Activity::operator|(const Flow &seqNext) const {
+    inline Flow ActivityBase::operator|(const Flow &seqNext) const {
         return Flow(*this) | seqNext;
     }
 
@@ -147,7 +168,7 @@ namespace CIS {
         std::list<string> xtraNamespaces;
         std::list<string> xtraAssemblies;
         string className;
-        Metadata(string className) : className(className) {}
+        explicit Metadata(string className) : className(className) {}
         Metadata() = delete;
 
     private:
diff --git a/xaml-template.hpp b/xaml-template.hpp
index 9920e95..1c2595d 100644
--- a/xaml-template.hpp
+++ b/xaml-template.hpp
@@ -96,7 +96,7 @@ constexpr auto STD_XAML_TAIL = "</Activity>";
 
 
 constexpr auto MANUAL_OPERATION_XAML = 
-R"XAML(    <mwcwa:ManualOperation DeprecatedTaskId="{x:Null}" TaskId="{x:Null}" DisplayName="__TEMPLATE_ARG_DisplayName" MonitoringSystems="icm" WaitUntilFinish="True">
+R"XAML(    <mwcwa:ManualOperation DeprecatedTaskId="{x:Null}" TaskId="{x:Null}" DisplayName="__TEMPLATE_ARG_DisplayName" MonitoringSystems="icm" WaitUntilFinish="True" __TEMPLATE_ARG_EntityDefPlaceholder>
       <mwcwa:ManualOperation.AdditionalContent>
         <InArgument x:TypeArguments="x:String">
           <mca:CSharpValue x:TypeArguments="x:String">__TEMPLATE_ARG_CodeLines</mca:CSharpValue>
diff --git a/xaml.gen.example.cc b/xaml.gen.example.cc
index 6909e9d..71b05af 100644
--- a/xaml.gen.example.cc
+++ b/xaml.gen.example.cc
@@ -1,3 +1,4 @@
+#include "activity.hpp"
 #include <cis-workflow-gen/quick-include.hpp>
 
 auto simpleExample() {
@@ -37,7 +38,7 @@ auto complexExample() {
     auto block1 = SCS >> (SearchAnalytics | (SearchFarms >> (ClassisSearchUX | ModernSearch)));
     auto block3 = Loki >> Yggdrasil >> OfficeGraph;
     auto block4 = IC3Tooling >> (MonitoringSetup | (MicroServices >> DevelopmentValidation >> IntegrationTesting));
-    auto completeFlow = (block1 | TSConfigAndInterop | block3 | block4) >> OneMoreMagicActivity;
+    auto completeFlow = (block1 | TSConfigAndInterop | block3 | block4) >> OneMoreMagicActivity >> ManualOperation("Manual Op Test", "Message") >> ManualOperation("AnotherManual", "", "PreRteg.TestEntity").explicitSetMessageInCSharp("123.ToString()");
 
     auto myMetadata = Metadata("FleetAGC.Workflows.BuildTeams").setXtraAssemblies({"FleetAGC.Workflows"});
     println(to_file("BuildTeams.xaml"), completeFlow.generateXaml(myMetadata));
-- 
GitLab