private void VideoProcess(string operation) { if (VideoDownloadList.SelectedItem == null) { return; } if (operation == "Copy") { App.SetClipboardText((VideoDownloadList.SelectedItems .OfType <YouTube.Downloadable>()).Where(url => url.UrlUnavailableException != null) .Aggregate(string.Empty, (current, url) => current + (url.GetUrlExtended() + Environment.NewLine))); } else { var links = VideoDownloadList.SelectedItems.OfType <YouTube.Downloadable>(); foreach (var link in links) { try { if (link.UrlUnavailableException != null) { continue; } switch (operation) { case "HideEar": App.Current.MainWindow.AddToHideEarQueue(new DownloadTask(link.GetUrlExtended(), link.GenerateFileName(false).ToValidPath(), link.Parent.Url)); break; case "Normal": Process.Start(link.GetUrlExtended()); break; case "Thunder": Process.Start(LinkConverter.ThunderEncode(link.GetUrlExtended())); break; case "FlashGet": Process.Start(LinkConverter.FlashGetEncode(link.GetUrlExtended())); break; case "QQDL": Process.Start(LinkConverter.QQDLEncode(link.GetUrlExtended())); break; case "RayFile": Process.Start(LinkConverter.RayFileEncode(link.GetUrlExtended())); break; } } catch (Win32Exception) { TaskDialog.Show(this, "错误", "您没有安装指定的软件,因此不能使用这项功能。", type: TaskDialogType.Error); return; } } } }
protected override JsonConverter ResolveContractConverter(Type objectType) { if (ErrorConverter.CanConvertStatic(objectType)) { return(new ErrorConverter()); } if (ErrorListConverter.CanConvertStatic(objectType)) { return(new ErrorListConverter()); } if (ResourceObjectConverter.CanConvert(objectType)) { return(ResourceObjectConverter); } if (_resourceObjectListConverter.CanConvert(objectType)) { return(_resourceObjectListConverter); } if (LinkConverter.CanConvertStatic(objectType)) { return(new LinkConverter()); } if (DocumentRootConverter.CanConvertStatic(objectType)) { return(new DocumentRootConverter()); } return(base.ResolveContractConverter(objectType)); }
public void LinkConverter_ConvertTo_String_ReturnsExpected() { var converter = new LinkConverter(); Assert.Equal("1, 2", converter.ConvertTo(new LinkLabel.Link(1, 2), typeof(string))); Assert.Equal("1, 2", converter.ConvertTo(null, null, new LinkLabel.Link(1, 2), typeof(string))); Assert.Equal("1, 2", converter.ConvertTo(null, CultureInfo.InvariantCulture, new LinkLabel.Link(1, 2), typeof(string))); }
public void LinkConverter_ConvertFrom_String_ReturnsExpected(string value, object expected) { var converter = new LinkConverter(); AssertEqualLink(expected, converter.ConvertFrom(value)); AssertEqualLink(expected, converter.ConvertFrom(null, null, value)); AssertEqualLink(expected, converter.ConvertFrom(null, CultureInfo.InvariantCulture, value)); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// linkconverter.ConvertTo<int>(context, culture, value); /// </example> /// </summary> public static T ConvertTo <T>(this LinkConverter linkconverter, System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value) { if (linkconverter == null) { throw new ArgumentNullException("linkconverter"); } return((T)linkconverter.ConvertTo(context, culture, value, typeof(T))); }
/// <summary> /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be /// used as generic method and casting is not required. /// <example> /// typeconverter.ConvertTo<int>(value); /// </example> /// </summary> public static T ConvertTo <T>(this LinkConverter typeconverter, Object value) { if (typeconverter == null) { throw new ArgumentNullException("typeconverter"); } return((T)typeconverter.ConvertTo(value, typeof(T))); }
public void LinkConverter_ConvertTo_InstanceDescriptor_ReturnsExpected() { var converter = new LinkConverter(); InstanceDescriptor descriptor = Assert.IsType <InstanceDescriptor>(converter.ConvertTo(new LinkLabel.Link(1, 2), typeof(InstanceDescriptor))); Assert.Equal(typeof(LinkLabel.Link).GetConstructor(new Type[] { typeof(int), typeof(int) }), descriptor.MemberInfo); Assert.Equal(new object[] { 1, 2 }, descriptor.Arguments); Assert.True(descriptor.IsComplete); }
public void ConvertTo() { LinkConverter lc = new LinkConverter(); Assert.AreEqual(string.Empty, lc.ConvertTo(null, null, null, typeof(string)), "N1"); Assert.AreEqual(string.Format("0{0} 0", CultureInfo.CurrentCulture.TextInfo.ListSeparator), lc.ConvertTo(null, null, new LinkLabel.Link(), typeof(string)), "N2"); Assert.AreEqual(string.Format("0{0} 7", CultureInfo.CurrentCulture.TextInfo.ListSeparator), lc.ConvertTo(null, null, new LinkLabel.Link(0, 7), typeof(string)), "N3"); Assert.AreEqual(string.Format("5{0} 12", CultureInfo.CurrentCulture.TextInfo.ListSeparator), lc.ConvertTo(null, null, new LinkLabel.Link(5, 12, "mydata"), typeof(string)), "N4"); }
static private Link CreateCharactersGroup(char[] text, int takeFrom, int takeUntil) { if (takeFrom < (takeUntil - 1)) { return(Link.Create(Net.Group, Net.ThatConsistsOf, LinkConverter.FromChars(text, takeFrom, takeUntil))); } else { return(LinkConverter.FromChar(text[takeFrom])); } }
public void CanConvertTo() { LinkConverter c = new LinkConverter(); Assert.AreEqual(true, c.CanConvertTo(null, typeof(string)), "A1"); Assert.AreEqual(false, c.CanConvertTo(null, typeof(int)), "A2"); Assert.AreEqual(false, c.CanConvertTo(null, typeof(float)), "A3"); Assert.AreEqual(false, c.CanConvertTo(null, typeof(object)), "A4"); Assert.AreEqual(false, c.CanConvertTo(null, typeof(LinkLabel)), "A5"); Assert.AreEqual(false, c.CanConvertTo(null, typeof(LinkLabel.Link)), "A6"); }
public void CanConvertFrom() { LinkConverter c = new LinkConverter(); Assert.AreEqual(true, c.CanConvertFrom(null, typeof(string)), "1"); Assert.AreEqual(false, c.CanConvertFrom(null, typeof(int)), "2"); Assert.AreEqual(false, c.CanConvertFrom(null, typeof(float)), "3"); Assert.AreEqual(false, c.CanConvertFrom(null, typeof(object)), "4"); Assert.AreEqual(false, c.CanConvertFrom(null, typeof(LinkLabel)), "5"); Assert.AreEqual(false, c.CanConvertFrom(null, typeof(LinkLabel.Link)), "6"); }
public void ConvertFrom() { LinkConverter lc = new LinkConverter(); Assert.AreEqual(null, lc.ConvertFrom(null, null, string.Empty), "N1"); Assert.AreEqual(new LinkLabel.Link().Start, ((LinkLabel.Link)lc.ConvertFrom(null, null, string.Format("0{0} 0", CultureInfo.CurrentCulture.TextInfo.ListSeparator))).Start, "N2"); Assert.AreEqual(new LinkLabel.Link(-1, 8).Start, ((LinkLabel.Link)lc.ConvertFrom(null, null, string.Format("-1{0} 8", CultureInfo.CurrentCulture.TextInfo.ListSeparator))).Start, "N3"); Assert.AreEqual(new LinkLabel.Link(12, 24).Start, ((LinkLabel.Link)lc.ConvertFrom(null, null, string.Format("12{0} 24", CultureInfo.CurrentCulture.TextInfo.ListSeparator))).Start, "N4"); Assert.AreEqual(new LinkLabel.Link().Length, ((LinkLabel.Link)lc.ConvertFrom(null, null, string.Format("0{0} 0", CultureInfo.CurrentCulture.TextInfo.ListSeparator))).Length, "N5"); Assert.AreEqual(new LinkLabel.Link(-1, 8).Length, ((LinkLabel.Link)lc.ConvertFrom(null, null, string.Format("-1{0} 8", CultureInfo.CurrentCulture.TextInfo.ListSeparator))).Length, "N6"); Assert.AreEqual(new LinkLabel.Link(12, 24).Length, ((LinkLabel.Link)lc.ConvertFrom(null, null, string.Format("12{0} 24", CultureInfo.CurrentCulture.TextInfo.ListSeparator))).Length, "N7"); }
static public Track FromLink(Link link) { if (IsTrackLink(link)) { var track = new Track(); var name = link.Target; track.Name = LinkConverter.ToString(name.Target); return(track); } else { throw new ArgumentOutOfRangeException("Переданная связь не представляет собой композицию."); } }
static public Artist FromLink(Link link) { if (IsArtistLink(link)) { var artist = new Artist(); var name = link.Target.Source; var tracks = link.Target.Target; artist.Name = LinkConverter.ToString(name.Target); artist.Tracks = LinkConverter.ToList(link).Select(x => Track.FromLink(x)).ToArray(); return(artist); } else { throw new ArgumentOutOfRangeException("Переданная связь не представляет собой исполнителя."); } }
static private void CollectAllSpecificLinks(Link linkDescription, ref HashSet <Link> result) { Link linkDescriptionParamsSequence = linkDescription.Target; List <Link> linkDescriptionParams = LinkConverter.ToList(linkDescriptionParamsSequence); foreach (var param in linkDescriptionParams) { Link paramSource = param.Source; if (IsLinkDescriptionParamSourceSpecific(paramSource)) { result.Add(paramSource); } else { Link subLinkDescription = paramSource; CollectAllSpecificLinks(subLinkDescription, ref result); } } }
public override void When() { IHtmlScraper scraper = new HtmlScraper(c => { c.UseHtmlFetcher(new ResourceHtmlFetcher()); }); var instruction = new HtmlScrapeInstruction <AmazonEntry>(config => { var linkConverter = new LinkConverter("https://www.amazon.com"); config .ScrapeUrl(Resource) .WithPaging("page", pagingStart: 1, pagingIncrement: 1, pagingEnd: 3) .AsEntries(e => e.FromCssSelector(".s-item-container") .MapProperty(p => p.Title, p => p.FromCssSelector("a.s-access-detail-page h2")) .MapProperty(p => p.Url, p => p.FromCssSelector("a.s-access-detail-page").UsingConverter(linkConverter))); }); _results = scraper.Scrape(instruction).Result; }
public List <DirectoryItem> GetFolderFiles(string path) { var allItems = new List <DirectoryItem>(); foreach (var info in new DirectoryInfo(path).EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly)) { if (info.Extension == ".lnk") { allItems.Add(new DirectoryItem(LinkConverter.GetLnkTarget(info.FullName), isFolder: true)); } else if ((info.Attributes & FileAttributes.Directory) == FileAttributes.Directory) { allItems.Add(new DirectoryItem(info.FullName, isFolder: true)); } else if (ShowFiles) { allItems.Add(new DirectoryItem(info.FullName, isFolder: false)); } } return(allItems.OrderBy(x => !x.IsFolder).ToList()); }
public ActionResult Index(string longLink, DateTime?expiration) { LinkConverter model = new LinkConverter(); model.LongLink = longLink; //check if the longlink entered has at least 8 chars if (longLink.Length > 8) { //capture the first 8 chars string validity = longLink.Substring(0, 8); //check if it has an https:// || http:// and add one if not if (!validity.Contains("http://") || !validity.Contains("https://")) { longLink = "http://" + longLink; } model.LongLink = longLink; //add the expiry if it has one if (expiration != null) { model.ExpirationDate = (DateTime)expiration; } //allowed characters for the shortlink string chars = "abcdefghijklmnopqrstuvwxyz0123456789"; //to exit the loop when we find a unique character sequence bool unique = true; string shortlink = ""; Random rand = new Random(); do { shortlink = ""; //loop 7 times, get 7 characters from the allowed characters //easily modified up and down if necessary for (int i = 0; i < 7; i++) { //take our existing shortlink and append another character shortlink = shortlink + chars[rand.Next(chars.Length - 1)]; } //make sure there are no existing results matching the link we made unique = db.LinkConverters.Any(x => x.ShortLinkExtension == shortlink); } while (unique); //add the chars to the model model.ShortLinkExtension = shortlink; //save to the database db.LinkConverters.Add(model); db.SaveChanges(); return(RedirectToAction("List", "Home")); } return(View(model)); }
public void LinkConverter_ConvertTo_ValueNotLink_ThrowsNotSupportedException() { var converter = new LinkConverter(); Assert.Throws <NotSupportedException>(() => converter.ConvertTo(1, typeof(InstanceDescriptor))); }
public void LinkConverter_CanConvertFrom_Invoke_ReturnsExpected(Type sourceType, bool expected) { var converter = new LinkConverter(); Assert.Equal(expected, converter.CanConvertFrom(sourceType)); }
public void LinkConverter_GetPropertiesSupported_Invoke_ReturnsFalse() { var converter = new LinkConverter(); Assert.False(converter.GetPropertiesSupported()); }
public void LinkConverter_GetCreateInstanceSupported_Invoke_ReturnsFalse() { var converter = new LinkConverter(); Assert.False(converter.GetCreateInstanceSupported()); }
public void LinkConverter_ConvertTo_InvalidDestinationType_ThrowsNotSupportedException(Type destinationType) { var converter = new LinkConverter(); Assert.Throws <NotSupportedException>(() => converter.ConvertTo(new LinkLabel.Link(), destinationType)); }
public void ConvertFromNSE() { LinkConverter lc = new LinkConverter(); Assert.AreEqual(new LinkLabel.Link(), lc.ConvertFrom(null, null, null), "N2"); }
public void LinkConverter_ConvertFrom_InvalidString_ThrowsArgumentException(string value) { var converter = new LinkConverter(); Assert.Throws <ArgumentException>(null, () => converter.ConvertFrom(value)); }
public void LinkConverter_CanConvertTo_Invoke_ReturnsExpected(Type destinationType, bool expected) { var converter = new LinkConverter(); Assert.Equal(expected, converter.CanConvertTo(destinationType)); }
static private List <Link> GetSubstringsWith(string word) { List <Link> charLinks = word.Select(x => LinkConverter.FromChar(x)).ToList(); return(SequenceHelpers.CollectMatchingSequences(charLinks)); }
/// <summary> /// Creates new variant and raises "Add" event if specified. /// </summary> /// <param name="name">Name of new variant</param> /// <param name="issueId">ID of source issue on which the new variant will be based</param> private void RaiseOnAddEvent(string name, int issueId) { // Get main issue (original) int currentIssuedId = IssueID; IssueInfo parentIssue = IssueInfoProvider.GetOriginalIssue(currentIssuedId); // Allow modifying issues in idle state only if ((parentIssue == null) || (parentIssue.IssueStatus != IssueStatusEnum.Idle)) { return; } // Get issue content specified by ID (if not found use original) IssueInfo contentIssue = null; if (issueId > 0) { if (issueId == parentIssue.IssueID) { contentIssue = parentIssue; } else { contentIssue = IssueInfoProvider.GetIssueInfo(issueId); } } NewsletterInfo newsletter = NewsletterInfoProvider.GetNewsletterInfo(parentIssue.IssueNewsletterID); // ID of the first child (if new A/B test is being created (i.e. parent and 2 children) int origVariantId = 0; // Check if current issue is variant issue if (!parentIssue.IssueIsABTest) { // Variant issue has not been created yet => create original and 2 child variants parentIssue.IssueIsABTest = true; // Create 1st variant based on parent issue, the 2nd variant will be created as ordinary variant below IssueInfo issueOrigVariant = parentIssue.Clone(true); issueOrigVariant.IssueVariantOfIssueID = parentIssue.IssueID; issueOrigVariant.IssueVariantName = GetString("newsletter.abvariantoriginal"); issueOrigVariant.IssueScheduledTaskID = 0; IssueInfoProvider.SetIssueInfo(issueOrigVariant); // Create scheduled task for variant mail-out and update issue variant issueOrigVariant.IssueScheduledTaskID = CreateScheduledTask(issueOrigVariant); IssueInfoProvider.SetIssueInfo(issueOrigVariant); // Update parent issue IssueInfoProvider.SetIssueInfo(parentIssue); try { ObjectVersionManager.DestroyObjectHistory(parentIssue.ObjectType, parentIssue.IssueID); } catch (Exception ex) { EventLogProvider.LogException("Newsletter-AddVariant", "EXCEPTION", ex); } origVariantId = issueOrigVariant.IssueID; } // Variant issue has been created => create new variant only IssueInfo issueVariant = (contentIssue != null ? contentIssue.Clone(true) : parentIssue.Clone(true)); issueVariant.IssueVariantName = name; issueVariant.IssueVariantOfIssueID = parentIssue.IssueID; // Prepare content with empty regions if empty content will be used string[] regions = null; if ((contentIssue == null) && (newsletter != null)) { EmailTemplateInfo template = EmailTemplateInfoProvider.GetEmailTemplateInfo(newsletter.NewsletterTemplateID); if (template != null) { bool isValidRegionName; List <string> regionNames = new List <string>(); EmailTemplateHelper.ValidateEditableRegions(template.TemplateBody, out isValidRegionName, out isValidRegionName, regionNames); for (int i = regionNames.Count - 1; i >= 0; i--) { regionNames[i] = regionNames[i] + "::"; } regions = regionNames.ToArray(); // Set template ID (i.e. this template with these regions is used for current issue) issueVariant.IssueTemplateID = template.TemplateID; } } issueVariant.IssueText = (contentIssue != null ? contentIssue.IssueText : IssueHelper.GetContentXML(regions)); issueVariant.IssueScheduledTaskID = 0; IssueInfoProvider.SetIssueInfo(issueVariant); // Duplicate attachments and replace old guids with new guids in issue text if current variant issue is based on content of another if (contentIssue != null) { List <Guid> guids = new List <Guid>(); MetaFileInfoProvider.CopyMetaFiles(contentIssue.IssueID, issueVariant.IssueID, (contentIssue.IssueIsVariant ? IssueInfo.OBJECT_TYPE_VARIANT : IssueInfo.OBJECT_TYPE), ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE, guids); if (guids.Count > 0) { for (int i = 0; i < guids.Count; i += 2) { issueVariant.IssueText = LinkConverter.ReplaceInLink(issueVariant.IssueText, guids[i].ToString(), guids[i + 1].ToString()); } } } // Create scheduled task for variant mail-out issueVariant.IssueScheduledTaskID = CreateScheduledTask(issueVariant); // Update issue variant IssueInfoProvider.SetIssueInfo(issueVariant); if (origVariantId > 0) { // New A/B test issue created => create new A/B test info ABTestInfo abi = new ABTestInfo { TestIssueID = parentIssue.IssueID, TestSizePercentage = 50, TestWinnerOption = ABTestWinnerSelectionEnum.OpenRate, TestSelectWinnerAfter = 60 }; ABTestInfoProvider.SetABTestInfo(abi); // Move attachments (meta files) from parent issue to first variant MetaFileInfoProvider.MoveMetaFiles(parentIssue.IssueID, origVariantId, IssueInfo.OBJECT_TYPE, ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE); MetaFileInfoProvider.MoveMetaFiles(parentIssue.IssueID, origVariantId, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE, IssueInfo.OBJECT_TYPE_VARIANT, ObjectAttachmentsCategories.ISSUE); } if (OnAddVariant != null) { VariantEventArgs args = new VariantEventArgs(name, issueVariant.IssueID); OnAddVariant(this, args); } }
public void LinkConverter_ConvertFrom_InvalidValue_ThrowsNotSupportedException(object value) { var converter = new LinkConverter(); Assert.Throws <NotSupportedException>(() => converter.ConvertFrom(value)); }
public void LinkConverter_ConvertTo_NullDestinationType_ThrowsArgumentNullException() { var converter = new LinkConverter(); Assert.Throws <ArgumentNullException>("destinationType", () => converter.ConvertTo(new object(), null)); }