Skip to content
Snippets Groups Projects
Commit 78c440cd authored by Bensong Liu's avatar Bensong Liu
Browse files

almost done

parent c856b170
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define CIS_WORKFLOW_GEN_ACTIVITY_HPP #define CIS_WORKFLOW_GEN_ACTIVITY_HPP
#include <iterator> #include <iterator>
#include <stdexcept>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <list> #include <list>
...@@ -18,6 +19,7 @@ namespace CIS { ...@@ -18,6 +19,7 @@ namespace CIS {
using std::string; using std::string;
using namespace rlib::literals; using namespace rlib::literals;
class Flow; class Flow;
class Metadata;
class Activity { class Activity {
public: public:
...@@ -30,6 +32,9 @@ namespace CIS { ...@@ -30,6 +32,9 @@ namespace CIS {
void addInputSetting(string k, string v) { void addInputSetting(string k, string v) {
inputSettings[k] = v; inputSettings[k] = v;
} }
void addRawActivityArgument(string xamlTypeString, string csharpValueCode) {
throw std::invalid_argument("Not implemented yet.");
}
private: private:
string displayName, className, entityName; string displayName, className, entityName;
string taskId; string taskId;
...@@ -40,18 +45,18 @@ namespace CIS { ...@@ -40,18 +45,18 @@ namespace CIS {
public: public:
Flow(const Activity &activity) { Flow(const Activity &activity) {
xamlCode = templates::ACTIVITY_XAML_TEMPLATE; xamlCode = templates::ACTIVITY_XAML_TEMPLATE;
xamlCode.replace("__TEMPLATE_ARG_ClassName", activity.className); xamlCode.replace_once("__TEMPLATE_ARG_ClassName", activity.className);
xamlCode.replace("__TEMPLATE_ARG_DisplayName", activity.displayName); xamlCode.replace_once("__TEMPLATE_ARG_DisplayName", activity.displayName);
xamlCode.replace("__TEMPLATE_ARG_TaskId", activity.taskId); xamlCode.replace_once("__TEMPLATE_ARG_TaskId", activity.taskId);
auto entityXaml = activity.entityName == "" ? "" : rlib::string(templates::ENTITY_DEF_TEMPLATE).replace("__TEMPLATE_ARG_EntityName", activity.entityName); auto entityXaml = activity.entityName == "" ? "" : rlib::string(templates::ENTITY_DEF_TEMPLATE).replace("__TEMPLATE_ARG_EntityName", activity.entityName);
xamlCode.replace("__TEMPLATE_ARG_EntityDefPlaceholder", entityXaml); xamlCode.replace_once("__TEMPLATE_ARG_EntityDefPlaceholder", entityXaml);
std::list<string> inputSettingStrings; std::list<string> inputSettingStrings;
std::transform(activity.inputSettings.begin(), activity.inputSettings.end(), std::back_inserter(inputSettingStrings), [](auto &&kv) { std::transform(activity.inputSettings.begin(), activity.inputSettings.end(), std::back_inserter(inputSettingStrings), [](auto &&kv) {
return "{\"{}\", \"{}\"}"_rs.format(kv.first, kv.second); return "{\"{}\", \"{}\"}"_rs.format(kv.first, kv.second);
}); });
auto inputSettingsString = ",\n "_rs.join(inputSettingStrings); auto inputSettingsString = ",\n "_rs.join(inputSettingStrings);
xamlCode.replace("__TEMPLATE_ARG_DictLines", inputSettingsString); xamlCode.replace_once("__TEMPLATE_ARG_DictLines", inputSettingsString);
} }
Flow(rlib::string xamlCode) : xamlCode(xamlCode) {} Flow(rlib::string xamlCode) : xamlCode(xamlCode) {}
Flow(const Flow &another) : queued(another.queued), xamlCode(another.xamlCode), prevOperationIsSequential(another.prevOperationIsSequential) {} Flow(const Flow &another) : queued(another.queued), xamlCode(another.xamlCode), prevOperationIsSequential(another.prevOperationIsSequential) {}
...@@ -66,12 +71,8 @@ namespace CIS { ...@@ -66,12 +71,8 @@ namespace CIS {
return binaryOperation(seqNext, false); return binaryOperation(seqNext, false);
} }
rlib::string generateXaml() const { auto generateXaml(Metadata metadata) const;
Flow finalized(*this); auto generateXaml() const;
if(!finalized.queued.empty())
finalized.reduceQueued();
return finalized.xamlCode;
}
private: private:
bool prevOperationIsSequential = false; bool prevOperationIsSequential = false;
...@@ -105,10 +106,35 @@ namespace CIS { ...@@ -105,10 +106,35 @@ namespace CIS {
return Flow(*this) >> seqNext; return Flow(*this) >> seqNext;
} }
struct Workflow { struct Metadata {
std::list<string> assemblyReferences; friend Flow;
std::list<string> xtraShorthands;
std::list<string> xtraNamespaces;
std::list<string> xtraAssemblies;
private:
auto generateXamlHead() const {
rlib::string result = templates::STD_XAML_HEAD;
result.replace_once("__TEMPLATE_ARG_XtraShorthands", "\n "_rs.join(xtraShorthands));
result.replace_once("__TEMPLATE_ARG_XtraNamespaces", "\n "_rs.join(xtraNamespaces));
result.replace_once("__TEMPLATE_ARG_XtraAssemblies", "\n "_rs.join(xtraAssemblies));
return result;
}
constexpr auto generateXamlTail() const {
return templates::STD_XAML_TAIL;
}
}; };
inline auto Flow::generateXaml(Metadata metadata) const {
Flow finalized(*this);
if(!finalized.queued.empty())
finalized.reduceQueued();
return metadata.generateXamlHead() + finalized.xamlCode + metadata.generateXamlTail();
}
inline auto Flow::generateXaml() const {
Metadata defaultMetadata;
return generateXaml(std::move(defaultMetadata));
}
} }
......
#ifndef RLIB_IMPL_QUICK_INCLUDE_XAML_GEN_HPP
#define RLIB_IMPL_QUICK_INCLUDE_XAML_GEN_HPP
#include <rlib/stdio.hpp> #include <rlib/stdio.hpp>
#include <stdexcept>
#include "activity.hpp" #include "activity.hpp"
using namespace CIS; using namespace CIS;
using rlib::println; using rlib::println;
#include <fstream>
inline auto &to_file(std::string filename) {
auto outf = new std::ofstream (filename, std::ios_base::trunc);
if(!*outf) {
throw std::invalid_argument("Failed to open file: " + filename);
}
return *outf;
}
#endif
\ No newline at end of file
...@@ -31,6 +31,58 @@ constexpr auto SEQ_END = R"( </mwcwa:ControlledSequence>)" "\n"; ...@@ -31,6 +31,58 @@ constexpr auto SEQ_END = R"( </mwcwa:ControlledSequence>)" "\n";
constexpr auto PAR_BEGIN = R"( <mwcwa:ControlledParallel IsHiddenFromOperator="False">)" "\n"; constexpr auto PAR_BEGIN = R"( <mwcwa:ControlledParallel IsHiddenFromOperator="False">)" "\n";
constexpr auto PAR_END = R"( </mwcwa:ControlledParallel>)" "\n"; constexpr auto PAR_END = R"( </mwcwa:ControlledParallel>)" "\n";
constexpr auto STD_XAML_HEAD = R"XAML(<?xml version='1.0' encoding='utf-8' standalone='yes'?>
<Activity
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:coordination="clr-namespace:Microsoft.WindowsAzure.Dependencies.Coordination;assembly=Microsoft.WindowsAzure.Dependencies.Coordination"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities"
xmlns:mwcwa="clr-namespace:Microsoft.WindowsAzure.Cis.Workflow.Activities;assembly=Microsoft.WindowsAzure.Cis.Workflow.Activities"
xmlns:mwcwcs="clr-namespace:Microsoft.WindowsAzure.Cis.Workflow.Contracts.Settings;assembly=Microsoft.WindowsAzure.Cis.Workflow.Contracts"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
sap2010:ExpressionActivityEditor.ExpressionActivityEditor="C#"
x:Class="FleetAGC.Workflows.BuildDomainControllerWorkflow"
__TEMPLATE_ARG_XtraShorthands mc:Ignorable="sap sap2010 sads">
<TextExpression.NamespacesForImplementation>
<sco:Collection x:TypeArguments="x:String">
<x:String>System</x:String>
<x:String>System.Collections.Generic</x:String>
<x:String>System.Data</x:String>
<x:String>System.Linq</x:String>
<x:String>System.Text</x:String>
__TEMPLATE_ARG_XtraNamespaces </sco:Collection>
</TextExpression.NamespacesForImplementation>
<TextExpression.ReferencesForImplementation>
<sco:Collection x:TypeArguments="AssemblyReference">
<AssemblyReference>Microsoft.CSharp</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAzure.Bootstrap.Common</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAzure.Bootstrap.ComponentBootstrap.Activities</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAzure.Bootstrap.ComponentBootstrap.Contracts</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAzure.Cis.Workflow.Activities</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAzure.Cis.Workflow.Activities.Design</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAzure.Cis.Workflow.Common</AssemblyReference>
<AssemblyReference>Microsoft.WindowsAzure.Cis.Workflow.Contracts</AssemblyReference>
<AssemblyReference>System</AssemblyReference>
<AssemblyReference>System.Activities</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System.Runtime.Serialization</AssemblyReference>
<AssemblyReference>System.ServiceModel</AssemblyReference>
<AssemblyReference>System.ServiceModel.Activities</AssemblyReference>
<AssemblyReference>System.Xaml</AssemblyReference>
<AssemblyReference>System.Xml</AssemblyReference>
<AssemblyReference>System.Xml.Linq</AssemblyReference>
<AssemblyReference>mscorlib</AssemblyReference>
<AssemblyReference>FleetAGC.Activities</AssemblyReference>
__TEMPLATE_ARG_XtraAssemblies </sco:Collection>
</TextExpression.ReferencesForImplementation>
)XAML";
constexpr auto STD_XAML_TAIL = "</Activity>";
} }
} }
......
...@@ -9,6 +9,7 @@ int main() { ...@@ -9,6 +9,7 @@ int main() {
SearchFarms.addInputSetting("AnotherMessage", "shit"); SearchFarms.addInputSetting("AnotherMessage", "shit");
println(((SCS >> SearchFarms) | SCS).generateXaml()); println(((SCS >> SearchFarms) | SCS).generateXaml());
println(to_file("out.xaml"), ((SCS >> SearchFarms) | SCS).generateXaml());
} }
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment