예제 #1
0
 public VeryLargeSQLBuilder(ISQLBuilder internaBuilder, int scriptPageSize)
     : base(internaBuilder)
 {
     SystemLog.Info("VeryLargeScriptBuilder created - scriptPageSize = {0}", scriptPageSize);
     _pageSize            = scriptPageSize;
     _generatedContainers = new List <LargeCollection <SQLStatement> >();
     // We clear again, which forces the base implementation to recreate the container
     base.Clear();
 }
예제 #2
0
        public void Start()
        {
            lock (_threadLock) {
                if (!Started)
                {
                    _resetEvent = new ManualResetEvent(false);
                    new Thread(() => {
                        var host =
                            _singletonImpl != null ?
                            new ServiceHost(_singletonImpl, new[] { ServiceUri }) :
                            new ServiceHost(typeof(TServiceImpl), new[] { ServiceUri });
                        using (host) {
                            host.Description.Behaviors.Add(
                                new ServiceMetadataBehavior {
                                HttpGetEnabled = true,
                                //MetadataExporter = {
                                //PolicyVersion = PolicyVersion.Policy15
                                //}
                            }
                                );
                            var debugBehavior = host.Description.Behaviors.Find <ServiceDebugBehavior>();
                            if (debugBehavior == null)
                            {
                                host.Description.Behaviors.Add(
                                    new ServiceDebugBehavior {
                                    IncludeExceptionDetailInFaults = true
                                });
                            }

                            host.Description.Behaviors.Find <ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
                            host.Description.Behaviors.Find <ServiceDebugBehavior>().HttpHelpPageUrl = ServiceUri;

                            var behaviour = host.Description.Behaviors.Find <ServiceBehaviorAttribute>();
                            behaviour.InstanceContextMode = ContextMode;


                            host.AddServiceEndpoint(typeof(TServiceContract), Binding, ServiceUri);

                            SystemLog.Info("Service '{0}' Starting", typeof(TServiceImpl).FullName);
                            try {
                                host.Open();
                            } catch (Exception error) {
                                SystemLog.Exception(error);
                                return;
                            }
                            SystemLog.Info("Service '{0}' Started", typeof(TServiceImpl).FullName);
                            Started = true;
                            _resetEvent.WaitOne();
                            SystemLog.Info("Service '{0}' Stopped", typeof(TServiceImpl).FullName);
                        }
                    }).Start();
                }
            }
        }
예제 #3
0
        public void ApplyUpgrades()
        {
            OnUpgrading(_timeService.UtcNow);
            _log.Info("Applying DB Upgrades, {0} scripts.", _upgradeInfo.AllScripts.Count);
            var             startedOn      = _timeService.UtcNow;
            var             driver         = _database.DbModel.Driver;
            var             conn           = driver.CreateConnection(_database.Settings.SchemaManagementConnectionString);
            DbUpgradeScript currScript     = null;
            IDbCommand      cmd            = null;
            var             appliedScripts = new List <DbUpgradeScript>();

            try {
                conn.Open();
                foreach (var script in _upgradeInfo.AllScripts)
                {
                    currScript      = script;
                    cmd             = conn.CreateCommand();
                    cmd.CommandText = script.Sql;
                    var start = _timeService.ElapsedMilliseconds;
                    driver.ExecuteCommand(cmd, DbExecutionType.NonQuery);
                    script.Duration = (int)(_timeService.ElapsedMilliseconds - start);
                    appliedScripts.Add(script);
                    //Important for SQLite
                    cmd.Connection = null;
                    cmd.Dispose();
                    cmd = null;
                }
                OnUpgraded(_upgradeInfo.AllScripts, startedOn, _timeService.UtcNow);
            } catch (Exception ex) {
                OnUpgraded(appliedScripts, startedOn, _timeService.UtcNow, ex, currScript);
                var logStr = ex.ToLogString();
                System.Diagnostics.Debug.WriteLine(logStr);
                _log.Error(logStr);
                throw;
            } finally {
                if (cmd != null)
                {
                    cmd.Connection = null;
                    cmd.Dispose();
                }
                conn.Close();
            }
        }//method
