Esempio n. 1
0
        public override IContext CreateContext(string contextName, ContextSchema schema)
        {
            if (string.IsNullOrEmpty(contextName))
            {
                throw new ArgumentNullException("contextName");
            }
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }

            IContext context;

            lock (padlock) {
                if (ContextsContains(contextName))
                {
                    throw new ContextAlreadyExistsException("A context with the name [" + contextName + "] already exists.");
                }
                using (var transaction = TransactionFactory.BeginTransaction(CurrentDB)) {
                    CurrentDB.ExecuteNonQuery("dbo.USER_CreateContext",
                                              transaction,
                                              CurrentDB.CreateStringInputParameter("@chvContext", DbType.AnsiString, contextName));
                    foreach (var s in schema)
                    {
                        AddSchemaToContext(s, contextName, transaction);
                    }
                    context = new Context(contextName);
                    transaction.Commit();
                }

                contexts.Add(context);
            }

            return(context);
        }
Esempio n. 2
0
 public override void DeleteUser(IUser user)
 {
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     UserCache.RemoveUserFromCache(user);
     CurrentDB.ExecuteNonQuery("dbo.USER_Delete",
                               CurrentDB.CreateInputParameter("@guidUserID", DbType.Guid, new Guid(user.Id)));
 }
Esempio n. 3
0
 protected virtual void AddSchemaToContext(PropertyDefinition definition, string contextName, ITransaction transaction)
 {
     CurrentDB.ExecuteNonQuery("dbo.USER_AddContextualPropertySchema",
                               transaction,
                               CurrentDB.CreateStringInputParameter("@chvContext", DbType.AnsiString, contextName, true),
                               CurrentDB.CreateStringInputParameter("@chvPropertyName",
                                                                    DbType.AnsiString,
                                                                    definition.PropertyName,
                                                                    true));
 }
Esempio n. 4
0
 public override void DeleteContext(IContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     lock (padlock) {
         using (var transaction = TransactionFactory.BeginTransaction(CurrentDB)) {
             CurrentDB.ExecuteNonQuery("dbo.USER_DeleteContext",
                                       transaction,
                                       CurrentDB.CreateStringInputParameter("@chvContext", DbType.AnsiString, context.Name, true));
             transaction.Commit();
         }
         contexts.Remove(context);
     }
 }
Esempio n. 5
0
        protected virtual void SaveProperty(IUser user, IProperty property, ITransaction transaction)
        {
            var propertyValue = string.Empty;

            if (!property.IsEmpty())
            {
                propertyValue = property.ToSerializedString();
            }

            if (propertyValue.Length > 0)
            {
                CurrentDB.ExecuteNonQuery("dbo.USER_UpdateProperty",
                                          transaction,
                                          CurrentDB.CreateInputParameter("@guidUserId", DbType.Guid, new Guid(user.Id)),
                                          CurrentDB.CreateStringInputParameter("@chvProperty", DbType.AnsiString, property.Name),
                                          CurrentDB.CreateStringInputParameter("@chvnPropertyValue",
                                                                               DbType.String,
                                                                               propertyValue.Length <= 4000 ? propertyValue : null),
                                          CurrentDB.CreateStringInputParameter("@txtnExtPropertyValue",
                                                                               DbType.String,
                                                                               propertyValue.Length > 4000 ? propertyValue : null),
                                          CurrentDB.CreateStringInputParameter("@chvContext",
                                                                               DbType.AnsiString,
                                                                               property.Context == null ||
                                                                               string.IsNullOrEmpty(property.Context.Name)
                                                                                                       ? null
                                                                                                       : property.Context.Name));
            }
            else
            {
                CurrentDB.ExecuteNonQuery("dbo.USER_DeleteProperty",
                                          transaction,
                                          CurrentDB.CreateInputParameter("@guidUserId", DbType.Guid, new Guid(user.Id)),
                                          CurrentDB.CreateStringInputParameter("@chvPropertyName", DbType.AnsiString, property.Name),
                                          CurrentDB.CreateStringInputParameter("@chvContextName",
                                                                               DbType.AnsiString,
                                                                               property.Context == null ||
                                                                               string.IsNullOrEmpty(property.Context.Name)
                                                                                                       ? null
                                                                                                       : property.Context.Name));
            }

            property.IsDirty = false;
        }