Initial project's source code check-in.

This commit is contained in:
ptsurbeleu 2011-07-13 16:07:32 -07:00
commit b03b0b373f
4573 changed files with 981205 additions and 0 deletions

View file

@ -0,0 +1,329 @@
// Copyright (c) 2011, 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.EnterpriseServer;
namespace WebsitePanel.Ecommerce.EnterpriseServer
{
public class DomainName : ProvisioningControllerBase, IProvisioningController
{
public const string REGISTRAR_ORDER_ID = "RegistrarOrderID";
public const string REGISTRAR = "Registrar";
public const string INTERNAL_DOMAIN_ID = "InternalDomainID";
public const string DOMAIN_NAME = "DomainName";
public const string DOMAIN_TLD = "DomainTLD";
public const string RENEW_ORDER_ID = "RenewOrderID";
public const string ROOT_SERVICE_ID = "RootServiceID";
public const string PACKAGE_ID = "PackageID";
private IDomainRegistrar registrar;
/// <summary>
/// Gets domain name
/// </summary>
public string Domain
{
get { return ServiceSettings[DOMAIN_NAME]; }
}
/// <summary>
/// Gets domain name tld
/// </summary>
public string TLD
{
get { return ServiceSettings[DOMAIN_TLD]; }
}
/// <summary>
/// Gets full qualified domain name
/// </summary>
public string FQDN
{
get { return Domain + "." + TLD; }
}
/// <summary>
/// Gets a reference to the registrar instance
/// </summary>
protected IDomainRegistrar Registrar
{
get { return registrar; }
}
/// <summary>
/// Gets registrar settings name
/// </summary>
protected string SettingsName
{
get { return Registrar.RegistrarName + "Settings"; }
}
public DomainName(Service serviceInfo)
: base(serviceInfo)
{
}
public override void LoadProvisioningSettings()
{
base.LoadProvisioningSettings();
InitRegistrar();
}
private void InitRegistrar()
{
string tld = TLD;
// check whether tld is already obtained
if (String.IsNullOrEmpty(TLD))
tld = RegistrarController.GetDomainTLD(TLD);
//
registrar = RegistrarController.GetTLDDomainRegistrar(ServiceInfo.SpaceId, tld);
}
private void CreateWebsitePanelDomain(int packageId)
{
// try to register domain in panel
DomainInfo domain = ServerController.GetDomain(FQDN);
// domain not found thus create newly one
if (domain == null)
{
domain = new DomainInfo();
domain.DomainName = FQDN;
domain.HostingAllowed = false;
domain.PackageId = packageId;
domain.DomainId = ServerController.AddDomain(domain);
}
// save domain id if it's created
if (domain.DomainId > 0)
ServiceSettings[INTERNAL_DOMAIN_ID] = domain.DomainId.ToString();
}
private void RenewDomainOnRegistrar()
{
// read service cycle
ServiceLifeCycle lifeCycle = ServiceController.GetServiceLifeCycle(
ServiceInfo.SpaceId,
ServiceInfo.ServiceId
);
// copy renew arguments
CommandParams args = new CommandParams();
args[CommandParams.DOMAIN_NAME] = Domain;
args[CommandParams.DOMAIN_TLD] = TLD;
args[CommandParams.YEARS] = lifeCycle.CycleLength.ToString();
// renew remote domain
RenewDomainResult result = Registrar.RenewDomain(args);
// save renew order id
ServiceSettings[RENEW_ORDER_ID] = result[RenewDomainResult.RENEW_ORDER_NUMBER];
ServiceSettings[REGISTRAR] = result[RenewDomainResult.REGISTRAR];
// renew service life-cycle suspend date
DateTime StartDate = ServiceController.GetServiceSuspendDate(
ServiceInfo.SpaceId,
ServiceInfo.ServiceId
);
// calculate end date
DateTime EndDate = StartDate.AddYears(lifeCycle.CycleLength);
// append life-cycle record
ServiceController.SetServiceLifeCycleRecord(
ServiceInfo.SpaceId,
ServiceInfo.ServiceId,
StartDate,
EndDate
);
}
private CommandParams PrepeareAccountParams()
{
CommandParams args = new CommandParams();
args[CommandParams.USERNAME] = UserInfo.Username;
args[CommandParams.PASSWORD] = UserInfo.Password;
args[CommandParams.FIRST_NAME] = UserInfo.FirstName;
args[CommandParams.LAST_NAME] = UserInfo.LastName;
args[CommandParams.EMAIL] = UserInfo.Email;
args[CommandParams.ADDRESS] = UserInfo.Address;
args[CommandParams.CITY] = UserInfo.City;
args[CommandParams.STATE] = UserInfo.State;
args[CommandParams.COUNTRY] = UserInfo.Country;
args[CommandParams.ZIP] = UserInfo.Zip;
args[CommandParams.PHONE] = UserInfo.PrimaryPhone;
args[CommandParams.FAX] = UserInfo.Fax;
return args;
}
private AccountResult GetRegistrarAccountInfo()
{
string userAccount = UserInfo.Username;
string emailAddress = UserInfo.Email;
// check for user account
bool exists = Registrar.CheckSubAccountExists(userAccount, emailAddress);
// sub-account doesn't exist then create it
if (!exists)
{
// create account params bunch
CommandParams accountArgs = PrepeareAccountParams();
// create sub-account
return Registrar.CreateSubAccount(accountArgs);
}
// just get sub-account info on registrar's side
return Registrar.GetSubAccount(userAccount, emailAddress);
}
private void EnsureUserSettings(CommandParams args)
{
// load user settings
UserSettings regSettings = UserController.GetUserSettings(
ServiceInfo.UserId,
SettingsName
);
// settings are empty
if (regSettings.SettingsArray == null || regSettings.SettingsArray.Length == 0)
{
// load registrar account info
AccountResult rmResult = GetRegistrarAccountInfo();
// update user settings locally
regSettings.SettingsName = SettingsName;
regSettings.UserId = UserInfo.UserId;
// copy account data
foreach (string key in rmResult.AllKeys)
{
regSettings[key] = rmResult[key];
args[key] = rmResult[key];
}
// save sub-account settings
UserController.UpdateUserSettings(regSettings);
}
else
{
// copy user settings
foreach (string[] pair in regSettings.SettingsArray)
{
args[pair[0]] = pair[1];
}
}
}
private void CreateRegistrarDomain(int packageId)
{
// create command arguments
CommandParams args = PrepeareAccountParams();
// ensure user settings are ok & copy them
EnsureUserSettings(args);
// get package info
PackageSettings nsSettings = PackageController.GetPackageSettings(
packageId,
PackageSettings.NAME_SERVERS
);
// read service cycle
ServiceLifeCycle lifeCycle = ServiceController.GetServiceLifeCycle(
ServiceInfo.SpaceId,
ServiceInfo.ServiceId
);
// copy domain name related settings
args[CommandParams.NAME_SERVERS] = nsSettings[PackageSettings.NAME_SERVERS];
args[CommandParams.DOMAIN_NAME] = Domain;
args[CommandParams.DOMAIN_TLD] = TLD;
args[CommandParams.YEARS] = lifeCycle.CycleLength.ToString();
// call registrar's API
RegisterDomainResult rdResult = Registrar.RegisterDomain(args);
// save registrar's order number
ServiceSettings[REGISTRAR_ORDER_ID] = rdResult[RegisterDomainResult.ORDER_NUMBER];
ServiceSettings[REGISTRAR] = Registrar.RegistrarName;
}
private void RemoveDomainOnPanel()
{
int domainId = Utils.ParseInt(ServiceSettings[INTERNAL_DOMAIN_ID], 0);
if (domainId > 0)
ServerController.DeleteDomain(domainId);
}
#region IProvisioningController Members
public void Activate()
{
RenewDomainOnRegistrar();
}
public void Suspend() {}
public void Cancel() {}
public void Order()
{
int parentId = Convert.ToInt32(ServiceSettings[ROOT_SERVICE_ID]);
KeyValueBunch rootSettings = ServiceController.GetServiceSettings(
ServiceInfo.SpaceId,
parentId
);
// check whether the parent service has been provisioned
if (String.IsNullOrEmpty(rootSettings[PACKAGE_ID]))
{
throw new Exception(
"Unable to provision service because parent service not provisioned yet"
);
}
int packageId = Utils.ParseInt(rootSettings[PACKAGE_ID], -1);
// create remote domain on registrar's side
CreateRegistrarDomain(packageId);
// create local domain on WebsitePanel's side
CreateWebsitePanelDomain(packageId);
}
public void Rollback()
{
RemoveDomainOnPanel();
}
#endregion
}
}