예제 #4
0
        private async Task GetProductDataInternal(IEnumerable <string> productIDs)
        {
            if (productIDs == null)
            {
                return;
            }

            SystemLog.Info("GetProductDataInternal - count of products requested {0}", productIDs.Count());

            productIDs.ForEach(x => {
                SystemLog.Info(x);
            });
            const int numRetry = 3;

            var productIdentifiers = productIDs.ToArray();

            if (productIdentifiers.Length == 0)
            {
                return;
            }

            for (int i = 0; i < numRetry; i++)
            {
                try {
                    using (_productCache.EnterWriteScope()) {
                        var requestor = new ProductDataRequestor();
                        foreach (var product in (await requestor.GetProductData(productIdentifiers)).Products)
                        {
                            _productCache [product.ProductIdentifier] = product;
                            SystemLog.Info("RECEIVED iTUNES RESPONSE {0}", product.ProductIdentifier);
                        }
                    }
                    break;
                } catch (Exception error) {
                    SystemLog.Exception(error);
                    if (i == numRetry - 1)
                    {
                        throw new Exception(string.Format("An error occured fetching product(s) '{0}' from iTunes.", productIdentifiers.ToDelimittedString(", ")), error);
                    }
                }
            }
        }
예제 #5
0
        public void Guid_ReadWriteConsistency()
        {
            const string tableDDL = @"CREATE TABLE [Table] (
	ID INTEGER PRIMARY KEY AUTOINCREMENT,
	Data1 UNIQUEIDENTIFIER NOT NULL
)";
            var          dbFile   = Tools.Paths.GenerateTempFilename();

            try {
                SystemLog.RegisterLogger(new ConsoleLogger());
                var guid = Guid.NewGuid();
                SystemLog.Info("Generated Guid: {0}", guid);
                var dac = Tools.Sqlite.Create(dbFile, logger: SystemLog.Logger);
                dac.ExecuteNonQuery(tableDDL);
                dac.Insert("Table", new[] { new ColumnValue("Data1", guid) });
                var read = dac.Select("Table", new[] { "Data1" }).Single().Get <Guid>(0);
                Assert.AreEqual(guid, read);
            } finally {
                if (File.Exists(dbFile))
                {
                    File.Delete(dbFile);
                }
            }
        }
예제 #6
0
        /// <summary>Performs the shutdown of the application. Notifies all components and modules about pending application shutdown.
        /// </summary>
        public virtual void Shutdown()
        {
            SystemLog.Info("Shutting down app {0}.", AppName);
            Flush();
            Status = EntityAppStatus.Shutdown;
            foreach (var module in this.Modules)
            {
                module.Shutdown();
            }
            //shutdown services
            var servList = this.GetAllServices();

            for (int i = 0; i < servList.Count; i++)
            {
                var service     = servList[i];
                var iEntService = service as IEntityService;
                if (iEntService != null)
                {
                    iEntService.Shutdown();
                }
            }
            AppEvents.OnShutdown();
            System.Threading.Thread.Sleep(100);
        }
예제 #7
0
        /// <summary>Initializes the entity app. </summary>
        /// <remarks>Call this method after you finished composing entity application of modules.
        /// The method is called automatically when you connect the application to the database
        /// with <c>ConnectTo()</c> extension method.</remarks>
        public virtual void Init()
        {
            if (Status != EntityAppStatus.Created)
            {
                return;
            }
            Status = EntityAppStatus.Initializing;
            SystemLog.Info("Initializing app {0}...", this.AppName);
            this.AppEvents.OnInitializing(EntityAppInitStep.Initializing);
            //Check dependencies
            foreach (var mod in this.Modules)
            {
                var depList = mod.GetDependencies();
                foreach (var dep in depList)
                {
                    var ok = Modules.Any(m => dep.IsTypeOrSubType(m));
                    if (!ok)
                    {
                        this.SystemLog.Error("Module {0} requires dependent module {1} which is not included in the app.", mod.GetType(), dep);
                    }
                }
            }
            this.CheckActivationErrors();
            // Init linked apps
            foreach (var linkedApp in LinkedApps)
            {
                linkedApp.Init();
            }
            // create default services, possibly importing from LinkedApps
            CreateDefaultServices();
            // Create log file writer
            if (!string.IsNullOrWhiteSpace(_logFilePath))
            {
                _logFileWriter = new LogFileWriter(this, _logFilePath);
            }

            //Build model
            SystemLog.Info("  Building entity model...", this.AppName);
            var modelBuilder = new EntityModelBuilder(this);

            modelBuilder.BuildModel();
            if (SystemLog.HasErrors)
            {
                var errors = SystemLog.GetAllAsText();
                throw new StartupFailureException("Entity model build failed.", errors);
            }
            //Notify modules that entity app is constructed
            foreach (var module in this.Modules)
            {
                module.Init();
            }
            //init services
            var servList = this.GetAllServices();

            for (int i = 0; i < servList.Count; i++)
            {
                var service      = servList[i];
                var iServiceInit = service as IEntityService;
                if (iServiceInit != null)
                {
                    iServiceInit.Init(this);
                }
            }
            //complete initialization
            this.AppEvents.OnInitializing(EntityAppInitStep.Initialized);
            foreach (var module in this.Modules)
            {
                module.AppInitComplete();
            }

            CheckActivationErrors();
            Status = EntityAppStatus.Initialized;
            SystemLog.Info("  App {0} initialized.", this.AppName);
        }
