Example #1
0
        public static bool ValidateConfiguration(Type configType)
        {
            Debug.Assert(configType.IsEnum);
            IConfig config         = Catalog.Factory.Resolve <IConfig>();
            string  missingConfigs = string.Empty;

            foreach (var key in Enum.GetNames(configType))
            {
                Enum   tkey = (Enum)Enum.Parse(configType, key);
                string val  = config.Get(tkey, _missingKeyString);
                if (val == _missingKeyString)
                {
                    var ms = string.Format("Configuration validation: cannot retrieve key {0}", key);
                    CriticalLog.Always.WarnFormat(ms);
                    missingConfigs += ms;
                }
            }

            if (!string.IsNullOrEmpty(missingConfigs))
            {
                IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                on.RaiseAlert(ApplicationAlertKind.Defect, missingConfigs);
            }

            return(true);
        }
        public byte[] RetrieveFromBlobStorage(string key)
        {
            var container = _bc.GetContainerReference(_containerName);

            container.CreateIfNotExist();


            string blobUri = key;
            var    blob    = container.GetBlobReference(blobUri);

            if (!blob.Exists())
            {
                var es = string.Format("Image {0} cannot be found in blob storage", key);
                _log.Error(es);
                IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                on.RaiseAlert(ApplicationAlertKind.Unknown, es);
                return(null);
            }


            byte[] bytes = blob.DownloadByteArray();

            lock (_cache)
            {
                if (!_cache.ContainsKey(key))
                {
                    _dblog.InfoFormat("Image {0} retrieved from blob storage, adding to cache", key);
                    _cache.Add(key, bytes);
                }
            }
            return(bytes);
        }
 public AccountController()
 {
     _accountBusinessLogic    = new AccountBusinessLogic();
     _navigationBusinessLogic = new NavigationBusinessLogic();
     _log = ClassLogger.Create(this.GetType());
     _applicationAlert = Catalog.Factory.Resolve <IApplicationAlert>();
 }
Example #4
0
        /// <summary>
        ///   This method prevents unhandled exceptions from being thrown from the worker thread.
        /// </summary>
        public void ProtectedRun()
        {
            try
            {
                // Call the Workers Run() method
                Run();
            }
            catch (SystemException sex)
            {
                var es = "Worker system exception, exiting";
                IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                on.RaiseAlert(ApplicationAlertKind.System, es, sex);

                _log.Fatal(es, sex);
                throw;
            }
            catch (Exception ex)
            {
                var es = string.Format("Swallowed exception while running worker {0}:", GetType().FullName);
                IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                on.RaiseAlert(ApplicationAlertKind.Defect, es, ex);

                _dblog.Error(es, ex);
            }
        }
        public virtual bool GetBillingPlanFromCoupon(string couponPassKey, out BillingPlan billingPlan,
                                                     out Coupon coupon)
        {
            Debug.Assert(!string.IsNullOrEmpty(couponPassKey));

            using (var ds = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute))
            {
                billingPlan = null;
                coupon      = ds.Load <Coupon>(couponPassKey);
            }

            if (null == coupon)
            {
                _dblog.InfoFormat("No coupon found for passkey {0}", couponPassKey);
                return(false);
            }

            IUserContext _uc  = Catalog.Factory.Resolve <IUserContext>();
            var          user = _uc.GetCurrentUser();

            if (!string.IsNullOrEmpty(coupon.Target))
            {
                if (user.PrincipalId != coupon.Target)
                {
                    _dblog.InfoFormat("User {0} is not the target of coupon {1}", user.PrincipalId, coupon.PassString);
                    return(false);
                }
            }

            if (coupon.TotalAllowed > 0 && (coupon.CurrentCount >= coupon.TotalAllowed))
            {
                _dblog.InfoFormat("Coupon {0} exceeded allowed counts of {1}", coupon.PassString, coupon.TotalAllowed);
                return(false);
            }

            billingPlan = coupon.BillingPlan;

            if (null == billingPlan)
            {
                var es = string.Format("Coupon does not have a proper billing plan: coupon {0}", coupon.PassString);
                _log.Error(es);
                IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                on.RaiseAlert(ApplicationAlertKind.System, es);

                return(false);
            }

            _dblog.InfoFormat("Coupon passkey {0} linked to billing plan {1}", couponPassKey, billingPlan.Name);

            return(true);
        }
Example #6
0
        public OwnerInvitationController()
        {
            _invitationUILogic = new InvitationUILogic();
            _systemOwnerId     = _invitationUILogic.GetSuperAdminId();

            _log = ClassLogger.Create(this.GetType());
            _applicationAlert = Catalog.Factory.Resolve <IApplicationAlert>();
            _command          = new List <string> {
                "Create", "Edit", "Details", "Delete", "Sent Email"
            };
            _command1 = new List <string> {
                "Edit", "Details", "Delete", "Sent Email"
            };
        }
