Skip to content

Commit 15c48b3

Browse files
authored
Merge pull request #9 from microting/master
Get last changes
2 parents 081cf7c + d3e08d4 commit 15c48b3

File tree

25 files changed

+709
-221
lines changed

25 files changed

+709
-221
lines changed

eFormAPI/Installation/AllowMultipleVersionsBundle/Program.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Linq;
55
using System.Security;
66
using Microsoft.Win32;
7+
using System.Reflection;
8+
using System.Threading;
79

810
namespace AlowMultipleVersionsBundle
911
{
@@ -13,6 +15,11 @@ static void Main(string[] args)
1315
{
1416
try
1517
{
18+
string path = Path.Combine(Path.GetTempPath(), "Eform Angular Frontend.exe");
19+
if (IsFileLocked(path))
20+
// wait for previous installer finish
21+
Thread.Sleep(2000);
22+
1623
var unistall =
1724
Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
1825
true);
@@ -26,8 +33,18 @@ static void Main(string[] args)
2633

2734
SetupIIS();
2835

29-
string path = Path.Combine(Path.GetTempPath(), "Eform Angular Frontend.exe");
30-
File.WriteAllBytes(path, Resources.Eform_Angular_Frontend);
36+
if (!IsFileLocked(path))
37+
File.WriteAllBytes(path, Resources.Eform_Angular_Frontend);
38+
39+
var drive = DriveInfo.GetDrives().First(t => t.DriveType == DriveType.Fixed).Name;
40+
var tmpDir = Path.Combine(drive, "tmp");
41+
if (Directory.Exists(tmpDir))
42+
Directory.Delete(tmpDir, true);
43+
44+
var dirInfo = Directory.CreateDirectory(tmpDir);
45+
dirInfo.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
46+
File.WriteAllText(dirInfo.FullName + "\\config.txt", Assembly.GetExecutingAssembly().Location);
47+
3148
Process.Start(path);
3249
}
3350
catch (SecurityException e)
@@ -37,6 +54,26 @@ static void Main(string[] args)
3754

3855
}
3956

57+
static bool IsFileLocked(string path)
58+
{
59+
FileStream stream = null;
60+
61+
try
62+
{
63+
stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None);
64+
}
65+
catch (IOException)
66+
{
67+
return true;
68+
}
69+
finally
70+
{
71+
if (stream != null)
72+
stream.Close();
73+
}
74+
return false;
75+
}
76+
4077
static void SetupIIS()
4178
{
4279
var featureNames = new[]

eFormAPI/Installation/CustomActions/CustomAction.cs

Lines changed: 224 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ public static ActionResult InstallCA(Session session)
216216
HostWebApi(webApiName, webApiPort, webApiLocation);
217217
IncrementProgressBar(session);
218218

219+
session.Log("Host WebAPI called");
220+
AddImageHandlers(webApiName);
221+
IncrementProgressBar(session);
222+
219223
session.Log("RunAngularAsWinService called");
220224
RunAngularAsWinService(webApiPort, uiPort, clientLocation, uiName);
221225
IncrementProgressBar(session);
@@ -310,6 +314,8 @@ public static ActionResult UpdateCA(Session session)
310314

311315
// client update
312316
var uiName = $"{customerNumber}_{domain}_client_{uiPort}";
317+
318+
var webApiName = $"{customerNumber}_{domain}_{apiPort}";
313319
var uiIisDir = Path.Combine(siteDir + uiName);
314320
var webApiLocation = Path.Combine(siteDir, domainName);
315321

@@ -342,6 +348,11 @@ public static ActionResult UpdateCA(Session session)
342348
BuildAngularApp(uiIisDir);
343349
IncrementProgressBar(session);
344350

351+
session.Log("AddImageHandlers called");
352+
AddImageHandlers(webApiName);
353+
IncrementProgressBar(session);
354+
355+
345356
session.Log("RunAngularAsWinService called");
346357
RunAngularAsWinService(apiPort, uiPort, uiIisDir, uiName);
347358
IncrementProgressBar(session);
@@ -438,6 +449,27 @@ public static ActionResult RemoveCA(Session session)
438449

439450
}
440451

