private void UpdateText() { if (Control == null || Element == null) { return; } var isHtml = HtmlLabel.GetIsHtml(Element); if (!isHtml) { return; } var attr = new NSAttributedStringDocumentAttributes(); var nsError = new NSError(); attr.DocumentType = NSDocumentType.HTML; var removeTags = HtmlLabel.GetRemoveHtmlTags(Element); var text = removeTags ? HtmlToText.ConvertHtml(Control.Text) : Element.Text; var helper = new LabelRendererHelper(Element, text); var htmlData = NSData.FromString(helper.ToString(), NSStringEncoding.Unicode); Control.AttributedText = new NSAttributedString(htmlData, attr, ref nsError); SetNeedsDisplay(); }
private void UpdateText() { if (Control == null || Element == null) { return; } var isHtml = HtmlLabel.GetIsHtml(Element); if (!isHtml) { return; } var removeTags = HtmlLabel.GetRemoveHtmlTags(Element); if (removeTags) { Control.Text = HtmlToText.ConvertHtml(Control.Text); } else { var value = Element.Text ?? string.Empty; var html = Build.VERSION.SdkInt >= BuildVersionCodes.N ? Html.FromHtml(value, FromHtmlOptions.ModeCompact) : Html.FromHtml(value); Control.SetText(html, TextView.BufferType.Spannable); } }
private void UpdateText() { if (Control == null || Element == null) { return; } var isHtml = HtmlLabel.GetIsHtml(Element); if (!isHtml) { return; } var removeTags = HtmlLabel.GetRemoveHtmlTags(Element); var text = removeTags ? HtmlToText.ConvertHtml(Control.Text) : Element.Text; var helper = new LabelRendererHelper(Element, text); var value = helper.ToString(); var html = Build.VERSION.SdkInt >= BuildVersionCodes.N ? Html.FromHtml(value, FromHtmlOptions.ModeCompact) : Html.FromHtml(value); Control.SetText(html, TextView.BufferType.Spannable); Control.MovementMethod = LinkMovementMethod.Instance; }
private void UpdateText() { if (Control == null || Element == null) { return; } var isHtml = HtmlLabel.GetIsHtml(Element); if (!isHtml) { return; } var removeTags = HtmlLabel.GetRemoveHtmlTags(Element); var text = removeTags ? HtmlToText.ConvertHtml(Control.Text) : Element.Text; var helper = new LabelRendererHelper(Element, text); CreateAttributedString(Control, helper.ToString()); SetNeedsDisplay(); }
private void UpdateText() { if (Control == null || Element == null) { return; } var isHtml = HtmlLabel.GetIsHtml(Element); if (!isHtml) { return; } var removeTags = HtmlLabel.GetRemoveHtmlTags(Element); var text = removeTags ? HtmlToText.ConvertHtml(Control.Text) : Element.Text; var helper = new LabelRendererHelper(Element, text); var html = Html.FromHtml(helper.ToString(), FromHtmlOptions.ModeCompact); Control.SetText(html, TextView.BufferType.Spannable); }
private void UpdateText() { if (Control == null || Element == null) { return; } var isHtml = HtmlLabel.GetIsHtml(Element); if (!isHtml) { return; } var removeTags = HtmlLabel.GetRemoveHtmlTags(Element); if (removeTags) { Control.Text = HtmlToText.ConvertHtml(Control.Text); } else { var value = Element.Text ?? string.Empty; var attr = new NSAttributedStringDocumentAttributes(); var nsError = new NSError(); attr.DocumentType = NSDocumentType.HTML; var myHtmlData = NSData.FromString(value, NSStringEncoding.Unicode); Control.AttributedText = new NSAttributedString(myHtmlData, attr, ref nsError); } SetNeedsDisplay(); }
override protected void GetNextRecord() { WikiArticlesViewItem wiki = WikiArticlesView.GetWikiArticlesViewItem(_loginUser, _itemIDList[_rowIndex]); _lastItemID = wiki.ArticleID; UpdatedItems.Add((int)_lastItemID); DocText = HtmlToText.ConvertHtml(wiki.Body == null ? string.Empty : wiki.Body); _docFields.Clear(); foreach (DataColumn column in wiki.Collection.Table.Columns) { object value = wiki.Row[column]; string s = value == null || value == DBNull.Value ? "" : value.ToString(); AddDocField(column.ColumnName, s); } DocFields = _docFields.ToString(); DocId = wiki.ArticleID; DocIsFile = false; DocName = wiki.ArticleID.ToString(); DocDisplayName = wiki.ArticleName; DocCreatedDate = wiki.CreatedDate; DocModifiedDate = DateTime.UtcNow; }
private void UpdateText() { if (Control == null || Element == null) { return; } var isHtml = HtmlLabel.GetIsHtml(Element); if (!isHtml) { return; } var removeTags = HtmlLabel.GetRemoveHtmlTags(Element); var text = removeTags ? HtmlToText.ConvertHtml(Control.Text) : Element.Text; var helper = new LabelRendererHelper(Element, text); Control.Text = helper.ToString(); var behavior = new HtmlTextBehavior(); Interaction.GetBehaviors(Control).Add(behavior); }
public async Task <Act> GetLegislationAsync(string id) { var idParts = id.Split('.'); var result = await _httpClient.GetAsync(string.Format(Options.UrlTemplate, $"20{idParts[2]}", idParts[3])); var doc = new HtmlToText(new [] { "Art.", "§", "[0-9][a-z]?\\)" }); var plainText = doc.ConvertHtml(await result.Content.ReadAsStringAsync()); return(await _actBuilder.CreateLegislation(plainText)); }
public void ConvertHtmlTest() { var converter = new HtmlToText(); const string headerText = "Header 1"; const string ulListItemText = "First bulleted item in the list."; const string olListItemText = "First item in the list."; var htmlContent = string.Format(@" <!DOCTYPE html> <html lang=""en"" xmlns=""http://www.w3.org/1999/xhtml""> <head> <meta charset=""utf-8"" /> <title></title> </head> <body> <p style=""margin-left: 40px""> {0}</p> <p> New paragraph. Plain text.</p> <p> a long sentence a long sentence a long sentence a long sentence a long sentence a long sentence a long sentence a long sentence a long sentence a long sentence a long sentence. </p> <div> <ul> <li>{1}</li> <li>Second bulleted item in the list.</li> </ul> <ol> <li>{2}</li> <li>Second item in the list.</li> </ol> </div> </body> </html>", headerText, ulListItemText, olListItemText); var plainText = converter.ConvertHtml(htmlContent); var paragrapthList = plainText.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).Where(p => !string.IsNullOrEmpty(p)).ToArray(); // New line after closing paragraph tag </p> Assert.IsTrue(paragrapthList.Contains(headerText)); // Each list item is on separate line. // ul list item should be started with "-" character. Assert.IsTrue(paragrapthList.Contains("- " + ulListItemText)); // Each list item is on separate line. Assert.IsTrue(paragrapthList.Contains(olListItemText)); }
public string ToPlainText() { var txt = ""; // txt += title + Environment.NewLine; txt += description + Environment.NewLine; if (references != null) { foreach (var reference in references) { txt += HtmlToText.ConvertHtml(reference.content) + Environment.NewLine; } } return(txt); }
public string[] Top10ContentWords(string url) { var proxy = new Web2StringProxy.ServiceClient(); var html = proxy.GetWebContent(url); proxy.Close(); var htmlToText = new HtmlToText(); var content = htmlToText.ConvertHtml(html); var contentWords = Regex.Split(content, @"[\W\d]+").Where(c => !String.IsNullOrWhiteSpace(c) && !_stopWords.Contains(c)); var topTenContentWords = (from w in contentWords group w by w into g let count = g.Count() orderby count descending select g.Key).Take(10); return(topTenContentWords.ToArray()); }
private void UpdateText() { if (Control == null || Element == null) { return; } var isHtml = HtmlLabel.GetIsHtml(Element); if (!isHtml) { return; } var plainText = HtmlToText.ConvertHtml(Element.Text); Control.Text = plainText; }
/// <summary> /// The DownloadArticleContent /// </summary> /// <param name="filters">The <see cref="string"/></param> public void DownloadArticleContent(string select, string[] filters) { var w = new HtmlAgilityPack.HtmlWeb(); HtmlDocument doc = new HtmlDocument(); if (Links.Count > 0) { try { HttpDownloader downloader = new HttpDownloader(Links[0].Uri.ToString(), null, Configuration.UserAgent); doc.LoadHtml(downloader.GetPage()); } catch (Exception ex) { doc = null; this.DisplayText = this.DisplayLine + " ERROR."; logger.Error($"Could not load {Links[0].Uri}"); logger.Error(ex); } } if (doc == null) { return; } HtmlToText conv = new HtmlToText() { Select = select, Filters = filters?.ToList(), LinkStartFrom = this.Links.Count }; Collection <Uri> links = new Collection <Uri>(); Collection <Uri> images = new Collection <Uri>(); var resultString = conv.ConvertHtml(doc.DocumentNode.OuterHtml, Links[0].Uri, out links, out images); //remove multiple lines from article content. It makes text more condensed. var cleanedContent = Regex.Replace(resultString, @"^\s+$[\r\n]*", "\r\n", RegexOptions.Multiline); ExternalLinks = links; ImageLinks = images; ArticleContent = cleanedContent; IsLoaded = true; Save(); }
private void UpdateText() { if (Control == null || Element == null) { return; } if (string.IsNullOrEmpty(Control.Text)) { return; } var isHtml = HtmlLabel.GetIsHtml(Element); if (!isHtml) { return; } var removeTags = HtmlLabel.GetRemoveHtmlTags(Element); var text = removeTags ? HtmlToText.ConvertHtml(Control.Text) : Element.Text; Control.MovementMethod = LinkMovementMethod.Instance; var helper = new LabelRendererHelper(Element, text); var value = helper.ToString(); var html = Build.VERSION.SdkInt >= BuildVersionCodes.N ? Html.FromHtml(value, FromHtmlOptions.ModeCompact, null, new ListTagHandler()) : #pragma warning disable CS0618 // Il tipo o il membro è obsoleto Html.FromHtml(value, null, new ListTagHandler()); #pragma warning restore CS0618 // Il tipo o il membro è obsoleto Control.SetIncludeFontPadding(false); html = RemoveLastChar(html); Control.SetText(html, TextView.BufferType.Spannable); }
override protected void GetNextRecord() { ProductVersionsViewItem productVersion = ProductVersionsView.GetProductVersionsViewItem(_loginUser, _itemIDList[_rowIndex]); _lastItemID = productVersion.ProductVersionID; UpdatedItems.Add((int)_lastItemID); DocText = HtmlToText.ConvertHtml(productVersion.Description == null ? string.Empty : productVersion.Description); _docFields.Clear(); foreach (DataColumn column in productVersion.Collection.Table.Columns) { object value = productVersion.Row[column]; string s = value == null || value == DBNull.Value ? "" : value.ToString(); AddDocField(column.ColumnName, s); } ProductVersionsSearch productVersionsSearch = new ProductVersionsSearch(productVersion); Tickets tickets = new Tickets(_loginUser); productVersionsSearch.openTicketCount = tickets.GetProductVersionTicketCount(productVersion.ProductVersionID, 0, _organizationID); AddDocField("**JSON", JsonConvert.SerializeObject(productVersionsSearch)); CustomValues customValues = new CustomValues(_loginUser); customValues.LoadByReferenceType(_organizationID, ReferenceType.ProductVersions, null, productVersion.ProductVersionID); foreach (CustomValue value in customValues) { object o = value.Row["CustomValue"]; string s = o == null || o == DBNull.Value ? "" : o.ToString(); AddDocField(value.Row["Name"].ToString(), s); } DocFields = _docFields.ToString(); DocIsFile = false; DocName = productVersion.ProductVersionID.ToString(); DocCreatedDate = productVersion.DateCreatedUtc; DocModifiedDate = DateTime.UtcNow; }
override protected void GetNextRecord() { WaterCoolerViewItem waterCooler = WaterCoolerView.GetWaterCoolerViewItem(_loginUser, _itemIDList[_rowIndex]); _lastItemID = waterCooler.MessageID; UpdatedItems.Add((int)_lastItemID); DocText = HtmlToText.ConvertHtml(waterCooler.Message); _docFields.Clear(); foreach (DataColumn column in waterCooler.Collection.Table.Columns) { object value = waterCooler.Row[column]; string s = value == null || value == DBNull.Value ? "" : value.ToString(); AddDocField(column.ColumnName, s); } DocFields = _docFields.ToString(); DocIsFile = false; DocName = waterCooler.MessageID.ToString(); DocCreatedDate = waterCooler.TimeStampUtc; DocModifiedDate = DateTime.UtcNow; }
override protected void GetNextRecord() { NotesViewItem note = NotesView.GetNotesViewItem(_loginUser, _itemIDList[_rowIndex]); _lastItemID = note.NoteID; UpdatedItems.Add((int)_lastItemID); DocText = HtmlToText.ConvertHtml(note.Description); _docFields.Clear(); foreach (DataColumn column in note.Collection.Table.Columns) { object value = note.Row[column]; string s = value == null || value == DBNull.Value ? "" : value.ToString(); AddDocField(column.ColumnName, s); } DocFields = _docFields.ToString(); DocIsFile = false; DocName = note.NoteID.ToString(); DocCreatedDate = note.DateCreatedUtc; DocModifiedDate = DateTime.UtcNow; }
public string MakeLink(string txt) { //Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase); //(http://|)(www\.)?([^\.]+)\.(\w{2})$ //(?<http>(http:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*) string testb = HtmlToText.ConvertHtml(txt); string fixedurl; //var resultString = new StringBuilder(testb); Regex regx = new Regex(@"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[.\!\/\\w]*))?)", RegexOptions.IgnoreCase); string resultString = regx.Replace(txt, (match) => { fixedurl = (match.Value.StartsWith("http://") || match.Value.StartsWith("https://")) ? match.Value : "http://" + match.Value; return("<a target='_blank' class='ts-link ui-state-default' href='" + fixedurl + "'>" + match.Value + "</a>"); }); // Regex regx = new Regex(@"((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[.\!\/\\w]*))?)", RegexOptions.IgnoreCase); //MatchCollection mactches = regx.Matches(txt); //foreach (Match match in mactches) //{ // if(match.Value.StartsWith("http://") || match.Value.StartsWith("https://")) // fixedurl = match.Value; // else // fixedurl = "http://" + match.Value; // resultString.Replace(match.Value, "<a target='_blank' class='ts-link ui-state-default' href='" + fixedurl + "'>" + match.Value + "</a>"); // //testb = testb.Replace(match.Value, "<a target='_blank' class='ts-link ui-state-default' href='" + fixedurl + "'>" + match.Value + "</a>"); //} return(GenerateTicketLink(resultString.ToString())); }
private async Task <bool> GetApproval(Guid itemId) { try { approval = await ApprovalRequestService.GetApprovalRequest(itemId); if (approval != null) { var item = new ApprovalRequestViewModel { Id = approval.Id.ToString(), Title = approval.ItemNumberFullAndNameDisplayPreference, Description = HtmlToText.ConvertHtml(approval.Description), //Status = ((ProjectInsightMobile.Enums.ApprovalRequestStateType)approval.ApprovalRequestStateType).ToString(), RequiresApprovalFromCurrentUser = approval.RequiresApprovalFromCurrentUser ?? false, Status = approval.ApprovalRequestStateTypeDescription, ApprovedDate = approval.ApprovedDateTimeUTC != null ? approval.ApprovedDateTimeUTC.Value : approval.CreatedDateTimeUTC.Value, RequestedBy = approval.Requestor != null ? "Requested By: " + approval.Requestor.Name : "", RequestedDate = approval.CreatedDateTimeUTC.HasValue ? approval.CreatedDateTimeUTC.Value.ToString("ddd M/d/yy htt") : string.Empty, DeadlineDate = approval.DeadlineDateTimeUTC.HasValue ? "Deadline: " + approval.DeadlineDateTimeUTC.Value.ToString("ddd M/d/yy htt") : string.Empty }; switch ((ApprovalRequestStateType)approval.ApprovalRequestStateType) { case ApprovalRequestStateType.Pending: item.StatusIcon = "pending.png"; item.StatusColor = ExtensionMethods.ConvertColorToHex((Color)Application.Current.Resources["PendingColor"]); break; case ApprovalRequestStateType.Approved: item.StatusIcon = "approved.png"; item.StatusColor = ExtensionMethods.ConvertColorToHex((Color)Application.Current.Resources["ApprovedColor"]); break; case ApprovalRequestStateType.Denied: item.StatusIcon = "rejected.png"; item.StatusColor = ExtensionMethods.ConvertColorToHex((Color)Application.Current.Resources["RejectedColor"]);; break; } //RequiresApprovalFromCurrentUser // item.RequiresApprovalFromCurrentUser = true; if (approval.ApprovalRequestApprovals != null && approval.ApprovalRequestApprovals.Count() > 0) { // item.RequiresApprovalFromCurrentUser = approval.ApprovalRequestApprovals.Any(x => x.Approver.Id == Common.CurrentWorkspace.UserID); foreach (var app in approval.ApprovalRequestApprovals) { if (app.Approver != null) { //---------------------------------- if (string.IsNullOrEmpty(app.Approver.PhotoUrl)) { if (!string.IsNullOrEmpty(app.Approver.AvatarHtml)) { string myDiv = app.Approver.AvatarHtml; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(myDiv); HtmlNode node = doc.DocumentNode.SelectSingleNode("div"); string AvatarInitials = "US"; string AvatarColor = "#fff"; string PhotoURL = string.Empty; if (node != null) { AvatarInitials = (node.ChildNodes[0]).OuterHtml; foreach (HtmlAttribute attr in node.Attributes) { if (attr.Name.ToLower() == "style") { string[] parts = attr.Value.Split('#'); if (parts != null && parts.Length > 1) { AvatarColor = parts[1]; } } } } else { HtmlNode node2 = doc.DocumentNode.SelectSingleNode("img"); if (node2 != null) { foreach (HtmlAttribute attr in node2.Attributes) { if (attr.Name.ToLower() == "src") { string imageUrl = attr.Value.Replace("/ProjectInsight.WebApp", ""); PhotoURL = Common.CurrentWorkspace.WorkspaceURL + imageUrl; } } } } StackLayout slAvatar = new StackLayout(); slAvatar.HeightRequest = 50; slAvatar.WidthRequest = 50; slAvatar.VerticalOptions = LayoutOptions.StartAndExpand; slAvatar.HorizontalOptions = LayoutOptions.StartAndExpand; slAvatar.Margin = new Thickness(0); Label lblUserId = new Label(); lblUserId.IsVisible = false; lblUserId.Text = app.Approver.Id.ToString(); lblUserId.Margin = 0; slAvatar.Children.Add(lblUserId); if (string.IsNullOrEmpty(PhotoURL)) { slAvatar.BackgroundColor = Color.FromHex(AvatarColor); Label lbInitials = new Label(); lbInitials.HeightRequest = 50; lbInitials.WidthRequest = 50; lbInitials.HorizontalOptions = LayoutOptions.CenterAndExpand; lbInitials.VerticalOptions = LayoutOptions.CenterAndExpand; lbInitials.HorizontalTextAlignment = TextAlignment.Center; lbInitials.VerticalTextAlignment = TextAlignment.Center; lbInitials.TextColor = Color.White; lbInitials.Text = AvatarInitials; lbInitials.FontSize = 26; if (Device.RuntimePlatform.ToLower() == "android") { lbInitials.FontFamily = "OpenSans-SemiBold.ttf#Open Sans"; } else { lbInitials.FontFamily = "OpenSans-SemiBold"; } slAvatar.Children.Add(lbInitials); } else { Image photo = new Image(); photo.Source = ImageSource.FromUri(new Uri(PhotoURL)); photo.HeightRequest = 50; photo.WidthRequest = 50; photo.HorizontalOptions = LayoutOptions.CenterAndExpand; photo.VerticalOptions = LayoutOptions.CenterAndExpand; slAvatar.Children.Add(photo); } var goToUserProfile = new TapGestureRecognizer(); goToUserProfile.Tapped += (s, e) => { StackLayout sl = (StackLayout)s; Label lbl = (Label)sl.Children[0]; Navigation.PushAsync(new UserProfile(new Guid(lbl.Text))); }; slAvatar.GestureRecognizers.Add(goToUserProfile); slApprovers.Children.Add(slAvatar); } } else { StackLayout slAvatar = new StackLayout(); slAvatar.HeightRequest = 50; slAvatar.WidthRequest = 50; slAvatar.VerticalOptions = LayoutOptions.StartAndExpand; slAvatar.HorizontalOptions = LayoutOptions.StartAndExpand; slAvatar.Margin = new Thickness(0); Label lblUserId = new Label(); lblUserId.IsVisible = false; lblUserId.Text = app.Approver.Id.ToString(); lblUserId.Margin = 0; slAvatar.Children.Add(lblUserId); Image photo = new Image(); photo.Source = ImageSource.FromUri(new Uri(Common.CurrentWorkspace.WorkspaceURL + app.Approver.PhotoUrl)); photo.HeightRequest = 50; photo.WidthRequest = 50; photo.HorizontalOptions = LayoutOptions.CenterAndExpand; photo.VerticalOptions = LayoutOptions.CenterAndExpand; slAvatar.Children.Add(photo); var goToUserProfile = new TapGestureRecognizer(); goToUserProfile.Tapped += (s, e) => { StackLayout sl = (StackLayout)s; Label lbl = (Label)sl.Children[0]; Navigation.PushAsync(new UserProfile(new Guid(lbl.Text))); }; slAvatar.GestureRecognizers.Add(goToUserProfile); slApprovers.Children.Add(slAvatar); } //-------------------------------- } } } if (approval.ApprovalRequestItems != null & approval.ApprovalRequestItems.Count > 0) { foreach (var appitem in approval.ApprovalRequestItems) { string Line1 = string.Empty; string Line2 = string.Empty; string Line3 = string.Empty; string Line4 = string.Empty; string Icon = string.Empty; Guid Id = appitem.Id.Value; if (appitem.ItemType == 8) { //Project Line1 = appitem.NameWithDisplayPreference; Line2 = FormatPeriodRange(appitem.StartDate, appitem.EndDate); Line3 = appitem.Status ?? string.Empty; Line4 = appitem.PrimaryProjectManager ?? string.Empty; Icon = "item_project.png"; } else if (appitem.ItemType == 9) { //Task Line1 = appitem.NameWithDisplayPreference; Line2 = FormatPeriodRange(appitem.StartDate, appitem.EndDate); Line3 = appitem.ProjectAffiliationNameAndNumber; Icon = "item_task.png"; } else if (appitem.ItemType == 10) { //To-Do Line1 = appitem.NameWithDisplayPreference; Line2 = FormatPeriodRange(appitem.StartDate, appitem.EndDate); Line3 = appitem.Status ?? string.Empty; Line4 = appitem.PrimaryProjectManager ?? string.Empty; Icon = "item_project.png"; } else if (appitem.ItemType == 21) { //Issue Line1 = appitem.NameWithDisplayPreference; string priority = appitem.IssuePriority ?? string.Empty; string separator = " - "; if (String.IsNullOrEmpty(priority)) { separator = ""; } Line2 = String.Format("{0}{1}{2}", FormatPeriodRange(appitem.StartDate, appitem.EndDate), separator, priority); Line3 = appitem.Status ?? string.Empty;; Line4 = appitem.ProjectAffiliationNameAndNumber ?? string.Empty; Icon = "item_issue.png"; } else if (appitem.ItemType == 22) { //Approval Request Line1 = appitem.NameWithDisplayPreference; Line2 = FormatPeriodRange(appitem.StartDate, appitem.EndDate); Line3 = appitem.Status ?? string.Empty; Line4 = appitem.PrimaryProjectManager ?? string.Empty; Icon = "item_project.png"; } else if (appitem.ItemType == 3) { //File Line1 = appitem.NameWithDisplayPreference; Line2 = FormatPeriodRange(appitem.StartDate, appitem.EndDate); Line3 = appitem.Status ?? string.Empty; Line4 = appitem.PrimaryProjectManager ?? string.Empty; Icon = "item_project.png"; } else { Line1 = appitem.NameWithDisplayPreference; Line2 = FormatPeriodRange(appitem.StartDate, appitem.EndDate); Line3 = appitem.Status ?? string.Empty; Line4 = appitem.PrimaryProjectManager ?? string.Empty; Icon = "item_project.png"; } StackLayout slItem = new StackLayout(); slItem.HorizontalOptions = LayoutOptions.FillAndExpand; slItem.VerticalOptions = LayoutOptions.FillAndExpand; slItem.Orientation = StackOrientation.Horizontal; slItem.Padding = new Thickness(0); slItem.Margin = new Thickness(20, 0, 20, 0); slItem.Spacing = 10; slItemList.Children.Add(slItem); StackLayout slIcon = new StackLayout(); slIcon.HorizontalOptions = LayoutOptions.Start; slIcon.VerticalOptions = LayoutOptions.StartAndExpand; slIcon.WidthRequest = 50; slIcon.HeightRequest = 50; slIcon.Padding = new Thickness(0, 8, 0, 0); slIcon.Margin = new Thickness(0); slIcon.Spacing = 0; slItem.Children.Add(slIcon); Image icon = new Image(); icon.HeightRequest = 50; icon.WidthRequest = 50; icon.HorizontalOptions = LayoutOptions.Center; icon.Source = Icon; icon.Margin = new Thickness(0); slIcon.Children.Add(icon); StackLayout slDetails = new StackLayout(); slDetails.HorizontalOptions = LayoutOptions.FillAndExpand; slDetails.VerticalOptions = LayoutOptions.FillAndExpand; slDetails.Orientation = StackOrientation.Vertical; slDetails.Padding = new Thickness(0); slDetails.Margin = new Thickness(0); slDetails.Spacing = 0; slItem.Children.Add(slDetails); StackLayout slLine1 = new StackLayout(); slLine1.HorizontalOptions = LayoutOptions.FillAndExpand; slLine1.VerticalOptions = LayoutOptions.FillAndExpand; slLine1.Orientation = StackOrientation.Vertical; slLine1.IsVisible = !string.IsNullOrEmpty(Line1); slLine1.Padding = new Thickness(0); slLine1.Margin = new Thickness(0); slLine1.Spacing = 0; slDetails.Children.Add(slLine1); Label lblLine1 = new Label(); lblLine1.LineBreakMode = LineBreakMode.NoWrap; lblLine1.FontSize = 20; lblLine1.Text = Line1; lblLine1.Margin = new Thickness(0); slLine1.Children.Add(lblLine1); StackLayout slLine2 = new StackLayout(); slLine2.HorizontalOptions = LayoutOptions.FillAndExpand; slLine2.VerticalOptions = LayoutOptions.FillAndExpand; slLine2.Orientation = StackOrientation.Vertical; slLine2.IsVisible = !string.IsNullOrEmpty(Line2); slLine2.Padding = new Thickness(0); slLine2.Margin = new Thickness(0); slLine2.Spacing = 0; slDetails.Children.Add(slLine2); Label lblLine2 = new Label(); lblLine2.LineBreakMode = LineBreakMode.NoWrap; lblLine2.FontSize = 14; lblLine2.Text = Line2; lblLine2.Margin = new Thickness(0); slLine2.Children.Add(lblLine2); StackLayout slLine3 = new StackLayout(); slLine3.HorizontalOptions = LayoutOptions.FillAndExpand; slLine3.VerticalOptions = LayoutOptions.FillAndExpand; slLine3.Orientation = StackOrientation.Vertical; slLine3.IsVisible = !string.IsNullOrEmpty(Line3); slLine3.Padding = new Thickness(0); slLine3.Margin = new Thickness(0); slLine3.Spacing = 0; slDetails.Children.Add(slLine3); Label lblLine3 = new Label(); lblLine3.LineBreakMode = LineBreakMode.NoWrap; lblLine3.FontSize = 14; lblLine3.Text = Line3; lblLine3.Margin = new Thickness(0); slLine3.Children.Add(lblLine3); StackLayout slLine4 = new StackLayout(); slLine4.HorizontalOptions = LayoutOptions.FillAndExpand; slLine4.VerticalOptions = LayoutOptions.FillAndExpand; slLine4.Orientation = StackOrientation.Vertical; slLine4.IsVisible = !string.IsNullOrEmpty(Line4); slLine4.Padding = new Thickness(0); slLine4.Margin = new Thickness(0); slLine4.Spacing = 0; slDetails.Children.Add(slLine4); Label lblLine4 = new Label(); lblLine4.LineBreakMode = LineBreakMode.NoWrap; lblLine4.FontSize = 14; lblLine4.Text = Line4; lblLine4.Margin = new Thickness(0); slLine4.Children.Add(lblLine4); BoxView line1 = new BoxView(); line1.HeightRequest = 0.5; line1.Color = (Color)Application.Current.Resources["DarkGrayTextColor"]; line1.HorizontalOptions = LayoutOptions.FillAndExpand; line1.VerticalOptions = LayoutOptions.End; line1.Margin = new Thickness(0, 2, 0, 2); slItemList.Children.Add(line1); } } viewModel = item; BindingContext = viewModel; } } catch (Exception ex) { return(false); } return(true); }
protected internal override void Work() { HttpWebRequest today_cal_request = (HttpWebRequest)HttpWebRequest.Create(Main.TODAY_URL); today_cal_request.AllowAutoRedirect = true; today_cal_request.AllowWriteStreamBuffering = true; today_cal_request.KeepAlive = false; today_cal_request.SendChunked = false; today_cal_request.ContentType = "text/calendar"; today_cal_request.Method = "GET"; today_cal_request.UseDefaultCredentials = true; today_cal_request.Proxy = null; HttpWebResponse today_cal_response = (HttpWebResponse)today_cal_request.GetResponse(); Stream today_cal_response_stream = today_cal_response.GetResponseStream(); byte[] today_cal_response_bytes = Main.readStream(today_cal_response_stream); string today_cal_response_str = System.Text.Encoding.UTF8.GetString(today_cal_response_bytes); vCalendar today_cal = new vCalendar(today_cal_response_str); CultureInfo en_us = new CultureInfo("en-US", true); char[] comma_delimiter = { ',' }; char[] semi_colon_delimiter = { ';' }; char[] equal_sign_delimiter = { '=' }; foreach (vEvent cal_event in today_cal.vEvents) { //START EVENT CODE DateTime cal_event_start = DateTime.MinValue; DateTime cal_event_end = DateTime.MinValue; string cal_event_summary = ""; string cal_event_description = ""; string cal_event_location = ""; bool cal_event_is_all_day = false; List <string> cal_event_repeat_days = new List <string>(); DateTime cal_event_repeat_end = DateTime.MinValue; string cal_event_repeat_frequency = ""; List <string> cal_event_tags = new List <string>(); bool cal_event_start_long = true; try{ cal_event_start = DateTime.ParseExact(cal_event.GetContentLine("DTSTART").Value, "yyyyMMddTHHmmss", en_us); }catch (Exception e) { cal_event_start_long = false; cal_event_is_all_day = true; } if (!cal_event_start_long) { try{ cal_event_start = DateTime.ParseExact(cal_event.GetContentLine("DTSTART").Value, "yyyyMMdd", en_us); }catch (Exception e) { } } bool cal_event_end_long = true; try{ cal_event_end = DateTime.ParseExact(cal_event.GetContentLine("DTEND").Value, "yyyyMMddTHHmmss", en_us); }catch (Exception e) { cal_event_end_long = false; } if (!cal_event_end_long) { try{ cal_event_end = DateTime.ParseExact(cal_event.GetContentLine("DTEND").Value, "yyyyMMdd", en_us); }catch (Exception e) { } } try{ cal_event_summary = cal_event.GetContentLine("SUMMARY").Value; }catch (Exception e) { } try{ cal_event_description = cal_event.GetContentLine("DESCRIPTION").Value; }catch (Exception e) { } try{ cal_event_location = cal_event.GetContentLine("LOCATION").Value; }catch (Exception e) { } try{ cal_event_tags = new List <string>(cal_event.GetContentLine("X-TAGS").Value.Split(comma_delimiter)); }catch (Exception e) { } cal_event_summary = normalize_ical_string(cal_event_summary); cal_event_description = normalize_ical_string(cal_event_description); cal_event_location = normalize_ical_string(cal_event_location); for (int i = 0; i < cal_event_tags.Count; i++) { cal_event_tags[i] = normalize_ical_string(cal_event_tags[i]); } cal_event_description = HtmlToText.ConvertHtml(cal_event_description); cal_event_description = Regex.Replace(cal_event_description, "<[^>]*>", ""); today_events.Add(new TodayEvent(cal_event_start, cal_event_end, cal_event_summary, cal_event_description, cal_event_location, cal_event_is_all_day, cal_event_tags)); //END EVENT CODE //START REPEAT CODE try{ List <string> repeat_parts = new List <string>(cal_event.GetContentLine("RRULE").Value.Split(semi_colon_delimiter)); foreach (string repeat_part in repeat_parts) { if (repeat_part.Contains("BYDAY")) { List <string> byday_part = new List <string>(repeat_part.Split(equal_sign_delimiter)); cal_event_repeat_days = new List <string>(byday_part[1].Split(comma_delimiter)); } else if (repeat_part.Contains("FREQ")) { List <string> repeat_frequency_part = new List <string>(repeat_part.Split(equal_sign_delimiter)); cal_event_repeat_frequency = repeat_frequency_part[1]; } else if (repeat_part.Contains("UNTIL")) { List <string> repeat_end_part = new List <string>(repeat_part.Split(equal_sign_delimiter)); cal_event_repeat_end = DateTime.ParseExact(repeat_end_part[1], "yyyyMMddTHHmmss", en_us); } } }catch (Exception e) { } if (cal_event_repeat_end == DateTime.MinValue) { try{ List <string> repeat_parts = new List <string>(cal_event.GetContentLine("RRULE").Value.Split(semi_colon_delimiter)); foreach (string repeat_part in repeat_parts) { if (repeat_part.Contains("UNTIL")) { List <string> repeat_end_part = new List <string>(repeat_part.Split(equal_sign_delimiter)); cal_event_repeat_end = DateTime.ParseExact(repeat_end_part[1], "yyyyMMdd", en_us); } } } catch (Exception e) { } } foreach (string repeat_day in cal_event_repeat_days) { if (cal_event_repeat_frequency == "WEEKLY") { for (int i = 0; i < WEEKS_LOADED; i++) { int offset = WEEK_DAYS_SHORT[repeat_day] - WEEK_DAYS[cal_event_start.DayOfWeek.ToString()]; if (i == 0) { if (offset <= 0) { continue; } } DateTime adjusted_start = cal_event_start.AddDays(i * 7 + offset); if (DateTime.Compare(adjusted_start, cal_event_repeat_end) > 0) { continue; } DateTime adjusted_end = (cal_event_end != DateTime.MinValue)?cal_event_end.AddDays(i * 7 + offset):DateTime.MinValue; today_events.Add(new TodayEvent(adjusted_start, adjusted_end, cal_event_summary, cal_event_description, cal_event_location, cal_event_is_all_day, cal_event_tags)); } } else if (cal_event_repeat_frequency == "MONTHLY") { for (int i = 1; i < MONTHS_LOADED; i++) { DateTime adjusted_start = cal_event_start.AddMonths(i); if (DateTime.Compare(adjusted_start, cal_event_repeat_end) > 0) { continue; } DateTime adjusted_end = (cal_event_end != DateTime.MinValue)?cal_event_end.AddMonths(i):DateTime.MinValue; today_events.Add(new TodayEvent(adjusted_start, adjusted_end, cal_event_summary, cal_event_description, cal_event_location, cal_event_is_all_day, cal_event_tags)); } } else if (cal_event_repeat_frequency == "YEARLY") { for (int i = 1; i < YEARS_LOADED; i++) { DateTime adjusted_start = cal_event_start.AddYears(i); if (DateTime.Compare(adjusted_start, cal_event_repeat_end) > 0) { continue; } DateTime adjusted_end = (cal_event_end != DateTime.MinValue)?cal_event_end.AddYears(i):DateTime.MinValue; today_events.Add(new TodayEvent(adjusted_start, adjusted_end, cal_event_summary, cal_event_description, cal_event_location, cal_event_is_all_day, cal_event_tags)); } } } //END REPEAT CODE } today_events.Sort((a, b) => a.CompareTo(b)); }
public void SendChat(string message, int userID, string name) { LoginUser loginUser = new LoginUser(connString, -1, -1, null); try { loginUser = new LoginUser(connString, TSAuthentication.GetLoginUser().UserID, TSAuthentication.GetLoginUser().OrganizationID, null); User u = Users.GetUser(loginUser, userID); //Console.WriteLine("message from " + loginUser.UserID + " to " + u.FirstLastName); //Clients.All.addMessage("message from " + Context.ConnectionId + " to " + u.FirstLastName); var result = pusher.Trigger("ticket-dispatch-" + TSAuthentication.GetLoginUser().OrganizationID, "chatMessage", new { message = HtmlToText.ConvertHtml(message), chatID = loginUser.UserID, chatname = name, reciever = userID }); //Clients.Client(u.AppChatID).chatMessage(HtmlToText.ConvertHtml(message), loginUser.UserID, name); } catch (Exception ex) { ExceptionLogs.LogException(loginUser, ex, "Socket.SendChat"); } }