Exemple #1
0
        public async Task <OpenApiResult> ListPets(int limit = 10, string?continuationToken = null)
        {
            int skip = ParseContinuationToken(continuationToken);

            PetResource[] pets = this.pets.Skip(skip).Take(limit).ToArray();

            string?     nextContinuationToken = (skip + limit < this.pets.Count) ? BuildContinuationToken(limit + skip) : null;
            HalDocument response = await this.petListMapper.MapAsync(
                new PetListResource(pets)
            {
                TotalCount = this.pets.Count,
                PageSize   = limit,
                CurrentContinuationToken = continuationToken,
                NextContinuationToken    = nextContinuationToken,
            }).ConfigureAwait(false);

            OpenApiResult result = this.OkResult(response, "application/hal+json");

            // We also add the next page link to the header, just to demonstrate that it's possible
            // to use WebLink items in this way.
            WebLink nextLink = response.GetLinksForRelation("next").FirstOrDefault();

            if (nextLink != default)
            {
                result.Results.Add("x-next", nextLink.Href);
            }

            result.AddAuditData(("skip", skip), ("limit", limit));

            return(result);
        }
Exemple #2
0
        public void TestWebLinkToString()
        {
            var webLink = new WebLink()
            {
                Url   = "/entries?page=2",
                Title = "Simple Title",
                Rel   = "next"
            };

            Assert.AreEqual("</entries?page=2>; title=\"Simple Title\" rel=\"next\"", webLink.ToString());

            webLink = new WebLink()
            {
                Url = "/entries?page=2",
                Rel = "next"
            };
            Assert.AreEqual("</entries?page=2>; rel=\"next\"", webLink.ToString());

            webLink = new WebLink()
            {
                Url   = "/entries?page=2",
                Title = "Hello"
            };
            Assert.AreEqual("</entries?page=2>; title=\"Hello\"", webLink.ToString());
        }
            // --

            public static Link ParseLink(JToken json)
            {
                if (json == null)
                {
                    return(null);
                }
                String  linkType = (string)json["type"];
                JObject value    = (JObject)json["value"];

                switch (linkType)
                {
                case "Link.web":
                    return(WebLink.Parse(value));

                case "Link.document":
                    return(DocumentLink.Parse(value));

                case "Link.file":
                    return(FileLink.Parse(value));

                case "Link.image":
                    return(ImageLink.Parse(value));
                }
                return(null);
            }
        public IActionResult Put(Guid id, [FromBody] WebLink webLink)
        {
            if (webLink == null)
            {
                return(BadRequest());
            }

            if (ModelState.IsValid)
            {
                var existingWebLink = _context.WebLinks.FirstOrDefault(w => w.Id == id);

                if (existingWebLink == null)
                {
                    return(NotFound(id));
                }

                existingWebLink.Name = webLink.Name;
                existingWebLink.Url  = webLink.Url;
                _context.SaveChanges();

                Ok(existingWebLink);
            }

            return(StatusCode(422));
        }
Exemple #5
0
 private void gridView2_DoubleClick(object sender, EventArgs e)
 {
     try
     {
         int k = gridView2.SelectedRowsCount;
         if (k > 0)
         {
             int RowHandle = gridView2.GetSelectedRows()[k - 1];
             if (RowHandle >= 0)
             {
                 long    iDDT = long.Parse(gridView2.GetRowCellValue(RowHandle, colID).ToString());
                 WebLink temp = WebLink.Get(iDDT);
                 if (temp != null)
                 {
                     frmWebLink frm = new frmWebLink(NumCode.UPEX);
                     frm._cus = temp;
                     if (frm.ShowDialog() == DialogResult.OK)
                     {
                         _LoadDSWebLink();
                     }
                 }
             }
         }
     }
     catch { }
 }
Exemple #6
0
		public void Ctor_Contract() {

			var result = new WebLink(webLinkContract);

			Assert.IsTrue(result.ContentEquals(webLinkContract), "constructed object is equal to contract");

		}