452+
[CustomAction]
453+
public static ActionResult RestartInstallerCA(Session session)
454+
{
455+
try
456+
{
457+
var drive = DriveInfo.GetDrives().First(t => t.DriveType == DriveType.Fixed).Name;
458+
var tmpDir = Path.Combine(drive, "tmp", "config.txt");
459+
460+
var location = File.ReadAllText(tmpDir);
461+
Process.Start(location);
462+
463+
return ActionResult.Success;
464+
}
465+
catch (Exception ex)
466+
{
467+
468+
MessageBox.Show(ex.Message + " " + ex.StackTrace);
469+
return ActionResult.Failure;
470+
}
471+
}
472+
441473
private static long GetSiteId(string uiName)
442474
{
443475
using (var serverManager = new ServerManager())
@@ -561,15 +593,15 @@ private static void BuildAngularApp(string appLocation)
561593
RunProcess(@"C:\Program Files\nodejs\npm.cmd", "run build", appLocation);
562594
}
563595

564-
private static void HostWebApi(string webApiName, int port, string iisDir)
596+
private static void HostWebApi(string siteName, int port, string iisDir)
565597
{
566598
using (var serverManager = new ServerManager())
567599
{
568-
CreateAppPool(serverManager, webApiName);
600+
CreateAppPool(serverManager, siteName);
569601

570-
serverManager.Sites.Add(webApiName, iisDir, port);
571-
foreach (var item in serverManager.Sites[webApiName].Applications)
572-
item.ApplicationPoolName = webApiName;
602+
serverManager.Sites.Add(siteName, iisDir, port);
603+
foreach (var item in serverManager.Sites[siteName].Applications)
604+
item.ApplicationPoolName = siteName;
573605

574606
serverManager.CommitChanges();
575607
}
@@ -613,6 +645,193 @@ private static void HostAngularApp(string folder, string domain, string siteName
613645
}
614646
}
615647

