Commit aa2e380745e21486d5ac26ba79aff8e05153f6dd

Authored by Schwirg László
1 parent 5df5f3e5

v1.15.0

WebApplication/SendUrl xml elem megvalósítása
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools - Http.cs
... ... @@ -23,21 +23,19 @@ using Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS;
23 23 using System.Net.Http;
24 24 using System.Net.Http.Headers;
25 25 using System.Collections.Generic;
26   -using System.Text.Json;
27   -using System.Text.Json.Serialization;
28   -
  26 +using Newtonsoft.Json;
29 27  
30 28 namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS
31 29 {
32 30 public static class HttpTools
33 31 {
34 32 public enum RequestType { GET,POST,}
35   - public static ReturnInfoJSON GetReturninfoJSON(string url, RequestType mode = RequestType.GET)
  33 + public static ReturnInfoJSON GetReturninfoJSON(string url, RequestType mode = RequestType.GET, List<Vrh.XmlProcessing.UrlElement.UrlParameter> dictparameterlist=null)
36 34 {
37 35 string returninfojsonstring = "";
38 36 try
39 37 {
40   - return mode == RequestType.GET? _GetReturninfoJSON(url,out returninfojsonstring) : _PostReturninfoJSON(url, out returninfojsonstring);
  38 + return mode == RequestType.GET? _GetReturninfoJSON(url,out returninfojsonstring) : _PostReturninfoJSON(url, out returninfojsonstring, dictparameterlist);
41 39 }
42 40 catch (Exception ex) { return new ReturnInfoJSON() { ReturnValue = -1, ReturnMessage = ex.Message + "\n" + returninfojsonstring, }; }
43 41 }
... ... @@ -46,16 +44,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS
46 44 {
47 45 var returninfojsonstream = Task.Run(async () => await (new HttpClient()).GetStreamAsync(url)).GetAwaiter().GetResult();
48 46 returninfojsonstring = GetStreamAsString(returninfojsonstream);
49   - ReturnInfoJSON returninfojson = JsonSerializer.Deserialize<ReturnInfoJSON>(returninfojsonstring);
  47 + ReturnInfoJSON returninfojson = (ReturnInfoJSON)JsonConvert.DeserializeObject(returninfojsonstring,typeof(ReturnInfoJSON));
50 48 //ReturnInfoJSON returninfojson = Task.Run(async () => await JsonSerializer.DeserializeAsync<ReturnInfoJSON>(returninfojsonstream)).GetAwaiter().GetResult();
51 49 return returninfojson;
52 50 }
53   - private static ReturnInfoJSON _PostReturninfoJSON(string url, out string returninfojsonstring)
  51 + private static ReturnInfoJSON _PostReturninfoJSON(string url, out string returninfojsonstring, List<Vrh.XmlProcessing.UrlElement.UrlParameter> dictparameterlist = null)
54 52 {
55   - var returninfojsonhttpresponsemessage = Task.Run(async () => await (new HttpClient()).PostAsync(url, null)).GetAwaiter().GetResult();
  53 + var jsonstring = JsonConvert.SerializeObject(dictparameterlist.Where(p => p.PassTo == Vrh.XmlProcessing.UrlElement.ParameterTypes.dict));
  54 + HttpContent requestcontent = new StringContent(jsonstring);
  55 + var returninfojsonhttpresponsemessage = Task.Run(async () => await (new HttpClient()).PostAsync(url, requestcontent)).GetAwaiter().GetResult();
56 56 var returninfojsonstream = Task.Run(async () => await returninfojsonhttpresponsemessage.Content.ReadAsStreamAsync()).GetAwaiter().GetResult();
57 57 returninfojsonstring = GetStreamAsString(returninfojsonstream);
58   - ReturnInfoJSON returninfojson = JsonSerializer.Deserialize<ReturnInfoJSON>(returninfojsonstring);
  58 + ReturnInfoJSON returninfojson = (ReturnInfoJSON)JsonConvert.DeserializeObject(returninfojsonstring, typeof(ReturnInfoJSON));
59 59 //var returninfojson = Task.Run(async () => await JsonSerializer.DeserializeAsync<ReturnInfoJSON>(returninfojsonstream)).GetAwaiter().GetResult();
60 60 return returninfojson;
61 61 }
... ... @@ -72,10 +72,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS
72 72 }
73 73 public class ReturnInfoJSON
74 74 {
75   - [JsonPropertyName("ReturnValue")]
76 75 public int ReturnValue { get; set; }
77 76  
78   - [JsonPropertyName("ReturnMessage")]
79 77 public string ReturnMessage { get; set; }
80 78 }
81 79 }
... ...
Vrh.Log4Pro.MaintenanceConsole/Manager - WebApplicationManager.cs
... ... @@ -88,23 +88,65 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS
88 88 var config = (parameters as Menu.ExecutorParameter).GetConfig<WebApplicationManagerXmlProcessor>();
89 89 var args = (parameters as Menu.ExecutorParameter).Args;
90 90 var selectedwaindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WebApplicationManager.Function.CMD_WEBAPPS);
  91 + var menuwapps = DisplayWebApplicationMenu(config, "Select the web application(s) to manage!", silent: true);
  92 + menuwapps.SetSelectionMode(Menu.SelectionMode.Single);
  93 + Menu.Selection sr = menuwapps.Select(selectedwaindexes);
