Inheritance: SpellbookPage
        public async Task LocalFileUploadRetryTest1()
        {
            const string FileName  = "File:Test image.jpg";
            var          localSite = await CreateIsolatedWikiSiteAsync(CredentialManager.DirtyTestsEntryPointUrl);

            // Cahce the token first so it won't be affected by the short timeout.
            await localSite.GetTokenAsync("edit");

            Output.WriteLine("Try uploading…");
            // We want to timeout and retry.
            localSite.WikiClient.Timeout    = TimeSpan.FromSeconds(0.5);
            localSite.WikiClient.RetryDelay = TimeSpan.FromSeconds(1);
            localSite.WikiClient.MaxRetries = 1;
            var buffer = new byte[1024 * 1024 * 2];     // 2MB, I think this size is fairly large.

            // If your connection speed is too fast then, well, trottle it plz.
            using (var ms = new MemoryStream(buffer))
            {
                await Assert.ThrowsAsync <TimeoutException>(async() =>
                {
                    try
                    {
                        await FilePage.UploadAsync(localSite, ms, FileName,
                                                   "This is an upload that is destined to fail. Upload timeout test.", false);
                    }
                    catch (UploadException ex)
                    {
                        Utility.Inconclusive(
                            "Your network speed might be too fast for the current timeout.\nException:" +
                            ex.Message);
                    }
                });
            }
        }
        public async Task LocalFileUploadTest1()
        {
            const string FileName       = "File:Test image.jpg";
            const string FileSHA1       = "81ED69FA2C2BDEEBBA277C326D1AAC9E0E57B346";
            const string ReuploadSuffix = "\n\nReuploaded.";
            var          file           = GetDemoImage();

            try
            {
                await FilePage.UploadAsync(await SiteAsync, file.Item1, FileName, file.Item2, false);
            }
            catch (UploadException ex)
            {
                // Client should rarely be checking like this
                // Usually we should notify the user.
                if (ex.UploadResult.Warnings[0].Key == "exists")
                {
                    // Just re-upload
                    await FilePage.UploadAsync(await SiteAsync, ex.UploadResult, FileName, file.Item2 + ReuploadSuffix, true);
                }
                else
                {
                    throw;
                }
            }
            var fp = new FilePage(await SiteAsync, FileName);
            await fp.RefreshAsync();

            ShallowTrace(fp);
            Assert.True(fp.Exists);
            Assert.Equal(FileSHA1, fp.LastFileRevision.Sha1.ToUpperInvariant());
        }
 public async Task LocalFileUploadTest2()
 {
     var stream = Stream.Null;
     var site   = await SiteAsync;
     await Assert.ThrowsAsync <OperationFailedException>(() => FilePage.UploadAsync(site, stream,
                                                                                    "File:Null.png", "This upload should have failed.", false));
 }
    public void ReloadFilePage()
    {
        FilePage filePage = filePagePanel.GetComponent <FilePage>();

        filePage.ClearCache();
        filePage.ReloadFilePanel();
    }
示例#5
0
        public ActionResult Index(int?pType, int?pPage)
        {
            FilePage mFilePage = new FilePage();
            string   mLevel    = "";

            if (pType == null)
            {
                if (Session["LoaiFileType"] != null)
                {
                    pType = (int)Session["LoaiFileType"];
                }
                else
                {
                    pType = 0;
                }
            }
            else
            {
                Session["LoaiFileType"] = pType;
            }
            if (pPage == null)
            {
                if (Session["LoaiFilePage"] != null)
                {
                    pPage = (int)Session["LoaiFilePage"];
                }
                else
                {
                    pPage = 1;
                }
            }
            else
            {
                Session["LoaiFilePage"] = pPage;
            }
            #endregion
            //lay Level cua Type
            if (pType != 0)
            {
                var mFileType = FileService.LayTheLoaiFileTheoId((int)pType);
                if (mFileType != null)
                {
                    mLevel = mFileType.Level.Trim();
                }
            }
            /*Lay danh sach cac tin theo page*/
            var mFileTypeAll = FileService.LayNhomFileAll();
            /*Lay danh sach cac tin theo page*/
            var mmFileList = FileService.LayFileTypeTrangAndGroupIdAdmin((int)pPage, 10, (int)pType, mLevel);
            if (mmFileList.Count < 10)
            {
                mFilePage.IsEnd = true;
            }
            //Tao Html cho danh sach tin nay
            mFilePage.Html     = V308HTMLHELPER.TaoDanhSachCacNhomFile(mmFileList, (int)pPage);
            mFilePage.HtmlNhom = V308HTMLHELPER.TaoDanhSachNhomFileHome2(mFileTypeAll, (int)pPage, (int)pType);
            mFilePage.Page     = (int)pPage;
            mFilePage.TypeId   = (int)pType;
            return(View("Index", mFilePage));
        }
