示例#1
0
        internal Guid[] FindObjects(int IndexID, IIndex <T> index, DynamicRole dynamicRole)
        {
            IndexData indexStorage = IndexStorageManager.IndexStorageManager <T> .GetIndexData(IndexID);

            try
            {
                DateTime indexStart = DateTime.Now;
                int?     operations;
                Guid[]   ret = index.FindObjects(indexStorage ?? index.EmptyIndexData, dynamicRole, out operations);
                IndexManager.IndexManager <T> .GetInstance().includeInStatistics(IndexID, IndexCostInformation.OneRoleSearch,
                                                                                 ((float)
                                                                                  (DateTime.Now.Ticks - indexStart.Ticks) /
                                                                                  10000000) / ret.Length == 0
                        ? 1
                        : ret.Length);

                if ((operations ?? 0) > 0)
                {
                    IndexManager.IndexManager <T> .GetInstance().includeInStatistics(IndexID, IndexCostInformation.HitRatio,
                                                                                     ret.Length / (float)operations);
                }
                return(ret);
            }
            catch (Exception ex)
            {
                if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger() != null)
                {
                    MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger()
                    .Log("IndexMechanism", string.Format("Index {0} throwed exception\n{1}", index.GetType(), ex),
                         MessageLevel.Error);
                }
                throw ex;
            }
        }
示例#2
0
        internal void AddDynamicRoles(int IndexID, IIndex <T> index, Oid[] obj, DynamicRole role, String[] attributes)
        {
            IndexData indexStorage = IndexStorageManager.IndexStorageManager <T> .GetIndexData(IndexID);

            try
            {
                foreach (Oid oid in obj)
                {
                    DateTime indexStart = DateTime.Now;
                    indexStorage = index.AddDynamicRole(indexStorage ?? index.EmptyIndexData, oid, role, attributes);
                    IndexManager.IndexManager <T> .GetInstance().includeInStatistics(IndexID,
                                                                                     IndexCostInformation.OneRoleIndexing,
                                                                                     (float)
                                                                                     (DateTime.Now.Ticks - indexStart.Ticks) /
                                                                                     10000000);
                }
            }
            catch (Exception ex)
            {
                if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger() != null)
                {
                    MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger()
                    .Log("IndexMechanism", string.Format("Index {0} throwed exception\n{1}", index.GetType(), ex),
                         MessageLevel.Error);
                }
                throw ex;
            }
            IndexStorageManager.IndexStorageManager <T> .UpdateIndexData(IndexID, indexStorage);
        }
示例#3
0
        internal void RemoveDynamicRole(int IndexID, IIndex <T> index, Oid obj, DynamicRole role)
        {
            IndexData indexStorage = IndexStorageManager.IndexStorageManager <T> .GetIndexData(IndexID);

            try
            {
                DateTime  indexStart      = DateTime.Now;
                IndexData newIndexStorage = index.RemoveDynamicRole(indexStorage ?? index.EmptyIndexData, obj, role);
                IndexManager.IndexManager <T> .GetInstance().includeInStatistics(IndexID,
                                                                                 IndexCostInformation.OneRoleIndexRemove,
                                                                                 (float)
                                                                                 (DateTime.Now.Ticks - indexStart.Ticks) /
                                                                                 10000000);

                IndexStorageManager.IndexStorageManager <T> .UpdateIndexData(IndexID, newIndexStorage);
            }
            catch (Exception ex)
            {
                if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger() != null)
                {
                    MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger()
                    .Log("IndexMechanism", string.Format("Index {0} throwed exception\n{1}", index.GetType(), ex),
                         MessageLevel.Error);
                }
                throw ex;
            }
        }
示例#4
0
        public async Task DynamicRoleAdd(string status, [OverrideTypeReader(typeof(AutomationTypeReader))] AutomationType type, IRole role)
        {
            if (string.IsNullOrWhiteSpace(status))
            {
                await ReplyAsync(_localization.GetMessage("Dynamic role invalid add status"));

                return;
            }

            var dynamicRole = await _dynamic.Get(Context.Guild.Id, status, type);

            if (dynamicRole != null)
            {
                try
                {
                    await _dynamic.Save(new DynamicRoleData
                    {
                        RoleId        = role.Id,
                        DynamicRoleId = dynamicRole.Id,
                        DynamicRole   = dynamicRole
                    });
                }
                catch (DataExistsException e)
                {
                    await ReplyAsync(_localization.GetMessage("Dynamic role invalid add role"));

                    return;
                }
            }
            else
            {
                dynamicRole = new DynamicRole
                {
                    ServerId = Context.Guild.Id,
                    Type     = type,
                    Status   = status.ToLower()
                };
                await _dynamic.Save(dynamicRole);

                await _dynamic.Save(new DynamicRoleData
                {
                    RoleId        = role.Id,
                    DynamicRoleId = dynamicRole.Id,
                    DynamicRole   = dynamicRole
                });
            }

            switch (type)
            {
            case AutomationType.Temporary:
                await ReplyAsync(_localization.GetMessage("Dynamic role add temp", role.Name, dynamicRole.Status));

                break;

            case AutomationType.Permanent:
                await ReplyAsync(_localization.GetMessage("Dynamic role add perm", role.Name, dynamicRole.Status));

                break;
            }
        }
示例#5
0
 protected void indexObjectsRoles(int indexID, IIndex <T> index, Oid[] obj, DynamicRole role,
                                  String[] attributes)
 {
     if (attributes == null)
     {
         _objectIndexer.AddDynamicRoles(indexID, index, obj, role);
     }
     else
     {
         _objectIndexer.AddDynamicRoles(indexID, index, obj, role, attributes);
     }
 }
示例#6
0
        /// <summary>
        ///     Save the (new) settings for a dynamic role.
        /// </summary>
        /// <param name="settings">The settings for a dynamic role.</param>
        /// <exception cref="InvalidStatusException">Thrown if the status is null or empty.</exception>
        /// <exception cref="StatusExistsException">Thrown if the status is already in use for the given type.</exception>
        public async Task Save(DynamicRole settings)
        {
            if (string.IsNullOrWhiteSpace(settings.Status))
            {
                throw new InvalidStatusException("The status of a dynamic role may not be empty.");
            }

            var roles = await _dbDynamic.List(settings.ServerId);

            if (roles.Any(x => x.Id != settings.Id && x.Type == settings.Type && x.Status.Equals(settings.Status, StringComparison.OrdinalIgnoreCase)))
            {
                throw new StatusExistsException("The status must be unique for every dynamic type.");
            }

            await _dbDynamic.Update(settings);
        }
示例#7
0
 public Guid[] FindObjects(int IndexID, DynamicRole role)
 {
     try
     {
         return(_objectIndexer.FindObjects(IndexID, global::IndexMechanism.IndexManager.IndexManager <T> .GetInstance().GetIndex(IndexID),
                                           role));
     }
     catch (Exception ex)
     {
         if (GetLoger() != null)
         {
             GetLoger().Log(Name, string.Format("While searching objects in indexed exception occurred\n{0}", ex),
                            MessageLevel.Error);
         }
         throw ex;
     }
 }
示例#8
0
 public bool IndexObjects(int indexID, Oid[] obj, DynamicRole role)
 {
     try
     {
         indexObjectsRoles(indexID, global::IndexMechanism.IndexManager.IndexManager <T> .GetInstance().GetIndex(indexID), obj, role, null);
     }
     catch (Exception ex)
     {
         if (GetLoger() != null)
         {
             GetLoger().Log(Name, string.Format("While indexing objects role exception occurred\n{0}", ex),
                            MessageLevel.Error);
         }
         throw ex;
     }
     return(true);
 }
示例#9
0
 public bool RemoveObjectRole(int indexID, Oid obj, DynamicRole role)
 {
     try
     {
         _objectIndexer.RemoveDynamicRole(indexID, global::IndexMechanism.IndexManager.IndexManager <T> .GetInstance().GetIndex(indexID), obj,
                                          role);
     }
     catch (Exception ex)
     {
         if (GetLoger() != null)
         {
             GetLoger().Log(Name, string.Format("While removing object role from index exception occurred\n{0}", ex),
                            MessageLevel.Error);
         }
         throw ex;
     }
     return(true);
 }
示例#10
0
 public Guid[] FindObjects(IndexData indexData, DynamicRole dynamicRole, string[] attributes, object[] values,
                           CompareType[] compareTypes, out int?readedObjects)
 {
     throw new NotImplementedException();
 }
示例#11
0
 public Guid[] FindObjects(IndexData indexData, DynamicRole dynamicRole, out int?readedObjects)
 {
     throw new NotImplementedException();
 }
示例#12
0
 public IndexData RemoveDynamicRole(IndexData indexData, Oid obj, DynamicRole role)
 {
     throw new NotImplementedException();
 }
示例#13
0
 public IndexData RemoveDynamicRole(IndexData indexData, Oid obj, DynamicRole role, string[] attributes)
 {
     throw new NotImplementedException();
 }
示例#14
0
 public Task Remove(DynamicRole value)
 {
     Context.DynamicRoles.Remove(value);
     return(Context.SaveChangesAsync());
 }
示例#15
0
 public Task Update(DynamicRole value)
 {
     Context.DynamicRoles.Update(value);
     return(Context.SaveChangesAsync());
 }
示例#16
0
 public Task Add(DynamicRole value)
 {
     Context.DynamicRoles.Add(value);
     return(Context.SaveChangesAsync());
 }
示例#17
0
 public Task Delete(DynamicRole role)
 {
     return(_dbDynamic.Remove(role));
 }