Esempio n. 1
0
        protected override void Execute(Csla.Rules.AuthorizationContext context)
        {
            if (context.Target is User)
            {
                var businessIdentity = (IBusinessIdentity)Csla.ApplicationContext.User.Identity;

                if (businessIdentity.UserId == ((User)context.Target).UserId)
                {
                    context.HasPermission = true;

                    return;
                }
            }

            if (context.Target is UserPassword)
            {
                var identity = (IBusinessIdentity)Csla.ApplicationContext.User.Identity;

                if (identity.UserId == ((UserPassword)context.Target).UserId)
                {
                    context.HasPermission = true;

                    return;
                }
            }

            context.HasPermission = false;
        }
Esempio n. 2
0
        protected override void PropertyHasChanged(Csla.Core.IPropertyInfo property)
        {
            base.PropertyHasChanged(property);

            switch (property.Name)
            {
                case "AssignedTo":
                    this.OnAssignedToChanged();
                    break;
                case "CategoryId":
                    this.OnCategoryIdChanged();
                    break;
                case "EstimatedCompletedDate":
                    this.OnEstimatedCompletedDateChanged();
                    break;
                case "ProjectId":
                    this.OnProjectIdChanged();
                    break;
                case "StatusId":
                    this.OnStatusIdChanged();
                    break;
                default:
                    break;
            }
        }
Esempio n. 3
0
 public DateTimeRequired(Csla.Core.IPropertyInfo primaryProperty, DateTime minValue, DateTime maxValue)
     : base(primaryProperty)
 {
     this.MinValue = minValue.Date;
     this.MaxValue = maxValue.Date;
     this.InputProperties = new List<Csla.Core.IPropertyInfo> { primaryProperty };
 }
Esempio n. 4
0
 protected override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info, Csla.Core.StateMode mode)
 {
   base.OnSetState(info, mode);
   Name = info.GetValue<string>("SilverlightPrincipal.Criteria.Name");
   Password = info.GetValue<string>("SilverlightPrincipal.Criteria.Password");
   ProviderType = info.GetValue<string>("SilverlightPrincipal.Criteria.ProviderType");
 }
Esempio n. 5
0
        /* This method rectifies to the closes possible muiltiplier */
        public static bool CorrectToIncrementSize(Csla.PropertyInfo<UnitValue> propertyName)
        {
            PropertyManager _propertyManager = PropertyManager.Instance;
            Factor propertyFactor = _propertyManager.GetFactor(propertyName);

            decimal[] increments = propertyFactor.IncrementSizes;
            if (increments.Length == 0) return false;

            decimal currentValue = _propertyManager.GetValue(propertyName);

            bool allowIncrementStepping = _propertyManager.GetFactor(propertyName).IncrementStepping;

            if (currentValue == 0) return false;

            decimal newValue = 0;
            List<int> foundIndices = new List<int>();

            if (!allowIncrementStepping)
                newValue = MathExt.GetNearestValueByIncrements(currentValue, increments.ToArray(), out foundIndices);
            else
                newValue = MathExt.GetNearestMultiplierByIncrements(currentValue, increments.ToArray(), out foundIndices);

            if ((double)newValue != (double)currentValue)
            {
                _propertyManager.SetValue(propertyName, newValue);
                return true;
            }

            return false;
        }
Esempio n. 6
0
 protected override void OnGetState(Csla.Serialization.Mobile.SerializationInfo info, Csla.Core.StateMode mode)
 {
   info.AddValue("SilverlightPrincipal.Criteria.Name", Name);
   info.AddValue("SilverlightPrincipal.Criteria.Password", Password);
   info.AddValue("SilverlightPrincipal.Criteria.ProviderType", ProviderType);
   base.OnGetState(info, mode);
 }
Esempio n. 7
0
 public CustomIdentity Fetch(Csla.Security.UsernameCriteria criteria)
 {
   if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["CslaIsInRoleProvider"]))
     return DoFetch(criteria);
   else
     return PermissionFetch(criteria);
 }