예제 #8
0
 public override void RestoreCompletedTransactionsFailedWithError(SKPaymentQueue queue, NSError error)
 {
     // Restore failed somewhere...
     SystemLog.Info(" ** RESTORE RestoreCompletedTransactionsFailedWithError " + error.LocalizedDescription);
 }
예제 #9
0
 public override void PaymentQueueRestoreCompletedTransactionsFinished(SKPaymentQueue queue)
 {
     // Restore succeeded
     SystemLog.Info(" ** RESTORE PaymentQueueRestoreCompletedTransactionsFinished ");
 }
예제 #10
0
            // called when the transaction status is updated
            public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
            {
                SystemLog.Debug("UpdatedTransactions - {0}", transactions.Length);

                foreach (var transaction in transactions)
                {
                    // ISSUE: The transaction (and any dangling ones) are marked as finished straight away. Apple recommends we finish after app has done
                    // what it needs to. What happens if user's phone turns off right after finish? The app may not
                    // have registered purchase and the user will have to re-buy again!
                    //
                    // Solution is to to return a scope in the "PurchaseMethod" that
                    // finishes the transaction on dispose
                    //
                    // using(inAppPurchaseManager.Purchase("productid")) {
                    //  UpgradeApp();
                    // }  <-- dispose will finish transaction
                    //
                    if (transaction.TransactionState != SKPaymentTransactionState.Purchasing)
                    {
                        SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
                    }
                }

                if (transactions.Any(p => p.TransactionState.IsIn(SKPaymentTransactionState.Purchased, SKPaymentTransactionState.Restored)))
                {
                    var paymentTransaction = transactions.First(t => t.TransactionState.IsIn(SKPaymentTransactionState.Purchased, SKPaymentTransactionState.Restored));

                    switch (paymentTransaction.TransactionState)
                    {
                    case SKPaymentTransactionState.Purchased:
                        SystemLog.Info("PURCHASED");
                        _result =
                            new PurchaseResult {
                            AppStoreProductID = paymentTransaction.Payment.ProductIdentifier,
                            Result            = TransactionResult.Purchased,
                            PurchaseDate      = paymentTransaction.TransactionDate.ToNullableDateTime()
                        };
                        break;

                    case SKPaymentTransactionState.Restored:
                        SystemLog.Info("RESTORED");
                        _result =
                            new PurchaseResult {
                            AppStoreProductID = paymentTransaction.Payment.ProductIdentifier,
                            Result            = TransactionResult.Restored,
                            PurchaseDate      = paymentTransaction.OriginalTransaction.TransactionDate.ToNullableDateTime()
                        };
                        break;
                    }
                    _waiter.Set();
                }
                else if (transactions.All(t => t.TransactionState == SKPaymentTransactionState.Failed))
                {
                    SystemLog.Info("FAILED");
                    var paymentTransaction = transactions.First(t => t.TransactionState == SKPaymentTransactionState.Failed);
                    SystemLog.Info("WITH ERROR {0}", paymentTransaction.Error);
                    _result =
                        new PurchaseResult {
                        AppStoreProductID = paymentTransaction.Payment.ProductIdentifier,
                        Result            = TransactionResult.Failed,
                        Error             = paymentTransaction.Error,
                        PurchaseDate      = null
                    };
                    _waiter.Set();
                }
                else
                {
                    // still waiting for response (this was just dangling response from prior requests)
                }
            }