91 94  
92   - const string TESTURL = "http://localhost/Log4ProIS/Import/Log/PurgeGet?numofdays=120&xml=config=ALM_Import;";
  95 + if (sr.Result == Menu.SelectionResult.Exit) { return o; }
  96 + else if (sr.Result == Menu.SelectionResult.None) { return o; }
  97 + else if (sr.Result == Menu.SelectionResult.Error) { return o; }
  98 + else if (sr.Result == Menu.SelectionResult.Ok) { }
  99 + else { }
  100 +
  101 + WebApplication selectedwebapplication = (sr.SelectedParameterList.First()).Parameters as WebApplication;
  102 + var therearepredefinedurls = selectedwebapplication.Xml_SendUrlList != null && selectedwebapplication.Xml_SendUrlList.Any();
  103 + string urlname;
  104 + List<string> sendurlnamelist=null;
  105 + if (therearepredefinedurls)
  106 + {
  107 + ColorConsole.WriteLine("Enter the name of the url to send, or * to enter url manually:", ConsoleColor.Yellow);
  108 + sendurlnamelist = selectedwebapplication.Xml_SendUrlList.Select(su => su.Name).ToList();
  109 + string sendurlnamecommalist = string.Join(",", sendurlnamelist);
  110 + ColorConsole.WriteLine("Select names from this list:", ConsoleColor.Gray, suffix: sendurlnamecommalist);
  111 + foreach (var su in selectedwebapplication.Xml_SendUrlList)
  112 + {
  113 + ColorConsole.WriteLine(su.UrlElement.GetUrlAbsolute(), ConsoleColor.Gray, prefix: $" {su.Name}: ");
  114 + }
  115 + urlname = ColorConsole.ReadLine();
  116 + }
  117 + else { urlname = "*"; }
  118 + if (urlname.ToLower() == "ex") return o;
  119 + string urltext;
  120 + HttpTools.RequestType gp;
  121 + List<Vrh.XmlProcessing.UrlElement.UrlParameter> uplist=null;
  122 + if (urlname.ToLower() == "*")
  123 + {
  124 + const string TESTURL = "http://localhost/Log4ProIS/Import/Log/PurgeGet?numofdays=120&xml=config=ALM_Import;";
  125 + ColorConsole.WriteLine("Enter url to send:", ConsoleColor.Yellow);
  126 + ColorConsole.WriteLine("Sample (Enter 'Sample' to use this):", ConsoleColor.Gray, suffix: TESTURL);
  127 + urltext = ColorConsole.ReadLine();
  128 + if (urltext.ToLower() == "ex") return o;
  129 + if (urltext.ToLower() == "sample") urltext = TESTURL;
  130 + ColorConsole.WriteLine("Enter request type (GET/POST):", ConsoleColor.Yellow);
  131 + string gpstr = ColorConsole.ReadLine();
  132 + gp = HttpTools.RequestType.GET;
  133 + if (gpstr.ToLower() == "ex") return o;
  134 + else if (gpstr.ToUpper() == nameof(HttpTools.RequestType.GET)) { gp = HttpTools.RequestType.GET; }
  135 + else if (gpstr.ToUpper() == nameof(HttpTools.RequestType.POST)) { gp = HttpTools.RequestType.POST; }
93 136  
94   - ColorConsole.WriteLine("Enter url to send:", ConsoleColor.Yellow);
95   - ColorConsole.WriteLine("Sample (Enter 'Sample' to use this):", ConsoleColor.Gray, suffix: TESTURL);
96   - string url = ColorConsole.ReadLine();
97   - if (url.ToLower() == "ex") return o;
98   - if (url.ToLower() == "sample") url = TESTURL;
99   - ColorConsole.WriteLine("Enter request type (GET/POST):", ConsoleColor.Yellow);
100   - string gpstr = ColorConsole.ReadLine();
101   - HttpTools.RequestType gp = HttpTools.RequestType.GET;
102   - if (gpstr.ToLower() == "ex") return o;
103   - else if (gpstr.ToUpper() == nameof(HttpTools.RequestType.GET)) { gp = HttpTools.RequestType.GET; }
104   - else if (gpstr.ToUpper() == nameof(HttpTools.RequestType.POST)) { gp = HttpTools.RequestType.POST; }
  137 + }
  138 + else if (sendurlnamelist!=null && !sendurlnamelist.Contains(urlname)) { ColorConsole.WriteLine("Invalid selection!", ConsoleColor.Red); return o; }
  139 + else
  140 + {
  141 + var sendurlobject = selectedwebapplication.Xml_SendUrlList.FirstOrDefault(u => u.Name == urlname);
  142 + var urlobject = sendurlobject.UrlElement;
  143 + urltext = urlobject.GetUrl();
  144 + uplist = urlobject.UrlParameters.Where(p => p.PassTo == Vrh.XmlProcessing.UrlElement.ParameterTypes.dict).ToList();
  145 + gp = sendurlobject.ForcePOST || uplist.Any() ? HttpTools.RequestType.POST : HttpTools.RequestType.GET;
  146 + }