Esempio n. 8
0
 private CustomIdentity PermissionFetch(Csla.Security.UsernameCriteria criteria)
 {
   CustomIdentity obj;
   using (var ctx = Csla.Data.ObjectContextManager<SecurityEntities>.GetManager("SecurityEntities"))
   {
     var q = (from r in ctx.ObjectContext.Users
              where r.Username == criteria.Username
              select r).FirstOrDefault();
     if (q != null)
     {
       q.Roles.Load();
       var roles = new List<string>();
       var permissions = new List<string>();
       foreach (var r in q.Roles)
       {
         roles.Add(r.Name);
         r.Permissions.Load();
         foreach (var p in r.Permissions)
           if (!permissions.Contains(p.Name))
             permissions.Add(p.Name);
       }
       obj = new CustomIdentity(q.Username, roles, permissions);
     }
     else
     {
       obj = new CustomIdentity();
     }
   }
   return obj;
 }
Esempio n. 9
0
 protected override void OnSetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
 {
   _username = (string)info.Values["_username"].Value;
   _password = (string)info.Values["_password"].Value;
   _roles = (string)info.Values["_roles"].Value;
   base.OnSetState(info, mode);
 }
Esempio n. 10
0
 public static void MapBrokenRules(ModelStateDictionary modelState, Csla.Core.BusinessBase businessObject)
 {
     foreach (var brokenRule in businessObject.BrokenRulesCollection)
     {
         modelState.AddModelError(brokenRule.Property, brokenRule.Description);
     }
 }
Esempio n. 11
0
 protected override void OnGetState(Csla.Serialization.Mobile.SerializationInfo info, StateMode mode)
 {
   info.AddValue("_username", _username);
   info.AddValue("_password", _password);
   info.AddValue("_roles", _roles);
   base.OnGetState(info, mode);
 }
        protected override void Execute(Csla.Rules.AuthorizationContext context)
        {
            if (context == null)
            {
                throw new ArgumentException("Context cannot be null.");
            }

            var entryType = context.Target as IHaveEntryType;
            context.HasPermission = false;

            if (entryType == null)
            {
                context.HasPermission = true;
            }
            else
            {
                if (entryType.EntryType == ActivityEntryType.Any)
                {
                    context.HasPermission = true;
                }
                else
                {
                    var role = entryType.EntryType.ToString();
                    if (entryType.EntryType != ActivityEntryType.Unset)
                    {
                        context.HasPermission = ApplicationContext.User.IsInRole(role);
                    }
                }
            }

            if (ApplicationContext.User.IsInRole(PermissionType.Administrator.ToString()))
            {
                context.HasPermission = true;
            }
        }
    protected void UserDataSource_UpdateObject( object sender, Csla.Web.UpdateObjectArgs e )
    {
        User obj = GetUser( User.ID );
        Csla.Data.DataMapper.Map( e.Values, obj );

        e.RowsAffected = SaveDetails( obj );
    }
Esempio n. 14
0
 private static void SetPrincipal(Csla.Security.CslaIdentity identity)
 {
   if (identity != null && identity.IsAuthenticated)
     Csla.ApplicationContext.User = new SLPrincipal(identity);
   else
     Csla.ApplicationContext.User = new Csla.Security.UnauthenticatedPrincipal();
 }