示例#6
0
        public ActionResult Create()
        {
            FilePage mFilePage     = new FilePage();
            var      mListFileType = FileService.LayNhomFileAll();

            //Tao danh sach cac nhom tin
            mFilePage.HtmlNhom = V308HTMLHELPER.TaoDanhSachNhomFile2(mListFileType, 0);
            return(View("Create", mFilePage));
        }
 public bool CacheEqualto(FilePage filePage)
 {
     return
         (pageNum == filePage.currentPageNum &&
          sortingMethod == filePage.sortMethodDropdown.value &&
          fliterType == filePage.filterDropdown.value &&
          filterTime == filePage.timeDropdown.value &&
          keyword == filePage.keyword &&
          rateFrom == filePage.rateFromDropdown.value &&
          rateTo == filePage.rateToDropdown.value + 1);
 }
示例#8
0
        public async Task WpLzhFetchFileTest()
        {
            var site = await WpLzhSiteAsync;
            var file = new FilePage(site, "File:Empress Suiko.jpg");
            await file.RefreshAsync();

            ShallowTrace(file);
            //Assert.True(file.Exists);   //It's on WikiMedia!
            Assert.Equal(58865, file.LastFileRevision.Size);
            Assert.Equal("7aa12c613c156dd125212d85a072b250625ae39f", file.LastFileRevision.Sha1.ToLowerInvariant());
        }
        public void Setup()
        {
            GameObject loginAndSignUpPanel = Object.Instantiate((GameObject)Resources.Load("Prefabs/LoginAndSignUp Panel"));

            loginAndSignUp = loginAndSignUpPanel.GetComponent <LoginAndSignUp>();
            Debug.Log(loginAndSignUp);

            GameObject o = new GameObject("cavasObj");

            o.AddComponent <Canvas>();
            GameObject filePagePanel = Object.Instantiate((GameObject)Resources.Load("Prefabs/File Page Panel"), o.transform);

            filePage = filePagePanel.GetComponent <FilePage>();
            Debug.Log(filePage);
        }
示例#10
0
        public async Task <string> UploadImage(string imageName, Stream contentStream, Coordinate location)
        {
            _logger.LogInformation($"Upload an image to wikimedia common: {imageName}, Location: {location.Y}, {location.X}");
            var wikiFileName = "File:Israel_Hiking_Map_" + imageName.Replace(" ", "_");
            var comment      = CreateWikipediaComment(location, imageName);
            var results      = await FilePage.UploadAsync(_site, contentStream, wikiFileName, comment, true);

            if (results.ResultCode != UploadResultCode.Success)
            {
                throw new Exception("Unable to upload the file\n" + string.Join("\n", results.Warnings.Select(kvp => kvp.Key + ": " + kvp.Value)));
            }
            if (results.Warnings.Any(kvp => kvp.Key == "badfilename"))
            {
                wikiFileName = "File:" + results.Warnings.First(kvp => kvp.Key == "badfilename").Value;
            }
            _logger.LogInformation($"Finished uploading image {imageName}");
            return(wikiFileName);
        }
 public FilePageCache(FilePage filePage)
 {
     fileOverviews = new List <GameObject>();
     foreach (Transform fileOverviewTrans in filePage.filePanel.transform)
     {
         if (fileOverviewTrans.gameObject.activeSelf)
         {
             fileOverviews.Add(fileOverviewTrans.gameObject);
         }
     }
     pageNum       = filePage.currentPageNum;
     sortingMethod = filePage.sortMethodDropdown.value;
     fliterType    = filePage.filterDropdown.value;
     filterTime    = filePage.timeDropdown.value;
     keyword       = filePage.keyword;
     rateFrom      = filePage.rateFromDropdown.value;
     rateTo        = filePage.rateToDropdown.value + 1;
 }