Exemple #7
0
        public static List <WebLink> GetOutlinks(HtmlDocument doc, Uri baseUri)
        {
            var links = new List <WebLink>();
            var nodes = doc.DocumentNode.Descendants("a").Where(a => a.GetAttributeValue("href", null) != null);

            foreach (var linkNode in nodes)
            {
                var href = linkNode.GetAttributeValue("href", "#");
                if (!Uri.IsWellFormedUriString(href, UriKind.RelativeOrAbsolute))
                {
                    continue;
                }
                var url     = href.ToAbsoluteUri(baseUri);
                var webLink = new WebLink();
                if (Uri.Compare(url, baseUri, UriComponents.Host, UriFormat.SafeUnescaped, StringComparison.CurrentCulture) == 0)
                {
                    webLink.LinkType = WebLinkType.Internal;
                }
                else
                {
                    webLink.LinkType = WebLinkType.External;
                }
                webLink.Scheme   = url.Scheme;
                webLink.LinkText = linkNode.InnerText;
                webLink.Uri      = url;
                links.Add(webLink);
            }
            return(links);
        }
Exemple #8
0
 private void btnDelLink_Click(object sender, EventArgs e)
 {
     try
     {
         int k = gridView2.SelectedRowsCount;
         if (k > 0)
         {
             if (
                 MessageBox.Show("Bạn muốn xóa những Topic này", "Thông tin", MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question) == DialogResult.OK)
             {
                 int[] arrSelect = gridView2.GetSelectedRows();
                 for (int i = 0; i < k; i++)
                 {
                     long    MaDT = long.Parse(gridView2.GetRowCellValue(arrSelect[i], colID).ToString());
                     WebLink temp = WebLink.Get(MaDT);
                     if (temp != null)
                     {
                         if (WebLink.Delete(temp.ID))
                         {
                             _LoadDSWebLink();
                         }
                         else
                         {
                             MessageBox.Show("Không thể link đang được sử dụng");
                         }
                     }
                 }
             }
         }
     }
     catch { }
 }
 public ActionResult Edit(WebLink link, int id)
 {
     _siteMetaData.Links.RemoveAt(id);
     _siteMetaData.Links.Insert(id, link);
     _metadataRepostory.Save(_siteMetaData);
     return(RedirectToAction("Manage", "Links"));
 }