Esempio n. 15
0
 public static bool ContainsRule(Csla.Core.BusinessBase obj, DbType type, string propertyName)
 {
     switch (type)
     {
         case DbType.Int16:
         case DbType.Int32:
         case DbType.Int64:
             return obj.BrokenRulesCollection.Any(
                  brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.integerrequired/{0}", propertyName))
                     || obj.BrokenRulesCollection.Any(
                         brokenRule => brokenRule.RuleName == string.Format("rule://csla.rules.commonrules.dataannotation/{0}?a=Epiworx.Core.Validation.IntegerRequiredAttribute", propertyName));
         case DbType.Decimal:
             return obj.BrokenRulesCollection.Any(
                 brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.decimalrequired/{0}", propertyName));
         case DbType.Date:
             return obj.BrokenRulesCollection.Any(
               brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.daterequired/{0}", propertyName));
         case DbType.DateTime:
             return obj.BrokenRulesCollection.Any(
               brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.datetimerequired/{0}", propertyName));
         case DbType.String:
         case DbType.StringFixedLength:
             return obj.BrokenRulesCollection.Any(
              brokenRule => brokenRule.RuleName == string.Format("rule://epiworx.core.validation.stringrequired/{0}", propertyName));
         default:
             throw new NotSupportedException();
     }
 }
Esempio n. 16
0
 /// <summary>
 /// Creates an instance of the rule.
 /// </summary>
 /// <param name="primaryProperty">Primary property for the rule.</param>
 /// <param name="dependencyProperties">Dependent property.</param>
 /// <remarks>
 /// When rules are run for one of the dependency properties the rules for primary property i rerun.
 /// </remarks>
 public DependencyFrom(Csla.Core.IPropertyInfo primaryProperty, params Csla.Core.IPropertyInfo[] dependencyProperties)
   : base(primaryProperty)
 {
   if (InputProperties == null) 
     InputProperties = new List<IPropertyInfo>();
   InputProperties.AddRange(dependencyProperties);
 }
 private void HtmlContentCache_FetchHtmlContentCompleted(object sender, Csla.DataPortalResult<HtmlContent> e)
 {
     if (e.Object.HtmlContentEnum != ContentEnum)
         return;
     DataContext = e.Object;
     Title = MetaDataHelper.CreateContentPageTitle(e.Object.Name);
 }
    protected void ForumPostDataSource_SelectObject( object sender, Csla.Web.SelectObjectArgs e )
    {
        if (MainGrid.SelectedIndex < 0) return;
        int id = Convert.ToInt32( MainGrid.SelectedDataKey.Value );
        e.BusinessObject = GetForumPost( id );

        MainDetails.ChangeMode( DetailsViewMode.Edit );
    }
Esempio n. 19
0
 public RichBrokenRule(Csla.Core.BusinessBase businessBase, Csla.Rules.BrokenRule brokenRule)
 {
     BusinessObject = businessBase;
     Description = brokenRule.Description;
     Severity = brokenRule.Severity;
     Property = brokenRule.Property;
     RuleName = brokenRule.RuleName;
 }
Esempio n. 20
0
 /// <summary>
 /// Creates an instance of the rule that applies
 /// to a specfic property.
 /// </summary>
 /// <param name="primaryProperty">Primary property for this rule.</param>
 protected BusinessRule(Csla.Core.IPropertyInfo primaryProperty)
 {
     AffectedProperties = new List<Core.IPropertyInfo>();
       InputProperties = new List<Core.IPropertyInfo>();
       PrimaryProperty = primaryProperty;
       this.RuleUri = new RuleUri(this, primaryProperty);
       RunMode = RunModes.Default;
 }
        public async Task<DataPortalResult> Delete(Type objectType, object criteria, Csla.Server.DataPortalContext context, bool isSync)
        {
            //evict cache items based on ObjectCacheEvictionAttribute
            RemoveCacheItems(objectType);

            proxy = GetDataPortalProxy();
            return await proxy.Delete(objectType, criteria, context, isSync);
        }
Esempio n. 22
0
 /// <summary>
 /// Creates an instance of the rule.
 /// </summary>
 /// <param name="primaryProperty">Primary property for the rule.</param>
 /// <param name="dependencyProperties">Dependent property.</param>
 /// <remarks>
 /// When rules are run for one of the dependency properties the rules for primary property i rerun.
 /// </remarks>
 public DependencyFrom(Csla.Core.IPropertyInfo primaryProperty, params Csla.Core.IPropertyInfo[] dependencyProperties)
   : base(primaryProperty)
 {
   if (InputProperties == null) 
     InputProperties = new List<IPropertyInfo>();
   InputProperties.AddRange(dependencyProperties);
   RuleUri.AddQueryParameter("dependencyfrom", string.Join(",", dependencyProperties.Select(p => p.Name)));
 }
Esempio n. 23
0
    public ValidRole(Csla.Core.IPropertyInfo primaryProperty)
      : base(primaryProperty)
    {
#if SILVERLIGHT
        IsAsync = true;
#endif
      InputProperties = new System.Collections.Generic.List<Csla.Core.IPropertyInfo> { primaryProperty };
    }
Esempio n. 24
0
    protected void CodexRecordDataSource_SelectObject( object sender, Csla.Web.SelectObjectArgs e )
    {
        if ( CodexMenu.SelectedValue.Length < 1 ) return;
        int id = Convert.ToInt32( CodexMenu.SelectedValue );
        e.BusinessObject = GetCodexRecord( id );

        MainDetails.ChangeMode( DetailsViewMode.Edit );
    }
Esempio n. 25
0
 protected override Csla.WcfPortal.WcfResponse ConvertResponse(Csla.WcfPortal.WcfResponse response)
 {
   Csla.WcfPortal.WcfResponse returnValue = new Csla.WcfPortal.WcfResponse();
   returnValue.GlobalContext = CompressionUtility.Decompress(response.GlobalContext);
   returnValue.ObjectData = CompressionUtility.Decompress(response.ObjectData);
   returnValue.ErrorData = response.ErrorData;
   return returnValue;
 }
        public Csla.Server.DataPortalResult Delete(Type objectType, object criteria, Csla.Server.DataPortalContext context)
        {
            //evict cache items based on ObjectCacheEvictionAttribute
            RemoveCacheItems(objectType);

            proxy = GetDataPortalProxy();
            return proxy.Delete(objectType, criteria, context);
        }
        public async Task<DataPortalResult> Update(object obj, Csla.Server.DataPortalContext context, bool isSync)
        {
            //evict cache items based on ObjectCacheEvictionAttribute
            RemoveCacheItems(obj.GetType());

            proxy = GetDataPortalProxy();
            return await proxy.Update(obj, context, isSync);
        }
Esempio n. 28
0
 protected override Csla.Server.Hosts.Silverlight.WcfResponse ConvertResponse(Csla.Server.Hosts.Silverlight.WcfResponse response)
 {
   Csla.Server.Hosts.Silverlight.WcfResponse returnValue = new Csla.Server.Hosts.Silverlight.WcfResponse();
   returnValue.GlobalContext = CompressionUtility.Compress(response.GlobalContext);
   returnValue.ObjectData = CompressionUtility.Compress(response.ObjectData);
   returnValue.ErrorData = response.ErrorData;
   return returnValue;
 }
        public Csla.Server.DataPortalResult Update(object obj, Csla.Server.DataPortalContext context)
        {
            //evict cache items based on ObjectCacheEvictionAttribute
            RemoveCacheItems(obj.GetType());

            proxy = GetDataPortalProxy();
            return proxy.Update(obj, context);
        }
Esempio n. 30
0
 protected override Csla.Server.Hosts.Silverlight.UpdateRequest ConvertRequest(Csla.Server.Hosts.Silverlight.UpdateRequest request)
 {
   Csla.Server.Hosts.Silverlight.UpdateRequest returnValue = new Csla.Server.Hosts.Silverlight.UpdateRequest();
   returnValue.ClientContext = CompressionUtility.Decompress(request.ClientContext);
   returnValue.GlobalContext = CompressionUtility.Decompress(request.GlobalContext);
   returnValue.ObjectData = CompressionUtility.Decompress(request.ObjectData);
   returnValue.Principal = CompressionUtility.Decompress(request.Principal);
   return returnValue;
 }