コード例 #1
0
        public void SetUp()
        {
            mocks = new MockRepository();

            ISettingsStorageProviderV30 settingsProvider = mocks.StrictMock <ISettingsStorageProviderV30>();

            Expect.Call(settingsProvider.GetSetting("ProcessSingleLineBreaks")).Return("false").Repeat.Any();
            Expect.Call(settingsProvider.GetSetting("WikiTitle")).Return("Title").Repeat.Any();

            Collectors.SettingsProvider = settingsProvider;

            IPagesStorageProviderV30 pagesProvider = mocks.StrictMock <IPagesStorageProviderV30>();

            Collectors.PagesProviderCollector = new ProviderCollector <IPagesStorageProviderV30>();
            Collectors.PagesProviderCollector.AddProvider(pagesProvider);

            Expect.Call(settingsProvider.GetSetting("DefaultPagesProvider")).Return(pagesProvider.GetType().FullName).Repeat.Any();

            PageInfo    page1        = new PageInfo("page1", pagesProvider, DateTime.Now);
            PageContent page1Content = new PageContent(page1, "Page 1", "User", DateTime.Now, "Comment", "Content", null, null);

            Expect.Call(pagesProvider.GetPage("page1")).Return(page1).Repeat.Any();
            Expect.Call(pagesProvider.GetContent(page1)).Return(page1Content).Repeat.Any();

            Expect.Call(pagesProvider.GetPage("page2")).Return(null).Repeat.Any();

            //Pages.Instance = new Pages();

            Host.Instance = new Host();

            Expect.Call(settingsProvider.GetSetting("CacheSize")).Return("100").Repeat.Any();
            Expect.Call(settingsProvider.GetSetting("CacheCutSize")).Return("20").Repeat.Any();

            Expect.Call(settingsProvider.GetSetting("DefaultCacheProvider")).Return(typeof(CacheProvider).FullName).Repeat.Any();

            // Cache needs setting to init
            mocks.Replay(settingsProvider);

            ICacheProviderV30 cacheProvider = new CacheProvider();

            cacheProvider.Init(Host.Instance, "");
            Collectors.CacheProviderCollector = new ProviderCollector <ICacheProviderV30>();
            Collectors.CacheProviderCollector.AddProvider(cacheProvider);

            mocks.Replay(pagesProvider);

            Collectors.FormatterProviderCollector = new ProviderCollector <IFormatterProviderV30>();

            //System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(new System.IO.StreamWriter(new System.IO.MemoryStream()));
            //System.Web.Hosting.SimpleWorkerRequest request = new System.Web.Hosting.SimpleWorkerRequest("Default.aspx", "?Page=MainPage", writer);
            System.Web.HttpContext.Current = new System.Web.HttpContext(new DummyRequest());
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:IndexRow" /> class.
        /// </summary>
        /// <param name="provider">The original provider.</param>
        public IndexRow(IPagesStorageProviderV30 provider)
        {
            this.command  = "Rebuild";           //command;
            this.provider = provider.Information.Name;
            providerType  = provider.GetType().FullName;
            documents     = "c";
            words         = "cc";
            occurrences   = "c";
            size          = "c";
            //int docCount, wordCount, matchCount;
            //long size;
            //TODO:  provider.GetIndexStats(out docCount, out wordCount, out matchCount, out size);

            //this.documents = docCount.ToString();
            //this.words = wordCount.ToString();
            //this.occurrences = matchCount.ToString();
            //this.size = Tools.BytesToString(size);

            this.isOk = true;             //TODO: !provider.IsIndexCorrupted;
        }
コード例 #3
0
ファイル: ProviderLoader.cs プロジェクト: wheeliemow/wiki
        /// <summary>
        /// Loads Providers from an assembly.
        /// </summary>
        /// <param name="assembly">The path of the Assembly to load the Providers from.</param>
        /// <param name="users">The Users Providers.</param>
        /// <param name="files">The Files Providers.</param>
        /// <param name="pages">The Pages Providers.</param>
        /// <param name="formatters">The Formatter Providers.</param>
        /// <param name="cache">The Cache Providers.</param>
        /// <remarks>The Components returned are <b>not</b> initialized.</remarks>
        public static void LoadFrom(string assembly, out IUsersStorageProviderV30[] users, out IPagesStorageProviderV30[] pages,
                                    out IFilesStorageProviderV30[] files, out IFormatterProviderV30[] formatters, out ICacheProviderV30[] cache)
        {
            Assembly asm = null;

            try
            {
                //asm = Assembly.LoadFile(assembly);
                // This way the DLL is not locked and can be deleted at runtime
                asm = Assembly.Load(LoadAssemblyFromProvider(Path.GetFileName(assembly)));
            }
            catch
            {
                files      = new IFilesStorageProviderV30[0];
                users      = new IUsersStorageProviderV30[0];
                pages      = new IPagesStorageProviderV30[0];
                formatters = new IFormatterProviderV30[0];
                cache      = new ICacheProviderV30[0];

                Log.LogEntry("Unable to load assembly " + Path.GetFileNameWithoutExtension(assembly), EntryType.Error, Log.SystemUsername);
                return;
            }

            Type[] types = null;

            try
            {
                types = asm.GetTypes( );
            }
            catch (ReflectionTypeLoadException)
            {
                files      = new IFilesStorageProviderV30[0];
                users      = new IUsersStorageProviderV30[0];
                pages      = new IPagesStorageProviderV30[0];
                formatters = new IFormatterProviderV30[0];
                cache      = new ICacheProviderV30[0];

                Log.LogEntry("Unable to load providers from (probably v2) assembly " + Path.GetFileNameWithoutExtension(assembly), EntryType.Error, Log.SystemUsername);
                return;
            }

            List <IUsersStorageProviderV30> urs = new List <IUsersStorageProviderV30>( );
            List <IPagesStorageProviderV30> pgs = new List <IPagesStorageProviderV30>( );
            List <IFilesStorageProviderV30> fls = new List <IFilesStorageProviderV30>( );
            List <IFormatterProviderV30>    frs = new List <IFormatterProviderV30>( );
            List <ICacheProviderV30>        che = new List <ICacheProviderV30>( );

            Type[] interfaces;
            for (int i = 0; i < types.Length; i++)
            {
                // Avoid to load abstract classes as they cannot be instantiated
                if (types[i].IsAbstract)
                {
                    continue;
                }

                interfaces = types[i].GetInterfaces( );
                foreach (Type iface in interfaces)
                {
                    if (iface == typeof(IUsersStorageProviderV30))
                    {
                        IUsersStorageProviderV30 tmpu = CreateInstance <IUsersStorageProviderV30>(asm, types[i]);
                        if (tmpu != null)
                        {
                            urs.Add(tmpu);
                            Collectors.FileNames[tmpu.GetType( ).FullName] = assembly;
                        }
                    }
                    if (iface == typeof(IPagesStorageProviderV30))
                    {
                        IPagesStorageProviderV30 tmpp = CreateInstance <IPagesStorageProviderV30>(asm, types[i]);
                        if (tmpp != null)
                        {
                            pgs.Add(tmpp);
                            Collectors.FileNames[tmpp.GetType( ).FullName] = assembly;
                        }
                    }
                    if (iface == typeof(IFilesStorageProviderV30))
                    {
                        IFilesStorageProviderV30 tmpd = CreateInstance <IFilesStorageProviderV30>(asm, types[i]);
                        if (tmpd != null)
                        {
                            fls.Add(tmpd);
                            Collectors.FileNames[tmpd.GetType( ).FullName] = assembly;
                        }
                    }
                    if (iface == typeof(IFormatterProviderV30))
                    {
                        IFormatterProviderV30 tmpf = CreateInstance <IFormatterProviderV30>(asm, types[i]);
                        if (tmpf != null)
                        {
                            frs.Add(tmpf);
                            Collectors.FileNames[tmpf.GetType( ).FullName] = assembly;
                        }
                    }
                    if (iface == typeof(ICacheProviderV30))
                    {
                        ICacheProviderV30 tmpc = CreateInstance <ICacheProviderV30>(asm, types[i]);
                        if (tmpc != null)
                        {
                            che.Add(tmpc);
                            Collectors.FileNames[tmpc.GetType( ).FullName] = assembly;
                        }
                    }
                }
            }

            users      = urs.ToArray( );
            pages      = pgs.ToArray( );
            files      = fls.ToArray( );
            formatters = frs.ToArray( );
            cache      = che.ToArray( );
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:IndexRow" /> class.
        /// </summary>
        /// <param name="provider">The original provider.</param>
        public IndexRow(IPagesStorageProviderV30 provider)
        {
            this.provider = provider.Information.Name;
            providerType = provider.GetType().FullName;

            int docCount, wordCount, matchCount;
            long size;
            provider.GetIndexStats(out docCount, out wordCount, out matchCount, out size);

            this.documents = docCount.ToString();
            this.words = wordCount.ToString();
            this.occurrences = matchCount.ToString();
            this.size = Tools.BytesToString(size);

            this.isOk = !provider.IsIndexCorrupted;
        }