105 147  
106   - ToolsNS.HttpTools.ReturnInfoJSON returninfojson = HttpTools.GetReturninfoJSON(url,gp);
107   - ColorConsole.WriteLine("ReturnValue:",ConsoleColor.Yellow,suffix: returninfojson.ReturnValue.ToString());
  148 + ToolsNS.HttpTools.ReturnInfoJSON returninfojson = HttpTools.GetReturninfoJSON(urltext, gp);
  149 + ColorConsole.WriteLine("ReturnValue:", ConsoleColor.Yellow, suffix: returninfojson.ReturnValue.ToString());
108 150 ColorConsole.WriteLine("ReturnMessage:", ConsoleColor.Yellow, suffix: returninfojson.ReturnMessage);
109 151 ColorConsole.WriteLine();
110 152  
... ... @@ -748,30 +790,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS
748 790 }
749 791 #endregion private method:SetImpersonateIdentity
750 792 #region private method:SetPoolUserAccount
751   - //public static void SetPoolUserAccountOLD(string appname, string sitename, string username, string password, ProcessModelIdentityType poolidentitytype)
752   - //{
753   - // using (var sm = new ServerManager())
754   - // {
755   - // //var pool = GetPool(GetPoolName(sitename, appname));
756   - // var pool = GetPool(sm, sitename, appname);
757   - // if (username == nameof(ProcessModelIdentityType.ApplicationPoolIdentity)
758   - // || username == nameof(ProcessModelIdentityType.LocalService)
759   - // || username == nameof(ProcessModelIdentityType.LocalSystem)
760   - // || username == nameof(ProcessModelIdentityType.NetworkService))
761   - // {
762   - // pool.ProcessModel.UserName = null;
763   - // pool.ProcessModel.Password = null;
764   - // pool.ProcessModel.IdentityType = (ProcessModelIdentityType)Enum.Parse(typeof(ProcessModelIdentityType), username);
765   - // }
766   - // else // if (ProcessModelIdentityType.SpecificUser)
767   - // {
768   - // pool.ProcessModel.UserName = username;
769   - // pool.ProcessModel.Password = password;
770   - // pool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
771   - // }
772   - // CommitChanges(sm, pool.Name);
773   - // }
774   - //}
775 793 public static void SetPoolUserAccount(string appname, string sitename, string username, string password, ProcessModelIdentityType poolidentitytype)
776 794 {
777 795 using (var sm = new ServerManager())
... ... @@ -1141,6 +1159,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS
1141 1159 public bool Xml_ForceRemovePool;
1142 1160 public bool Xml_ForceRemoveSite;
1143 1161 public List<VirtualDirectory> Xml_VirtualDirectoryList;
  1162 + public List<SendUrl> Xml_SendUrlList;
1144 1163 #endregion properties from Xml definition
1145 1164  
1146 1165 #region properties from environment
... ... @@ -1203,10 +1222,17 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS
1203 1222 var vddefinitionXmlList = GetAllXElements(webappXml, nameof(XmlStructure.WebApplication.VirtualDirectory));
1204 1223 if (vddefinitionXmlList != null && vddefinitionXmlList.Any())
1205 1224 {
1206   - foreach (var vddefinitionXml in vddefinitionXmlList)
1207   - {
1208   - Xml_VirtualDirectoryList.Add(new VirtualDirectory(vddefinitionXml));
1209   - }
  1225 + foreach (var vddefinitionXml in vddefinitionXmlList) { Xml_VirtualDirectoryList.Add(new VirtualDirectory(vddefinitionXml)); }
  1226 + }
  1227 + }
  1228 + catch { }
  1229 + Xml_SendUrlList = new List<SendUrl>();
  1230 + try
  1231 + {
  1232 + var sendurldefinitionXmlList = GetAllXElements(webappXml, nameof(XmlStructure.WebApplication.SendUrl));
  1233 + if (sendurldefinitionXmlList != null && sendurldefinitionXmlList.Any())
  1234 + {
  1235 + foreach (var sendurldefinitionXml in sendurldefinitionXmlList) { Xml_SendUrlList.Add(new SendUrl(sendurldefinitionXml)); }
1210 1236 }
1211 1237 }
1212 1238 catch { }
... ... @@ -1230,6 +1256,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS
1230 1256 Xml_ForceRemovePool = wadef.Xml_ForceRemovePool;
1231 1257 Xml_ForceRemoveSite = wadef.Xml_ForceRemoveSite;
1232 1258 Xml_VirtualDirectoryList = wadef.Xml_VirtualDirectoryList.Select(x => new VirtualDirectory(x)).ToList();
  1259 + Xml_SendUrlList = wadef.Xml_SendUrlList.Select(x => new SendUrl(x)).ToList();
