-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeploy.cs
127 lines (121 loc) · 6.18 KB
/
Deploy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Thibaud Lopez Schneider, Ciber
2017-02-08
V4: Added option to not deploy
V3: Add code to generate the .lawsonapp in case it's needed to deploy to LCM
V2: Added this comments section; moved usage to: if args.Length==0; added Mashup version number to _.mashup filename; corrected profile message to say "this" tool
V1: https://m3ideas.org/2016/06/07/continuous-integration-of-mashups-4-command-line/
*/
using System;
using System.IO;
using System.Reflection;
using Mango.UI.Services.Mashup;
using Mango.UI.Services.Mashup.Internal;
using MangoServer.mangows;
using Mashup.Designer;
using System.Xml;
using Ionic.Utils.Zip;
namespace Mashups
{
class Deploy
{
static void Main(string[] args)
{
// check the arguments
if (args.Length == 0)
{
Console.WriteLine("Usage: Deploy.exe Mashup1,Mashup2,Mashup3 [DEV,TST]");
return;
}
string userid = null;
string password = null;
if (args.Length > 1) {
// get the M3 userid/password
Console.Write ("Userid: ");
userid = Console.ReadLine ();
Console.Write ("Password: ");
password = Console.ReadLine ();
}
// for each directory
string[] directories = args[0].Split(',');
foreach (string directory in directories)
{
// for each Mashup
string[] files = Directory.GetFiles(directory, "*.manifest", SearchOption.AllDirectories);
foreach (string file in files)
{
Console.WriteLine("Opening {0}", file);
ManifestDesigner manifest = new ManifestDesigner(new FileInfo(file));
string name = manifest.DeploymentName + Defines.ExtensionMashup;
string nameAndVersion = manifest.DeploymentName + "_" + manifest.Version + Defines.ExtensionMashup;
Console.WriteLine("Generating {0}", nameAndVersion);
// generate the Mashup package
if (SaveMashupFile(manifest))
{
if (args.Length > 1) {
// get the resulting binary contents
byte[] bytes = File.ReadAllBytes(manifest.File.Directory + "\\" + nameAndVersion);
// for each M3 environment
string[] environments = args[1].Split(',');
foreach (string environment in environments)
{
// deploy
Console.WriteLine("Deploying {0} to {1}", name, environment);
DeployMashup(name, bytes, environment, userid, password);
}
}
}
// generate the LawsonApp for LCM
string package = manifest.File.Directory + "\\" + manifest.DeploymentName + "_" + manifest.Version + Mango.Core.ApplicationConstants.FileExtension;
Console.WriteLine("Generating {0}", package);
XmlDocument appConfigDoc = (XmlDocument) typeof(DeploymentHelper).InvokeMember("CreateAppConfig", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static, null, null, new Object[] { manifest, PackageHelper.DeployTarget_LSO });
Stream stream = new FileInfo(package).OpenWrite();
FileStream appStream = (FileStream)typeof(DeploymentHelper).InvokeMember("CreateAppStream", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static, null, null, new Object[] { manifest, appConfigDoc, PackageHelper.DeployTarget_LSO });
appStream.CopyTo(stream);
appStream.Close();
stream.Close();
}
}
Console.WriteLine("DONE");
}
/*
Create the Mashup package (*.mashup) from the specified Mashup Manifest.
Inspired by Mashup.Designer.DeploymentHelper.SaveMashupFile
*/
static bool SaveMashupFile(ManifestDesigner manifest)
{
try
{
// validate Manifest
typeof(DeploymentHelper).InvokeMember("ValidateManifest", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static, null, null, new Object[] { manifest });
// create Mashup package
string defaultFileName = manifest.DeploymentName + "_" + manifest.Version + Defines.ExtensionMashup;
FileInfo packageFile = new FileInfo(manifest.File.Directory + "\\" + defaultFileName);
PackageHelper.CreatePackageFromManifest(manifest, manifest.File, packageFile, PackageHelper.DeployTarget_LSO);
// check Mashup profile
if (manifest.GetProfileNode() != null)
{
string message = "Please note that this Mashup contains a profile section and should be deployed using Life Cycle Manager. Warning - Using this tool will not result in a merge of profile information into the profile.";
Console.WriteLine(message);
}
return true;
}
catch (Exception exception)
{
Console.Error.WriteLine(exception);
return false;
}
}
/*
Deploy the specified Mashup name and file (*.mashup binary contents) to the specified M3 environment (see App.config) authenticating with the specified M3 userid and password.
Inspired by /mangows/InstallationPointManager.wsdl/DeployMashup
*/
static void DeployMashup(string Name, byte[] MashupFile, string environment, string userid, string password)
{
InstallationPointManagerClient client = new MangoServer.mangows.InstallationPointManagerClient(environment);
client.ClientCredentials.UserName.UserName = userid;
client.ClientCredentials.UserName.Password = password;
client.DeployMashup(Name, MashupFile);
}
}
}