Example #7
0
        public ItemRegistrationController()
        {
            _itemRegistrationUILogic = new ItemRegistrationUILogic();

            _log = ClassLogger.Create(GetType());
            _applicationAlert = Catalog.Factory.Resolve <IApplicationAlert>();
            _command          = new List <string>
            {
                "Add",
                "Delete",
                "Assign Tag",
                "Clear Tag"
            };
        }
Example #8
0
        private void MirrorCopy()
        {
            if (!Directory.Exists(_targetPath))
            {
                Directory.CreateDirectory(_targetPath);
            }


            var blobs  = Client.FromConfig().ForBlobs();
            var source = blobs.GetContainerReference(SourcePath);

            source.CreateIfNotExist();

            var    versionBlob   = source.GetBlobReference("Version.txt");
            string versionString = versionBlob.DownloadText();

            if (string.IsNullOrEmpty(versionString))
            {
                var es = string.Format("Local File Mirror source in blob container {0} does not have blob Version.txt",
                                       SourcePath);
                _log.Error(es);
                IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                on.RaiseAlert(ApplicationAlertKind.Unknown, es);

                versionString = Guid.NewGuid().ToString();
            }

            string completedFile = TargetPath + "\\LFMComplete.txt";


            if (!File.Exists(completedFile) || File.ReadAllText(completedFile) != versionString)
            {
                var theBlobs = source.ListBlobs();

                foreach (IListBlobItem b in theBlobs)
                {
                    var    fileBlob = source.GetBlobReference(b.Uri.ToString());
                    string filename = Path.GetFileName(b.Uri.ToString());
                    File.Delete(filename);
                    fileBlob.DownloadToFile(_targetPath + "\\" + filename);
                }

                File.WriteAllText(completedFile, versionString);
            }
        }
        public virtual BillingPlan GetDefaultBillingPlan()
        {
            BillingPlan dbp = null;

            using (var ds = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute))
            {
                dbp = ds.Load <BillingPlan>(DefaultBillingPlanName);
            }

            Debug.Assert(null != dbp);
            if (null == dbp)
            {
                var es = "No default billing plan found!";
                _log.FatalFormat(es);
                IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                on.RaiseAlert(ApplicationAlertKind.System, es);
            }

            return(dbp);
        }
Example #10
0
        public RavenApplicationNodeRunner()
        {
            var cf         = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed);
            var companyKey = cf[ApplicationTopologyLocalConfig.CompanyKey];
            var appKey     = cf[ApplicationTopologyLocalConfig.ApplicationKey];

            _reg = new ApplicationNodeRegistry(companyKey, appKey);

            var logPath  = cf[ApplicationTopologyLocalConfig.LogFilePath];
            var compType = cf[ApplicationTopologyLocalConfig.ComponentType];
            var logName  = compType + ".log";

            _recurrence  = Catalog.Factory.Resolve <IRecurrence <object> >();
            _logFilePath = Path.Combine(logPath, logName);
            _logConfig   = new LogConfigConsumer(_logFilePath);
            _gatherer    = Catalog.Factory.Resolve <IApplicationNodeGatherer>();

            _alert = Catalog.Factory.Resolve <IApplicationAlert>();

            var rnd = new Random();

            _updateCycle = TimeSpan.FromSeconds(60.0 + (rnd.NextDouble() * 30.0));
        }
Example #11
0
        public UserController()
        {
            _userBusinessLogic = new UserBusinessLogic();
            _userUILogic       = new UserUILogic();
            _log = ClassLogger.Create(GetType());

            _applicationAlert = Catalog.Factory.Resolve <IApplicationAlert>();

            _command = new List <string>
            {
                "Invite New User",
                "Enable",
                "Disable",
                "Change User Role",
                "Edit User",
                "Details User",
                "Delete User",
                "Assign Tags",
                "Clear Tags",
                "ReSent Email",
                "Assign Group",
                "Remove Group"
            };
        }