View file

@ -0,0 +1,21 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WebsitePanel.Products.DomainName")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("WebsitePanel.Products.DomainName")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("08c24372-5d0b-4914-9a2c-f0aaf212cc0a")]

View file

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{FFE9BFD3-AAB8-4703-AF8F-A41F0D878DB8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WebsitePanel.Ecommerce.EnterpriseServer</RootNamespace>
<AssemblyName>WebsitePanel.Products.DomainName</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\WebsitePanel.EnterpriseServer\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<WarningsAsErrors>618</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\WebsitePanel.EnterpriseServer\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<WarningsAsErrors>618</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\VersionInfo.cs">
<Link>VersionInfo.cs</Link>
</Compile>
<Compile Include="DomainName.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WebsitePanel.EnterpriseServer.Base\WebsitePanel.EnterpriseServer.Base.csproj">
<Project>{C09CE910-F16B-48A1-B2CC-C99B8C1CF775}</Project>
<Name>WebsitePanel.EnterpriseServer.Base</Name>
</ProjectReference>
<ProjectReference Include="..\WebsitePanel.EnterpriseServer\WebsitePanel.EnterpriseServer.csproj">
<Project>{59C7623A-5181-48A5-880A-C9B82B48F589}</Project>
<Name>WebsitePanel.EnterpriseServer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>