示例#12
0
        public ActionResult Edit(int pId = 0)
        {
            FilePage mFilePage = new FilePage();
            var      mFileType = FileService.LayTheLoaiFileTheoId(pId);

            if (mFileType != null)
            {
                var mFileTypeList = FileService.LayNhomFileAll();
                //Tao danh sach cac nhom tin
                mFilePage.HtmlNhom  = V308HTMLHELPER.TaoDanhSachNhomFile3(mFileTypeList, (int)mFileType.ParentID);
                mFilePage.pFileType = mFileType;
            }
            else
            {
                mFilePage.Html = "Không tìm thấy loại file cần sửa.";
            }
            return(View("Edit", mFilePage));
        }
示例#13
0
        public async Task <string> UploadImage(string title, string fileName, Stream contentStream, Coordinate location)
        {
            _logger.LogInformation($"Upload an image to wikimedia common. title: {title}, fileName: {fileName}, Location: {location.Y}, {location.X}");
            var wikiFileName = GetNonExistingFilePageName(title, fileName);
            var comment      = CreateWikipediaComment(location, string.IsNullOrWhiteSpace(title) ? title : fileName);
            await _site.GetTokenAsync("edit", true);

            var results = await FilePage.UploadAsync(_site, contentStream, wikiFileName, comment, true);

            if (results.ResultCode != UploadResultCode.Success)
            {
                throw new Exception("Unable to upload the file\n" + string.Join("\n", results.Warnings.Select(kvp => kvp.Key + ": " + kvp.Value)));
            }
            if (results.Warnings.Any(kvp => kvp.Key == "badfilename"))
            {
                var correctWikiFileName = results.Warnings.First(kvp => kvp.Key == "badfilename").Value;
                _logger.LogWarning($"Received bad file name from wikipedia. old: {wikiFileName}, correct: File:{correctWikiFileName}");
                wikiFileName = "File:" + correctWikiFileName;
            }
            _logger.LogInformation($"Finished uploading image succesfully. title: {title}, fileName: {fileName}, wikipage: {wikiFileName}");
            return(wikiFileName);
        }
示例#14
0
        public async Task ExternalFileUploadTest1()
        {
            const string SourceUrl   = "https://upload.wikimedia.org/wikipedia/commons/5/55/8-cell-simple.gif";
            const string Description =
                @"A 3D projection of an 8-cell performing a simple rotation about a plane which bisects the figure from front-left to back-right and top to bottom.

This work has been released into the public domain by its author, JasonHise at English Wikipedia. This applies worldwide.

In some countries this may not be legally possible; if so:

JasonHise grants anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.";
            const string ReuploadSuffix = "\n\nReuploaded.";
            const string FileName       = "File:8-cell-simple.gif";
            var          site           = await CreateIsolatedWikiSiteAsync(CredentialManager.DirtyTestsEntryPointUrl);

            // Allow for more time to wait.
            site.WikiClient.Timeout = TimeSpan.FromSeconds(30);
            try
            {
                await FilePage.UploadAsync(site, SourceUrl, FileName, Description, false);
            }
            catch (UploadException ex)
            {
                // Client should rarely be checking like this
                // Usually we should notify the user.
                if (ex.UploadResult.Warnings[0].Key == "exists")
                {
                    // Just re-upload
                    await FilePage.UploadAsync(site, ex.UploadResult, FileName, Description + ReuploadSuffix, true);
                }
                else
                {
                    throw;
                }
            }
        }