648+
private static void AddImageHandlers(string siteName)
649+
{
650+
651+
using (ServerManager serverManager = new ServerManager())
652+
{
653+
//MessageBox.Show("AddImageHandlers called for siteName " + siteName);
654+
655+
Configuration config = serverManager.GetWebConfiguration(siteName);
656+
657+
ConfigurationSection handlersSection = config.GetSection("system.webServer/handlers");
658+
ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();
659+
bool pngHandlerMissing = true;
660+
bool jpgHandlerMissing = true;
661+
bool jpegHandlerMissing = true;
662+
bool add1Missing = true;
663+
bool remove1Missing = true;
664+
bool remove2Missing = true;
665+
bool remove3Missing = true;
666+
//ConfigurationElement toRemoveCe = null;
667+
668+
List<ConfigurationElement> toRemoveElements = new List<ConfigurationElement>();
669+
670+
foreach (ConfigurationElement ce in handlersCollection)
671+
{
672+
//if (ce.GetAttributeValue("name").ToString() == "get-image-png")
673+
//{
674+
// //MessageBox.Show("pngHandlerMissing");
675+
// pngHandlerMissing = false;
676+
//}
677+
//if (ce.GetAttributeValue("name").ToString() == "get-image-jpg")
678+
//{
679+
// //MessageBox.Show("jpgHandlerMissing");
680+
// jpgHandlerMissing = false;
681+
//}
682+
//if (ce.GetAttributeValue("name").ToString() == "get-image-jpeg")
683+
//{
684+
// //MessageBox.Show("jpegHandlerMissing");
685+
// jpegHandlerMissing = false;
686+
//}
687+
//if (ce.GetAttributeValue("name").ToString() == "ExtensionlessUrlHandler-Integrated-4.0")
688+
//{
689+
// add1Missing = false;
690+
//}
691+
//if (ce.GetAttributeValue("name").ToString() == "OPTIONSVerbHandler")
692+
//{
693+
// remove2Missing = false;
694+
//}
695+
//if (ce.GetAttributeValue("name").ToString() == "TRACEVerbHandler")
696+
//{
697+
// remove3Missing = false;
698+
//}
699+
700+
//if (ce.GetAttributeValue("name").ToString() == "ExtensionlessUrlHandler-Integrated-4.0")
701+
//{
702+
// toRemoveCe = ce;
703+
//}
704+
toRemoveElements.Add(ce);
705+
706+
}
707+
//try
708+
//{
709+
// if (toRemoveCe != null)
710+
// handlersCollection.Remove(toRemoveCe);
711+
//} catch { }
712+
foreach (ConfigurationElement ce in toRemoveElements)
713+
{
714+
handlersCollection.Remove(ce);
715+
}
716+
handlersCollection.Clear();
717+
718+
if (remove1Missing)
719+
{
720+
try
721+
{
722+
ConfigurationElement ele = handlersCollection.CreateElement("remove");
723+
ele["name"] = "ExtensionlessUrlHandler-Integrated-4.0";
724+
handlersCollection.Add(ele);
725+
}
726+
catch (Exception ex)
727+
{
728+
//MessageBox.Show("ExtensionlessUrlHandler ex is : " + ex.Message + "stacktrace : " + ex.StackTrace);
729+
}
730+
}
731+
732+
if (remove2Missing)
733+
{
734+
try
735+
{
736+
ConfigurationElement ele = handlersCollection.CreateElement("remove");
737+
ele["name"] = "OPTIONSVerbHandler";
738+
handlersCollection.Add(ele);
739+
}
740+
catch (Exception ex)
741+
{
742+
//MessageBox.Show("OPTIONSVerbHandler ex is : " + ex.Message + "stacktrace : " + ex.StackTrace);
743+
}
744+
}
745+
746+
if (remove3Missing) {
747+
try
748+
{
749+
ConfigurationElement ele = handlersCollection.CreateElement("remove");
750+
ele["name"] = "TRACEVerbHandler";
751+
handlersCollection.Add(ele);
752+
}
753+
catch (Exception ex)
754+
{
755+
//MessageBox.Show("TRACEVerbHandler ex is : " + ex.Message + "stacktrace : " + ex.StackTrace);
756+
}
757+
}
758+
if (add1Missing)
759+
{
760+
try
761+
{
762+
ConfigurationElement ele = handlersCollection.CreateElement("add");
763+
ele["name"] = "ExtensionlessUrlHandler-Integrated-4.0";
764+
ele["path"] = @"*.";
765+
ele["verb"] = "*";
766+
ele["type"] = @"System.Web.Handlers.TransferRequestHandler";
767+
ele["preCondition"] = "integratedMode,runtimeVersionv4.0";
768+
handlersCollection.Add(ele);
769+
}
770+
catch
771+
{
772+
//MessageBox.Show("pngHandlerMissing ex is : " + ex.Message + "stacktrace : " + ex.StackTrace);
773+
}
774+
}
775+
776+
if (pngHandlerMissing) {
777+
try
778+
{
779+
ConfigurationElement ele = handlersCollection.CreateElement("add");
780+
ele["name"] = "get-image-png";
781+
ele["path"] = @"*.png";
782+
ele["verb"] = "GET";
783+
ele["type"] = @"System.Web.Handlers.TransferRequestHandler";
784+
ele["preCondition"] = "integratedMode,runtimeVersionv4.0";
785+
ele["responseBufferLimit"] = 0;
786+
handlersCollection.Add(ele);
787+
}
788+
catch (Exception ex)
789+
{
790+
MessageBox.Show("pngHandlerMissing ex is : " + ex.Message + "stacktrace : " + ex.StackTrace);
791+
}
792+
}
793+
794+
if (jpgHandlerMissing) {
795+
try
796+
{
797+
ConfigurationElement ele = handlersCollection.CreateElement("add");
798+
ele["name"] = "get-image-jpg";
799+
ele["path"] = @"*.jpg";
800+
ele["verb"] = "GET";
801+
ele["type"] = @"System.Web.Handlers.TransferRequestHandler";
802+
ele["preCondition"] = "integratedMode,runtimeVersionv4.0";
803+
ele["responseBufferLimit"] = 0;
804+
handlersCollection.Add(ele);
805+
}
806+
catch (Exception ex)
807+
{
808+
MessageBox.Show("jpgHandlerMissing ex is : " + ex.Message + "stacktrace : " + ex.StackTrace);
809+
}
810+
}
811+
812+
if (jpegHandlerMissing) {
813+
try
814+
{
815+
ConfigurationElement ele = handlersCollection.CreateElement("add");
816+
ele["name"] = "get-image-jpeg";
817+
ele["path"] = @"*.jpeg";
818+
ele["verb"] = "GET";
819+
ele["type"] = @"System.Web.Handlers.TransferRequestHandler";
820+
ele["preCondition"] = "integratedMode,runtimeVersionv4.0";
821+
ele["responseBufferLimit"] = 0;
822+
823+
handlersCollection.Add(ele);
824+
}
825+
catch (Exception ex)
826+
{
827+
MessageBox.Show("jpegHandlerMissing ex is : " + ex.Message + "stacktrace : " + ex.StackTrace);
828+
}
829+
}
830+
831+
serverManager.CommitChanges();
832+
}
833+
}
834+
616835
private static void AddRedirectionRules(string siteName, string uiServiceLink)
617836
{
618837
using (ServerManager serverManager = new ServerManager())
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
4+
<Fragment>
5+
<UI>
6+
<Dialog Id="ExitDlgModified" Width="370" Height="270" Title="!(loc.ExitDialog_Title)">
7+
<Control Id="Finish" Type="PushButton" X="248" Y="243" Width="56" Height="17" Default="yes" Cancel="yes" Text="!(loc.WixUIFinish)" />
8+
<Control Id="Bitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="234" TabSkip="no" Text="!(loc.ExitDialogBitmap)" />
9+
<Control Id="StartOver" Type="PushButton" X="309" Y="243" Width="56" Height="17" Cancel="yes" Text="Start over" >
10+
<Publish Event="DoAction" Value="RestartInstaller">1</Publish>
11+
</Control>
12+
<Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
13+
<Control Id="Description" Type="Text" X="135" Y="70" Width="220" Height="40" Transparent="yes" NoPrefix="yes" Text="!(loc.ExitDialogDescription)" />
14+
<Control Id="Title" Type="Text" X="135" Y="20" Width="220" Height="60" Transparent="yes" NoPrefix="yes" Text="!(loc.ExitDialogTitle)" />
15+
</Dialog>
16+
17+
<InstallUISequence>
18+
<Show Dialog="ExitDlgModified" OnExit="success" Overridable="yes" />
19+
</InstallUISequence>
20+
21+
<AdminUISequence>
22+
<Show Dialog="ExitDlgModified" OnExit="success" Overridable="yes" />
23+
</AdminUISequence>
24+
</UI>
25+
</Fragment>
26+
</Wix>

eFormAPI/Installation/MainInstaller/MainInstaller.wixproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
</PropertyGroup>
2525
<ItemGroup>
2626
<Compile Include="ApiFileList.wxs" />
27+
<Compile Include="ExitDlgModified.wxs" />
2728
<Compile Include="DomainNameDlg.wxs" />
2829
<Compile Include="EmptyFIieldDlg.wxs" />
2930
<Compile Include="ClientFileList.wxs" />

eFormAPI/Installation/MainInstaller/Product.wxs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
<Fragment>
6565
<CustomAction Id="GetAPIsList" BinaryKey="BinaryCA" DllEntry="GetAPIsListCA" Execute="immediate" />
6666
<CustomAction Id="TryFindConfigs" BinaryKey="BinaryCA" DllEntry="TryFindConfigs" Execute="immediate"/>
67-
67+
<CustomAction Id="RestartInstaller" BinaryKey="BinaryCA" DllEntry="RestartInstallerCA" Execute="immediate" />
68+
6869
<CustomAction Id="Install" BinaryKey="BinaryCA" DllEntry="InstallCA" Execute="deferred" Impersonate="no" />
6970
<CustomAction Id="UpdateService" BinaryKey="BinaryCA" DllEntry="UpdateCA" Execute="deferred" Impersonate="no" />
7071
<CustomAction Id="RemoveService" BinaryKey="BinaryCA" DllEntry="RemoveCA" Execute="deferred" Impersonate="no" />

0 commit comments

Comments
 (0)