Exemplo n.º 1
0
        public async Task TestTextDocument()
        {
            MacroscopeJobMaster          JobMaster;
            MacroscopeDocumentCollection DocCollection;

            List <string> UrlList = new List <string>();

            UrlList.Add("https://nazuke.github.io/robots.txt");

            JobMaster = new MacroscopeJobMaster(
                JobRunTimeMode: MacroscopeConstants.RunTimeMode.LIVE,
                TaskController: this
                );

            DocCollection = new MacroscopeDocumentCollection(JobMaster: JobMaster);

            foreach (string Url in UrlList)
            {
                MacroscopeDocument msDoc = DocCollection.CreateDocument(Url: Url);

                Assert.IsNotNull(msDoc, string.Format("FAIL: {0}", Url));

                bool ExecuteResult = await msDoc.Execute();

                Assert.IsTrue(ExecuteResult, string.Format("FAIL: {0}", "Execute()"));

                Assert.AreEqual(Url, msDoc.GetUrl(), string.Format("FAIL: {0}", Url));

                Assert.IsTrue(msDoc.IsDocumentType(Type: MacroscopeConstants.DocumentType.TEXT), string.Format("FAIL: {0}", Url));

                /** Content Property Assertions ------------------------------------ **/

                Assert.AreEqual("text/plain", msDoc.GetMimeType());
                Assert.Greater(msDoc.GetContentLength(), 0);
            }
        }
        /**************************************************************************/

        protected override void RenderListView(
            List <ListViewItem> ListViewItems,
            MacroscopeDocumentCollection DocCollection,
            MacroscopeDocument msDoc,
            string Url
            )
        {
            if (msDoc.GetIsRedirect())
            {
                return;
            }

            if (!msDoc.IsDocumentType(Type: MacroscopeConstants.DocumentType.AUDIO))
            {
                return;
            }

            string StatusCode = msDoc.GetStatusCode().ToString();
            string MimeType   = msDoc.GetMimeType();
            string FileSize   = msDoc.GetContentLength().ToString();

            string PairKey = string.Join("", Url);

            ListViewItem lvItem = null;

            if (this.DisplayListView.Items.ContainsKey(PairKey))
            {
                try
                {
                    lvItem = this.DisplayListView.Items[PairKey];
                    lvItem.SubItems[COL_URL].Text         = Url;
                    lvItem.SubItems[COL_STATUS_CODE].Text = StatusCode;
                    lvItem.SubItems[COL_MIMETYPE].Text    = MimeType;
                    lvItem.SubItems[COL_FILESIZE].Text    = FileSize;
                }
                catch (Exception ex)
                {
                    DebugMsg(string.Format("MacroscopeDisplayAudios 1: {0}", ex.Message));
                }
            }
            else
            {
                try
                {
                    lvItem = new ListViewItem(PairKey);
                    lvItem.UseItemStyleForSubItems = false;
                    lvItem.Name = PairKey;

                    lvItem.SubItems[COL_URL].Text = Url;
                    lvItem.SubItems.Add(StatusCode);
                    lvItem.SubItems.Add(MimeType);
                    lvItem.SubItems.Add(FileSize);

                    this.DisplayListView.Items.Add(lvItem);
                }
                catch (Exception ex)
                {
                    DebugMsg(string.Format("MacroscopeDisplayAudios 2: {0}", ex.Message));
                }
            }

            if (lvItem != null)
            {
                lvItem.ForeColor = Color.Blue;

                /** URL ------------------------------------------------------------ **/

                if (msDoc.GetIsInternal())
                {
                    lvItem.SubItems[COL_URL].ForeColor = Color.Green;
                }
                else
                {
                    lvItem.SubItems[COL_URL].ForeColor = Color.Gray;
                }

                /** Status Code ---------------------------------------------------- **/

                if (msDoc.GetStatusCode() != HttpStatusCode.OK)
                {
                    lvItem.SubItems[COL_STATUS_CODE].ForeColor = Color.Red;
                }
                else
                {
                    lvItem.SubItems[COL_STATUS_CODE].ForeColor = Color.Green;
                }
            }
        }
        /**************************************************************************/

        protected override void RenderListView(
            List <ListViewItem> ListViewItems,
            MacroscopeDocument msDoc,
            string Url
            )
        {
            if (msDoc.GetIsRedirect())
            {
                return;
            }

            if (!msDoc.GetIsVideo())
            {
                return;
            }

            string StatusCode = msDoc.GetStatusCode().ToString();
            string MimeType   = msDoc.GetMimeType();
            string FileSize   = msDoc.GetContentLength().ToString();

            string PairKey = string.Join("", Url);

            ListViewItem lvItem = null;

            if (this.DisplayListView.Items.ContainsKey(PairKey))
            {
                try
                {
                    lvItem = this.DisplayListView.Items[PairKey];
                    lvItem.SubItems[0].Text = Url;
                    lvItem.SubItems[1].Text = StatusCode;
                    lvItem.SubItems[2].Text = MimeType;
                    lvItem.SubItems[3].Text = FileSize;
                }
                catch (Exception ex)
                {
                    DebugMsg(string.Format("MacroscopeDisplayVideos 1: {0}", ex.Message));
                }
            }
            else
            {
                try
                {
                    lvItem = new ListViewItem(PairKey);
                    lvItem.UseItemStyleForSubItems = false;
                    lvItem.Name = PairKey;

                    lvItem.SubItems[0].Text = Url;
                    lvItem.SubItems.Add(StatusCode);
                    lvItem.SubItems.Add(MimeType);
                    lvItem.SubItems.Add(FileSize);

                    ListViewItems.Add(lvItem);
                }
                catch (Exception ex)
                {
                    DebugMsg(string.Format("MacroscopeDisplayVideos 2: {0}", ex.Message));
                }
            }

            if (lvItem != null)
            {
                lvItem.ForeColor = Color.Blue;

                // URL -------------------------------------------------------------//

                if (msDoc.GetIsInternal())
                {
                    lvItem.SubItems[0].ForeColor = Color.Green;
                }
                else
                {
                    lvItem.SubItems[0].ForeColor = Color.Gray;
                }

                // Status Code -------------------------------------------------------//

                if (msDoc.GetStatusCode() != HttpStatusCode.OK)
                {
                    lvItem.SubItems[1].ForeColor = Color.Red;
                }
                else
                {
                    lvItem.SubItems[1].ForeColor = Color.Green;
                }
            }
        }