Пример #1
0
 public ISchema[] GetSchemas()
 {
     if (!_allSchemasLoaded)
     {
         Sync(() =>
         {
             if (_allSchemasLoaded)
                 return;
             _allSchemasLoaded = true;
             var qry = _store.CreateQuery<SchemaModel>();
             var schemas = qry.Find();
             ISchema schema = null;
             foreach (var schemaModel in schemas)
             {
                 if (!_schemas.TryGetValue(schemaModel.SchemaId.ToLower(), out schema))
                 {
                     schema = new SchemaImpl(schemaModel);
                     _schemas[schema.Id.ToLower()] = schema;
                 }
             }
         });
     }
     return _schemas.Values.OrderBy(s => s.Name).ToArray();
 }
Пример #2
0
 private ISchema GetSchemaInternal(String schemaId, bool throwIfNotExists)
 {
     Assert.EmptyString(schemaId, "schemaId");
     ISchema result = null;
     schemaId = schemaId.ToLower();
     if (!_schemas.TryGetValue(schemaId, out result))
     {
         var qry = _store.CreateQuery<SchemaModel>();
         qry.AddFilterEqual("SchemaId", schemaId);
         var model = qry.FindFirst();
         if (model != null)
         {
             result = new SchemaImpl(model);
             _schemas[schemaId] = result;
         }
     }
     if (result == null && throwIfNotExists)
         throw new InvalidOperationException("Não existe um esquema de usuários com o id " + schemaId);
     return result;
 }
Пример #3
0
 public ISchema CreateSchema(string schemaId, string name)
 {
     Assert.EmptyString(schemaId, "schemaId");
     Assert.EmptyString(name, "name");
     ISchema schema = null;
     Sync(() =>
     {
         schema = GetSchemaInternal(schemaId, false);
         if (schema == null)
         {
             var model = new SchemaModel()
             {
                 SchemaId = schemaId,
                 Name = name
             };
             if (_store.Save(model))
             {
                 schema = new SchemaImpl(model);
                 _schemas[schemaId.ToLower()] = schema;
             }
             else
                 throw new Exception("Não foi possivel criar o esquema de usuários - erro ao persistir as informações");
         }
         else
             throw new Exception("Já existe um esquema de usuários com o id " + schemaId);
     });
     return schema;
 }