1233 1260  
1234 1261 Xml_ImpersonateIdentityConfigFile = wadef.Xml_ImpersonateIdentityConfigFile;
1235 1262 Xml_ImpersonateIdentity = wadef.Xml_ImpersonateIdentity;
... ... @@ -1249,6 +1276,64 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS
1249 1276 PhysicalPath = GetValue(nameof(XmlStructure.WebApplication.VirtualDirectory.Attributes.PhysicalPath), vdxml, "");
1250 1277 }
1251 1278 }
  1279 + public class SendUrl : XmlLinqBase
  1280 + {
  1281 + public Vrh.XmlProcessing.UrlElement UrlElement;
  1282 + public bool ForcePOST = false;
  1283 + public string Name;
  1284 + public bool IsOK
  1285 + {
  1286 + get
  1287 + {
  1288 + if (string.IsNullOrWhiteSpace(Name)) return false;
  1289 + if (!string.IsNullOrWhiteSpace(UrlElement.Url)) return true;
  1290 + if (string.IsNullOrWhiteSpace(UrlElement.Area) || string.IsNullOrWhiteSpace(UrlElement.Controller) || string.IsNullOrWhiteSpace(UrlElement.Action)) return false;
  1291 + if (UrlElement.UrlParameters!=null && UrlElement.UrlParameters.Any())
  1292 + {
  1293 + foreach (var urlparameter in UrlElement.UrlParameters)
  1294 + {
  1295 + if (string.IsNullOrWhiteSpace(urlparameter.Name)) { return false; }
  1296 + if (urlparameter.PassTo != Vrh.XmlProcessing.UrlElement.ParameterTypes.url && urlparameter.PassTo != Vrh.XmlProcessing.UrlElement.ParameterTypes.dict) { return false; }
  1297 + }
  1298 + }
  1299 + return true;
  1300 + }
  1301 + }
  1302 + public SendUrl(SendUrl sendurl)
  1303 + {
  1304 + Name = sendurl.Name;
  1305 + ForcePOST = sendurl.ForcePOST;
  1306 + UrlElement = new UrlElement(sendurl.UrlElement);
  1307 + }
  1308 + public SendUrl(XElement sendurlxmlelement)
  1309 + {
  1310 + Name = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.Name), sendurlxmlelement, "");
  1311 + ForcePOST = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.ForcePost), sendurlxmlelement, XmlStructure.WebApplication.SendUrl.Attributes.ForcePost.Values.DEFAULT);
  1312 + UrlElement = new Vrh.XmlProcessing.UrlElement();
  1313 + UrlElement.Url = GetValue(sendurlxmlelement, "");
  1314 + UrlElement.Protocol = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.protocol), sendurlxmlelement, "");
  1315 + UrlElement.HostName = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.hostname), sendurlxmlelement, "");
  1316 + UrlElement.AppName = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.appname), sendurlxmlelement, "");
  1317 + UrlElement.Area = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.area), sendurlxmlelement, "");
  1318 + UrlElement.Controller = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.controller), sendurlxmlelement, "");
  1319 + UrlElement.Action = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.action), sendurlxmlelement, "");
  1320 + UrlElement.Fragment = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Attributes.fragment), sendurlxmlelement, "");
  1321 + UrlElement.UrlParameters = new List<UrlElement.UrlParameter>();
  1322 + var urlparameterxmllist = sendurlxmlelement.Elements(nameof(XmlStructure.WebApplication.SendUrl.Parameter));
  1323 + if (urlparameterxmllist != null)
  1324 + {
  1325 + foreach (var urlparameterxml in urlparameterxmllist)
  1326 + {
  1327 + UrlElement.UrlParameters.Add(new UrlElement.UrlParameter()
  1328 + {
  1329 + Name = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Parameter.Attributes.Name), urlparameterxml, ""),
  1330 + PassTo = GetValue(nameof(XmlStructure.WebApplication.SendUrl.Parameter.Attributes.PassTo), urlparameterxml, Vrh.XmlProcessing.UrlElement.ParameterTypes.url),
  1331 + Value = GetValue(urlparameterxml, ""),
  1332 + });
  1333 + }
  1334 + }
  1335 + }
  1336 + }
