示例#1
0
        internal static IndexInfo Load(string path)
        {
            IndexInfo ixi = null;

            try
            {
                using (TextReader textReader = new StreamReader(path))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(IndexInfo));
                    ixi = serializer.Deserialize(textReader) as IndexInfo;
                    textReader.Close();
                    ixi._xmlFileLoacation = path;
                    ixi.IndexStatistic.StatisticsChangedHandler += new StatisticsChanged(ixi.saveAfterStatisticsChanged);
                    if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism.GetLoger() != null)
                    {
                        MUTDOD.Server.Common.IndexMechanism.IndexMechanism.GetLoger().Log("IndexMechanism", message: "Loaded IndexInfo: " + ixi.IndexClassName, messageLevel: MessageLevel.Info);
                    }
                }
            }
            catch (Exception ex)
            {
                if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism.GetLoger() != null)
                {
                    MUTDOD.Server.Common.IndexMechanism.IndexMechanism.GetLoger().Log("IndexMechanism", string.Format("Unable to load IndexInfo\n{0}", ex), MessageLevel.Error);
                }
            }

            return(ixi);
        }
示例#2
0
        internal static bool Save(IndexInfo ixi, string path)
        {
            bool ret = false;

            try
            {
                using (TextWriter textWriter = new StreamWriter(path))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(IndexInfo));
                    serializer.Serialize(textWriter, ixi);
                    textWriter.Close();
                    ret = true;
                    if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism.GetLoger() != null)
                    {
                        MUTDOD.Server.Common.IndexMechanism.IndexMechanism.GetLoger().Log("IndexMechanism", string.Format("Saved IndexInfo: {0}", ixi.IndexClassName), MessageLevel.Info);
                    }
                    ixi._xmlFileLoacation = path;
                }
            }
            catch (Exception ex)
            {
                if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism.GetLoger() != null)
                {
                    MUTDOD.Server.Common.IndexMechanism.IndexMechanism.GetLoger().Log("IndexMechanism", string.Format("Unable to save IndexInfo\n{0}", ex), MessageLevel.Warning);
                }
            }

            return(ret);
        }
示例#3
0
        private void LoadIndex(string path)
        {
            IndexInfo <T> i;

            if ((i = IndexInfo <T> .Load(path)) != null)
            {
                if (i.IsValid())
                {
                    _indexes.Add(i);
                }
                else if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger() != null)
                {
                    MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger().Log("IndexMechanism", string.Format("Unable to load index plugin: {0}", i.IndexClassName), MessageLevel.Warning);
                }
            }
        }
示例#4
0
        public void IIndexSettingsChanged(IIndex <T> sender, string XML)
        {
            IndexInfo <T> index = null;

            foreach (KeyValuePair <IndexInfo <T>, IIndex <T> > keyValuePair in _indexesObjects)
            {
                if (keyValuePair.Value.Equals(sender))
                {
                    index = keyValuePair.Key;
                }
            }
            if (index == null)
            {
                return;
            }

            index.IndexSettings = XML;
        }
