move the scheduler to a windows service
This commit is contained in:
parent
97f09a5683
commit
5e414136b2
115 changed files with 587 additions and 166 deletions
|
@ -0,0 +1,201 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using WebsitePanel.EnterpriseServer;
|
||||
|
||||
namespace WebsitePanel.Ecommerce.EnterpriseServer
|
||||
{
|
||||
public class ActivatePaidInvoicesTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
//
|
||||
PickupReceivedTransactions();
|
||||
// activate paid services
|
||||
ActivatePaidServices();
|
||||
}
|
||||
|
||||
public void PickupReceivedTransactions()
|
||||
{
|
||||
TaskManager.Write("Start looking for transactions submitted");
|
||||
//
|
||||
List<HandlerResponse> transactions = ServiceHandlerController.GetServiceHandlersResponsesByReseller(SecurityContext.User.UserId);
|
||||
//
|
||||
if (transactions.Count > 0)
|
||||
{
|
||||
XmlDocument xmldoc = new XmlDocument();
|
||||
XmlElement root = xmldoc.CreateElement("Result");
|
||||
XmlElement succeedNode = xmldoc.CreateElement("Succeed");
|
||||
XmlElement failedNode = xmldoc.CreateElement("Failed");
|
||||
root.AppendChild(succeedNode);
|
||||
root.AppendChild(failedNode);
|
||||
//
|
||||
List<HandlerResponse> succeedItems = new List<HandlerResponse>();
|
||||
List<HandlerResponse> failedItems = new List<HandlerResponse>();
|
||||
//
|
||||
TaskManager.Write("Found {0} transactions pending", transactions.Count.ToString());
|
||||
foreach (HandlerResponse transaction in transactions)
|
||||
{
|
||||
XmlElement responseNode = xmldoc.CreateElement("Response");
|
||||
responseNode.SetAttribute("ID", Convert.ToString(transaction.ResponseId));
|
||||
//
|
||||
try
|
||||
{
|
||||
CheckoutDetails details = new CheckoutDetails();
|
||||
//
|
||||
string[] dataPairs = transaction.TextResponse.Split('&');
|
||||
foreach (string dataPair in dataPairs)
|
||||
{
|
||||
string[] data = dataPair.Split('=');
|
||||
if (data.Length >= 2)
|
||||
details[data[0]] = data[1];
|
||||
}
|
||||
//
|
||||
CheckoutResult result = PaymentGatewayController.CheckOut(transaction.ContractId, transaction.InvoiceId,
|
||||
transaction.MethodName, details);
|
||||
//
|
||||
if (result.Succeed)
|
||||
{
|
||||
succeedNode.AppendChild(responseNode);
|
||||
succeedItems.Add(transaction);
|
||||
}
|
||||
else
|
||||
{
|
||||
responseNode.SetAttribute("Error", result.StatusCode);
|
||||
failedNode.AppendChild(responseNode);
|
||||
//
|
||||
transaction.ErrorMessage = result.StatusCode;
|
||||
failedItems.Add(transaction);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//
|
||||
if (!failedItems.Contains(transaction))
|
||||
{
|
||||
responseNode.SetAttribute("Error", ex.StackTrace);
|
||||
failedNode.AppendChild(responseNode);
|
||||
//
|
||||
transaction.ErrorMessage = ex.StackTrace;
|
||||
failedItems.Add(transaction);
|
||||
}
|
||||
//
|
||||
TaskManager.WriteError(ex);
|
||||
}
|
||||
}
|
||||
// peform transactions update
|
||||
ServiceHandlerController.UpdateServiceHandlersResponses(SecurityContext.User.UserId, root.InnerXml);
|
||||
}
|
||||
else
|
||||
{
|
||||
TaskManager.Write("No transactions found");
|
||||
}
|
||||
TaskManager.Write("End looking for transactions submitted");
|
||||
}
|
||||
|
||||
public void ActivatePaidServices()
|
||||
{
|
||||
// load paid invoice items
|
||||
List<InvoiceItem> items = InvoiceController.GetInvoicesItemsToActivate(SecurityContext.User.UserId);
|
||||
// TRACE
|
||||
TaskManager.Write("Activate paid services");
|
||||
TaskManager.WriteParameter("Items found", items.Count);
|
||||
// iterate
|
||||
foreach (InvoiceItem item in items)
|
||||
{
|
||||
try
|
||||
{
|
||||
TaskManager.Write("Activating service");
|
||||
// activating
|
||||
GenericSvcResult result = ActivateInvoiceItem(item);
|
||||
// LOG ERROR
|
||||
if (!result.Succeed)
|
||||
{
|
||||
TaskManager.WriteError(result.Error);
|
||||
if (!String.IsNullOrEmpty(result.ErrorCode))
|
||||
TaskManager.WriteParameter("Error code", result.ErrorCode);
|
||||
TaskManager.WriteParameter("Result code", result.ResultCode);
|
||||
// go to next item
|
||||
continue;
|
||||
}
|
||||
//
|
||||
TaskManager.Write("Activated");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GenericSvcResult ActivateInvoiceItem(InvoiceItem item)
|
||||
{
|
||||
GenericSvcResult svc_result = ActivateService(item.ServiceId, true, true);
|
||||
//
|
||||
if (svc_result.Succeed)
|
||||
InvoiceController.SetInvoiceItemProcessed(item.InvoiceId, item.ItemId);
|
||||
//
|
||||
return svc_result;
|
||||
}
|
||||
|
||||
public GenericSvcResult ActivateService(int serviceId, bool sendEmail, bool logSvcUsage)
|
||||
{
|
||||
GenericSvcResult result = null;
|
||||
// load svc type
|
||||
ProductType svc_type = ServiceController.GetServiceItemType(serviceId);
|
||||
//
|
||||
if (svc_type == null)
|
||||
{
|
||||
result = new GenericSvcResult();
|
||||
result.Succeed = true;
|
||||
return result;
|
||||
}
|
||||
// instantiate svc controller
|
||||
IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
|
||||
Type.GetType(svc_type.ProvisioningController));
|
||||
// create context
|
||||
ProvisioningContext context = controller.GetProvisioningContext(serviceId, sendEmail);
|
||||
// activate svc
|
||||
result = controller.ActivateService(context);
|
||||
// check result
|
||||
if (result.Succeed)
|
||||
{
|
||||
// log svc usage
|
||||
if (logSvcUsage)
|
||||
controller.LogServiceUsage(context);
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using WebsitePanel.Providers.Database;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class BackupDatabaseTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - DATABASE_GROUP
|
||||
// - DATABASE_NAME
|
||||
// - BACKUP_FOLDER
|
||||
// - BACKUP_NAME
|
||||
// - ZIP_BACKUP
|
||||
|
||||
string databaseGroup = (string)TaskManager.TaskParameters["DATABASE_GROUP"];
|
||||
string databaseName = (string)TaskManager.TaskParameters["DATABASE_NAME"];
|
||||
string backupFolder = (string)TaskManager.TaskParameters["BACKUP_FOLDER"];
|
||||
string backupName = (string)TaskManager.TaskParameters["BACKUP_NAME"];
|
||||
string strZipBackup = (string)TaskManager.TaskParameters["ZIP_BACKUP"];
|
||||
|
||||
// check input parameters
|
||||
if (String.IsNullOrEmpty(databaseName))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Database Name' task parameter.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool zipBackup = (strZipBackup.ToLower() == "true");
|
||||
|
||||
if (String.IsNullOrEmpty(backupName))
|
||||
{
|
||||
backupName = databaseName + (zipBackup ? ".zip" : ".bak");
|
||||
}
|
||||
else
|
||||
{
|
||||
// check extension
|
||||
string ext = Path.GetExtension(backupName);
|
||||
if (zipBackup && String.Compare(ext, ".zip", true) != 0)
|
||||
{
|
||||
// change extension to .zip
|
||||
backupName = Path.GetFileNameWithoutExtension(backupName) + ".zip";
|
||||
}
|
||||
}
|
||||
|
||||
// try to find database
|
||||
SqlDatabase item = (SqlDatabase)PackageController.GetPackageItemByName(TaskManager.PackageId, databaseGroup,
|
||||
databaseName, typeof(SqlDatabase));
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
TaskManager.WriteError("Database with the specified name was not found in the current hosting space.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(backupFolder))
|
||||
backupFolder = "\\";
|
||||
|
||||
// substitute parameters
|
||||
DateTime d = DateTime.Now;
|
||||
string date = d.ToString("yyyyMMdd");
|
||||
string time = d.ToString("HHmm");
|
||||
|
||||
backupFolder = Utils.ReplaceStringVariable(backupFolder, "date", date);
|
||||
backupFolder = Utils.ReplaceStringVariable(backupFolder, "time", time);
|
||||
backupName = Utils.ReplaceStringVariable(backupName, "date", date);
|
||||
backupName = Utils.ReplaceStringVariable(backupName, "time", time);
|
||||
|
||||
// backup database
|
||||
DatabaseServerController.BackupSqlDatabase(item.Id, backupName, zipBackup, false, backupFolder);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.UI.WebControls.WebParts;
|
||||
using System.Web.UI.HtmlControls;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents scheduler task that performs hosting space backup.
|
||||
/// </summary>
|
||||
public class BackupTask : SchedulerTask
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs actual backup.
|
||||
/// </summary>
|
||||
public override void DoWork()
|
||||
{
|
||||
string backupFileName;
|
||||
int storePackageId;
|
||||
string storePackageFolder;
|
||||
string storeServerFolder;
|
||||
bool deleteTempBackup;
|
||||
try
|
||||
{
|
||||
backupFileName = (string)TaskManager.TaskParameters["BACKUP_FILE_NAME"];
|
||||
storePackageId = Convert.ToInt32(TaskManager.TaskParameters["STORE_PACKAGE_ID"]);
|
||||
storePackageFolder = (string)TaskManager.TaskParameters["STORE_PACKAGE_FOLDER"];
|
||||
storeServerFolder = (string)TaskManager.TaskParameters["STORE_SERVER_FOLDER"];
|
||||
deleteTempBackup = Convert.ToBoolean(TaskManager.TaskParameters["DELETE_TEMP_BACKUP"]);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex, "Some parameters are absent or have incorrect value.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
PackageInfo package = PackageController.GetPackage(TaskManager.PackageId);
|
||||
// We do not take into account service id as long as scheduled tasks run against packages.
|
||||
BackupController.Backup(false, "BackupTask", package.UserId, package.PackageId, 0, 0,
|
||||
backupFileName, storePackageId, storePackageFolder, storeServerFolder, deleteTempBackup);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex, "Failed to do backup.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using WebsitePanel.Providers.Exchange;
|
||||
using WebsitePanel.Providers.HostedSolution;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class CalculateExchangeDiskspaceTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
CalculateDiskspace();
|
||||
}
|
||||
|
||||
public void CalculateDiskspace()
|
||||
{
|
||||
// get all space organizations recursively
|
||||
List<Organization> items = ExchangeServerController.GetExchangeOrganizations(TaskManager.PackageId, true);
|
||||
|
||||
foreach (Organization item in items)
|
||||
{
|
||||
ExchangeServerController.CalculateOrganizationDiskspaceInternal(item.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
|
||||
using WebsitePanel.Providers;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class CalculatePackagesBandwidthTask : SchedulerTask
|
||||
{
|
||||
private readonly bool suspendOverused = false;
|
||||
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - SUSPEND_OVERUSED_PACKAGES
|
||||
|
||||
CalculateBandwidth();
|
||||
}
|
||||
|
||||
public void CalculateBandwidth()
|
||||
{
|
||||
// get all owned packages
|
||||
List<PackageInfo> packages = PackageController.GetPackagePackages(TaskManager.PackageId, true);
|
||||
TaskManager.Write("Packages to calculate: " + packages.Count.ToString());
|
||||
|
||||
foreach (PackageInfo package in packages)
|
||||
{
|
||||
// calculating package bandwidth
|
||||
CalculatePackage(package.PackageId);
|
||||
}
|
||||
}
|
||||
|
||||
public void CalculatePackage(int packageId)
|
||||
{
|
||||
DateTime since = PackageController.GetPackageBandwidthUpdate(packageId);
|
||||
DateTime nextUpdate = DateTime.Now;
|
||||
|
||||
try
|
||||
{
|
||||
// get all package items
|
||||
List<ServiceProviderItem> items = PackageController.GetServiceItemsForStatistics(
|
||||
0, packageId, false, true, false, false);
|
||||
|
||||
// order items by service
|
||||
Dictionary<int, List<ServiceProviderItem>> orderedItems =
|
||||
PackageController.OrderServiceItemsByServices(items);
|
||||
|
||||
// calculate statistics for each service set
|
||||
List<ServiceProviderItemBandwidth> itemsBandwidth = new List<ServiceProviderItemBandwidth>();
|
||||
foreach (int serviceId in orderedItems.Keys)
|
||||
{
|
||||
ServiceProviderItemBandwidth[] serviceBandwidth = CalculateItems(serviceId,
|
||||
orderedItems[serviceId], since);
|
||||
if (serviceBandwidth != null)
|
||||
itemsBandwidth.AddRange(serviceBandwidth);
|
||||
}
|
||||
|
||||
// update info in the database
|
||||
string xml = BuildDiskBandwidthStatisticsXml(itemsBandwidth.ToArray());
|
||||
PackageController.UpdatePackageBandwidth(packageId, xml);
|
||||
|
||||
// if everything is OK
|
||||
// update date
|
||||
PackageController.UpdatePackageBandwidthUpdate(packageId, nextUpdate);
|
||||
|
||||
// suspend package if requested
|
||||
if (suspendOverused)
|
||||
{
|
||||
// disk space
|
||||
QuotaValueInfo dsQuota = PackageController.GetPackageQuota(packageId, Quotas.OS_BANDWIDTH);
|
||||
|
||||
if (dsQuota.QuotaExhausted)
|
||||
PackageController.ChangePackageStatus(null, packageId, PackageStatus.Suspended, false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// load package details
|
||||
PackageInfo package = PackageController.GetPackage(packageId);
|
||||
|
||||
// load user details
|
||||
UserInfo user = PackageController.GetPackageOwner(package.PackageId);
|
||||
|
||||
// log error
|
||||
TaskManager.WriteError(String.Format("Error calculating bandwidth for '{0}' space of user '{1}': {2}",
|
||||
package.PackageName, user.Username, ex.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceProviderItemBandwidth[] CalculateItems(int serviceId, List<ServiceProviderItem> items,
|
||||
DateTime since)
|
||||
{
|
||||
// convert items to SoapObjects
|
||||
List<SoapServiceProviderItem> objItems = new List<SoapServiceProviderItem>();
|
||||
foreach (ServiceProviderItem item in items)
|
||||
objItems.Add(SoapServiceProviderItem.Wrap(item));
|
||||
|
||||
int attempt = 0;
|
||||
int ATTEMPTS = 3;
|
||||
while (attempt < ATTEMPTS)
|
||||
{
|
||||
// increment attempt
|
||||
attempt++;
|
||||
|
||||
try
|
||||
{
|
||||
// send packet for calculation
|
||||
// invoke service provider
|
||||
//TaskManager.Write(String.Format("{0} - Invoke GetServiceItemsDiskSpace method ('{1}' items) - {2} attempt",
|
||||
// DateTime.Now, objItems.Count, attempt));
|
||||
|
||||
ServiceProvider prov = new ServiceProvider();
|
||||
ServiceProviderProxy.Init(prov, serviceId);
|
||||
return prov.GetServiceItemsBandwidth(objItems.ToArray(), since);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("The number of attemtps has been reached. The package calculation has been aborted.");
|
||||
}
|
||||
|
||||
private string BuildDiskBandwidthStatisticsXml(ServiceProviderItemBandwidth[] itemsBandwidth)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("<items>");
|
||||
|
||||
if (itemsBandwidth != null)
|
||||
{
|
||||
CultureInfo culture = CultureInfo.InvariantCulture;
|
||||
|
||||
if (itemsBandwidth != null)
|
||||
{
|
||||
foreach (ServiceProviderItemBandwidth item in itemsBandwidth)
|
||||
{
|
||||
if (item != null && item.Days != null)
|
||||
{
|
||||
foreach (DailyStatistics day in item.Days)
|
||||
{
|
||||
string dt = new DateTime(day.Year, day.Month, day.Day).ToString("MM/dd/yyyy", culture);
|
||||
sb.Append("<item id=\"").Append(item.ItemId).Append("\"")
|
||||
.Append(" date=\"").Append(dt).Append("\"")
|
||||
.Append(" sent=\"").Append(day.BytesSent).Append("\"")
|
||||
.Append(" received=\"").Append(day.BytesReceived).Append("\"")
|
||||
.Append("></item>\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sb.Append("</items>");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,238 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using WebsitePanel.EnterpriseServer.Code.SharePoint;
|
||||
using WebsitePanel.Providers;
|
||||
using WebsitePanel.Providers.HostedSolution;
|
||||
using WebsitePanel.Providers.SharePoint;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class CalculatePackagesDiskspaceTask : SchedulerTask
|
||||
{
|
||||
private readonly bool suspendOverused = false;
|
||||
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - SUSPEND_OVERUSED_PACKAGES
|
||||
|
||||
CalculateDiskspace();
|
||||
}
|
||||
|
||||
public void CalculateDiskspace()
|
||||
{
|
||||
// get all owned packages
|
||||
List<PackageInfo> packages = PackageController.GetPackagePackages(TaskManager.PackageId, true);
|
||||
TaskManager.Write("Packages to calculate: " + packages.Count.ToString());
|
||||
|
||||
foreach (PackageInfo package in packages)
|
||||
{
|
||||
// calculating package diskspace
|
||||
CalculatePackage(package.PackageId);
|
||||
}
|
||||
}
|
||||
|
||||
public void CalculatePackage(int packageId)
|
||||
{
|
||||
try
|
||||
{
|
||||
// get all package items
|
||||
List<ServiceProviderItem> items = PackageController.GetServiceItemsForStatistics(
|
||||
0, packageId, true, false, false, false);
|
||||
|
||||
//TaskManager.Write("Items: " + items.Count);
|
||||
|
||||
// order items by service
|
||||
Dictionary<int, List<ServiceProviderItem>> orderedItems =
|
||||
PackageController.OrderServiceItemsByServices(items);
|
||||
|
||||
// calculate statistics for each service set
|
||||
List<ServiceProviderItemDiskSpace> itemsDiskspace = new List<ServiceProviderItemDiskSpace>();
|
||||
foreach (int serviceId in orderedItems.Keys)
|
||||
{
|
||||
ServiceProviderItemDiskSpace[] serviceDiskspace = CalculateItems(serviceId, orderedItems[serviceId]);
|
||||
if (serviceDiskspace != null)
|
||||
itemsDiskspace.AddRange(serviceDiskspace);
|
||||
}
|
||||
|
||||
// update info in the database
|
||||
string xml = BuildDiskSpaceStatisticsXml(itemsDiskspace.ToArray());
|
||||
PackageController.UpdatePackageDiskSpace(packageId, xml);
|
||||
//TaskManager.Write("XML: " + xml);
|
||||
|
||||
// suspend package if requested
|
||||
if (suspendOverused)
|
||||
{
|
||||
// disk space
|
||||
QuotaValueInfo dsQuota = PackageController.GetPackageQuota(packageId, Quotas.OS_DISKSPACE);
|
||||
|
||||
if (dsQuota.QuotaExhausted)
|
||||
PackageController.ChangePackageStatus(null, packageId, PackageStatus.Suspended, false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// load package details
|
||||
PackageInfo package = PackageController.GetPackage(packageId);
|
||||
|
||||
// load user details
|
||||
UserInfo user = PackageController.GetPackageOwner(package.PackageId);
|
||||
|
||||
// log error
|
||||
TaskManager.WriteError(String.Format("Error calculating diskspace for '{0}' space of user '{1}': {2}",
|
||||
package.PackageName, user.Username, ex.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetExchangeServiceID(int packageId)
|
||||
{
|
||||
return PackageController.GetPackageServiceId(packageId, ResourceGroups.Exchange);
|
||||
}
|
||||
|
||||
|
||||
public ServiceProviderItemDiskSpace[] CalculateItems(int serviceId, List<ServiceProviderItem> items)
|
||||
{
|
||||
// convert items to SoapObjects
|
||||
List<SoapServiceProviderItem> objItems = new List<SoapServiceProviderItem>();
|
||||
|
||||
//hack for organization... Refactoring!!!
|
||||
|
||||
|
||||
List<ServiceProviderItemDiskSpace> organizationDiskSpaces = new List<ServiceProviderItemDiskSpace>();
|
||||
foreach (ServiceProviderItem item in items)
|
||||
{
|
||||
long size = 0;
|
||||
if (item is Organization)
|
||||
{
|
||||
Organization org = (Organization) item;
|
||||
|
||||
//Exchange DiskSpace
|
||||
if (!string.IsNullOrEmpty(org.GlobalAddressList))
|
||||
{
|
||||
int exchangeServiceId = GetExchangeServiceID(org.PackageId);
|
||||
ServiceProvider exchangeProvider = ExchangeServerController.GetExchangeServiceProvider(exchangeServiceId, item.ServiceId);
|
||||
|
||||
SoapServiceProviderItem soapOrg = SoapServiceProviderItem.Wrap(org);
|
||||
ServiceProviderItemDiskSpace[] itemsDiskspace =
|
||||
exchangeProvider.GetServiceItemsDiskSpace(new SoapServiceProviderItem[] {soapOrg});
|
||||
|
||||
if (itemsDiskspace != null && itemsDiskspace.Length > 0)
|
||||
{
|
||||
size += itemsDiskspace[0].DiskSpace;
|
||||
}
|
||||
}
|
||||
|
||||
// Crm DiskSpace
|
||||
if (org.CrmOrganizationId != Guid.Empty)
|
||||
{
|
||||
//CalculateCrm DiskSpace
|
||||
}
|
||||
|
||||
//SharePoint DiskSpace
|
||||
|
||||
int res;
|
||||
|
||||
PackageContext cntx = PackageController.GetPackageContext(org.PackageId);
|
||||
|
||||
if (cntx.Groups.ContainsKey(ResourceGroups.HostedSharePoint))
|
||||
{
|
||||
SharePointSiteDiskSpace[] sharePointSiteDiskSpaces =
|
||||
HostedSharePointServerController.CalculateSharePointSitesDiskSpace(org.Id, out res);
|
||||
if (res == 0)
|
||||
{
|
||||
foreach (SharePointSiteDiskSpace currecnt in sharePointSiteDiskSpaces)
|
||||
{
|
||||
size += currecnt.DiskSpace;
|
||||
}
|
||||
}
|
||||
}
|
||||
ServiceProviderItemDiskSpace tmp = new ServiceProviderItemDiskSpace();
|
||||
tmp.ItemId = item.Id;
|
||||
tmp.DiskSpace = size;
|
||||
organizationDiskSpaces.Add(tmp);
|
||||
}
|
||||
else
|
||||
objItems.Add(SoapServiceProviderItem.Wrap(item));
|
||||
}
|
||||
|
||||
|
||||
int attempt = 0;
|
||||
int ATTEMPTS = 3;
|
||||
while (attempt < ATTEMPTS)
|
||||
{
|
||||
// increment attempt
|
||||
attempt++;
|
||||
|
||||
try
|
||||
{
|
||||
// send packet for calculation
|
||||
// invoke service provider
|
||||
//TaskManager.Write(String.Format("{0} - Invoke GetServiceItemsDiskSpace method ('{1}' items) - {2} attempt",
|
||||
// DateTime.Now, objItems.Count, attempt));
|
||||
|
||||
ServiceProvider prov = new ServiceProvider();
|
||||
ServiceProviderProxy.Init(prov, serviceId);
|
||||
ServiceProviderItemDiskSpace[] itemsDiskSpace = prov.GetServiceItemsDiskSpace(objItems.ToArray());
|
||||
if (itemsDiskSpace != null && itemsDiskSpace.Length > 0)
|
||||
organizationDiskSpaces.AddRange(itemsDiskSpace);
|
||||
|
||||
return organizationDiskSpaces.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("The number of attemtps has been reached. The package calculation has been aborted.");
|
||||
}
|
||||
|
||||
private string BuildDiskSpaceStatisticsXml(ServiceProviderItemDiskSpace[] itemsDiskspace)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("<items>");
|
||||
|
||||
if (itemsDiskspace != null)
|
||||
{
|
||||
foreach (ServiceProviderItemDiskSpace item in itemsDiskspace)
|
||||
{
|
||||
sb.Append("<item id=\"").Append(item.ItemId).Append("\"")
|
||||
.Append(" bytes=\"").Append(item.DiskSpace).Append("\"></item>\n");
|
||||
}
|
||||
}
|
||||
|
||||
sb.Append("</items>");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using WebsitePanel.EnterpriseServer;
|
||||
|
||||
namespace WebsitePanel.Ecommerce.EnterpriseServer
|
||||
{
|
||||
public class CancelOverdueInvoicesTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
// cancel overdue services
|
||||
CancelOverdueServices();
|
||||
}
|
||||
|
||||
public void CancelOverdueServices()
|
||||
{
|
||||
// load store settings
|
||||
StoreSettings settings = StorehouseController.GetStoreSettings(SecurityContext.User.UserId,
|
||||
StoreSettings.SYSTEM_SETTINGS);
|
||||
//
|
||||
int threshold = Convert.ToInt32(settings["SvcCancelThreshold"]);
|
||||
//
|
||||
TimeSpan ts = new TimeSpan(threshold, 0, 0, 0);
|
||||
// calculate actual suspend date
|
||||
DateTime dueDate = DateTime.Now.Subtract(ts);
|
||||
// lookup for overdue invoices
|
||||
List<InvoiceItem> items = InvoiceController.GetInvoicesItemsOverdue(SecurityContext.User.UserId, dueDate);
|
||||
// TRACE
|
||||
TaskManager.Write("Cancel overdue services");
|
||||
TaskManager.WriteParameter("Items found", items.Count);
|
||||
//
|
||||
foreach (InvoiceItem item in items)
|
||||
{
|
||||
try
|
||||
{
|
||||
TaskManager.Write("Cancelling service");
|
||||
// cancelling
|
||||
GenericSvcResult result = CancelService(item.ServiceId, true);
|
||||
// LOG ERROR
|
||||
if (!result.Succeed)
|
||||
{
|
||||
TaskManager.WriteError(result.Error);
|
||||
if (!String.IsNullOrEmpty(result.ErrorCode))
|
||||
TaskManager.WriteParameter("Error code", result.ErrorCode);
|
||||
TaskManager.WriteParameter("Result code", result.ResultCode);
|
||||
// go to next item
|
||||
continue;
|
||||
}
|
||||
//
|
||||
TaskManager.Write("Cancelled");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GenericSvcResult CancelService(int serviceId, bool sendEmail)
|
||||
{
|
||||
GenericSvcResult result = null;
|
||||
// load svc type
|
||||
ProductType svc_type = ServiceController.GetServiceItemType(serviceId);
|
||||
// instantiate svc controller
|
||||
IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
|
||||
Type.GetType(svc_type.ProvisioningController));
|
||||
// create context
|
||||
ProvisioningContext context = controller.GetProvisioningContext(serviceId, sendEmail);
|
||||
// cancel svc
|
||||
result = controller.CancelService(context);
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,233 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class CheckWebSiteTask : SchedulerTask
|
||||
{
|
||||
private class WebSiteResponse
|
||||
{
|
||||
public int Status;
|
||||
public string Text;
|
||||
}
|
||||
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - URL
|
||||
// - USERNAME
|
||||
// - PASSWORD
|
||||
// - RESPONSE_STATUS
|
||||
// - RESPONSE_CONTAIN
|
||||
// - RESPONSE_DOESNT_CONTAIN
|
||||
// - MAIL_FROM
|
||||
// - MAIL_TO
|
||||
// - MAIL_SUBJECT
|
||||
// - MAIL_BODY
|
||||
|
||||
// get input parameters
|
||||
string url = (string)TaskManager.TaskParameters["URL"];
|
||||
string username = (string)TaskManager.TaskParameters["USERNAME"];
|
||||
string password = (string)TaskManager.TaskParameters["PASSWORD"];
|
||||
string strResponseStatus = (string)TaskManager.TaskParameters["RESPONSE_STATUS"];
|
||||
string responseContains = (string)TaskManager.TaskParameters["RESPONSE_CONTAIN"];
|
||||
string responseNotContains = (string)TaskManager.TaskParameters["RESPONSE_DOESNT_CONTAIN"];
|
||||
|
||||
bool useResponseStatus = Convert.ToBoolean(TaskManager.TaskParameters["USE_RESPONSE_STATUS"]);
|
||||
bool useResponseContains = Convert.ToBoolean(TaskManager.TaskParameters["USE_RESPONSE_CONTAIN"]);
|
||||
bool useResponseDoesntContain = Convert.ToBoolean(TaskManager.TaskParameters["USE_RESPONSE_DOESNT_CONTAIN"]);
|
||||
|
||||
// check input parameters
|
||||
if (String.IsNullOrEmpty(url))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Web Site URL' task parameter.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((String.IsNullOrEmpty(strResponseStatus) || !useResponseStatus)
|
||||
&& (String.IsNullOrEmpty(responseContains) || !useResponseContains)
|
||||
&& (String.IsNullOrEmpty(responseNotContains) || !useResponseDoesntContain))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify one of 'Response Status', 'Response Contain' or 'Response Doesn't Contain' parameters.");
|
||||
return;
|
||||
}
|
||||
|
||||
int responseStatus = Utils.ParseInt(strResponseStatus, -1);
|
||||
if (!String.IsNullOrEmpty(strResponseStatus) && responseStatus == -1)
|
||||
{
|
||||
TaskManager.WriteWarning("Specify correct response HTTP status, e.g. 404, 500, 503, etc.");
|
||||
return;
|
||||
}
|
||||
|
||||
// load web site
|
||||
WebSiteResponse resp = GetWebDocument(url, username, password);
|
||||
|
||||
// check if there was a generic error
|
||||
if (resp.Status == -1)
|
||||
{
|
||||
SendMailMessage(url, resp.Text, "");
|
||||
}
|
||||
|
||||
bool sendMessage = false;
|
||||
|
||||
// check status
|
||||
if (responseStatus != -1)
|
||||
{
|
||||
sendMessage |= ((resp.Status == responseStatus) && useResponseStatus);
|
||||
}
|
||||
|
||||
// check "contains"
|
||||
if (!String.IsNullOrEmpty(responseContains))
|
||||
{
|
||||
sendMessage |= ((resp.Text.ToLower().IndexOf(responseContains.ToLower()) != -1) && useResponseContains);
|
||||
}
|
||||
|
||||
// check "not contains"
|
||||
if (!String.IsNullOrEmpty(responseNotContains))
|
||||
{
|
||||
sendMessage |= ((resp.Text.ToLower().IndexOf(responseNotContains.ToLower()) == -1) && useResponseDoesntContain);
|
||||
}
|
||||
|
||||
if (sendMessage)
|
||||
SendMailMessage(url, "", resp.Text);
|
||||
}
|
||||
|
||||
private void SendMailMessage(string url, string message, string content)
|
||||
{
|
||||
// input parameters
|
||||
string mailFrom = (string)TaskManager.TaskParameters["MAIL_FROM"];
|
||||
string mailTo = (string)TaskManager.TaskParameters["MAIL_TO"];
|
||||
string mailSubject = (string)TaskManager.TaskParameters["MAIL_SUBJECT"];
|
||||
string mailBody = (string)TaskManager.TaskParameters["MAIL_BODY"];
|
||||
|
||||
if (String.IsNullOrEmpty(mailTo))
|
||||
{
|
||||
TaskManager.WriteWarning("The e-mail message has not been sent because 'Mail To' is empty.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (String.IsNullOrEmpty(mailFrom))
|
||||
mailFrom = "automatic@localhost";
|
||||
|
||||
if (!String.IsNullOrEmpty(mailSubject))
|
||||
{
|
||||
mailSubject = Utils.ReplaceStringVariable(mailSubject, "url", url);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(mailBody))
|
||||
{
|
||||
mailBody = Utils.ReplaceStringVariable(mailBody, "url", url);
|
||||
mailBody = Utils.ReplaceStringVariable(mailBody, "message", message);
|
||||
mailBody = Utils.ReplaceStringVariable(mailBody, "content", content);
|
||||
}
|
||||
else
|
||||
{
|
||||
mailBody = message;
|
||||
}
|
||||
|
||||
// send mail message
|
||||
MailHelper.SendMessage(mailFrom, mailTo, mailSubject, mailBody, false);
|
||||
}
|
||||
}
|
||||
|
||||
private WebSiteResponse GetWebDocument(string url, string username, string password)
|
||||
{
|
||||
WebSiteResponse result = new WebSiteResponse();
|
||||
HttpWebResponse resp = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Stream respStream = null;
|
||||
try
|
||||
{
|
||||
WebRequest req = WebRequest.Create(url);
|
||||
|
||||
// set site credentials if required
|
||||
if (!String.IsNullOrEmpty(username))
|
||||
{
|
||||
req.Credentials = new NetworkCredential(username, password);
|
||||
}
|
||||
|
||||
resp = (HttpWebResponse)req.GetResponse();
|
||||
respStream = resp.GetResponseStream();
|
||||
string charSet = !String.IsNullOrEmpty(resp.CharacterSet) ? resp.CharacterSet : "utf-8";
|
||||
Encoding encode = System.Text.Encoding.GetEncoding(charSet);
|
||||
|
||||
StreamReader sr = new StreamReader(respStream, encode);
|
||||
|
||||
Char[] read = new Char[256];
|
||||
int count = sr.Read(read, 0, 256);
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
String str = new String(read, 0, count);
|
||||
sb.Append(str);
|
||||
count = sr.Read(read, 0, 256);
|
||||
}
|
||||
|
||||
result.Status = (int)resp.StatusCode;
|
||||
result.Text = sb.ToString();
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
result.Status = (int)((HttpWebResponse)ex.Response).StatusCode;
|
||||
result.Text = ex.ToString();
|
||||
TaskManager.WriteError(ex.ToString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Status = -1;
|
||||
result.Text = ex.ToString();
|
||||
TaskManager.WriteError(ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (respStream != null)
|
||||
{
|
||||
respStream.Close();
|
||||
}
|
||||
|
||||
if (resp != null)
|
||||
{
|
||||
resp.Close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using WebsitePanel.Server;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class FTPFilesTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - FILE_PATH
|
||||
// - FTP_SERVER
|
||||
// - FTP_USERNAME
|
||||
// - FTP_PASSWORD
|
||||
// - FTP_FOLDER
|
||||
|
||||
// get input parameters
|
||||
string filePath = (string)TaskManager.TaskParameters["FILE_PATH"];
|
||||
string ftpServer = (string)TaskManager.TaskParameters["FTP_SERVER"];
|
||||
string ftpUsername = (string)TaskManager.TaskParameters["FTP_USERNAME"];
|
||||
string ftpPassword = (string)TaskManager.TaskParameters["FTP_PASSWORD"];
|
||||
string ftpFolder = (string)TaskManager.TaskParameters["FTP_FOLDER"];
|
||||
|
||||
// check input parameters
|
||||
if (String.IsNullOrEmpty(filePath))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'File' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(ftpServer))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'FTP Server' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
// substitute parameters
|
||||
DateTime d = DateTime.Now;
|
||||
string date = d.ToString("yyyyMMdd");
|
||||
string time = d.ToString("HHmm");
|
||||
|
||||
filePath = Utils.ReplaceStringVariable(filePath, "date", date);
|
||||
filePath = Utils.ReplaceStringVariable(filePath, "time", time);
|
||||
|
||||
// build FTP command file
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringWriter writer = new StringWriter(sb);
|
||||
|
||||
// FTP server
|
||||
writer.WriteLine("open " + ftpServer);
|
||||
|
||||
// check if anonymous mode
|
||||
if (String.IsNullOrEmpty(ftpUsername))
|
||||
{
|
||||
ftpUsername = "anonymous";
|
||||
ftpPassword = "anonymous@email.com";
|
||||
}
|
||||
|
||||
// FTP username/password
|
||||
writer.WriteLine(ftpUsername);
|
||||
writer.WriteLine(ftpPassword);
|
||||
|
||||
// check if we need to change remote folder
|
||||
if (!String.IsNullOrEmpty(ftpFolder))
|
||||
{
|
||||
writer.WriteLine("cd " + ftpFolder.Replace("\\", "/"));
|
||||
}
|
||||
|
||||
// file to send
|
||||
writer.WriteLine("binary");
|
||||
writer.WriteLine("put " + FilesController.GetFullPackagePath(TaskManager.PackageId, filePath));
|
||||
|
||||
// bye
|
||||
writer.WriteLine("bye");
|
||||
|
||||
string cmdBatch = sb.ToString();
|
||||
|
||||
// create temp file in user space
|
||||
string cmdPath = Utils.GetRandomString(10) + ".txt";
|
||||
string fullCmdPath = FilesController.GetFullPackagePath(TaskManager.PackageId, cmdPath);
|
||||
|
||||
// upload batch
|
||||
FilesController.UpdateFileBinaryContent(TaskManager.PackageId, cmdPath, Encoding.UTF8.GetBytes(cmdBatch));
|
||||
|
||||
// execute system command
|
||||
// load OS service
|
||||
int serviceId = PackageController.GetPackageServiceId(TaskManager.PackageId, ResourceGroups.Os);
|
||||
|
||||
// load service
|
||||
ServiceInfo service = ServerController.GetServiceInfo(serviceId);
|
||||
if (service == null)
|
||||
return;
|
||||
|
||||
WindowsServer winServer = new WindowsServer();
|
||||
ServiceProviderProxy.ServerInit(winServer, service.ServerId);
|
||||
TaskManager.Write(winServer.ExecuteSystemCommand("ftp.exe", "-s:" + fullCmdPath));
|
||||
|
||||
// delete batch file
|
||||
FilesController.DeleteFiles(TaskManager.PackageId, new string[] { cmdPath });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using WebsitePanel.EnterpriseServer;
|
||||
|
||||
namespace WebsitePanel.Ecommerce.EnterpriseServer
|
||||
{
|
||||
public class GenerateInvoicesTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
// invoice active services
|
||||
InvoiceActiveServices();
|
||||
}
|
||||
|
||||
public void InvoiceActiveServices()
|
||||
{
|
||||
DateTime dateTimeNow = DateTime.Now;
|
||||
// load store settings
|
||||
StoreSettings settings = StorehouseController.GetStoreSettings(SecurityContext.User.UserId,
|
||||
StoreSettings.SYSTEM_SETTINGS);
|
||||
//
|
||||
int threshold = Convert.ToInt32(settings["SvcInvoiceThreshold"]);
|
||||
// get expiring services today
|
||||
List<Service> services = ServiceController.GetServicesToInvoice(SecurityContext.User.UserId,
|
||||
dateTimeNow, threshold);
|
||||
// group services by users
|
||||
Dictionary<string, List<int>> usersServices = new Dictionary<string, List<int>>();
|
||||
// iterate
|
||||
foreach (Service service in services)
|
||||
{
|
||||
if (!usersServices.ContainsKey(service.ContractId))
|
||||
usersServices.Add(service.ContractId, new List<int>());
|
||||
|
||||
usersServices[service.ContractId].Add(service.ServiceId);
|
||||
}
|
||||
// generate invoice per contract
|
||||
foreach (string contractId in usersServices.Keys)
|
||||
{
|
||||
try
|
||||
{
|
||||
TaskManager.Write("Creating invoice");
|
||||
// TRACE
|
||||
Contract contract = ContractSystem.ContractController.GetContract(contractId);
|
||||
ContractAccount account = ContractSystem.ContractController.GetContractAccountSettings(contractId);
|
||||
TaskManager.WriteParameter("ContractID", contractId);
|
||||
TaskManager.WriteParameter("Username", account[ContractAccount.USERNAME]);
|
||||
//
|
||||
List<int> userSvcs = usersServices[contractId];
|
||||
// build invoice items
|
||||
List<InvoiceItem> invoiceLines = InvoiceController.CalculateInvoiceLinesForServices(userSvcs);
|
||||
//
|
||||
int resultCode = InvoiceController.AddInvoice(contractId, invoiceLines, null);
|
||||
//
|
||||
if (resultCode < 1)
|
||||
{
|
||||
TaskManager.WriteParameter("ResultCode", resultCode);
|
||||
continue;
|
||||
}
|
||||
//
|
||||
if (ServiceController.SetUsageRecordsClosed(userSvcs.ToArray()) != 0)
|
||||
TaskManager.WriteWarning("Unable to close usage records automatically");
|
||||
// TRACE
|
||||
TaskManager.WriteParameter("InvoiceID", resultCode);
|
||||
TaskManager.Write("Succeed");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Mail;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using WebsitePanel.EnterpriseServer.Code.HostedSolution;
|
||||
using WebsitePanel.Providers.HostedSolution;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class HostedSolutionReportTask : SchedulerTask
|
||||
{
|
||||
private static readonly string EXCHANGE_REPORT = "EXCHANGE_REPORT";
|
||||
private static readonly string ORGANIZATION_REPORT = "ORGANIZATION_REPORT";
|
||||
private static readonly string SHAREPOINT_REPORT = "SHAREPOINT_REPORT";
|
||||
private static readonly string LYNC_REPORT = "LYNC_REPORT";
|
||||
private static readonly string CRM_REPORT = "CRM_REPORT";
|
||||
private static readonly string EMAIL = "EMAIL";
|
||||
|
||||
|
||||
public override void DoWork()
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isExchange = Utils.ParseBool(TaskManager.TaskParameters[EXCHANGE_REPORT], false);
|
||||
bool isSharePoint = Utils.ParseBool(TaskManager.TaskParameters[SHAREPOINT_REPORT], false);
|
||||
bool isLync = Utils.ParseBool(TaskManager.TaskParameters[LYNC_REPORT], false);
|
||||
bool isCRM = Utils.ParseBool(TaskManager.TaskParameters[CRM_REPORT], false);
|
||||
bool isOrganization = Utils.ParseBool(TaskManager.TaskParameters[ORGANIZATION_REPORT], false);
|
||||
|
||||
string email = TaskManager.TaskParameters[EMAIL].ToString();
|
||||
|
||||
|
||||
UserInfo user = PackageController.GetPackageOwner(TaskManager.PackageId);
|
||||
EnterpriseSolutionStatisticsReport report =
|
||||
ReportController.GetEnterpriseSolutionStatisticsReport(user.UserId, isExchange, isSharePoint, isCRM,
|
||||
isOrganization, isLync);
|
||||
|
||||
|
||||
SendMessage(user, email, isExchange && report.ExchangeReport != null ? report.ExchangeReport.ToCSV() : string.Empty,
|
||||
isSharePoint && report.SharePointReport != null ? report.SharePointReport.ToCSV() : string.Empty,
|
||||
isCRM && report.CRMReport != null ? report.CRMReport.ToCSV() : string.Empty,
|
||||
isOrganization && report.OrganizationReport != null ? report.OrganizationReport.ToCSV() : string.Empty,
|
||||
isLync && report.LyncReport != null ? report.LyncReport.ToCSV() : string.Empty);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void PrepareAttament(string name, string csv, List<Attachment> attacments)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(csv))
|
||||
{
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
|
||||
byte[] buffer = encoding.GetBytes(csv);
|
||||
MemoryStream stream = new MemoryStream(buffer);
|
||||
Attachment attachment = new Attachment(stream, name, MediaTypeNames.Text.Plain);
|
||||
|
||||
attacments.Add(attachment);
|
||||
}
|
||||
}
|
||||
|
||||
private void SendMessage(UserInfo user,string email, string exchange_csv, string sharepoint_csv, string crm_csv, string organization_csv, string lync_csv)
|
||||
{
|
||||
List<Attachment> attacments = new List<Attachment>();
|
||||
PrepareAttament("exchange.csv", exchange_csv, attacments);
|
||||
PrepareAttament("sharepoint.csv", sharepoint_csv, attacments);
|
||||
PrepareAttament("lync.csv", lync_csv, attacments);
|
||||
PrepareAttament("crm.csv", crm_csv, attacments);
|
||||
PrepareAttament("organization.csv", organization_csv, attacments);
|
||||
|
||||
|
||||
|
||||
|
||||
// get letter settings
|
||||
UserSettings settings = UserController.GetUserSettings(user.UserId, UserSettings.HOSTED_SOLUTION_REPORT);
|
||||
|
||||
string from = settings["From"];
|
||||
string cc = settings["CC"];
|
||||
string subject = settings["Subject"];
|
||||
string body = user.HtmlMail ? settings["HtmlBody"] : settings["TextBody"];
|
||||
bool isHtml = user.HtmlMail;
|
||||
|
||||
MailPriority priority = MailPriority.Normal;
|
||||
|
||||
MailHelper.SendMessage(from, email, cc, subject, body, priority, isHtml, attacments.ToArray());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,267 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class NotifyOverusedDatabasesTask : SchedulerTask
|
||||
{
|
||||
public const string DISKSPACE_FORMAT_STRING = "{0} - {1}Mb ({2}%)";
|
||||
public const string ALLOC_FORMAT_STRING = "{0} - {1}Mb";
|
||||
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - DISKSPACE_OVERUSED
|
||||
// - BANDWIDTH_OVERUSED
|
||||
|
||||
// get the list of all packages
|
||||
List<PackageInfo> packages = PackageController.GetPackagePackages(TaskManager.PackageId, false);
|
||||
TaskManager.Write("Packages to verify: " + packages.Count.ToString());
|
||||
|
||||
bool checkMSSQL = (String.Compare((string)TaskManager.TaskParameters["MSSQL_OVERUSED"], "true", true) == 0);
|
||||
bool checkMySQL = (String.Compare((string)TaskManager.TaskParameters["MYSQL_OVERUSED"], "true", true) == 0);
|
||||
|
||||
bool sendWarningEmail = Convert.ToBoolean(TaskManager.TaskParameters["SEND_WARNING_EMAIL"]);
|
||||
bool sendOverusedEmail = Convert.ToBoolean(TaskManager.TaskParameters["SEND_OVERUSED_EMAIL"]);
|
||||
int warningUsageThreshold = Convert.ToInt32(TaskManager.TaskParameters["WARNING_USAGE_THRESHOLD"]);
|
||||
int overusedUsageThreshold = Convert.ToInt32(TaskManager.TaskParameters["OVERUSED_USAGE_THRESHOLD"]);
|
||||
string warningMailFrom = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_FROM"]);
|
||||
string warningMailBcc = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_BCC"]);
|
||||
string warningMailSubject = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_SUBJECT"]);
|
||||
string warningMailBody = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_BODY"]);
|
||||
string overusedMailFrom = Convert.ToString(TaskManager.TaskParameters["OVERUSED_MAIL_FROM"]);
|
||||
string overusedMailBcc = Convert.ToString(TaskManager.TaskParameters["OVERUSED_MAIL_BCC"]);
|
||||
string overusedMailSubject = Convert.ToString(TaskManager.TaskParameters["OVERUSED_MAIL_SUBJECT"]);
|
||||
string overusedMailBody = Convert.ToString(TaskManager.TaskParameters["OVERUSED_MAIL_BODY"]);
|
||||
|
||||
int overusedPackages = 0;
|
||||
|
||||
foreach (PackageInfo package in packages)
|
||||
{
|
||||
UserInfo userInfo = UserController.GetUser(package.UserId);
|
||||
|
||||
List<DatabaseQuota> quotaMSSQL = new List<DatabaseQuota>();
|
||||
List<DatabaseQuota> quotaMYSQL = new List<DatabaseQuota>();
|
||||
|
||||
if (checkMSSQL || checkMySQL)
|
||||
{
|
||||
QuotaValueInfo dsQuota = null;
|
||||
DataSet Diskspace = PackageController.GetPackageDiskspace(package.PackageId);
|
||||
foreach (DataRow spaceRow in Diskspace.Tables[0].Rows)
|
||||
{
|
||||
string groupName = spaceRow["GroupName"].ToString();
|
||||
if (checkMSSQL && groupName.ToUpper().Contains("MSSQL"))
|
||||
{
|
||||
dsQuota = PackageController.GetPackageQuota(package.PackageId, groupName + ".MaxDatabaseSize");
|
||||
if (dsQuota.QuotaAllocatedValue > 0)
|
||||
{
|
||||
int databaseSpaceUsage = Convert.ToInt32(spaceRow["Diskspace"]) * 100 / dsQuota.QuotaAllocatedValue;
|
||||
quotaMSSQL.Add(new DatabaseQuota(groupName.ToUpper().Replace("MSSQL","SQL Server "),
|
||||
Convert.ToInt32(spaceRow["Diskspace"]), dsQuota.QuotaAllocatedValue,
|
||||
databaseSpaceUsage < warningUsageThreshold,
|
||||
databaseSpaceUsage < overusedUsageThreshold));
|
||||
}
|
||||
}
|
||||
if (checkMySQL && groupName.ToUpper().Contains("MYSQL"))
|
||||
{
|
||||
dsQuota = PackageController.GetPackageQuota(package.PackageId, groupName + ".MaxDatabaseSize");
|
||||
if (dsQuota.QuotaAllocatedValue > 0)
|
||||
{
|
||||
int databaseSpaceUsage = Convert.ToInt32(spaceRow["Diskspace"]) * 100 / dsQuota.QuotaAllocatedValue;
|
||||
quotaMYSQL.Add(new DatabaseQuota(groupName.ToUpper().Replace("MYSQL", "MySQL "),
|
||||
Convert.ToInt32(spaceRow["Diskspace"]), dsQuota.QuotaAllocatedValue,
|
||||
databaseSpaceUsage < warningUsageThreshold,
|
||||
databaseSpaceUsage < overusedUsageThreshold));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string userName = String.Format("{0} {1} ({2})/{3}", userInfo.FirstName, userInfo.LastName, userInfo.Username, userInfo.Email);
|
||||
bool notifyOverusedByMail = false;
|
||||
bool notifyWarningByMail = false;
|
||||
List<string> formatItems = new List<string>();
|
||||
List<string> formatWarningThreshold = new List<string>();
|
||||
List<string> formatOverusedThreshold = new List<string>();
|
||||
// add Microsoft SQL usage if enabled
|
||||
if (checkMSSQL)
|
||||
{
|
||||
foreach (DatabaseQuota q in quotaMSSQL)
|
||||
{
|
||||
if (!q.BelowWarningThreshold || !q.BelowUsageThreshold)
|
||||
{
|
||||
formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, q.ProviderName, q.SpaceUsed, q.SpaceUsed * 100 / q.SpaceAllocated));
|
||||
}
|
||||
if (!q.BelowWarningThreshold)
|
||||
{
|
||||
formatWarningThreshold.Add(String.Format(ALLOC_FORMAT_STRING, q.ProviderName, q.SpaceAllocated));
|
||||
notifyWarningByMail = true;
|
||||
}
|
||||
if (!q.BelowUsageThreshold)
|
||||
{
|
||||
formatOverusedThreshold.Add(String.Format(ALLOC_FORMAT_STRING, q.ProviderName, q.SpaceAllocated));
|
||||
notifyOverusedByMail = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add MySQL usage if enabled
|
||||
if (checkMySQL)
|
||||
{
|
||||
foreach (DatabaseQuota q in quotaMYSQL)
|
||||
{
|
||||
if (!q.BelowWarningThreshold || !q.BelowUsageThreshold)
|
||||
{
|
||||
formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, q.ProviderName, q.SpaceUsed, (q.SpaceUsed * 100) / q.SpaceAllocated));
|
||||
}
|
||||
if (!q.BelowWarningThreshold)
|
||||
{
|
||||
formatWarningThreshold.Add(String.Format(ALLOC_FORMAT_STRING, q.ProviderName, q.SpaceAllocated));
|
||||
notifyWarningByMail = true;
|
||||
}
|
||||
if (!q.BelowUsageThreshold)
|
||||
{
|
||||
formatOverusedThreshold.Add(String.Format(ALLOC_FORMAT_STRING, q.ProviderName, q.SpaceAllocated));
|
||||
notifyOverusedByMail = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// build usage strings
|
||||
string usage = String.Join("\n", formatItems.ToArray());
|
||||
string usageWarning = String.Join("\n", formatWarningThreshold.ToArray());
|
||||
string usageOverused = String.Join("\n", formatOverusedThreshold.ToArray());
|
||||
|
||||
string warningMailSubjectProcessed = ReplaceVariables(warningMailSubject, usageWarning, usage, package.PackageName, userName);
|
||||
string warningMailBodyProcessed = ReplaceVariables(warningMailBody, usageWarning, usage, package.PackageName, userName);
|
||||
|
||||
string overusedMailSubjectProcessed = ReplaceVariables(overusedMailSubject, usageOverused, usage, package.PackageName, userName);
|
||||
string overusedMailBodyProcessed = ReplaceVariables(overusedMailBody, usageOverused, usage, package.PackageName, userName);
|
||||
|
||||
|
||||
// Send email notifications
|
||||
if (sendWarningEmail && notifyWarningByMail)
|
||||
{
|
||||
// Send warning email.
|
||||
this.SendEmail(warningMailFrom, userInfo.Email, warningMailBcc, warningMailSubjectProcessed, warningMailBodyProcessed, false);
|
||||
}
|
||||
|
||||
if (sendOverusedEmail && notifyOverusedByMail)
|
||||
{
|
||||
// Send overused email.
|
||||
this.SendEmail(overusedMailFrom, userInfo.Email, overusedMailBcc, overusedMailSubjectProcessed, overusedMailBodyProcessed, false);
|
||||
}
|
||||
if (notifyOverusedByMail)
|
||||
{
|
||||
overusedPackages++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log results
|
||||
TaskManager.Write("Total packages overused: " + overusedPackages.ToString());
|
||||
}
|
||||
|
||||
private string ReplaceVariables(string content, string threshold, string usage, string spaceName, string customerName)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(content))
|
||||
{
|
||||
content = Utils.ReplaceStringVariable(content, "threshold", threshold);
|
||||
content = Utils.ReplaceStringVariable(content, "date", DateTime.Now.ToString());
|
||||
content = Utils.ReplaceStringVariable(content, "usage", usage);
|
||||
content = Utils.ReplaceStringVariable(content, "space", spaceName);
|
||||
content = Utils.ReplaceStringVariable(content, "customer", customerName);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
private void SendEmail(string from, string to, string bcc, string subject, string body, bool isHtml)
|
||||
{
|
||||
// check input parameters
|
||||
if (String.IsNullOrEmpty(from))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Mail From' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(to))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Mail To' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
// send mail message
|
||||
MailHelper.SendMessage(from, to, bcc, subject, body, isHtml);
|
||||
}
|
||||
}
|
||||
|
||||
internal class DatabaseQuota
|
||||
{
|
||||
private string providerName = string.Empty;
|
||||
private int spaceUsed = 0;
|
||||
private int spaceAllocated = 0;
|
||||
private bool belowWarningThreshold = false;
|
||||
private bool belowUsageThreshold = false;
|
||||
public DatabaseQuota(string ProviderName, int SpaceUsed, int SpaceAllocated, bool BelowWarningThreshold, bool BelowUsageThreshold)
|
||||
{
|
||||
providerName = ProviderName;
|
||||
spaceUsed = SpaceUsed;
|
||||
spaceAllocated = SpaceAllocated;
|
||||
belowWarningThreshold = BelowWarningThreshold;
|
||||
belowUsageThreshold = BelowUsageThreshold;
|
||||
}
|
||||
|
||||
public string ProviderName
|
||||
{
|
||||
get { return providerName; }
|
||||
}
|
||||
|
||||
public int SpaceUsed
|
||||
{
|
||||
get { return spaceUsed; }
|
||||
}
|
||||
|
||||
public int SpaceAllocated
|
||||
{
|
||||
get { return spaceAllocated; }
|
||||
}
|
||||
|
||||
public bool BelowWarningThreshold
|
||||
{
|
||||
get { return belowWarningThreshold; }
|
||||
}
|
||||
|
||||
public bool BelowUsageThreshold
|
||||
{
|
||||
get { return belowUsageThreshold; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using WebsitePanel.EnterpriseServer;
|
||||
|
||||
namespace WebsitePanel.Ecommerce.EnterpriseServer
|
||||
{
|
||||
public class RunPaymentQueueTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
// run payment queue
|
||||
RunPaymentQueue();
|
||||
}
|
||||
|
||||
public void RunPaymentQueue()
|
||||
{
|
||||
int resellerId = SecurityContext.User.UserId;
|
||||
// 1. load unpaid invoices
|
||||
List<Invoice> invoices = InvoiceController.GetUnpaidInvoices(resellerId);
|
||||
// TRACE
|
||||
TaskManager.Write("Running payment queue");
|
||||
TaskManager.WriteParameter("Items found", invoices.Count);
|
||||
// 2. load payment profile for each customer
|
||||
foreach (Invoice invoice in invoices)
|
||||
{
|
||||
try
|
||||
{
|
||||
// load payment profile
|
||||
CheckoutDetails details = StorehouseController.GetPaymentProfileInternally(invoice.ContractId);
|
||||
//
|
||||
if (details != null)
|
||||
{
|
||||
// TRACE
|
||||
TaskManager.Write("Trying to submit payment");
|
||||
TaskManager.WriteParameter("InvoiceID", invoice.InvoiceId);
|
||||
// 3. submit payment for each invoice if profile exists
|
||||
CheckoutResult result = PaymentGatewayController.CheckOut(invoice.ContractId,
|
||||
invoice.InvoiceId, PaymentMethod.CREDIT_CARD, details);
|
||||
// ERROR
|
||||
if (!result.Succeed)
|
||||
{
|
||||
TaskManager.WriteError("Payment failed");
|
||||
TaskManager.WriteParameter("Result code", result.StatusCode);
|
||||
continue;
|
||||
}
|
||||
// OK
|
||||
TaskManager.Write("Payment OK");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex, "Payment failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using WebsitePanel.Server;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class RunSystemCommandTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - SERVER_NAME
|
||||
// - EXECUTABLE_PATH
|
||||
|
||||
// get input parameters
|
||||
string serverName = (string)TaskManager.TaskParameters["SERVER_NAME"];
|
||||
string execPath = (string)TaskManager.TaskParameters["EXECUTABLE_PATH"];
|
||||
string execParams = (string)TaskManager.TaskParameters["EXECUTABLE_PARAMS"];
|
||||
|
||||
if (execParams == null)
|
||||
execParams = "";
|
||||
|
||||
// check input parameters
|
||||
if (String.IsNullOrEmpty(serverName))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Server Name' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(execPath))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Executable Path' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
// find server by name
|
||||
ServerInfo server = ServerController.GetServerByName(serverName);
|
||||
if (server == null)
|
||||
{
|
||||
TaskManager.WriteWarning(String.Format("Server with the name '{0}' was not found", serverName));
|
||||
return;
|
||||
}
|
||||
|
||||
// execute system command
|
||||
WindowsServer winServer = new WindowsServer();
|
||||
ServiceProviderProxy.ServerInit(winServer, server.ServerId);
|
||||
TaskManager.Write(winServer.ExecuteSystemCommand(execPath, execParams));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class SendMailNotificationTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - MAIL_FROM
|
||||
// - MAIL_TO
|
||||
// - MAIL_SUBJECT
|
||||
// - MAIL_BODY
|
||||
|
||||
// get input parameters
|
||||
string mailFrom = (string)TaskManager.TaskParameters["MAIL_FROM"];
|
||||
string mailTo = (string)TaskManager.TaskParameters["MAIL_TO"];
|
||||
string mailSubject = (string)TaskManager.TaskParameters["MAIL_SUBJECT"];
|
||||
string mailBody = (string)TaskManager.TaskParameters["MAIL_BODY"];
|
||||
|
||||
// check input parameters
|
||||
if (String.IsNullOrEmpty(mailFrom))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Mail From' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(mailTo))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Mail To' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(mailSubject))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Mail Subject' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
// send mail message
|
||||
MailHelper.SendMessage(mailFrom, mailTo, mailSubject, mailBody, false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using WebsitePanel.EnterpriseServer;
|
||||
|
||||
namespace WebsitePanel.Ecommerce.EnterpriseServer
|
||||
{
|
||||
public class SuspendOverdueInvoicesTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
// suspend overdue services
|
||||
SuspendOverdueServices();
|
||||
}
|
||||
|
||||
public GenericSvcResult SuspendService(int serviceId, bool sendEmail)
|
||||
{
|
||||
GenericSvcResult result = null;
|
||||
// load svc type
|
||||
ProductType svc_type = ServiceController.GetServiceItemType(serviceId);
|
||||
// instantiate svc controller
|
||||
IServiceProvisioning controller = (IServiceProvisioning)Activator.CreateInstance(
|
||||
Type.GetType(svc_type.ProvisioningController));
|
||||
// create context
|
||||
ProvisioningContext context = controller.GetProvisioningContext(serviceId, sendEmail);
|
||||
// suspend svc
|
||||
result = controller.SuspendService(context);
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SuspendOverdueServices()
|
||||
{
|
||||
// lookup for today's overdue invoices
|
||||
List<InvoiceItem> items = InvoiceController.GetInvoicesItemsOverdue(SecurityContext.User.UserId, DateTime.Now);
|
||||
// TRACE
|
||||
TaskManager.Write("Suspend overdue services");
|
||||
TaskManager.WriteParameter("Items found", items.Count);
|
||||
//
|
||||
foreach (InvoiceItem item in items)
|
||||
{
|
||||
try
|
||||
{
|
||||
TaskManager.Write("Suspending service");
|
||||
// suspending
|
||||
GenericSvcResult result = SuspendService(item.ServiceId, true);
|
||||
// LOG ERROR
|
||||
if (!result.Succeed)
|
||||
{
|
||||
TaskManager.WriteError(result.Error);
|
||||
if (!String.IsNullOrEmpty(result.ErrorCode))
|
||||
TaskManager.WriteParameter("Error code", result.ErrorCode);
|
||||
TaskManager.WriteParameter("Result code", result.ResultCode);
|
||||
// go to next item
|
||||
continue;
|
||||
}
|
||||
//
|
||||
TaskManager.Write("Suspended");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskManager.WriteError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,211 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class SuspendOverusedPackagesTask : SchedulerTask
|
||||
{
|
||||
public const string DISKSPACE_FORMAT_STRING = "disk space usage - {0}%";
|
||||
public const string BANDWIDTH_FORMAT_STRING = "bandwidth usage - {0}%";
|
||||
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - DISKSPACE_OVERUSED
|
||||
// - BANDWIDTH_OVERUSED
|
||||
|
||||
// get the list of all packages
|
||||
List<PackageInfo> packages = PackageController.GetPackagePackages(TaskManager.PackageId, false);
|
||||
TaskManager.Write("Packages to verify: " + packages.Count.ToString());
|
||||
|
||||
bool checkDiskspace = (String.Compare((string)TaskManager.TaskParameters["DISKSPACE_OVERUSED"], "true", true) == 0);
|
||||
bool checkBandwidth = (String.Compare((string)TaskManager.TaskParameters["BANDWIDTH_OVERUSED"], "true", true) == 0);
|
||||
|
||||
bool suspendOverused = Convert.ToBoolean(TaskManager.TaskParameters["SUSPEND_OVERUSED"]);
|
||||
|
||||
bool sendWarningEmail = Convert.ToBoolean(TaskManager.TaskParameters["SEND_WARNING_EMAIL"]);
|
||||
bool sendSuspensionEmail = Convert.ToBoolean(TaskManager.TaskParameters["SEND_SUSPENSION_EMAIL"]);
|
||||
int warningUsageThreshold = Convert.ToInt32(TaskManager.TaskParameters["WARNING_USAGE_THRESHOLD"]);
|
||||
int suspensionUsageThreshold = Convert.ToInt32(TaskManager.TaskParameters["SUSPENSION_USAGE_THRESHOLD"]);
|
||||
string warningMailFrom = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_FROM"]);
|
||||
string warningMailBcc = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_BCC"]);
|
||||
string warningMailSubject = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_SUBJECT"]);
|
||||
string warningMailBody = Convert.ToString(TaskManager.TaskParameters["WARNING_MAIL_BODY"]);
|
||||
string suspensionMailFrom = Convert.ToString(TaskManager.TaskParameters["SUSPENSION_MAIL_FROM"]);
|
||||
string suspensionMailBcc = Convert.ToString(TaskManager.TaskParameters["SUSPENSION_MAIL_BCC"]);
|
||||
string suspensionMailSubject = Convert.ToString(TaskManager.TaskParameters["SUSPENSION_MAIL_SUBJECT"]);
|
||||
string suspensionMailBody = Convert.ToString(TaskManager.TaskParameters["SUSPENSION_MAIL_BODY"]);
|
||||
|
||||
int suspendedPackages = 0;
|
||||
|
||||
foreach (PackageInfo package in packages)
|
||||
{
|
||||
bool isBandwidthBelowWarningThreshold = true;
|
||||
bool isBandwidthBelowSuspensionThreshold = true;
|
||||
bool isDiskSpaceBelowWarningThreshold = true;
|
||||
bool isDiskSpaceBelowSuspensionThreshold = true;
|
||||
|
||||
UserInfo userInfo = UserController.GetUser(package.UserId);
|
||||
|
||||
int diskSpaceUsage = 0;
|
||||
int bandwidthUsage = 0;
|
||||
// disk space
|
||||
if (checkDiskspace)
|
||||
{
|
||||
QuotaValueInfo dsQuota = PackageController.GetPackageQuota(package.PackageId, Quotas.OS_DISKSPACE);
|
||||
if (dsQuota.QuotaAllocatedValue > 0)
|
||||
{
|
||||
diskSpaceUsage = (dsQuota.QuotaUsedValue*100/dsQuota.QuotaAllocatedValue);
|
||||
isDiskSpaceBelowWarningThreshold = diskSpaceUsage < warningUsageThreshold;
|
||||
isDiskSpaceBelowSuspensionThreshold = diskSpaceUsage < suspensionUsageThreshold;
|
||||
}
|
||||
}
|
||||
|
||||
// bandwidth
|
||||
if (checkBandwidth)
|
||||
{
|
||||
QuotaValueInfo bwQuota = PackageController.GetPackageQuota(package.PackageId, Quotas.OS_BANDWIDTH);
|
||||
if (bwQuota.QuotaAllocatedValue > 0)
|
||||
{
|
||||
bandwidthUsage = (bwQuota.QuotaUsedValue*100/bwQuota.QuotaAllocatedValue);
|
||||
isBandwidthBelowWarningThreshold = bandwidthUsage < warningUsageThreshold;
|
||||
isBandwidthBelowSuspensionThreshold = bandwidthUsage < suspensionUsageThreshold;
|
||||
}
|
||||
}
|
||||
|
||||
string userName = String.Format("{0} {1} ({2})/{3}", userInfo.FirstName, userInfo.LastName, userInfo.Username, userInfo.Email);
|
||||
//
|
||||
List<string> formatItems = new List<string>();
|
||||
// add diskspace usage if enabled
|
||||
if (checkDiskspace) formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, diskSpaceUsage));
|
||||
// add bandwidth usage if enabled
|
||||
if (checkBandwidth) formatItems.Add(String.Format(BANDWIDTH_FORMAT_STRING, bandwidthUsage));
|
||||
// build usage string
|
||||
string usage = String.Join(", ", formatItems.ToArray());
|
||||
|
||||
// cleanup items
|
||||
formatItems.Clear();
|
||||
// add diskspace warning max usage
|
||||
if (checkDiskspace) formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, warningUsageThreshold));
|
||||
// add bandwidth warning max usage
|
||||
if (checkBandwidth) formatItems.Add(String.Format(BANDWIDTH_FORMAT_STRING, warningUsageThreshold));
|
||||
// build warning max usage string
|
||||
string warningMaxUsage = String.Join(", ", formatItems.ToArray());
|
||||
|
||||
// cleanup items
|
||||
formatItems.Clear();
|
||||
// add diskspace suspension max usage
|
||||
if (checkDiskspace) formatItems.Add(String.Format(DISKSPACE_FORMAT_STRING, suspensionUsageThreshold));
|
||||
// add bandwidth suspension max usage
|
||||
if (checkBandwidth) formatItems.Add(String.Format(BANDWIDTH_FORMAT_STRING, suspensionUsageThreshold));
|
||||
// build suspension max usage string
|
||||
string suspensionMaxUsage = String.Join(", ", formatItems.ToArray());
|
||||
|
||||
string warningMailSubjectProcessed = ReplaceVariables(warningMailSubject, warningMaxUsage, usage, package.PackageName, userName);
|
||||
string warningMailBodyProcessed = ReplaceVariables(warningMailBody, warningMaxUsage, usage, package.PackageName, userName);
|
||||
|
||||
string suspensionMailSubjectProcessed = ReplaceVariables(suspensionMailSubject, suspensionMaxUsage, usage, package.PackageName, userName);
|
||||
string suspensionMailBodyProcessed = ReplaceVariables(suspensionMailBody, suspensionMaxUsage, usage, package.PackageName, userName);
|
||||
|
||||
|
||||
// Send email notifications
|
||||
if (sendWarningEmail && (!isDiskSpaceBelowWarningThreshold || !isBandwidthBelowWarningThreshold))
|
||||
{
|
||||
// Send warning email.
|
||||
this.SendEmail(warningMailFrom, userInfo.Email, warningMailBcc, warningMailSubjectProcessed, warningMailBodyProcessed, false);
|
||||
}
|
||||
|
||||
if (sendSuspensionEmail && (!isDiskSpaceBelowSuspensionThreshold || !isBandwidthBelowSuspensionThreshold))
|
||||
{
|
||||
// Send suspension email.
|
||||
this.SendEmail(suspensionMailFrom, userInfo.Email, suspensionMailBcc, suspensionMailSubjectProcessed, suspensionMailBodyProcessed, false);
|
||||
}
|
||||
|
||||
// suspend package if required
|
||||
if (suspendOverused && (!isDiskSpaceBelowSuspensionThreshold || !isBandwidthBelowSuspensionThreshold))
|
||||
{
|
||||
suspendedPackages++;
|
||||
|
||||
// load user details
|
||||
UserInfo user = PackageController.GetPackageOwner(package.PackageId);
|
||||
|
||||
TaskManager.Write(String.Format("Suspend space '{0}' of user '{1}'",
|
||||
package.PackageName, user.Username));
|
||||
|
||||
try
|
||||
{
|
||||
PackageController.ChangePackageStatus(null, package.PackageId, PackageStatus.Suspended, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TaskManager.WriteError("Error while changing space status: " + ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// log results
|
||||
TaskManager.Write("Total packages suspended: " + suspendedPackages.ToString());
|
||||
}
|
||||
|
||||
private string ReplaceVariables(string content, string threshold, string usage, string spaceName, string customerName)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(content))
|
||||
{
|
||||
content = Utils.ReplaceStringVariable(content, "threshold", threshold);
|
||||
content = Utils.ReplaceStringVariable(content, "date", DateTime.Now.ToString());
|
||||
content = Utils.ReplaceStringVariable(content, "usage", usage);
|
||||
content = Utils.ReplaceStringVariable(content, "space", spaceName);
|
||||
content = Utils.ReplaceStringVariable(content, "customer", customerName);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
private void SendEmail(string from, string to, string bcc, string subject, string body, bool isHtml)
|
||||
{
|
||||
// check input parameters
|
||||
if (String.IsNullOrEmpty(from))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Mail From' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(to))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Mail To' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
// send mail message
|
||||
MailHelper.SendMessage(from, to, bcc, subject, body, isHtml);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
// Copyright (c) 2012, Outercurve Foundation.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice, this
|
||||
// list of conditions and the following disclaimer.
|
||||
//
|
||||
// - Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// - Neither the name of the Outercurve Foundation nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace WebsitePanel.EnterpriseServer
|
||||
{
|
||||
public class ZipFilesTask : SchedulerTask
|
||||
{
|
||||
public override void DoWork()
|
||||
{
|
||||
// Input parameters:
|
||||
// - FOLDER
|
||||
// - ZIP_FILE
|
||||
|
||||
// get input parameters
|
||||
string filesList = (string)TaskManager.TaskParameters["FOLDER"];
|
||||
string zipFile = (string)TaskManager.TaskParameters["ZIP_FILE"];
|
||||
|
||||
// check input parameters
|
||||
if (String.IsNullOrEmpty(filesList))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Files List' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(zipFile))
|
||||
{
|
||||
TaskManager.WriteWarning("Specify 'Zip File' task parameter");
|
||||
return;
|
||||
}
|
||||
|
||||
// substitute parameters
|
||||
DateTime d = DateTime.Now;
|
||||
string date = d.ToString("yyyyMMdd");
|
||||
string time = d.ToString("HHmm");
|
||||
|
||||
filesList = Utils.ReplaceStringVariable(filesList, "date", date);
|
||||
filesList = Utils.ReplaceStringVariable(filesList, "time", time);
|
||||
zipFile = Utils.ReplaceStringVariable(zipFile, "date", date);
|
||||
zipFile = Utils.ReplaceStringVariable(zipFile, "time", time);
|
||||
|
||||
// zip files and folders
|
||||
FilesController.ZipFiles(TaskManager.PackageId, new string[] { filesList }, zipFile);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue