public void Should_not_split() { string name = "lonE01-SQL02v.0"; var nameparser = new NameParser("::", name); Assert.That(nameparser.Host, Is.EqualTo("")); Assert.That(nameparser.Metric, Is.EqualTo("lonE01-SQL02v.0")); }
public void Should_split_names_to_get_tail_only() { string name = "LONBTI-ESX01p::lonE01-SQL02v.0::fred"; var nameparser = new NameParser("::", name); Assert.That(nameparser.Host, Is.EqualTo("LONBTI-ESX01p")); Assert.That(nameparser.Metric, Is.EqualTo("lonE01-SQL02v.0")); }
static PersonGenerator() { nameParser = new NameParser(PICTURES_COUNT); // Might be a little heavy, but since it's only done once, it's not that bad pictureIndexesMale = new List<int>(PICTURES_COUNT); pictureIndexesFemale = new List<int>(PICTURES_COUNT); for (int i = 1; i <= PICTURES_COUNT; i++) { pictureIndexesFemale.Add(i); pictureIndexesMale.Add(i); } }
public static string CatchVariableName(ITreeNode treeNode, IDeclaredType exceptionType) { var namingPolicyManager = new NamingPolicyManager(LanguageManager.Instance, treeNode.GetSolution()); var nameParser = new NameParser(treeNode.GetSolution(), namingPolicyManager); var nameSuggestionManager = new NameSuggestionManager(treeNode.GetSolution(), nameParser, namingPolicyManager); var policy = namingPolicyManager.GetPolicy(NamedElementKinds.Locals, treeNode.Language, treeNode.GetSourceFile()); var namesCollection = nameSuggestionManager.CreateEmptyCollection( PluralityKinds.Single, treeNode.Language, true, treeNode.GetSourceFile()); var entryOptions = new EntryOptions { PluralityKind = PluralityKinds.Single, PredefinedPrefixPolicy = PredefinedPrefixPolicy.Preserve, Emphasis = Emphasis.Good, SubrootPolicy = SubrootPolicy.Decompose }; namesCollection.Add(exceptionType, entryOptions); namesCollection.Prepare(policy.NamingRule, ScopeKind.Common, new SuggestionOptions()); return namesCollection.FirstName(); }
public FunctionPointerTypeRule(NameParser nameParser) { this.nameParser = nameParser; }
private async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(ItemLookupInfo idInfo, string searchType, CancellationToken cancellationToken) { var name = idInfo.Name; var year = idInfo.Year; int?yearInName = null; var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.base_url + "original"; NameParser.ParseName(name, out name, out yearInName); year = year ?? yearInName; _logger.Info("MovieDbProvider: Finding id for item: " + name); var language = idInfo.MetadataLanguage.ToLower(); //nope - search for it //var searchType = item is BoxSet ? "collection" : "movie"; var results = await GetSearchResults(name, searchType, year, language, tmdbImageUrl, cancellationToken).ConfigureAwait(false); if (results.Count == 0) { //try in english if wasn't before if (!string.Equals(language, "en", StringComparison.OrdinalIgnoreCase)) { results = await GetSearchResults(name, searchType, year, "en", tmdbImageUrl, cancellationToken).ConfigureAwait(false); } } if (results.Count == 0) { // try with dot and _ turned to space var originalName = name; name = name.Replace(",", " "); name = name.Replace(".", " "); name = name.Replace("_", " "); name = name.Replace("-", " "); name = name.Replace("!", " "); name = name.Replace("?", " "); name = name.Trim(); // Search again if the new name is different if (!string.Equals(name, originalName)) { results = await GetSearchResults(name, searchType, year, language, tmdbImageUrl, cancellationToken).ConfigureAwait(false); if (results.Count == 0 && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase)) { //one more time, in english results = await GetSearchResults(name, searchType, year, "en", tmdbImageUrl, cancellationToken).ConfigureAwait(false); } } } return(results.Where(i => { if (year.HasValue && i.ProductionYear.HasValue) { return year.Value == i.ProductionYear.Value; } return true; })); }
public string GetSubFolderPath() { return(NameParser.Parse(NameParserType.URL, SubFolderPath.Replace("%host", Helpers.ExpandFolderVariables(LocalhostRoot)))); }
private void ControlSettings() { ImageList imageUploadersImageList = new ImageList(); imageUploadersImageList.ColorDepth = ColorDepth.Depth32Bit; imageUploadersImageList.Images.Add("ImageShack", Resources.ImageShack); imageUploadersImageList.Images.Add("TinyPic", Resources.TinyPic); imageUploadersImageList.Images.Add("Imgur", Resources.Imgur); imageUploadersImageList.Images.Add("Flickr", Resources.Flickr); imageUploadersImageList.Images.Add("Photobucket", Resources.Photobucket); imageUploadersImageList.Images.Add("Picasa", Resources.Picasa); imageUploadersImageList.Images.Add("TwitPic", Resources.TwitPic); imageUploadersImageList.Images.Add("TwitSnaps", Resources.TwitSnaps); imageUploadersImageList.Images.Add("YFrog", Resources.YFrog); tcImageUploaders.ImageList = imageUploadersImageList; ImageList fileUploadersImageList = new ImageList(); fileUploadersImageList.ColorDepth = ColorDepth.Depth32Bit; fileUploadersImageList.Images.Add("Dropbox", Resources.Dropbox); fileUploadersImageList.Images.Add("GoogleDrive", Resources.GoogleDrive); fileUploadersImageList.Images.Add("Box", Resources.Box); fileUploadersImageList.Images.Add("Minus", Resources.Minus); fileUploadersImageList.Images.Add("FTP", Resources.folder_network); fileUploadersImageList.Images.Add("RapidShare", Resources.RapidShare); fileUploadersImageList.Images.Add("SendSpace", Resources.SendSpace); fileUploadersImageList.Images.Add("Gett", Resources.Gett); fileUploadersImageList.Images.Add("Localhostr", Resources.Localhostr); fileUploadersImageList.Images.Add("CustomUploader", Resources.globe_network); fileUploadersImageList.Images.Add("SharedFolders", Resources.server_network); fileUploadersImageList.Images.Add("Email", Resources.mail); fileUploadersImageList.Images.Add("Jira", Resources.jira); fileUploadersImageList.Images.Add("Mega", Resources.Mega); tcFileUploaders.ImageList = fileUploadersImageList; ImageList textUploadersImageList = new ImageList(); textUploadersImageList.ColorDepth = ColorDepth.Depth32Bit; textUploadersImageList.Images.Add("Pastebin", Resources.Pastebin); textUploadersImageList.Images.Add("Gist", Resources.Gist); tcTextUploaders.ImageList = textUploadersImageList; ImageList urlShortenersImageList = new ImageList(); urlShortenersImageList.ColorDepth = ColorDepth.Depth32Bit; urlShortenersImageList.Images.Add("Google", Resources.Google); urlShortenersImageList.Images.Add("Bitly", Resources.Bitly); tcURLShorteners.ImageList = urlShortenersImageList; ImageList socialNetworkingServicesImageList = new ImageList(); socialNetworkingServicesImageList.ColorDepth = ColorDepth.Depth32Bit; socialNetworkingServicesImageList.Images.Add("Twitter", Resources.Twitter); tcSocialNetworkingServices.ImageList = socialNetworkingServicesImageList; tpImageShack.ImageKey = "ImageShack"; tpTinyPic.ImageKey = "TinyPic"; tpImgur.ImageKey = "Imgur"; tpFlickr.ImageKey = "Flickr"; tpPhotobucket.ImageKey = "Photobucket"; tpPicasa.ImageKey = "Picasa"; tpTwitPic.ImageKey = "TwitPic"; tpTwitSnaps.ImageKey = "TwitSnaps"; tpYFrog.ImageKey = "YFrog"; tpDropbox.ImageKey = "Dropbox"; tpGoogleDrive.ImageKey = "GoogleDrive"; tpBox.ImageKey = "Box"; tpMinus.ImageKey = "Minus"; tpFTP.ImageKey = "FTP"; tpRapidShare.ImageKey = "RapidShare"; tpSendSpace.ImageKey = "SendSpace"; tpSharedFolder.ImageKey = "SharedFolders"; tpEmail.ImageKey = "Email"; tpJira.ImageKey = "Jira"; tpGe_tt.ImageKey = "Gett"; tpHostr.ImageKey = "Localhostr"; tpCustomUploaders.ImageKey = "CustomUploader"; tpPastebin.ImageKey = "Pastebin"; tpGoogleURLShortener.ImageKey = "Google"; tpBitly.ImageKey = "Bitly"; tpTwitter.ImageKey = "Twitter"; tpMega.ImageKey = "Mega"; tpGist.ImageKey = "Gist"; cmsCustomUploaderArgValue = NameParser.CreateCodesMenu(txtCustomUploaderArgValue, ReplacementVariables.n); txtCustomUploaderLog.AddContextMenu(); }
public TaskSettingsForm(TaskSettings hotkeySetting, bool isDefault = false) { InitializeComponent(); Icon = ShareXResources.Icon; TaskSettings = hotkeySetting; IsDefault = isDefault; if (IsDefault) { Text = Application.ProductName + " - Task settings"; tcHotkeySettings.TabPages.Remove(tpTask); chkUseDefaultGeneralSettings.Visible = chkUseDefaultImageSettings.Visible = chkUseDefaultCaptureSettings.Visible = chkUseDefaultActions.Visible = chkUseDefaultUploadSettings.Visible = chkUseDefaultIndexerSettings.Visible = chkUseDefaultAdvancedSettings.Visible = false; panelGeneral.BorderStyle = BorderStyle.None; } else { Text = Application.ProductName + " - Task settings for " + TaskSettings; tbDescription.Text = TaskSettings.Description; cbUseDefaultAfterCaptureSettings.Checked = TaskSettings.UseDefaultAfterCaptureJob; cbUseDefaultAfterUploadSettings.Checked = TaskSettings.UseDefaultAfterUploadJob; cbUseDefaultDestinationSettings.Checked = TaskSettings.UseDefaultDestinations; chkUseDefaultGeneralSettings.Checked = TaskSettings.UseDefaultGeneralSettings; chkUseDefaultImageSettings.Checked = TaskSettings.UseDefaultImageSettings; chkUseDefaultCaptureSettings.Checked = TaskSettings.UseDefaultCaptureSettings; chkUseDefaultActions.Checked = TaskSettings.UseDefaultActions; chkUseDefaultUploadSettings.Checked = TaskSettings.UseDefaultUploadSettings; chkUseDefaultIndexerSettings.Checked = TaskSettings.UseDefaultIndexerSettings; chkUseDefaultAdvancedSettings.Checked = TaskSettings.UseDefaultAdvancedSettings; } AddEnumItems <HotkeyType>(x => TaskSettings.Job = x, cmsTask); AddMultiEnumItems <AfterCaptureTasks>(x => TaskSettings.AfterCaptureJob = TaskSettings.AfterCaptureJob.Swap(x), cmsAfterCapture); AddMultiEnumItems <AfterUploadTasks>(x => TaskSettings.AfterUploadJob = TaskSettings.AfterUploadJob.Swap(x), cmsAfterUpload); AddEnumItems <ImageDestination>(x => TaskSettings.ImageDestination = x, cmsImageUploaders); AddEnumItems <TextDestination>(x => TaskSettings.TextDestination = x, cmsTextUploaders); AddEnumItems <FileDestination>(x => TaskSettings.FileDestination = x, cmsFileUploaders); AddEnumItems <UrlShortenerType>(x => TaskSettings.URLShortenerDestination = x, cmsURLShorteners); AddEnumItems <SocialNetworkingService>(x => TaskSettings.SocialNetworkingServiceDestination = x, cmsSocialNetworkingServices); SetEnumChecked(TaskSettings.Job, cmsTask); SetMultiEnumChecked(TaskSettings.AfterCaptureJob, cmsAfterCapture); SetMultiEnumChecked(TaskSettings.AfterUploadJob, cmsAfterUpload); SetEnumChecked(TaskSettings.ImageDestination, cmsImageUploaders); SetEnumChecked(TaskSettings.TextDestination, cmsTextUploaders); SetEnumChecked(TaskSettings.FileDestination, cmsFileUploaders); SetEnumChecked(TaskSettings.URLShortenerDestination, cmsURLShorteners); SetEnumChecked(TaskSettings.SocialNetworkingServiceDestination, cmsSocialNetworkingServices); // FTP if (Program.UploadersConfig != null && Program.UploadersConfig.FTPAccountList.Count > 1) { chkOverrideFTP.Checked = TaskSettings.OverrideFTP; cboFTPaccounts.Items.Clear(); cboFTPaccounts.Items.AddRange(Program.UploadersConfig.FTPAccountList.ToArray()); cboFTPaccounts.SelectedIndex = TaskSettings.FTPIndex.BetweenOrDefault(0, Program.UploadersConfig.FTPAccountList.Count - 1); } UpdateDestinationStates(); UpdateUploaderMenuNames(); // General cbPlaySoundAfterCapture.Checked = TaskSettings.GeneralSettings.PlaySoundAfterCapture; cbShowAfterCaptureTasksForm.Checked = TaskSettings.GeneralSettings.ShowAfterCaptureTasksForm; cbPlaySoundAfterUpload.Checked = TaskSettings.GeneralSettings.PlaySoundAfterUpload; chkShowAfterUploadForm.Checked = TaskSettings.GeneralSettings.ShowAfterUploadForm; cbTrayBalloonTipAfterUpload.Checked = TaskSettings.GeneralSettings.TrayBalloonTipAfterUpload; cbShowToastWindowAfterTask.Checked = TaskSettings.GeneralSettings.ShowToastWindowAfterTask; cbHistorySave.Checked = TaskSettings.GeneralSettings.SaveHistory; // Image - Quality cbImageFormat.SelectedIndex = (int)TaskSettings.ImageSettings.ImageFormat; nudImageJPEGQuality.Value = TaskSettings.ImageSettings.ImageJPEGQuality; cbImageGIFQuality.SelectedIndex = (int)TaskSettings.ImageSettings.ImageGIFQuality; nudUseImageFormat2After.Value = TaskSettings.ImageSettings.ImageSizeLimit; cbImageFormat2.SelectedIndex = (int)TaskSettings.ImageSettings.ImageFormat2; // Image - Effects chkShowImageEffectsWindowAfterCapture.Checked = TaskSettings.ImageSettings.ShowImageEffectsWindowAfterCapture; cbImageEffectOnlyRegionCapture.Checked = TaskSettings.ImageSettings.ImageEffectOnlyRegionCapture; // Capture cbShowCursor.Checked = TaskSettings.CaptureSettings.ShowCursor; cbCaptureTransparent.Checked = TaskSettings.CaptureSettings.CaptureTransparent; cbCaptureShadow.Enabled = TaskSettings.CaptureSettings.CaptureTransparent; cbCaptureShadow.Checked = TaskSettings.CaptureSettings.CaptureShadow; nudCaptureShadowOffset.Value = TaskSettings.CaptureSettings.CaptureShadowOffset; cbCaptureClientArea.Checked = TaskSettings.CaptureSettings.CaptureClientArea; cbScreenshotDelay.Checked = TaskSettings.CaptureSettings.IsDelayScreenshot; nudScreenshotDelay.Value = TaskSettings.CaptureSettings.DelayScreenshot; cbCaptureAutoHideTaskbar.Checked = TaskSettings.CaptureSettings.CaptureAutoHideTaskbar; if (TaskSettings.CaptureSettings.SurfaceOptions == null) { TaskSettings.CaptureSettings.SurfaceOptions = new SurfaceOptions(); } pgShapesCapture.SelectedObject = TaskSettings.CaptureSettings.SurfaceOptions; // Capture / Screen recorder cbScreenRecorderOutput.Items.AddRange(Helpers.GetEnumDescriptions <ScreenRecordOutput>()); cbScreenRecorderOutput.SelectedIndex = (int)TaskSettings.CaptureSettings.ScreenRecordOutput; nudScreenRecorderFPS.Value = TaskSettings.CaptureSettings.ScreenRecordFPS; cbScreenRecorderFixedDuration.Checked = TaskSettings.CaptureSettings.ScreenRecordFixedDuration; nudScreenRecorderDuration.Enabled = TaskSettings.CaptureSettings.ScreenRecordFixedDuration; nudScreenRecorderDuration.Value = (decimal)TaskSettings.CaptureSettings.ScreenRecordDuration; nudScreenRecorderStartDelay.Value = (decimal)TaskSettings.CaptureSettings.ScreenRecordStartDelay; gbCommandLineEncoderSettings.Enabled = TaskSettings.CaptureSettings.ScreenRecordOutput == ScreenRecordOutput.AVICommandLine; txtScreenRecorderCommandLinePath.Text = TaskSettings.CaptureSettings.ScreenRecordCommandLinePath; txtScreenRecorderCommandLineArgs.Text = TaskSettings.CaptureSettings.ScreenRecordCommandLineArgs; txtScreenRecorderCommandLineOutputExtension.Text = TaskSettings.CaptureSettings.ScreenRecordCommandLineOutputExtension; // Actions TaskHelpers.AddDefaultExternalPrograms(TaskSettings); foreach (ExternalProgram fileAction in TaskSettings.ExternalPrograms) { AddFileAction(fileAction); } // Watch folders cbWatchFolderEnabled.Checked = TaskSettings.WatchFolderEnabled; if (TaskSettings.WatchFolderList == null) { TaskSettings.WatchFolderList = new List <WatchFolderSettings>(); } else { foreach (WatchFolderSettings watchFolder in TaskSettings.WatchFolderList) { AddWatchFolder(watchFolder); } } // Upload / Name pattern txtNameFormatPattern.Text = TaskSettings.UploadSettings.NameFormatPattern; txtNameFormatPatternActiveWindow.Text = TaskSettings.UploadSettings.NameFormatPatternActiveWindow; cmsNameFormatPattern = NameParser.CreateCodesMenu(txtNameFormatPattern, ReplacementVariables.n); cmsNameFormatPatternActiveWindow = NameParser.CreateCodesMenu(txtNameFormatPatternActiveWindow, ReplacementVariables.n); cbFileUploadUseNamePattern.Checked = TaskSettings.UploadSettings.FileUploadUseNamePattern; // Upload / Clipboard upload cbClipboardUploadAutoDetectURL.Checked = TaskSettings.UploadSettings.ClipboardUploadAutoDetectURL; // Indexer pgIndexerConfig.SelectedObject = TaskSettings.IndexerSettings; // Advanced pgTaskSettings.SelectedObject = TaskSettings.AdvancedSettings; UpdateDefaultSettingVisibility(); loaded = true; }
public MemberTypeRule(NameParser nameParser) { this.nameParser = nameParser; }
public void it_returns_an_empty_string_when_parsing_an_empty_string() { string result = NameParser.Parse(""); result.Should().Be(""); }
private static String generateShortName(NameParser nameParser) { String name = nameParser.OriginalName; String s = name; if (nameParser.PathPackageAndFilename) { s = nameParser.Filename; } else { /* do we have a file name? */ int dotAt = name.LastIndexOf('.'); if (dotAt > 1) { /* yes let's strip the directory off */ int lastSlashAt = name.LastIndexOf('\\', dotAt); lastSlashAt = Math.Max(lastSlashAt, name.LastIndexOf('/', dotAt)); s = name.Substring(lastSlashAt + 1); } else { /* not a file name ... */ s = name; } } return s.Trim(); }
public override IList<IResult> Get() { var rtn = new List<IResult>(); try { foreach (var o in this.GetWmiObject(this.Sql, this.machineName, RootPath)) { var value = -1; var dateTime = DateTime.Now; var name = string.Empty; foreach (var col in o.Properties) { if (col.Type == CimType.String) { var np = new NameParser("::", Convert.ToString(col.Value)); name = np.Metric; } if (col.Type == CimType.UInt32) { value = Convert.ToInt32(col.Value); } if (col.Type == CimType.UInt64) { value = Convert.ToInt32(col.Value); } if (col.Type == CimType.DateTime) { dateTime = Convert.ToDateTime(col.Value); } } this.Log.Debug(string.Format("Name {0} value {1} datetime {2}", name, value, dateTime)); var r = new Result(name, dateTime, this.Path); r.SetValue(value); rtn.Add(r); } } catch (ManagementException e) { this.Log.Error(string.Format("Error with {0} {1} {2}", this.Type, this.Path, this.Sql)); this.Log.Error(e.Message); this.Log.Error(e.StackTrace); } return rtn; }
public void it_throws_an_exception_when_parsing_null() { (new Action(() => NameParser.Parse((string)null))).Should().Throw <ArgumentNullException>(); }
/// <summary> /// /// </summary> /// <param name="recordingFile"></param> public void AddOrUpdateRecordingFile(String recordingFile) { try { NameParser parser = new NameParser(); parser.SingleFileInitialise(recordingFile); Speaker spk = this.Speaker.SingleOrDefault(x => x.Name == parser.Speaker); if (spk == null) { spk = new Speaker() { Name = parser.Speaker }; this.Speaker.AddOrUpdate(x => x.Name, spk); this.SaveChanges(); } Category cty = this.Category.SingleOrDefault(x => x.Name == parser.Category); if (cty == null) { cty = new Category() { // Vocal tract videos are of vowel sounds, and so need to be categorised as such. // However, the category section of the filename is also used to differentiate between videos and vocal tracts. Name = parser.Category.Equals("vocaltract") ? "vowel" : parser.Category }; this.Category.AddOrUpdate(x => x.Name, cty); this.SaveChanges(); } Word word = this.Word.SingleOrDefault(x => x.Name == parser.Word); if (word == null) { word = new Word() { Name = parser.Word, CategoryId = cty.CategoryId }; this.Word.AddOrUpdate(x => x.Name, word); this.SaveChanges(); } Recording rd = this.Recording.SingleOrDefault(x => x.Name == parser.Recording);; if (rd == null) { rd = new Recording() { Name = parser.Recording, SpeakerId = spk.SpeakerId, WordId = word.WordId }; this.Recording.AddOrUpdate(x => x.Name, rd); this.SaveChanges(); } SingleFile sf = this.SingleFile.SingleOrDefault(x => x.Name == parser.FullName); if (sf == null) { sf = new SingleFile() { Name = parser.FullName, Address = parser.Address, }; if (parser.MediaFormat.Equals("audio")) { sf.Audio = rd; } else if (parser.MediaFormat.Equals("video")) { sf.Video = rd; } else if (parser.MediaFormat.Equals("vocaltract")) { sf.VocalTract = rd; } this.SingleFile.AddOrUpdate(x => x.Name, sf); this.SaveChanges(); } } catch (Exception exp) { Console.WriteLine(exp); } }
public string GetSubFolderPath() { NameParser parser = new NameParser(NameParserType.URL); return(parser.Parse(SubFolderPath.Replace("%host", Host))); }
public WatermarkForm(WatermarkConfig watermarkConfig) { InitializeComponent(); config = watermarkConfig; codesMenu = NameParser.CreateCodesMenu(txtWatermarkText, ReplacementVariables.t); }
private string GetObjectKey(string fileName) { string objectPrefix = NameParser.Parse(NameParserType.FolderPath, S3Settings.ObjectPrefix.Trim('/')); return(URLHelpers.CombineURL(objectPrefix, fileName)); }
public void it_returns_the_same_string_when_parsing_a_single_word() { string result = NameParser.Parse("foo"); result.Should().Be("foo"); }
private static readonly String m_newline = Environment.NewLine; //$NON-NLS-1$ /// <param name="name">filename in "basepath;package;filename" format /// </param> public DModule(SourceLocator sourceLocator, int id, int bitmap, String name, String script) { // If the caller gave us the script text, then we will create m_script // now. But if the caller gave us an empty string, then we won't bother // looking for a disk file until someone actually asks for it. if (script != null && script.Length > 0) { m_script = new ScriptText(script); m_gotRealScript = true; } NameParser nameParser = new NameParser(name); m_sourceLocator = sourceLocator; m_rawName = name; m_basePath = nameParser.BasePath; // may be null m_bitmap = bitmap; m_id = id; m_shortName = generateShortName(nameParser); m_path = generatePath(nameParser); m_line2Offset = new System.Collections.ArrayList(); m_line2Func = new System.Collections.ArrayList(); m_func2FirstLine = new System.Collections.Hashtable(); m_func2LastLine = new System.Collections.Hashtable(); m_packageName = nameParser.Package; m_gotAllFncNames = false; }
public void it_returns_two_strings_when_parsing_words_separated_by_semicolons() { string result = NameParser.Parse("foo_bar"); result.Should().Be("foo bar"); }
/// <summary> Produce a name that contains a file specification including full path. /// File names may come in as 'mx.bla : file:/bla.foo.as' or as /// 'file://bla.foo.as' or as 'C:\'(?) or as 'basepath;package;filename' /// </summary> private static String generatePath(NameParser nameParser) { String name = nameParser.OriginalName; String s = name; /* strip off first colon of stuff if package exists */ int colonAt = name.IndexOf(':'); if (colonAt > 1 && !name.StartsWith("Actions for")) //$NON-NLS-1$ { if (name[colonAt + 1] == ' ') s = name.Substring(colonAt + 2); } else if (name.IndexOf('.') > - 1 && name[0] != '<') { /* some other type of file name */ s = nameParser.recombine(); } else { // no path s = ""; //$NON-NLS-1$ } return s.Trim(); }
public override Image Apply(Image img) { if (string.IsNullOrEmpty(Text)) { return(img); } using (Font textFont = TextFont) { if (textFont == null || textFont.Size < 1) { return(img); } NameParser parser = new NameParser(NameParserType.Text); if (img != null) { parser.ImageWidth = img.Width; parser.ImageHeight = img.Height; } string parsedText = parser.Parse(Text); Size textSize = Helpers.MeasureText(parsedText, textFont); Size watermarkSize = new Size(Padding.Left + textSize.Width + Padding.Right, Padding.Top + textSize.Height + Padding.Bottom); Point watermarkPosition = Helpers.GetPosition(Placement, Offset, img.Size, watermarkSize); Rectangle watermarkRectangle = new Rectangle(watermarkPosition, watermarkSize); if (AutoHide && !new Rectangle(0, 0, img.Width, img.Height).Contains(watermarkRectangle)) { return(img); } using (Graphics g = Graphics.FromImage(img)) { g.SmoothingMode = SmoothingMode.HighQuality; using (GraphicsPath gp = new GraphicsPath()) { gp.AddRoundedRectangleProper(watermarkRectangle, CornerRadius); if (DrawBackground) { Brush backgroundBrush = null; try { if (UseGradient) { if (UseCustomGradient && Gradient != null && Gradient.IsValid) { backgroundBrush = new LinearGradientBrush(watermarkRectangle, Color.Transparent, Color.Transparent, Gradient.Type); ColorBlend colorBlend = new ColorBlend(); IEnumerable <GradientStop> gradient = Gradient.Colors.OrderBy(x => x.Location); colorBlend.Colors = gradient.Select(x => x.Color).ToArray(); colorBlend.Positions = gradient.Select(x => x.Location / 100).ToArray(); ((LinearGradientBrush)backgroundBrush).InterpolationColors = colorBlend; } else { backgroundBrush = new LinearGradientBrush(watermarkRectangle, BackgroundColor, BackgroundColor2, GradientType); } } else { backgroundBrush = new SolidBrush(BackgroundColor); } g.FillPath(backgroundBrush, gp); } finally { if (backgroundBrush != null) { backgroundBrush.Dispose(); } } } if (DrawBorder) { int borderSize = BorderSize.Min(1); if (borderSize.IsEvenNumber()) { g.PixelOffsetMode = PixelOffsetMode.Half; } using (Pen borderPen = new Pen(BorderColor, borderSize)) { g.DrawPath(borderPen, gp); } g.PixelOffsetMode = PixelOffsetMode.Default; } } float centerX = watermarkRectangle.Width / 2f - (Padding.Right - Padding.Left); float centerY = watermarkRectangle.Height / 2f - (Padding.Bottom - Padding.Top); if (DrawTextShadow) { using (Brush textShadowBrush = new SolidBrush(TextShadowColor)) { g.DrawString(parsedText, textFont, textShadowBrush, watermarkRectangle.X + Padding.Left + TextShadowOffset.X, watermarkRectangle.Y + Padding.Top + TextShadowOffset.Y); } } using (Brush textBrush = new SolidBrush(TextColor)) { g.DrawString(parsedText, textFont, textBrush, watermarkRectangle.X + Padding.Left, watermarkRectangle.Y + Padding.Top); } } } return(img); }
public override Image Apply(Image img) { if (string.IsNullOrEmpty(Text)) { return(img); } using (Font textFont = TextFont) { if (textFont == null || textFont.Size < 1) { return(img); } NameParser parser = new NameParser(NameParserType.Text) { Picture = img }; string parsedText = parser.Parse(Text); Size textSize = Helpers.MeasureText(parsedText, textFont); Size watermarkSize = new Size(textSize.Width + BackgroundPadding * 2, textSize.Height + BackgroundPadding * 2); Point watermarkPosition = Helpers.GetPosition(Placement, Offset, img.Size, watermarkSize); Rectangle watermarkRectangle = new Rectangle(watermarkPosition, watermarkSize); if (AutoHide && !new Rectangle(0, 0, img.Width, img.Height).Contains(watermarkRectangle)) { return(img); } using (Bitmap bmpWatermark = new Bitmap(watermarkSize.Width, watermarkSize.Height)) using (Graphics gWatermark = Graphics.FromImage(bmpWatermark)) { gWatermark.SetHighQuality(); if (DrawBackground) { using (GraphicsPath backgroundPath = new GraphicsPath()) { Rectangle backgroundRect = new Rectangle(0, 0, watermarkSize.Width, watermarkSize.Height); backgroundPath.AddRoundedRectangle(backgroundRect, CornerRadius); Brush backgroundBrush = null; try { if (UseGradient) { backgroundBrush = new LinearGradientBrush(backgroundRect, BackgroundColor, BackgroundColor2, GradientType); if (UseCustomGradient && CustomGradientList != null && CustomGradientList.Count > 1) { ColorBlend colorBlend = new ColorBlend(); IEnumerable <GradientStop> gradient = CustomGradientList.OrderBy(x => x.Offset); colorBlend.Colors = gradient.Select(x => x.Color).ToArray(); colorBlend.Positions = gradient.Select(x => x.Offset).ToArray(); ((LinearGradientBrush)backgroundBrush).InterpolationColors = colorBlend; } } else { backgroundBrush = new SolidBrush(BackgroundColor); } gWatermark.FillPath(backgroundBrush, backgroundPath); } finally { if (backgroundBrush != null) { backgroundBrush.Dispose(); } } using (Pen borderPen = new Pen(BorderColor)) { gWatermark.DrawPath(borderPen, backgroundPath); } } } gWatermark.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }) { float centerX = bmpWatermark.Width / 2f; float centerY = bmpWatermark.Height / 2f; if (DrawTextShadow) { using (Brush textShadowBrush = new SolidBrush(TextShadowColor)) { gWatermark.DrawString(parsedText, textFont, textShadowBrush, centerX + TextShadowOffset.X, centerY + TextShadowOffset.Y, sf); } } using (Brush textBrush = new SolidBrush(TextColor)) { gWatermark.DrawString(parsedText, textFont, textBrush, centerX, centerY, sf); } } using (Graphics gResult = Graphics.FromImage(img)) { gResult.SetHighQuality(); gResult.DrawImage(bmpWatermark, watermarkRectangle); } } } return(img); }
public void NameParser_Parse_thows_exception_when_null_is_passed(string fullName) { var parser = new NameParser().Parse(fullName); }
private static IParser <ServiceAttributeInfo> AttributeParser(Context context) => from name in NameParser.Named("attribute name") from parameters in AttributeParameterParser(context).Delimited(",").Bracketed("(", ")").OrDefault() select new ServiceAttributeInfo(name.Value, parameters, context.GetPart(ServicePartKind.Name, name));
public override Bitmap Apply(Bitmap bmp) { if (string.IsNullOrEmpty(Text)) { return(bmp); } using (Font font = Font) { if (font == null || font.Size < 1) { return(bmp); } NameParser parser = new NameParser(NameParserType.Text); parser.ImageWidth = bmp.Width; parser.ImageHeight = bmp.Height; string parsedText = parser.Parse(Text); using (Graphics g = Graphics.FromImage(bmp)) using (GraphicsPath gp = new GraphicsPath()) { g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.Half; gp.FillMode = FillMode.Winding; float emSize = g.DpiY * font.SizeInPoints / 72; gp.AddString(parsedText, font.FontFamily, (int)font.Style, emSize, Point.Empty, StringFormat.GenericDefault); if (Angle != 0) { using (Matrix matrix = new Matrix()) { matrix.Rotate(Angle); gp.Transform(matrix); } } RectangleF pathRect = gp.GetBounds(); if (pathRect.IsEmpty) { return(bmp); } Size textSize = pathRect.Size.ToSize().Offset(1); Point textPosition = Helpers.GetPosition(Placement, Offset, bmp.Size, textSize); Rectangle textRectangle = new Rectangle(textPosition, textSize); if (AutoHide && !new Rectangle(0, 0, bmp.Width, bmp.Height).Contains(textRectangle)) { return(bmp); } using (Matrix matrix = new Matrix()) { matrix.Translate(textRectangle.X - pathRect.X, textRectangle.Y - pathRect.Y); gp.Transform(matrix); } // Draw text shadow if (Shadow && ((!ShadowUseGradient && ShadowColor.A > 0) || (ShadowUseGradient && ShadowGradient.IsVisible))) { using (Matrix matrix = new Matrix()) { matrix.Translate(ShadowOffset.X, ShadowOffset.Y); gp.Transform(matrix); if (Outline && OutlineSize > 0) { if (ShadowUseGradient) { using (LinearGradientBrush textShadowBrush = ShadowGradient.GetGradientBrush( Rectangle.Round(textRectangle).Offset(OutlineSize + 1).LocationOffset(ShadowOffset))) using (Pen textShadowPen = new Pen(textShadowBrush, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textShadowPen, gp); } } else { using (Pen textShadowPen = new Pen(ShadowColor, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textShadowPen, gp); } } } else { if (ShadowUseGradient) { using (Brush textShadowBrush = ShadowGradient.GetGradientBrush( Rectangle.Round(textRectangle).Offset(1).LocationOffset(ShadowOffset))) { g.FillPath(textShadowBrush, gp); } } else { using (Brush textShadowBrush = new SolidBrush(ShadowColor)) { g.FillPath(textShadowBrush, gp); } } } matrix.Reset(); matrix.Translate(-ShadowOffset.X, -ShadowOffset.Y); gp.Transform(matrix); } } // Draw text outline if (Outline && OutlineSize > 0) { if (OutlineUseGradient) { if (OutlineGradient.IsVisible) { using (LinearGradientBrush textOutlineBrush = OutlineGradient.GetGradientBrush(Rectangle.Round(textRectangle).Offset(OutlineSize + 1))) using (Pen textOutlinePen = new Pen(textOutlineBrush, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textOutlinePen, gp); } } } else if (OutlineColor.A > 0) { using (Pen textOutlinePen = new Pen(OutlineColor, OutlineSize) { LineJoin = LineJoin.Round }) { g.DrawPath(textOutlinePen, gp); } } } // Draw text if (UseGradient) { if (Gradient.IsVisible) { using (Brush textBrush = Gradient.GetGradientBrush(Rectangle.Round(textRectangle).Offset(1))) { g.FillPath(textBrush, gp); } } } else if (Color.A > 0) { using (Brush textBrush = new SolidBrush(Color)) { g.FillPath(textBrush, gp); } } } return(bmp); } }
public void it_returns_two_strings_when_parsing_a_words_using_pascal_case() { string result = NameParser.Parse("FooBar"); result.Should().Be("Foo Bar"); }
public string GetHttpHomePath() { return(NameParser.Parse(NameParserType.URL, HttpHomePath.Replace("%host", Host))); }