示例#5
0
        internal bool AddIndex(string dllPath)
        {
            if (!File.Exists(dllPath))
            {
                return(false);
            }

            string newIndexFileName = dllPath.Split('\\').Last();
            int    tries            = 0;

            while (File.Exists(string.Format("{0}\\{1}", this._indexesStoragePath, newIndexFileName)))
            {
                newIndexFileName = string.Format("{0}({1}).{2}", dllPath.Split('\\').Last().Split('.').First(), ++tries,
                                                 dllPath.Split('\\').Last().Split('.').Last());
            }


            AppDomain tempDomain = AppDomain.CreateDomain("tempDomain");
            Assembly  assembly   = tempDomain.Load(AssemblyName.GetAssemblyName(dllPath));
            //Assembly assembly = Assembly.LoadFile(dllPath);
            bool ret = false;

            Type[] assemblyTypes;
            try
            {
                assemblyTypes = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException ex)
            {
                if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger() != null)
                {
                    MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger().Log("IndexMechanism", string.Format("Iterating types in new index plugin assembly failed\n{0}", ex.LoaderExceptions.First().Message),
                                                                                           MessageLevel.Warning);
                }
                return(false);
            }
            catch (Exception ex)
            {
                if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger() != null)
                {
                    MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger().Log("IndexMechanism", string.Format("Iterating types in new index plugin assembly failed\n{0}", ex.Message),
                                                                                           MessageLevel.Warning);
                }
                return(false);
            }

            foreach (Type type in assemblyTypes)
            {
                if (type.IsClass && type.GetInterfaces().Contains(typeof(IndexPlugin.IIndex <object>)))
                {
                    try
                    {
                        IndexPlugin.IIndex <object> i = (IndexPlugin.IIndex <object>)Activator.CreateInstance(type);

                        if (!i.EmptyIndexData.GetType().IsSerializable)
                        {
                            throw new Exception();
                        }

                        IndexInfo <T> ixi = new IndexInfo <T>
                        {
                            IndexFileName  = newIndexFileName,
                            IndexName      = i.Name,
                            IndexClassName = type.FullName,
                            IndexID        = CORE.Settings <T> .GetInstance().NextIndexesIdentity
                        };

                        if (IndexInfo <T> .Save(ixi,
                                                string.Format("{0}\\{1}-{2}.xml", this._indexesStoragePath, type.GUID,
                                                              newIndexFileName)))
                        {
                            _indexes.Add(ixi);
                            ret = true;
                        }
                        i.Dispose();
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            if (ret)
            {
                try
                {
                    File.Copy(dllPath, string.Format("{0}\\{1}", this._indexesStoragePath, newIndexFileName));
                    File.SetAttributes(string.Format("{0}\\{1}", this._indexesStoragePath, newIndexFileName),
                                       FileAttributes.Normal);
                    if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger() != null)
                    {
                        MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger().Log("IndexMechanism", string.Format("Added new index plugin assembly: {0}", newIndexFileName),
                                                                                               MessageLevel.Info);
                    }
                }
                catch (Exception ex)
                {
                    if (MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger() != null)
                    {
                        MUTDOD.Server.Common.IndexMechanism.IndexMechanism <T> .GetLoger().Log("IndexMechanism", string.Format("Unable to add new index plugin assebly {0}", dllPath),
                                                                                               MessageLevel.Error);
                    }
                    ret = false;
                }
            }

            AppDomain.Unload(tempDomain);
            return(ret);
        }
示例#6
0
        private float getStatistics(IndexInfo <T> index, IndexCostType type, IndexCostInformation info)
        {
            StatisticInfo statisticInfo;

            switch (info)
            {
            case IndexCostInformation.OneObjectSearch:
                statisticInfo = index.IndexStatistic.ObjectSearch;
                break;

            case IndexCostInformation.OneObjectIndexAdd:
                statisticInfo = index.IndexStatistic.ObjectIndexing;
                break;

            case IndexCostInformation.OneObjectIndexRemove:
                statisticInfo = index.IndexStatistic.ObjectIndexRemove;
                break;

            case IndexCostInformation.OneObjectIndexRefresh:
                statisticInfo = index.IndexStatistic.ObjectIndexRefresh;
                break;

            case IndexCostInformation.HitRatio:
                statisticInfo = index.IndexStatistic.HitRatio;
                break;

            case IndexCostInformation.OneRoleIndexRefresh:
                statisticInfo = index.IndexStatistic.RoleIndexRefresh;
                break;

            case IndexCostInformation.OneRoleIndexRemove:
                statisticInfo = index.IndexStatistic.RoleIndexRemove;
                break;

            case IndexCostInformation.OneRoleIndexing:
                statisticInfo = index.IndexStatistic.RoleIndexing;
                break;

            case IndexCostInformation.OneRoleSearch:
                statisticInfo = index.IndexStatistic.RoleSearch;
                break;

            default:
                throw new UnexpectedStatisticRequestException(info);
            }

            float ret;

            switch (type)
            {
            case IndexCostType.Optimistic:
                ret = statisticInfo.Optimistic;
                break;

            case IndexCostType.Pessimistic:
                ret = statisticInfo.Pessimistic;
                break;

            case IndexCostType.Average:
                ret = statisticInfo.Average;
                break;

            default:
                throw new UnexpectedStatisticTypeException(type);
            }

            return(ret);
        }
示例#7
0
 public List <IndexInfo <T> > GetIndexes()
 {
     IndexInfo <T>[] ret = new IndexInfo <T> [_indexes.Count];
     _indexes.CopyTo(ret);
     return(ret.ToList());
 }