Example #12
0
        protected override void ProcessUpgradeTrx(string trxInfo, string trxCode,
                                                  string subRole, string unSubRole,
                                                  string subFailTemplate, string signUpTempl, string shareTempl)
        {
            Debug.Assert(!string.IsNullOrEmpty(trxInfo));
            Debug.Assert(!string.IsNullOrEmpty(trxCode));
            Debug.Assert(!string.IsNullOrEmpty(subRole));
            Debug.Assert(!string.IsNullOrEmpty(unSubRole));
            Debug.Assert(!string.IsNullOrEmpty(subFailTemplate));
            Debug.Assert(!string.IsNullOrEmpty(signUpTempl));
            Debug.Assert(!string.IsNullOrEmpty(shareTempl));

            _dblogger.InfoFormat("Processing upgrade transaction, trxInfo {0}, trxCode {1}", trxInfo, trxCode);

            ApplicationUser             user   = null;
            ApplicationUserSubscription subscr = null;

            using (var ds = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute))
            {
                user   = ds.Load <ApplicationUser>(trxInfo);
                subscr =
                    (ApplicationUserSubscription)
                    user.Extensions.GetOrAdd(ApplicationUserSubscription.Extension,
                                             _ => new ApplicationUserSubscription());
            }

            if (null != user)
            {
                var bp = subscr.BillingPlan;

                if (null == bp)
                {
                    var es = string.Format("billing plan {0} not found for user {1}", subscr.BillingPlan,
                                           user.PrincipalId);
                    _logger.Error(es);
                    IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                    on.RaiseAlert(ApplicationAlertKind.System, es);
                    return;
                }

                switch (trxCode)
                {
                case PayPal.SubscriptionSignUp:
                case PayPal.SubscriptionPayment:
                    SignUpUser(user, signUpTempl, subRole, unSubRole, shareTempl);
                    break;

                case PayPal.SubscriptionFailed:
                case PayPal.SubscriptionCancel:
                case PayPal.SubscriptionEnd:
                    UnsignUser(user, subFailTemplate, unSubRole);
                    break;
                }
            }
            else
            {
                var es = string.Format("user {0} not found for upgrade", trxInfo);
                _logger.Error(es);
                IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                on.RaiseAlert(ApplicationAlertKind.System, es);
            }
        }
Example #13
0
        protected override void ProcessExpressTrx(
            string trxInfo, string trxCode, string buyerEmail, string invoice,
            string unSubRole,
            string sendAuthCodeTemplate, string subscriptionFailTemplate)
        {
            Debug.Assert(!string.IsNullOrEmpty(trxCode));
            Debug.Assert(!string.IsNullOrEmpty(trxInfo));
            Debug.Assert(!string.IsNullOrEmpty(invoice));
            Debug.Assert(!string.IsNullOrEmpty(unSubRole));
            Debug.Assert(invoice.Contains(";"));

            _dblogger.InfoFormat("Processing express transaction: trxInfo {0}, trxCode {1}, invoice {2}", trxInfo,
                                 trxCode, invoice);

            var         detail = invoice.Split(';');
            BillingPlan bp     = null;

            Debug.Assert(detail.Length == 3);

            using (var ds = DocumentStoreLocator.ResolveOrRoot(CommonConfiguration.CoreDatabaseRoute))
            {
                try
                {
                    string billingName = detail[1];

                    bp = ds.Load <BillingPlan>(billingName);

                    if (null == bp)
                    {
                        var es = string.Format("no billing plan found from invoice {0}", invoice);
                        _logger.Error(es);
                        IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                        on.RaiseAlert(ApplicationAlertKind.System, es);
                        throw new ApplicationException();
                    }
                }
                catch (Exception ex)
                {
                    IApplicationAlert on = Catalog.Factory.Resolve <IApplicationAlert>();
                    on.RaiseAlert(ApplicationAlertKind.System, ex);
                    return;
                }

                AuthorizationCode ac = ds.Load <AuthorizationCode>(trxInfo);


                switch (trxCode)
                {
                case PayPal.SubscriptionSignUp:
                case PayPal.SubscriptionPayment:
                    Debug.Assert(!string.IsNullOrEmpty(buyerEmail));

                    if (null == ac || ac.Principal == null)
                    {
                        // no user, no auth code. So send the user an authcode to use
                        var newAuthCode = new AuthorizationCode
                        {
                            Code           = trxInfo,
                            ExpirationTime = DateTime.UtcNow + TimeSpan.FromDays(90.0),
                            Referent       = bp.Name,
                            EmailedTo      = buyerEmail
                        };

                        ds.Store(newAuthCode);
                        ds.SaveChanges();


                        var email = SendEmail.CreateFromTemplate(_sender,
                                                                 Enumerable.Repeat(buyerEmail, 1).ToArray(),
                                                                 sendAuthCodeTemplate,
                                                                 trxInfo,
                                                                 newAuthCode.Code);
                        email.Send();

                        _logger.InfoFormat("Sent authcode {0} to user {1}", newAuthCode.Code, buyerEmail);
                    }
                    break;

                case PayPal.SubscriptionFailed:
                case PayPal.SubscriptionCancel:
                case PayPal.SubscriptionEnd:
                {
                    Debug.Assert(null != ac);

                    var user = ds.Load <ApplicationUser>(ac.Principal);


                    if (null == user)
                    {
                        _logger.ErrorFormat("Payment notification for unknown user {0}", ac.Principal);
                    }
                    else
                    {
                        UnsignUser(user, subscriptionFailTemplate, unSubRole);
                    }
                }
                break;
                }
            } // doc session
        }
Example #14
0
 static TenantHelper()
 {
     Log = ClassLogger.Create(typeof(TenantHelper));
     ApplicationAlert = Catalog.Factory.Resolve <IApplicationAlert>();
 }