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

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
# Generate CIS workflow from an easy format
## Build
```
make
sudo make install
```
## Use
1. Write your `Workflow.cc` with our lib.
2. Build and run `Workflow.cc`. You're all set.
#ifndef CIS_WORKFLOW_GEN_ACTIVITY_HPP
#define CIS_WORKFLOW_GEN_ACTIVITY_HPP
#include <string>
#include <map>
#include "uuid.hpp"
#include "xaml-template.hpp"
#include <rlib/string.hpp>
namespace CIS {
using std::string;
class Flow;
class Activity {
public:
friend Flow;
Activity(string displayName, string className, string entityName = "")
: displayName(displayName), className(className), entityName(entityName), taskId(GenUUID()) {}
Flow &operator>>(const Flow &seqNext) {
return Flow(*this) >> seqNext;
}
private:
string displayName, className, entityName;
string taskId;
std::map<string, string>
};
class Flow {
public:
Flow(const Activity &activity) {
xamlCode = ACTIVITY_XAML_TEMPLATE;
xamlCode.replace("__TEMPLATE_ARG_ClassName", activity.className);
xamlCode.replace("__TEMPLATE_ARG_DisplayName", activity.displayName);
auto entityXaml = activity.entityName == "" ? "" : rlib::string(ENTITY_DEF_TEMPLATE).replace("__TEMPLATE_ARG_EntityName", activity.entityName);
xamlCode.replace("__TEMPLATE_ARG_EntityDefPlaceholder", entityXaml);
}
Flow &operator>>(const Flow &seqNext) {
}
rlib::string xamlCode;
};
struct Workflow {
std::list<string> assemblyReferences;
};
}
#endif
uuid.hpp 0 → 100644
#ifndef CIS_WF_GEN_UUID_HPP
#define CIS_WF_GEN_UUID_HPP
#include <random>
#include <string>
inline static string GenUUID() {
static std::random_device dev;
static std::mt19937 rng(dev());
std::uniform_int_distribution<int> dist(0, 15);
const char *v = "0123456789ABCDEF";
const bool dash[] = { 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0 };
std::string res;
for (int i = 0; i < 16; i++) {
if (dash[i]) res += "-";
res += v[dist(rng)];
res += v[dist(rng)];
}
return res;
}
#endif
\ No newline at end of file
#ifndef XAML_TEMPLATE_HPP
#define XAML_TEMPLATE_HPP
#include <string>
namespace CIS::impl {
constexpr auto ACTIVITY_XAML_TEMPLATE = R"XAMLTL(
<mwcwa:ControlledActivity ClassName="__TEMPLATE_ARG_ClassName" DisplayName="__TEMPLATE_ARG_DisplayName" TaskId="__TEMPLATE_ARG_TaskId" __TEMPLATE_ARG_EntityDefPlaceholder>
<mwcwa:ControlledActivity.InputSettings>
<InArgument x:TypeArguments="scg:Dictionary(x:String, x:String)">
<mca:CSharpValue x:TypeArguments="scg:Dictionary(x:String, x:String)" xml:space="preserve">
new Dictionary&lt;string, string&gt;()
{
__TEMPLATE_ARG_DictLines
}
</mca:CSharpValue>
</InArgument>
</mwcwa:ControlledActivity.InputSettings>
</mwcwa:ControlledActivity>
)XAMLTL"
constexpr auto ENTITY_DEF_TEMPLATE = R"XAMLTL(coordination:DependencyBinder.EntityName="__TEMPLATE_ARG_EntityName")XAMLTL";
}
#endif
// Define some handy c# types.
auto dict = 'System.Collections.Generic.Dictionary<string, string>';
// Define activities.
Activity SCS (ClassName='...', EntityName='...');
// SCS.AddRawArgument(Type=dict, CSharpCode='new Dictionary() {{"Message", "Doing SCS"}}');
SCS.AddInputSetting("Message", "Doing SCS");
Activity SearchAnalytics (......);
SearchAnalytics.AddArgument(......);
......;
// `->` means sequence, and `|` means parallel.
auto block1 = SCS -> (SearchAnalytics | (SearchFarms -> (ClassisSearchUX | ModernSearch)));
auto block3 = Loki -> Yggdrasil -> OfficeGraph;
auto block4 = IC3Tooling -> (MonitoringSetup | (MicroServices -> DevelopmentValidation -> IntegrationTesting))
// TODO: How to represent controlled-if?
(block1 | 3SConfigAndInterop | block3 | block4).GenerateXaml("/home/recolic/code/Azure/myWorkflow.xaml");
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