Another quantum leap ahead - init is now loading database, provisioning geographies. Deploying to test on Mono.

This commit is contained in:
Rick Falkvinge
2012-11-17 18:23:01 +00:00
parent 2dc2835050
commit d218e8e6d1
13 changed files with 1002 additions and 94 deletions
+15 -1
View File
@@ -10,6 +10,9 @@ namespace Activizr.Database
{
public partial class PirateDb
{
// This class is in horrible need of serious refactoring. For its simplicity in task, it's a horrible bowl of spaghetti.
[Serializable]
public class Configuration
{
@@ -37,13 +40,24 @@ namespace Activizr.Database
string testString = _configuration.Admin.Username;
return !String.IsNullOrEmpty(DatabaseConnect.Default.Admin);
return !String.IsNullOrEmpty(testString);
}
public Credentials Read { get; set; }
public Credentials Write { get; set; }
public Credentials Admin { get; set; }
public Configuration Get()
{
if (_configuration == null)
{
Load();
}
return _configuration;
}
private static Configuration _configuration;
public static bool TestConfigurationWritable()
+9 -3
View File
@@ -17,17 +17,23 @@ namespace Activizr.Database
{
public static PirateDb GetDatabaseForReading()
{
return new PirateDb(DatabaseConnect.Default.Read);
return new PirateDb(ConstructConnectString(new Configuration().Get().Read));
}
public static PirateDb GetDatabaseForWriting()
{
return new PirateDb(DatabaseConnect.Default.Write);
return new PirateDb(ConstructConnectString(new Configuration().Get().Write));
}
public static PirateDb GetDatabaseForAdmin()
{
return new PirateDb(DatabaseConnect.Default.Admin);
return new PirateDb(ConstructConnectString(new Configuration().Get().Admin));
}
private static string ConstructConnectString (Credentials credentials)
{
return "server=" + credentials.ServerSet.ServerPriorities[0].Split(';')[0] + ";database=" + credentials.Database +
";user=" + credentials.Username + ";password=" + credentials.Password;
}
+24 -4
View File
@@ -126,10 +126,8 @@ namespace Activizr.Database
public int CreateCountry (string name, string code)
public int CreateCountry (string name, string code, string culture, int geographyId, int postalCodeLength, string collation)
{
throw new NotImplementedException("Creating a country is not implemented at the moment. (It is not a common event.)");
/*
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
@@ -139,9 +137,31 @@ namespace Activizr.Database
AddParameterWithName(command, "name", name);
AddParameterWithName(command, "code", code);
AddParameterWithName(command, "culture", culture);
AddParameterWithName(command, "geographyId", geographyId);
AddParameterWithName(command, "postalCodeLength", postalCodeLength);
AddParameterWithName(command, "collation", collation);
return Convert.ToInt32(command.ExecuteScalar());
}*/
}
}
public int SetCountryGeographyId (int countryId, int geographyId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetCountryGeographyId", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "countryId", countryId);
AddParameterWithName(command, "geographyId", geographyId);
return Convert.ToInt32(command.ExecuteScalar());
}
}
}
}
+18
View File
@@ -465,5 +465,23 @@ namespace Activizr.Database
return result.ToArray();
}
public int CreateGeography (string name, int parentGeographyId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("CreateGeography", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "name", name);
AddParameterWithName(command, "parentGeographyId", parentGeographyId);
return Convert.ToInt32(command.ExecuteScalar());
}
}
}
}
+30
View File
@@ -0,0 +1,30 @@
using System.Text;
using System.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
namespace Activizr.Database
{
partial class PirateDb
{
// This function is bloody dangerous, mmkay?
public void ExecuteAdminCommand(string sqlSequence)
{
// TODO: Verify that we're in admin mode
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand(sqlSequence, connection);
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
}
}
}
}
+1 -9
View File
@@ -57,6 +57,7 @@
<ItemGroup>
<Compile Include="Configuration.cs" />
<Compile Include="Database-Currencies.cs" />
<Compile Include="Database-Initialization.cs" />
<Compile Include="Database-Meetings.cs" />
<Compile Include="Database-CommunicationTurnarounds.cs" />
<Compile Include="Database-ExternalActivities.cs" />
@@ -117,19 +118,10 @@
<Compile Include="Database-Volunteers.cs" />
<Compile Include="Database-Permissions.cs" />
<Compile Include="Database-InternalPollVotes.cs" />
<Compile Include="DatabaseConnect.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>DatabaseConnect.settings</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Database-Constructors.cs" />
<Compile Include="Database-Newsletters.cs" />
<None Include="app.config" />
<None Include="DatabaseConnect.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>DatabaseConnect.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Basic\Basic.csproj">
-53
View File
@@ -1,53 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.269
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Activizr.Database {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class DatabaseConnect : global::System.Configuration.ApplicationSettingsBase {
private static DatabaseConnect defaultInstance = ((DatabaseConnect)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new DatabaseConnect())));
public static DatabaseConnect Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string Read {
get {
return ((string)(this["Read"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string Write {
get {
return ((string)(this["Write"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string Admin {
get {
return ((string)(this["Admin"]));
}
}
}
}
-15
View File
@@ -1,15 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Activizr.Database" GeneratedClassName="DatabaseConnect">
<Profiles />
<Settings>
<Setting Name="Read" Type="System.String" Scope="Application">
<Value Profile="(Default)" />
</Setting>
<Setting Name="Write" Type="System.String" Scope="Application">
<Value Profile="(Default)" />
</Setting>
<Setting Name="Admin" Type="System.String" Scope="Application">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
+1
View File
@@ -200,6 +200,7 @@
<Compile Include="Structure\PostalCodes.cs" />
<Compile Include="Structure\UptakeGeography.cs" />
<Compile Include="Support\ActivistEvents.cs" />
<Compile Include="Support\DatabaseMaintenance.cs" />
<Compile Include="Support\Imagery.cs" />
<Compile Include="Support\ObjectOptionalData.cs" />
<Compile Include="Support\PluralBase.cs" />
+52
View File
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using Activizr.Database;
using Activizr.Logic.Pirates;
namespace Activizr.Logic.Support
{
public class DatabaseMaintenance
{
/// <summary>
/// Feeds a newly-created database with an empty structure. Do not use on populated databases; it's like a Genesis Device.
/// </summary>
static public void FirstInitialization()
{
// Security check: make sure we throw an exception if we try to get person 1.
bool initialized = false;
Person personOne = null;
string sql = string.Empty;
try
{
personOne = Person.FromIdentity(1);
initialized = true;
}
catch (Exception)
{
// Do nothing, the exception is expected
}
if (initialized == true && personOne != null) // double checks in case Database behavior should change to return null rather than throw later
{
throw new InvalidOperationException("Cannot run Genesis Device style initalization on already-populated database");
}
using (WebClient client = new WebClient())
{
sql = client.DownloadString("http://packages.activizr.com/schemas/initialize.sql"); // Hardcoded as security measure - don't want to pass arbitrary sql in from web layer
}
string[] sqlCommands = sql.Split('#'); // in the file, the commands are split by a single # sign. (Semicolons are an integral part of storedprocs, so they can't be used.)
foreach (string sqlCommand in sqlCommands)
{
PirateDb.GetDatabaseForAdmin().ExecuteAdminCommand(sqlCommand.Trim());
}
}
}
}
+754
View File
@@ -0,0 +1,754 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.296
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
//
// This source code was auto-generated by wsdl, Version=4.0.30319.1.
//
namespace Activizr.Site.Automation
{
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="GetGeographyDataSoap", Namespace="http://activizr.com/")]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BasicGeography))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BasicPostalCode))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BasicCity))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(BasicCountry))]
public partial class GetGeographyData : System.Web.Services.Protocols.SoapHttpClientProtocol {
private System.Threading.SendOrPostCallback GetCountriesOperationCompleted;
private System.Threading.SendOrPostCallback GetCountriesInUseOperationCompleted;
private System.Threading.SendOrPostCallback GetCitiesForCountryOperationCompleted;
private System.Threading.SendOrPostCallback GetPostalCodesForCountryOperationCompleted;
private System.Threading.SendOrPostCallback GetGeographyOperationCompleted;
private System.Threading.SendOrPostCallback GetGeographyForCountryOperationCompleted;
/// <remarks/>
public GetGeographyData() {
this.Url = "http://pirate.activizr.com/Automation/GetGeographyData.asmx";
}
/// <remarks/>
public event GetCountriesCompletedEventHandler GetCountriesCompleted;
/// <remarks/>
public event GetCountriesInUseCompletedEventHandler GetCountriesInUseCompleted;
/// <remarks/>
public event GetCitiesForCountryCompletedEventHandler GetCitiesForCountryCompleted;
/// <remarks/>
public event GetPostalCodesForCountryCompletedEventHandler GetPostalCodesForCountryCompleted;
/// <remarks/>
public event GetGeographyCompletedEventHandler GetGeographyCompleted;
/// <remarks/>
public event GetGeographyForCountryCompletedEventHandler GetGeographyForCountryCompleted;
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://activizr.com/GetCountries", RequestNamespace="http://activizr.com/", ResponseNamespace="http://activizr.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public Country[] GetCountries() {
object[] results = this.Invoke("GetCountries", new object[0]);
return ((Country[])(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginGetCountries(System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetCountries", new object[0], callback, asyncState);
}
/// <remarks/>
public Country[] EndGetCountries(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((Country[])(results[0]));
}
/// <remarks/>
public void GetCountriesAsync() {
this.GetCountriesAsync(null);
}
/// <remarks/>
public void GetCountriesAsync(object userState) {
if ((this.GetCountriesOperationCompleted == null)) {
this.GetCountriesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetCountriesOperationCompleted);
}
this.InvokeAsync("GetCountries", new object[0], this.GetCountriesOperationCompleted, userState);
}
private void OnGetCountriesOperationCompleted(object arg) {
if ((this.GetCountriesCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetCountriesCompleted(this, new GetCountriesCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://activizr.com/GetCountriesInUse", RequestNamespace="http://activizr.com/", ResponseNamespace="http://activizr.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public Country[] GetCountriesInUse() {
object[] results = this.Invoke("GetCountriesInUse", new object[0]);
return ((Country[])(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginGetCountriesInUse(System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetCountriesInUse", new object[0], callback, asyncState);
}
/// <remarks/>
public Country[] EndGetCountriesInUse(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((Country[])(results[0]));
}
/// <remarks/>
public void GetCountriesInUseAsync() {
this.GetCountriesInUseAsync(null);
}
/// <remarks/>
public void GetCountriesInUseAsync(object userState) {
if ((this.GetCountriesInUseOperationCompleted == null)) {
this.GetCountriesInUseOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetCountriesInUseOperationCompleted);
}
this.InvokeAsync("GetCountriesInUse", new object[0], this.GetCountriesInUseOperationCompleted, userState);
}
private void OnGetCountriesInUseOperationCompleted(object arg) {
if ((this.GetCountriesInUseCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetCountriesInUseCompleted(this, new GetCountriesInUseCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://activizr.com/GetCitiesForCountry", RequestNamespace="http://activizr.com/", ResponseNamespace="http://activizr.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public City[] GetCitiesForCountry(string countryCode) {
object[] results = this.Invoke("GetCitiesForCountry", new object[] {
countryCode});
return ((City[])(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginGetCitiesForCountry(string countryCode, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetCitiesForCountry", new object[] {
countryCode}, callback, asyncState);
}
/// <remarks/>
public City[] EndGetCitiesForCountry(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((City[])(results[0]));
}
/// <remarks/>
public void GetCitiesForCountryAsync(string countryCode) {
this.GetCitiesForCountryAsync(countryCode, null);
}
/// <remarks/>
public void GetCitiesForCountryAsync(string countryCode, object userState) {
if ((this.GetCitiesForCountryOperationCompleted == null)) {
this.GetCitiesForCountryOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetCitiesForCountryOperationCompleted);
}
this.InvokeAsync("GetCitiesForCountry", new object[] {
countryCode}, this.GetCitiesForCountryOperationCompleted, userState);
}
private void OnGetCitiesForCountryOperationCompleted(object arg) {
if ((this.GetCitiesForCountryCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetCitiesForCountryCompleted(this, new GetCitiesForCountryCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://activizr.com/GetPostalCodesForCountry", RequestNamespace="http://activizr.com/", ResponseNamespace="http://activizr.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public PostalCode[] GetPostalCodesForCountry(string countryCode) {
object[] results = this.Invoke("GetPostalCodesForCountry", new object[] {
countryCode});
return ((PostalCode[])(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginGetPostalCodesForCountry(string countryCode, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetPostalCodesForCountry", new object[] {
countryCode}, callback, asyncState);
}
/// <remarks/>
public PostalCode[] EndGetPostalCodesForCountry(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((PostalCode[])(results[0]));
}
/// <remarks/>
public void GetPostalCodesForCountryAsync(string countryCode) {
this.GetPostalCodesForCountryAsync(countryCode, null);
}
/// <remarks/>
public void GetPostalCodesForCountryAsync(string countryCode, object userState) {
if ((this.GetPostalCodesForCountryOperationCompleted == null)) {
this.GetPostalCodesForCountryOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetPostalCodesForCountryOperationCompleted);
}
this.InvokeAsync("GetPostalCodesForCountry", new object[] {
countryCode}, this.GetPostalCodesForCountryOperationCompleted, userState);
}
private void OnGetPostalCodesForCountryOperationCompleted(object arg) {
if ((this.GetPostalCodesForCountryCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetPostalCodesForCountryCompleted(this, new GetPostalCodesForCountryCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://activizr.com/GetGeography", RequestNamespace="http://activizr.com/", ResponseNamespace="http://activizr.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public Geography GetGeography(int nodeId) {
object[] results = this.Invoke("GetGeography", new object[] {
nodeId});
return ((Geography)(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginGetGeography(int nodeId, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetGeography", new object[] {
nodeId}, callback, asyncState);
}
/// <remarks/>
public Geography EndGetGeography(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((Geography)(results[0]));
}
/// <remarks/>
public void GetGeographyAsync(int nodeId) {
this.GetGeographyAsync(nodeId, null);
}
/// <remarks/>
public void GetGeographyAsync(int nodeId, object userState) {
if ((this.GetGeographyOperationCompleted == null)) {
this.GetGeographyOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetGeographyOperationCompleted);
}
this.InvokeAsync("GetGeography", new object[] {
nodeId}, this.GetGeographyOperationCompleted, userState);
}
private void OnGetGeographyOperationCompleted(object arg) {
if ((this.GetGeographyCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetGeographyCompleted(this, new GetGeographyCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://activizr.com/GetGeographyForCountry", RequestNamespace="http://activizr.com/", ResponseNamespace="http://activizr.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public Geography GetGeographyForCountry(string countryCode) {
object[] results = this.Invoke("GetGeographyForCountry", new object[] {
countryCode});
return ((Geography)(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginGetGeographyForCountry(string countryCode, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("GetGeographyForCountry", new object[] {
countryCode}, callback, asyncState);
}
/// <remarks/>
public Geography EndGetGeographyForCountry(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((Geography)(results[0]));
}
/// <remarks/>
public void GetGeographyForCountryAsync(string countryCode) {
this.GetGeographyForCountryAsync(countryCode, null);
}
/// <remarks/>
public void GetGeographyForCountryAsync(string countryCode, object userState) {
if ((this.GetGeographyForCountryOperationCompleted == null)) {
this.GetGeographyForCountryOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetGeographyForCountryOperationCompleted);
}
this.InvokeAsync("GetGeographyForCountry", new object[] {
countryCode}, this.GetGeographyForCountryOperationCompleted, userState);
}
private void OnGetGeographyForCountryOperationCompleted(object arg) {
if ((this.GetGeographyForCountryCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.GetGeographyForCountryCompleted(this, new GetGeographyForCountryCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/>
public new void CancelAsync(object userState) {
base.CancelAsync(userState);
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://activizr.com/")]
public partial class Country : BasicCountry {
}
/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Country))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://activizr.com/")]
public partial class BasicCountry {
private int countryIdField;
private string nameField;
private string codeField;
private string cultureField;
private int geographyIdField;
/// <remarks/>
public int CountryId {
get {
return this.countryIdField;
}
set {
this.countryIdField = value;
}
}
/// <remarks/>
public string Name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
/// <remarks/>
public string Code {
get {
return this.codeField;
}
set {
this.codeField = value;
}
}
/// <remarks/>
public string Culture {
get {
return this.cultureField;
}
set {
this.cultureField = value;
}
}
/// <remarks/>
public int GeographyId {
get {
return this.geographyIdField;
}
set {
this.geographyIdField = value;
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(Geography))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://activizr.com/")]
public partial class BasicGeography {
private int geographyIdField;
private int parentGeographyIdField;
private string nameField;
private int generationField;
/// <remarks/>
public int GeographyId {
get {
return this.geographyIdField;
}
set {
this.geographyIdField = value;
}
}
/// <remarks/>
public int ParentGeographyId {
get {
return this.parentGeographyIdField;
}
set {
this.parentGeographyIdField = value;
}
}
/// <remarks/>
public string Name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
/// <remarks/>
public int Generation {
get {
return this.generationField;
}
set {
this.generationField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://activizr.com/")]
public partial class Geography : BasicGeography {
private Geography[] childrenField;
/// <remarks/>
public Geography[] Children {
get {
return this.childrenField;
}
set {
this.childrenField = value;
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(PostalCode))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://activizr.com/")]
public partial class BasicPostalCode {
private string postalCodeField;
private string cityNameField;
private string countryCodeField;
/// <remarks/>
public string PostalCode {
get {
return this.postalCodeField;
}
set {
this.postalCodeField = value;
}
}
/// <remarks/>
public string CityName {
get {
return this.cityNameField;
}
set {
this.cityNameField = value;
}
}
/// <remarks/>
public string CountryCode {
get {
return this.countryCodeField;
}
set {
this.countryCodeField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://activizr.com/")]
public partial class PostalCode : BasicPostalCode {
}
/// <remarks/>
[System.Xml.Serialization.XmlIncludeAttribute(typeof(City))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://activizr.com/")]
public partial class BasicCity {
private int cityIdField;
private string nameField;
private int countryIdField;
private int geographyIdField;
/// <remarks/>
public int CityId {
get {
return this.cityIdField;
}
set {
this.cityIdField = value;
}
}
/// <remarks/>
public string Name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
/// <remarks/>
public int CountryId {
get {
return this.countryIdField;
}
set {
this.countryIdField = value;
}
}
/// <remarks/>
public int GeographyId {
get {
return this.geographyIdField;
}
set {
this.geographyIdField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://activizr.com/")]
public partial class City : BasicCity {
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GetCountriesCompletedEventHandler(object sender, GetCountriesCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetCountriesCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal GetCountriesCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public Country[] Result {
get {
this.RaiseExceptionIfNecessary();
return ((Country[])(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GetCountriesInUseCompletedEventHandler(object sender, GetCountriesInUseCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetCountriesInUseCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal GetCountriesInUseCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public Country[] Result {
get {
this.RaiseExceptionIfNecessary();
return ((Country[])(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GetCitiesForCountryCompletedEventHandler(object sender, GetCitiesForCountryCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetCitiesForCountryCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal GetCitiesForCountryCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public City[] Result {
get {
this.RaiseExceptionIfNecessary();
return ((City[])(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GetPostalCodesForCountryCompletedEventHandler(object sender, GetPostalCodesForCountryCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetPostalCodesForCountryCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal GetPostalCodesForCountryCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public PostalCode[] Result {
get {
this.RaiseExceptionIfNecessary();
return ((PostalCode[])(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GetGeographyCompletedEventHandler(object sender, GetGeographyCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetGeographyCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal GetGeographyCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public Geography Result {
get {
this.RaiseExceptionIfNecessary();
return ((Geography)(this.results[0]));
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
public delegate void GetGeographyForCountryCompletedEventHandler(object sender, GetGeographyForCountryCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class GetGeographyForCountryCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal GetGeographyForCountryCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public Geography Result {
get {
this.RaiseExceptionIfNecessary();
return ((Geography)(this.results[0]));
}
}
}
}
+1 -1
View File
@@ -442,7 +442,7 @@
<div id="DivInitializingDatabase">
<h2>Initializing database</h2>
<div id="DivProgressDatabase"></div>
<p>Please wait while the database is being initialized with schemas and geographic data from the Activizr servers.</p>
<p>Please wait while the database is being initialized with schemas and geographic data from the Activizr servers. This is going to take a significant amount of time; we're loading tons of geodata onto your new server.</p>
</div>
<div id="DivCreateFirstUser" style="display:none">
<h2>Step 3 Content</h2>
+97 -8
View File
@@ -9,9 +9,12 @@ using System.Web.Services;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using Activizr.Basic.Types;
using Activizr.Site.Automation;
using Telerik.Web.UI;
using Activizr.Database;
using Country = Activizr.Logic.Structure.Country;
public partial class Pages_v5_Init_Default : System.Web.UI.Page
{
@@ -277,25 +280,111 @@ public partial class Pages_v5_Init_Default : System.Web.UI.Page
HttpSessionState currentSessionObject = HttpContext.Current.Session;
Thread initThread = new Thread(() => InitDatabaseThread(currentSessionObject) );
Thread initThread = new Thread(InitDatabaseThread);
initThread.Start();
}
public static void InitDatabaseThread (object sessionObject)
/// <summary>
/// This function copies the schemas and geography data off an existing Activizr installation. Runs in its own thread.
/// </summary>
public static void InitDatabaseThread()
{
System.Web.SessionState.HttpSessionState session = (HttpSessionState) sessionObject;
// Ignore the session object, that method of sharing data didn't work, but a static variable did.
for (int loop = 0; loop <= 100; loop++)
_initProgress = 1;
// Get the schema and initialize the database structures. Requires ADMIN access to database.
Activizr.Logic.Support.DatabaseMaintenance.FirstInitialization();
_initProgress = 5;
// Create translation lists
Dictionary<int, int> geographyIdTranslation = new Dictionary<int, int>();
Dictionary<int, int> cityIdTranslation = new Dictionary<int, int>();
Dictionary<string, int> countryIdTranslation = new Dictionary<string, int>();
// Initialize the root geography (which becomes #1 if everything works)
int rootGeographyId = PirateDb.GetDatabaseForWriting().CreateGeography("World", 0);
// Get the list of countries
Activizr.Site.Automation.GetGeographyData geoDataFetcher = new GetGeographyData();
Activizr.Site.Automation.Country[] countries = geoDataFetcher.GetCountries();
_initProgress = 7;
// Create all countries in our own database
foreach (Activizr.Site.Automation.Country country in countries)
{
// Use session variable AND a static variable to store this
countryIdTranslation[country.Code] = PirateDb.GetDatabaseForWriting().CreateCountry(country.Name,
country.Code,
country.Culture,
rootGeographyId, 5,
string.Empty);
}
session["PercentInitComplete"] = loop;
_initProgress = loop;
System.Threading.Thread.Sleep(100);
_initProgress = 10;
// Construct list of countries that have geographic data
List<string> initializableCountries = new List<string>();
foreach (Activizr.Site.Automation.Country country in countries)
{
if (country.GeographyId != 1)
{
initializableCountries.Add(country.Code);
}
}
float initStepPerCountry = 90f/initializableCountries.Count;
int countryCount = 0;
// For each country...
foreach (string countryCode in initializableCountries)
{
// Get the geography layout
Activizr.Site.Automation.Geography geography = geoDataFetcher.GetGeographyForCountry(countryCode);
_initProgress = 10 + (int) (countryCount*initStepPerCountry + initStepPerCountry/6);
// Create the country's root geography
int countryRootGeographyId = PirateDb.GetDatabaseForWriting().CreateGeography(geography.Name, rootGeographyId);
geographyIdTranslation[geography.GeographyId] = countryRootGeographyId;
InitDatabaseThreadCreateGeographyChildren(geography.Children, countryRootGeographyId, ref geographyIdTranslation);
_initProgress = 10 + (int) (countryCount*initStepPerCountry + initStepPerCountry/3);
countryCount++;
}
_initProgress = 100;
Thread.Sleep(1000); // give some time for static var to stick and web interface to react before killing thread
}
private static void InitDatabaseThreadCreateGeographyChildren (Activizr.Site.Automation.Geography[] children, int parentGeographyId, ref Dictionary<int,int> geographyIdTranslation)
{
foreach (Activizr.Site.Automation.Geography geography in children)
{
int newGeographyId = PirateDb.GetDatabaseForWriting().CreateGeography(geography.Name, parentGeographyId);
geographyIdTranslation[geography.GeographyId] = newGeographyId;
InitDatabaseThreadCreateGeographyChildren(geography.Children, newGeographyId, ref geographyIdTranslation);
}
}
private static int _initProgress = 0;