Exemple #10
0
 private void _InitData()
 {
     _LoadNhomWebLink();
     _dtTable = new DataTable();
     _dtTable.Columns.Add("ID", typeof(long));
     _dtTable.Columns.Add("Url", typeof(string));
     _dtTable.Columns.Add("UrlPost", typeof(string));
     _dtTable.Columns.Add("UserName", typeof(string));
     _dtTable.Columns.Add("Password", typeof(string));
     _dtTable.Columns.Add("Topic", typeof(string));
     _dtTable.Columns.Add("Group", typeof(int));
     _dtTable.Columns.Add("Note", typeof(string));
     _dtTable.Columns.Add("Type", typeof(string));
     foreach (DataRow dtRow in _dtLogEntry.Rows)
     {
         if (dtRow["Status"] == "Successful")
         {
             WebLink webLink = WebLink.Get(long.Parse(dtRow["ID"].ToString()));
             if (webLink != null)
             {
                 DataRow dataRow = _dtTable.NewRow();
                 dataRow["ID"]       = webLink.ID;
                 dataRow["Url"]      = webLink.Url;
                 dataRow["UrlPost"]  = dtRow["LinkUp"];
                 dataRow["Topic"]    = _Subject;
                 dataRow["UserName"] = webLink.UserName;
                 dataRow["Password"] = webLink.Password;
                 dataRow["Group"]    = webLink.Group;
                 dataRow["Type"]     = NumCode.UPFORUM;
                 _dtTable.Rows.Add(dataRow);
             }
         }
     }
     grid_KhachHang.DataSource = _dtTable;
 }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            WebLink temp = _getFormInfo();

            if (temp != null)
            {
                if (_cus == null) //thêm mới
                {
                    _cus         = temp;
                    txtID.Text   = WebLink.Insert(_cus).ToString();
                    DialogResult = DialogResult.OK;
                    if (chkCloseAlterSave.Checked)
                    {
                        this.Close();
                        return;
                    }

                    _setFormStatus(-1);
                }
                else //cập nhật
                {
                    temp.ID = _cus.ID;
                    _cus    = temp;
                    WebLink.Update(_cus);
                    DialogResult = DialogResult.OK;
                    if (chkCloseAlterSave.Checked)
                    {
                        this.Close();
                        return;
                    }
                    _setFormStatus(-1);
                }
            }
        }
        private WebLink _getFormInfo()
        {
            WebLink temp = null;


            if (lookUpEdit_Nhom.EditValue != null)
            {
                if (txtUrl.Text != "")
                {
                    if (txtUrl.Text != "")
                    {
                        if (txtUsername.Text != "")
                        {
                            if (txtPassword.Text != "")
                            {
                                temp = new WebLink();

                                temp.Group    = (int)lookUpEdit_Nhom.EditValue;
                                temp.Type     = _Type;
                                temp.UrlPost  = txtUrlPost.Text;
                                temp.Url      = txtUrl.Text;
                                temp.UserName = txtUsername.Text;
                                temp.Password = txtPassword.Text;
                                temp.Note     = txtNote.Text;
                                temp.Topic    = txtTopic.Text;
                                temp.IDTopic  = txtIDTopic.Text;
                            }
                            else
                            {
                                MessageBox.Show("Nhập password đăng nhập", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                txtPassword.Focus();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Nhập user name đăng nhập", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            txtUsername.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Nhập link topic cần post tin", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtUrlPost.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Nhập Web page", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtUrl.Focus();
                }
            }
            else
            {
                MessageBox.Show("Chọn nhóm link", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                lookUpEdit_Nhom.Focus();
            }


            return(temp);
        }
Exemple #13
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            WebLink  webLink  = WebLink.Get(8);
            AutoUpEx autoUpEx = new AutoUpEx(null, webLink, 1);

            autoUpEx.UpTopic();



            return;

            if (dtContent == null || dtContent.Rows.Count == 0)
            {
                MessageBox.Show("Chưa có nội dung up.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (_WebLink == null || _WebLink.Rows.Count == 0)
            {
                MessageBox.Show("Chưa chọn danh sách link cần up bài.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (typeTime == 0)
            {
                MessageBox.Show("Thiết lập thời gian up bài.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (typeTime == 1)
            {
                timer1.Interval = timeTick * 60000;
                timer1.Tick    += new EventHandler(timer1_Tick);
                timer1.Start();
            }
            else
            {
                timer1.Interval = 50000;
                timer1.Tick    += new EventHandler(timer2_Tick);
                foreach (DataRow dtRow in dtTime.Rows)
                {
                    string[] time  = dtRow["Value"].ToString().Split(':');
                    TimeSpan span1 = new TimeSpan(int.Parse(time[0]), int.Parse(time[1]), 0);
                    TimeSpan span2 = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0);
                    if (span1 <= span2)
                    {
                        dtRow["Value"] = DateTime.Now.AddDays(1).ToString("yyyyMMdd") + dtRow["Value"].ToString();
                    }
                    else
                    {
                        dtRow["Value"] = DateTime.Now.ToString("yyyyMMdd") + dtRow["Value"].ToString();
                    }
                }

                timer1.Start();
            }
            btnOption.Enabled = false;
            btnStop.Enabled   = true;
            btnStart.Enabled  = false;
            btnClose.Enabled  = false;
        }
Exemple #14
0
        public void ContentEquals_AnotherLink_AreSame()
        {
            var copy = new WebLink(webLinkContract);

            var result = copy.ContentEquals(webLinkContract);

            Assert.IsTrue(result, "are equal");
        }
Exemple #15
0
        public void ContentEquals_AnotherLink_AreDifferent()
        {
            var copy = new WebLink(webLinkContract);

            var result = copy.ContentEquals(webLinkContract2);

            Assert.IsFalse(result, "are not equal");
        }
Exemple #16
0
        public ActionResult DeleteConfirmed(int id)
        {
            WebLink webLink = db.WebLinks.Find(id);

            db.WebLinks.Remove(webLink);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void WhenConstructingWebLinkItInitializesParameters()
        {
            // Act
            WebLink l = new WebLink();

            // Assert
            Assert.IsNotNull(l.Parameters);
        }
        public ArchivedWebLinkContract(WebLink webLink)
        {
            ParamIs.NotNull(() => webLink);

            Category = webLink.Category;
            Description = webLink.Description;
            Url = webLink.Url;
        }
        public void ContentEquals_AnotherLink_AreDifferent()
        {
            var copy = new WebLink(webLinkContract);

            var result = copy.ContentEquals(webLinkContract2);

            Assert.IsFalse(result, "are not equal");
        }
Exemple #20
0
        public ArchivedWebLinkContract(WebLink webLink)
        {
            ParamIs.NotNull(() => webLink);

            Category    = webLink.Category;
            Description = webLink.Description;
            Url         = webLink.Url;
        }
        public void ContentEquals_AnotherLink_AreSame()
        {
            var copy = new WebLink(webLinkContract);

            var result = copy.ContentEquals(webLinkContract);

            Assert.IsTrue(result, "are equal");
        }
        public void ItDoesIncludeBaseUrlWhenCreatingRelativeLinks()
        {
            // Act
            WebLink l = new WebLink(new Uri("http://dr.dk"), "/xxx/yyy?z=1", "abc", "app/x", "hello");

            // Assert
            Assert.AreEqual("http://dr.dk/xxx/yyy?z=1", l.Parameters["href"]);
            Assert.AreEqual("http://dr.dk/xxx/yyy?z=1", l.HRef.AbsoluteUri);
        }
        public void WhenBaseUrlIsNullItHandlesAbsoluteLinks()
        {
            // Act
            WebLink l = new WebLink(null, "http://dr.dk", "abc", "app/x", "hello");

            // Assert
            Assert.AreEqual("http://dr.dk/", l.Parameters["href"]);
            Assert.AreEqual("http://dr.dk/", l.HRef.AbsoluteUri);
        }
Exemple #24
0
        private void _LoadDSWebLink(string Page)
        {
            int i = gridView1.TopRowIndex;
            int k = gridView1.FocusedRowHandle;

            gridControl1.DataSource    = WebLink.GetByPage(Page);
            gridView1.FocusedRowHandle = k;
            gridView1.TopRowIndex      = i;
        }
        public WebLinkForApiContract(WebLink webLink)
        {
            ParamIs.NotNull(() => webLink);

            Category    = webLink.Category;
            Description = webLink.Description;
            Id          = webLink.Id;
            Url         = webLink.Url;
        }
Exemple #26
0
        /// <summary>
        /// Emits a deeplink event using the specified path.
        /// </summary>
        public void Emit(string path)
        {
            WebLink webPath = new WebLink(path);

            if (hooks.TryGetValue(webPath.Path, out HookHandler handler))
            {
                handler?.Invoke(webPath);
            }
        }
Exemple #27
0
        private void _LoadDSForum()
        {
            int i = gridView1.TopRowIndex;
            int k = gridView1.FocusedRowHandle;

            gridControl1.DataSource    = WebLink.GetByType(NumCode.UPFORUM);
            gridView1.FocusedRowHandle = k;
            gridView1.TopRowIndex      = i;
        }
        private void _LoadDSWebLink()
        {
            int i = gridView1.TopRowIndex;
            int k = gridView1.FocusedRowHandle;

            grid_KhachHang.DataSource  = WebLink.GetByType(_Type);
            gridView1.FocusedRowHandle = k;
            gridView1.TopRowIndex      = i;
        }
Exemple #29
0
        public static List <WebLink> Parse(string linkHeader)
        {
            var links = new List <WebLink>();
            var lines = linkHeader.Split(',');

            foreach (var line in lines)
            {
                var link       = new WebLink();
                var attributes = line.Split(';').Select(w => w.Trim()).ToList();
                var uri        = attributes.First(); // first element is URI-Reference
                link.Uri = uri.Substring(1, uri.Length - 2);
                foreach (var attribute in attributes.Skip(1))
                {
                    // key=value
                    var kv = attribute.Split('=');
                    var(key, value) = (kv[0], kv.Length == 2 ? Normalize(kv[1]) : "");

                    switch (key)
                    {
                    case "rel":
                        link.Rel = value;
                        break;

                    case "anchor":
                        link.Anchor = value;
                        break;

                    case "rev":
                        link.Rev = value.Split(' ').Where(w => !string.IsNullOrWhiteSpace(w)).ToList();
                        break;

                    case "hreflang":
                        link.HrefLang = value;
                        break;

                    case "title":
                        link.Title = value;
                        break;

                    case "title*":
                        link.TitleExt = value;
                        break;

                    case "type":
                        link.Type = value;
                        break;

                    // https://www.iana.org/assignments/link-relations/link-relations.xhtml
                    default:
                        link.Extensions.Add(key, value);
                        break;
                    }
                }
                links.Add(link);
            }
            return(links);
        }
        protected WebLink ParseLink()
        {
            Condition.Requires(NextToken.Type, "CurrentToken.Type").IsEqualTo(TokenType.Url);

            string url     = NextToken.Value;
            string rel     = null;
            string title   = null;
            string title_s = null;
            string type    = null;

            GetNextToken();

            while (NextToken.Type == TokenType.Semicolon)
            {
                try
                {
                    GetNextToken();
                    bool isExtended;
                    KeyValuePair <string, string> p = ParseParameter(out isExtended);

                    if (p.Key == "rel" && rel == null)
                    {
                        rel = p.Value;
                    }
                    else if (p.Key == "title" && title == null && !isExtended)
                    {
                        title = p.Value;
                    }
                    else if (p.Key == "title" && title_s == null && isExtended)
                    {
                        title_s = p.Value;
                    }
                    else if (p.Key == "type" && type == null)
                    {
                        type = p.Value;
                    }
                }
                catch (FormatException)
                {
                    while (NextToken.Type != TokenType.Semicolon && NextToken.Type != TokenType.Comma && NextToken.Type != TokenType.EOF)
                    {
                        try
                        {
                            GetNextToken();
                        }
                        catch (FormatException)
                        {
                        }
                    }
                }
            }

            WebLink link = new WebLink(BaseUrl, url, rel, type, title_s ?? title);

            return(link);
        }
Exemple #31
0
 private void PostTopic()
 {
     while (dtTableUp.Rows.Count > 0)
     {
         if (isAbort == false)
         {
             if (isLock == false)
             {
                 if (dtTableUp.Rows.Count > 0)
                 {
                     try
                     {
                         isLock = true;
                         string strErr = "";
                         long   id     = long.Parse(dtTableUp.Rows[0]["ID"].ToString());
                         dtTableUp.Rows.RemoveAt(0);
                         WebLink weblink = WebLink.Get(id);
                         isLock = false;
                         StatusObj statusObj = new StatusObj();
                         if (weblink != null)
                         {
                             strErr = "Up page " + weblink.Url + " [ " + weblink.Topic + " ] " + "....................";
                             DataRow dtRow = dtLogEntries.NewRow();
                             dtRow["ID"]         = id;
                             dtRow["LogEntries"] = strErr;
                             dtRow["DateTime"]   = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
                             dtLogEntries.Rows.Add(dtRow);
                             try
                             {
                                 WebBrowser webBrowser = (WebBrowser)panelControl1.Controls[id.ToString()];
                                 AutoUpEx   post       = new AutoUpEx(webBrowser, weblink);
                                 statusObj = post.UpTopic();
                                 strErr    = strErr + statusObj.Message;
                                 try { webBrowser.Dispose(); }
                                 catch { }
                                 try { panelControl1.Controls.Remove(webBrowser); }
                                 catch { }
                             }
                             catch
                             {
                                 strErr = strErr + " Error.";
                             }
                             dtRow["LogEntries"] = strErr;
                             dtRow["LinkUp"]     = statusObj.Value;
                             dtRow["Status"]     = statusObj.Status;
                         }
                     }
                     catch
                     {
                         isLock = false;
                     }
                 }
             }
         }
     }
 }
Exemple #32
0
            public static Fragment Parse(String type, JToken json)
            {
                switch (type)
                {
                case "StructuredText":
                    return(StructuredText.Parse(json));

                case "Image":
                    return(Image.Parse(json));

                case "Link.web":
                    return(WebLink.Parse(json));

                case "Link.document":
                    return(DocumentLink.Parse(json));

                case "Link.file":
                    return(FileLink.Parse(json));

                case "Link.image":
                    return(ImageLink.Parse(json));

                case "Text":
                    return(Text.Parse(json));

                case "Select":
                    return(Text.Parse(json));

                case "Date":
                    return(Date.Parse(json));

                case "Timestamp":
                    return(Timestamp.Parse(json));

                case "Number":
                    return(Number.Parse(json));

                case "Color":
                    return(Color.Parse(json));

                case "Embed":
                    return(Embed.Parse(json));

                case "GeoPoint":
                    return(GeoPoint.Parse(json));

                case "Group":
                    return(Group.Parse(json));

                case "SliceZone":
                    return(SliceZone.Parse(json));

                default:
                    return(json != null?Raw.Parse(json) : null);
                }
            }
Exemple #33
0
        /// <summary>
        /// Starts listening to links of specified path.
        /// </summary>
        public void LinkPath(string path, HookHandler handler)
        {
            if (handler == null || path == null)
            {
                return;
            }

            path        = WebLink.ExtractPath(path);
            hooks[path] = handler;
        }
        public static WebLink CreateLink(string _url, string title)
        {
            var url      = new Uri(_url);
            var document = new WebLink();

            document.Title = title;
            document.Text  = "";
            document.Uri   = url;
            return(document);
        }
        public WebLinkContract(WebLink link)
        {
            ParamIs.NotNull(() => link);

            Category = link.Category;
            Description = link.Description;
            DescriptionOrUrl = link.DescriptionOrUrl;
            Id = link.Id;
            Url = link.Url;
        }
Exemple #36
0
        public static IEnumerable<WebLink> Parse(String linkFormat)
        {
            if (!String.IsNullOrEmpty(linkFormat))
            {
                Scanner scanner = new Scanner(linkFormat);
                String path = null;
                while ((path = scanner.Find(ResourceNameRegex)) != null)
                {
                    path = path.Substring(1, path.Length - 2);
                    WebLink link = new WebLink(path);

                    String attr = null;
                    while (scanner.Find(DelimiterRegex, 1) == null &&
                        (attr = scanner.Find(WordRegex)) != null)
                    {
                        if (scanner.Find(EqualRegex, 1) == null)
                        {
                            // flag attribute without value
                            link.Attributes.Add(attr);
                        }
                        else
                        {
                            String value = null;
                            if ((value = scanner.Find(QuotedString)) != null)
                            {
                                // trim " "
                                value = value.Substring(1, value.Length - 2);
                                if (Title.Equals(attr))
                                    link.Attributes.Add(attr, value);
                                else
                                    foreach (String part in BlankRegex.Split(value))
                                        link.Attributes.Add(attr, part);
                            }
                            else if ((value = scanner.Find(WordRegex)) != null)
                            {
                                link.Attributes.Set(attr, value);
                            }
                            else if ((value = scanner.Find(Cardinal)) != null)
                            {
                                link.Attributes.Set(attr, value);
                            }
                        }
                    }

                    yield return link;
                }
            }

            yield break;
        }