/
CommandManager.cs
96 lines (87 loc) · 4.21 KB
/
CommandManager.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
using Artech.Architecture.Common.Objects;
using Artech.Architecture.UI.Framework.Helper;
using Artech.Architecture.UI.Framework.Services;
using Artech.Common.Framework.Commands;
using Artech.Genexus.Common.Objects;
using System;
using System.IO;
using System.Windows.Forms;
namespace Abstracta.Packages.GeneraWebxml
{
class CommandManager : CommandDelegator
{
public CommandManager()
{
AddCommand(CommandKeys.GeneraWebxmlCommand, new ExecHandler(ExecGeneraWebxmlCommand), new QueryHandler(QueryGeneraWebxmlCommand));
}
// This is where you implement whatever you want to do
// when this command is invoked
public bool ExecGeneraWebxmlCommand(CommandData cmdData)
{
DateTime inicio = DateTime.Now;
IKBService kbserv = UIServices.KB;
if (kbserv != null && kbserv.CurrentKB != null)
{
try
{
SaveFileDialog SFD = new SaveFileDialog();
SFD.Filter = "web.xml file (web.xml)|";
SFD.FileName = "web.xml";
DialogResult Res = SFD.ShowDialog();
if (Res == DialogResult.OK)
{
string filename = SFD.FileName;
if (!filename.ToLower().EndsWith("xml"))
{
filename = filename + ".xml";
}
string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<web-app xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns=\"http://java.sun.com/xml/ns/javaee\" " +
"xmlns:web=\"http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd\" " +
"xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd\" " +
"version=\"2.4\">\n" +
"<listener><listener-class>com.genexus.webpanels.ServletEventListener</listener-class></listener>\n" +
"<listener><listener-class>com.genexus.webpanels.SessionEventListener</listener-class></listener>\n";
KBModel model = kbserv.CurrentKB.WorkingEnvironment.DesignModel;
string servletTemplate = "<servlet-mapping><servlet-name>{objName}</servlet-name><url-pattern>/{objName}</url-pattern> </servlet-mapping> \n" +
"<servlet> <servlet-name>{objName}</servlet-name><servlet-class>{objName}</servlet-class> </servlet>\n";
foreach (KBObject obj in Transaction.GetAll(model))
{
string servlet = servletTemplate.Replace("{objName}", obj.Name);
xml += servlet;
}
foreach (KBObject obj in WebPanel.GetAll(model))
{
string servlet = servletTemplate.Replace("{objName}", obj.Name);
xml += servlet;
}
xml += "</web-app>";
File.WriteAllText(filename, xml);
MessageBox.Show("Archivo generado en " + SFD.FileName);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Error while exporting the KB");
}
}
return true;
}
private bool QueryGeneraWebxmlCommand(CommandData cmdData, ref CommandStatus status)
{
// This is where you have a chance to modify the status of
// menu / toolbar items.
status.State = CommandState.Disabled;
IKBService kbserv = UIServices.KB;
if (kbserv != null && kbserv.CurrentKB != null)
{
status.State = CommandState.Enabled;
}
// return true to indicate you already resolved the command status;
// otherwise the framework will try with its next registered
// command target
return true;
}
}
}