87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
//
|
|
// <copyright file="CustomAction.cs" company="Microsoft">
|
|
// Copyright (C) Microsoft. All rights reserved.
|
|
// </copyright>
|
|
//
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Microsoft.Deployment.WindowsInstaller;
|
|
using Microsoft.WindowsServerSolutions.HostedEmail;
|
|
using System.IO;
|
|
using Contoso.EmailService;
|
|
|
|
namespace ContosoCustomAction
|
|
{
|
|
public class CustomActions
|
|
{
|
|
// This is copied from ContosoHostedEmail.addin
|
|
private const string addinId = "3983E9AC-B6D1-4A2A-881C-4B1CEFCA5266";
|
|
[CustomAction]
|
|
public static ActionResult UninstallCheck(Session session)
|
|
{
|
|
session.Log("Begin UninstallCheck");
|
|
try
|
|
{
|
|
|
|
if (HostedEmailIntegrationManager.EnabledAddinId.Equals(new Guid(addinId)))
|
|
{
|
|
session.Log("Current hosted email addin is enabled, prevent it being uninstalled");
|
|
return ActionResult.Failure;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
session.Log("UninstallCheck failed due to {0}", e.Message);
|
|
return ActionResult.Failure;
|
|
}
|
|
return ActionResult.Success;
|
|
}
|
|
|
|
[CustomAction]
|
|
public static ActionResult RemoveAutoGeneratedDataFilesAndFolders(Session session)
|
|
{
|
|
session.Log("Begin RemoveAutoGeneratedDataFilesAndFolders");
|
|
try
|
|
{
|
|
var file = Constants.AccountDataFilePath;
|
|
if (File.Exists(file))
|
|
{
|
|
session.Log("Remove {0}", file);
|
|
File.Delete(file);
|
|
}
|
|
file = Constants.ConfigrationFilePath;
|
|
if (File.Exists(file))
|
|
{
|
|
session.Log("Remove {0}", file);
|
|
File.Delete(file);
|
|
}
|
|
file = Constants.ConfigurationSchemaPath;
|
|
if (File.Exists(file))
|
|
{
|
|
session.Log("Remove {0}", file);
|
|
File.Delete(file);
|
|
}
|
|
var folder = Constants.BaseDirectory;
|
|
if (Directory.EnumerateDirectories(folder).Count() == 0 && Directory.EnumerateFiles(folder).Count() == 0)
|
|
{
|
|
session.Log("Remove directory {0}", folder);
|
|
Directory.Delete(folder);
|
|
}
|
|
}
|
|
catch (IOException e)
|
|
{
|
|
session.Log(e.Message);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
session.Log(e.Message);
|
|
return ActionResult.Failure;
|
|
}
|
|
return ActionResult.Success;
|
|
}
|
|
}
|
|
}
|