1252 1337  
1253 1338 #region XmlStructure
1254 1339 public static class XmlStructure
... ... @@ -1285,6 +1370,29 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS
1285 1370 public static class PhysicalPath {}
1286 1371 }
1287 1372 }
  1373 + public static class SendUrl
  1374 + {
  1375 + public static class Attributes
  1376 + {
  1377 + public static class Name { }
  1378 + public static class ForcePost { public static class Values { public static bool DEFAULT = false; } }
  1379 + public static class protocol { }
  1380 + public static class hostname { }
  1381 + public static class appname { }
  1382 + public static class area { }
  1383 + public static class controller { }
  1384 + public static class action { }
  1385 + public static class fragment { }
  1386 + }
  1387 + public static class Parameter
  1388 + {
  1389 + public static class Attributes
  1390 + {
  1391 + public static class PassTo { }
  1392 + public static class Name { }
  1393 + }
  1394 + }
  1395 + }
1288 1396 }
1289 1397 }
1290 1398 #endregion XmlStructure
... ...
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
... ... @@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
32 32 // You can specify all the values or you can default the Build and Revision Numbers
33 33 // by using the '*' as shown below:
34 34 // [assembly: AssemblyVersion("1.0.*")]
35   -[assembly: AssemblyVersion("1.14.0.0")]
36   -[assembly: AssemblyFileVersion("1.14.0.0")]
  35 +[assembly: AssemblyVersion("1.15.0.0")]
  36 +[assembly: AssemblyFileVersion("1.15.0.0")]
... ...
Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj
... ... @@ -353,8 +353,8 @@
353 353 <Reference Include="Vrh.Web.Providers, Version=2.0.2.0, Culture=neutral, processorArchitecture=MSIL">
354 354 <HintPath>..\packages\VRH.Web.Providers.2.0.2\lib\net452\Vrh.Web.Providers.dll</HintPath>
355 355 </Reference>
356   - <Reference Include="Vrh.XmlProcessing, Version=1.30.0.0, Culture=neutral, processorArchitecture=MSIL">
357   - <HintPath>..\packages\Vrh.XmlProcessing.1.30.0\lib\net45\Vrh.XmlProcessing.dll</HintPath>
  356 + <Reference Include="Vrh.XmlProcessing, Version=1.30.1.0, Culture=neutral, processorArchitecture=MSIL">
  357 + <HintPath>..\packages\Vrh.XmlProcessing.1.30.1\lib\net45\Vrh.XmlProcessing.dll</HintPath>
358 358 </Reference>
359 359 <Reference Include="WindowsBase" />
360 360 </ItemGroup>
... ...
Vrh.Log4Pro.MaintenanceConsole/packages.config
... ... @@ -75,5 +75,5 @@
75 75 <package id="System.Xml.XDocument" version="4.0.11" targetFramework="net472" />
76 76 <package id="VRH.Common" version="2.23.1" targetFramework="net472" />
77 77 <package id="VRH.Web.Providers" version="2.0.2" targetFramework="net472" />
78   - <package id="Vrh.XmlProcessing" version="1.30.0" targetFramework="net472" />
  78 + <package id="Vrh.XmlProcessing" version="1.30.1" targetFramework="net472" />
79 79 </packages>
80 80 \ No newline at end of file
... ...