예제 #1
0
        public static string GetImageFilename(TaskSettings taskSettings, Image image)
        {
            string filename;

            NameParser nameParser = new NameParser(NameParserType.FileName);

            nameParser.MaxNameLength       = 100;
            nameParser.Picture             = image;
            nameParser.AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber;

            ImageTag imageTag = image.Tag as ImageTag;

            if (imageTag != null)
            {
                nameParser.WindowText = imageTag.ActiveWindowTitle;
            }

            if (string.IsNullOrEmpty(nameParser.WindowText))
            {
                filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPattern) + ".bmp";
            }
            else
            {
                filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPatternActiveWindow) + ".bmp";
            }

            Program.Settings.NameParserAutoIncrementNumber = nameParser.AutoIncrementNumber;

            return(filename);
        }
예제 #2
0
파일: TaskHelpers.cs 프로젝트: KoMiI/ShareX
        public static string GetImageFilename(TaskSettings taskSettings, Image image)
        {
            string filename;

            NameParser nameParser = new NameParser(NameParserType.FileName)
            {
                Picture             = image,
                AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber,
                MaxNameLength       = taskSettings.AdvancedSettings.NamePatternMaxLength,
                MaxTitleLength      = taskSettings.AdvancedSettings.NamePatternMaxTitleLength,
                CustomTimeZone      = taskSettings.UploadSettings.UseCustomTimeZone ? taskSettings.UploadSettings.CustomTimeZone : null
            };

            ImageTag imageTag = image.Tag as ImageTag;

            if (imageTag != null)
            {
                nameParser.WindowText  = imageTag.ActiveWindowTitle;
                nameParser.ProcessName = imageTag.ActiveProcessName;
            }

            if (string.IsNullOrEmpty(nameParser.WindowText))
            {
                filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPattern) + ".bmp";
            }
            else
            {
                filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPatternActiveWindow) + ".bmp";
            }

            Program.Settings.NameParserAutoIncrementNumber = nameParser.AutoIncrementNumber;

            return(filename);
        }
예제 #3
0
        public void TestParseNotZhangSanCase()
        {
            IParser p = new NameParser(GeneralParserTest.CreateParserContext("李三买了一张三角桌子", dictServer));
            ParseResultCollection prc = p.Parse(0);

            Assert.AreEqual(2, prc.Count);

            GeneralParserTest.AssertParseResult(prc[0], "李", 0, POSType.A_NR);
            GeneralParserTest.AssertParseResult(prc[1], "三", 1, POSType.A_NR);

            prc = p.Parse(5);
            Assert.AreEqual(0, prc.Count);
        }
예제 #4
0
파일: FTPAccount.cs 프로젝트: Z1ni/ShareX
        public string GetHttpHomePath()
        {
            HttpHomePath = FTPHelpers.RemovePrefixes(HttpHomePath);
            NameParser nameParser = new NameParser(NameParserType.URL);

            return(nameParser.Parse(HttpHomePath.Replace("%host", Host)));
        }
예제 #5
0
        private void B2UpdateCustomDomainPreview()
        {
            string uploadPath = NameParser.Parse(NameParserType.FolderPath, Config.B2UploadPath);

            if (cbB2CustomUrl.Checked)
            {
                string customUrl = NameParser.Parse(NameParserType.FolderPath, Config.B2CustomUrl);
                if (URLHelpers.IsValidURL(customUrl))
                {
                    txtB2UrlPreview.Text = customUrl + uploadPath + "example.png";
                }
                else
                {
                    txtB2UrlPreview.Text = "invalid custom URL";
                }
            }
            else
            {
                string bucket = string.IsNullOrEmpty(Config.B2BucketName) ?
                                "[bucket]" :
                                URLHelpers.URLEncode(Config.B2BucketName);
                string url = $"https://f001.backblazeb2.com/file/{bucket}/{uploadPath}example.png";
                txtB2UrlPreview.Text = url;
            }
        }
예제 #6
0
        public string GetSubFolderPath(string filename = null)
        {
            NameParser parser = new NameParser(NameParserType.URL);
            string     path   = parser.Parse(SubFolderPath.Replace("%host", Host));

            return(Helpers.CombineURL(path, filename));
        }
예제 #7
0
        private IEnumerable <string> GetStepDefinitions(string keyword)
        {
            var names = new List <string>();

            foreach (var a in _assemblies)
            {
                foreach (var t in a.GetTypes())
                {
                    foreach (var m in t.GetMethods())
                    {
                        if (NameParser.IsStepDefinition(m))
                        {
                            string name = NameParser.Parse(m);

                            if (name.StartsWith(keyword, StringComparison.OrdinalIgnoreCase))
                            {
                                names.Add(name);
                            }
                        }
                    }
                }
            }

            names.Sort();

            return(names);
        }
예제 #8
0
 public void LastNamePrefix()
 {
     Assert.AreEqual("van der Graaf", NameParser.Parse("van der Graaf").LastName);
     Assert.AreEqual("del Rio", NameParser.Parse("Ms. Rebecca del Rio").LastName);
     Assert.AreEqual("von Braun", NameParser.Parse("Matthias von Braun").LastName);
     Assert.AreEqual("de los Llanos", NameParser.Parse("Sra. de los Llanos").LastName);
 }
예제 #9
0
 public void Suffix()
 {
     Assert.AreEqual("I", NameParser.Parse("John Doe I").Suffix);
     Assert.AreEqual("IV", NameParser.Parse("John Doe iv").Suffix);
     Assert.AreEqual("Sr.", NameParser.Parse("George Bush SR.").Suffix);
     Assert.AreEqual("Jr.", NameParser.Parse("jr").Suffix);
 }
예제 #10
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override EntityName ParseNonNullNode(ParseContext context, XmlNode node, BareANY parseResult, Type expectedReturnType
                                                       , XmlToModelResult xmlToModelResult)
        {
            EntityName result = null;
            // The incoming xml should specify a specializationType or xsi:type in order to determine how to process the field. (CDA/R1 does allow for EN)
            // However, it should be possible to determine which concrete type to use by applying all known name parsers.
            string specializationType = GetSpecializationType(node);

            if (StringUtils.IsBlank(specializationType))
            {
                specializationType = GetXsiType(node);
            }
            string     upperCaseST = StringUtils.IsBlank(specializationType) ? string.Empty : specializationType.ToUpper();
            NameParser nameParser  = nameParsers.SafeGet(upperCaseST);

            if (nameParser == null && StringUtils.IsNotBlank(specializationType))
            {
                // log error based on bad ST/XT
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Could not determine appropriate parser to use for EN specializationType/xsi:type of: "
                                                          + specializationType, (XmlElement)node));
            }
            if (nameParser != null && nameParser.IsParseable(node, context))
            {
                result = (EntityName)nameParser.Parse(context, node, xmlToModelResult).BareValue;
            }
            else
            {
                string actualParserUsed = null;
                // try all known name parsers
                if (tnElementParser.IsParseable(node, context))
                {
                    actualParserUsed = "TN";
                    result           = (EntityName)tnElementParser.Parse(context, node, xmlToModelResult).BareValue;
                }
                else
                {
                    if (pnElementParser.IsParseable(node, context))
                    {
                        actualParserUsed = "PN";
                        result           = (EntityName)pnElementParser.Parse(context, node, xmlToModelResult).BareValue;
                    }
                    else
                    {
                        if (onElementParser.IsParseable(node, context))
                        {
                            actualParserUsed = "ON";
                            result           = (EntityName)onElementParser.Parse(context, node, xmlToModelResult).BareValue;
                        }
                        else
                        {
                            throw new XmlToModelTransformationException("Cannot figure out how to parse EN node " + node.ToString());
                        }
                    }
                }
                // need to log warning - not able to parse name as expected
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, ErrorLevel.WARNING, "EN field has been handled as type "
                                                          + actualParserUsed, (XmlElement)node));
            }
            return(result);
        }
예제 #11
0
        public string GetUriPath(string filename)
        {
            if (string.IsNullOrEmpty(Host))
            {
                return(string.Empty);
            }

            if (HttpHomePathNoExtension)
            {
                filename = Path.GetFileNameWithoutExtension(filename);
            }

            string path;

            HttpHomePath = FTPHelpers.RemovePrefixes(HttpHomePath);
            NameParser nameParser   = new NameParser(NameParserType.URL);
            string     httpHomePath = nameParser.Parse(HttpHomePath.Replace("%host", Host));

            string subFolderPath   = GetSubFolderPath();
            string browserProtocol = BrowserProtocol.GetDescription();

            if (string.IsNullOrEmpty(httpHomePath))
            {
                string host = Host;

                if (host.StartsWith("ftp."))
                {
                    host = host.Substring(4);
                }

                path = Helpers.CombineURL(host, subFolderPath, filename);
            }
            else
            {
                if (!httpHomePath.StartsWith("@"))
                {
                    path = Helpers.CombineURL(httpHomePath, subFolderPath);
                }
                else
                {
                    path = httpHomePath.Substring(1);
                }

                if (path.EndsWith("="))
                {
                    path += filename;
                }
                else
                {
                    path = Helpers.CombineURL(path, filename);
                }
            }

            if (!path.StartsWith(browserProtocol))
            {
                path = browserProtocol + path;
            }

            return(path);
        }
예제 #12
0
 public void Title()
 {
     Assert.AreEqual("Mr.", NameParser.Parse("Mr. Pink").Title);
     Assert.AreEqual("Miss", NameParser.Parse("miss Sunshine").Title);
     Assert.AreEqual("Dr.", NameParser.Parse("DR MacCoy").Title);
     Assert.AreEqual("Rev.", NameParser.Parse("rev").Title);
 }
예제 #13
0
        public void TestParseSingleName()
        {
            IParser p = new NameParser(GeneralParserTest.CreateParserContext("你好,我叫毛泽东,这位是朱德同志。", dictServer));
            ParseResultCollection prc = p.Parse(5);

            Assert.AreEqual(2, prc.Count);

            GeneralParserTest.AssertParseResult(prc[0], "毛", 5, POSType.A_NR);
            GeneralParserTest.AssertParseResult(prc[1], "泽东", 6, POSType.A_NR);

            prc = p.Parse(12);
            Assert.AreEqual(3, prc.Count);
            GeneralParserTest.AssertParseResult(prc[0], "朱", 12, POSType.A_NR);
            GeneralParserTest.AssertParseResult(prc[1], "德", 13, POSType.A_NR);
            GeneralParserTest.AssertParseResult(prc[2], "同志", 14, POSType.D_N);
        }
예제 #14
0
파일: AmazonS3.cs 프로젝트: Z1ni/ShareX
        private string GetObjectKey(string fileName)
        {
            NameParser parser       = new NameParser(NameParserType.FolderPath);
            string     objectPrefix = S3Settings.ObjectPrefix.Trim('/');

            return(Helpers.CombineURL(parser.Parse(objectPrefix), fileName));
        }
예제 #15
0
        //Future Plans
        //[DataRow("Mr Baker", "Mr", E, E, "Baker", E, false)]
        //[DataRow("Mr. Baker", "Mr.", E, E, "Baker", E, false)]
        //MultiPartName
        //[DataRow("Mr. Adam and Mrs. Crystal Baker", "Mr.", E, E, "Baker", E, false)]
        public void NameParser_Parse_correctly_returns_parses_human_name(
            string fullName,
            string prefix,
            string firstName,
            string middleName,
            string lastName,
            string suffix,
            bool isBusinessName
            )
        {
            Name expectedResult = new Name()
            {
                Prefix         = prefix,
                First          = firstName,
                Middle         = middleName,
                Last           = lastName,
                Suffix         = suffix,
                IsOrganization = isBusinessName
            };
            var parser  = new NameParser();
            var results = parser.Parse(fullName);

            Assert.AreEqual(
                expected: expectedResult,
                actual: results);
        }
        public string GetHttpHomePath()
        {
            NameParser parser = new NameParser(NameParserType.URL);

            HttpHomePath = FTPHelpers.RemovePrefixes(HttpHomePath.Replace("%host", LocalhostRoot));
            return(parser.Parse(HttpHomePath));
        }
예제 #17
0
        public override UploadResult Upload(Stream stream, string fileName)
        {
            string UploadPath = NameParser.Parse(NameParserType.URL, TidyUploadPath(Config.DropboxUploadPath));

            CheckEarlyURLCopy(UploadPath, fileName);

            return(UploadFile(stream, UploadPath, fileName, Config.DropboxAutoCreateShareableLink, Config.DropboxURLType));
        }
예제 #18
0
        public void ReversedName()
        {
            var name = NameParser.Parse("Cousteau,  Jacques-Yves, ");

            Assert.AreEqual("Jacques-Yves", name.FirstName);
            Assert.AreEqual("", name.MiddleName);
            Assert.AreEqual("Cousteau", name.LastName);
        }
예제 #19
0
파일: MediaFire.cs 프로젝트: luandev/ShareX
 public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
 {
     return(new MediaFire(APIKeys.MediaFireAppId, APIKeys.MediaFireApiKey, config.MediaFireUsername, config.MediaFirePassword)
     {
         UploadPath = NameParser.Parse(NameParserType.URL, config.MediaFirePath),
         UseLongLink = config.MediaFireUseLongLink
     });
 }
예제 #20
0
        public void MiddleName()
        {
            var name = NameParser.Parse("Philip Howard Lovecraft");

            Assert.AreEqual("Philip", name.FirstName);
            Assert.AreEqual("Howard", name.MiddleName);
            Assert.AreEqual("Lovecraft", name.LastName);
        }
예제 #21
0
파일: Dropbox.cs 프로젝트: felartu/ShareX
 public override FileUploader CreateUploader(UploadersConfig uploadersConfig)
 {
     return(new Dropbox(uploadersConfig.DropboxOAuth2Info, uploadersConfig.DropboxAccountInfo)
     {
         UploadPath = NameParser.Parse(NameParserType.URL, Dropbox.TidyUploadPath(uploadersConfig.DropboxUploadPath)),
         AutoCreateShareableLink = uploadersConfig.DropboxAutoCreateShareableLink,
         ShareURLType = uploadersConfig.DropboxURLType
     });
 }
예제 #22
0
파일: Dropbox.cs 프로젝트: dasilva94/ShareX
 public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
 {
     return new Dropbox(config.DropboxOAuth2Info, config.DropboxAccountInfo)
     {
         UploadPath = NameParser.Parse(NameParserType.URL, Dropbox.TidyUploadPath(config.DropboxUploadPath)),
         AutoCreateShareableLink = config.DropboxAutoCreateShareableLink,
         ShareURLType = config.DropboxURLType
     };
 }
예제 #23
0
 public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
 {
     return(new Dropbox(config.DropboxOAuth2Info)
     {
         UploadPath = NameParser.Parse(NameParserType.Default, Dropbox.VerifyPath(config.DropboxUploadPath)),
         AutoCreateShareableLink = config.DropboxAutoCreateShareableLink,
         UseDirectLink = config.DropboxUseDirectLink
     });
 }
예제 #24
0
        private void UpdateNameFormatPreviews()
        {
            NameParser nameParser = new NameParser(NameParserType.FileName)
            {
                AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber,
                WindowText          = Text,
                ProcessName         = "ShareX",
                MaxNameLength       = TaskSettings.AdvancedSettings.NamePatternMaxLength,
                MaxTitleLength      = TaskSettings.AdvancedSettings.NamePatternMaxTitleLength,
                CustomTimeZone      = TaskSettings.UploadSettings.UseCustomTimeZone ? TaskSettings.UploadSettings.CustomTimeZone : null
            };

            lblNameFormatPatternPreview.Text = Resources.TaskSettingsForm_txtNameFormatPatternActiveWindow_TextChanged_Preview_ + " " +
                                               nameParser.Parse(TaskSettings.UploadSettings.NameFormatPattern);

            lblNameFormatPatternPreviewActiveWindow.Text = Resources.TaskSettingsForm_txtNameFormatPatternActiveWindow_TextChanged_Preview_ + " " +
                                                           nameParser.Parse(TaskSettings.UploadSettings.NameFormatPatternActiveWindow);
        }
예제 #25
0
        public static string GetFilename(TaskSettings taskSettings, string extension = null, Image image = null)
        {
            string filename;

            NameParser nameParser = new NameParser(NameParserType.FileName)
            {
                AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber,
                MaxNameLength       = taskSettings.AdvancedSettings.NamePatternMaxLength,
                MaxTitleLength      = taskSettings.AdvancedSettings.NamePatternMaxTitleLength,
                CustomTimeZone      = taskSettings.UploadSettings.UseCustomTimeZone ? taskSettings.UploadSettings.CustomTimeZone : null
            };

            if (image != null)
            {
                nameParser.ImageWidth  = image.Width;
                nameParser.ImageHeight = image.Height;

                ImageTag imageTag = image.Tag as ImageTag;

                if (imageTag != null)
                {
                    nameParser.WindowText  = imageTag.WindowTitle;
                    nameParser.ProcessName = imageTag.ProcessName;
                }
            }

            if (!string.IsNullOrEmpty(nameParser.WindowText))
            {
                filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPatternActiveWindow);
            }
            else
            {
                filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPattern);
            }

            Program.Settings.NameParserAutoIncrementNumber = nameParser.AutoIncrementNumber;

            if (!string.IsNullOrEmpty(extension))
            {
                filename += "." + extension.TrimStart('.');
            }

            return(filename);
        }
예제 #26
0
        private void txtNameFormatPattern_TextChanged(object sender, EventArgs e)
        {
            TaskSettings.UploadSettings.NameFormatPattern = txtNameFormatPattern.Text;
            NameParser nameParser = new NameParser(NameParserType.FileName)
            {
                AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber
            };

            lblNameFormatPatternPreview.Text = "Preview: " + nameParser.Parse(TaskSettings.UploadSettings.NameFormatPattern);
        }
예제 #27
0
        public void EmptyName()
        {
            var name = NameParser.Parse("");

            Assert.AreEqual("", name.Title);
            Assert.AreEqual("", name.FirstName);
            Assert.AreEqual("", name.MiddleName);
            Assert.AreEqual("", name.LastName);
            Assert.AreEqual("", name.Suffix);
        }
예제 #28
0
        public string GetScreenshotsFolder()
        {
            if (OverrideScreenshotsFolder && !string.IsNullOrEmpty(ScreenshotsFolder))
            {
                string screenshotsFolderPath = NameParser.Parse(NameParserType.FolderPath, ScreenshotsFolder);
                return(Helpers.GetAbsolutePath(screenshotsFolderPath));
            }

            return(Program.ScreenshotsFolder);
        }
예제 #29
0
        public void FullNameWithNoise()
        {
            var name = NameParser.Parse("## ( MR Edward J. Hawkins  jR.  ) ");

            Assert.AreEqual("Mr.", name.Title);
            Assert.AreEqual("Edward", name.FirstName);
            Assert.AreEqual("J", name.MiddleName);
            Assert.AreEqual("Hawkins", name.LastName);
            Assert.AreEqual("Jr.", name.Suffix);
        }
예제 #30
0
        public void NoName()
        {
            var name = NameParser.Parse(" #@ (@?!:*: ");

            Assert.AreEqual("", name.Title);
            Assert.AreEqual("", name.FirstName);
            Assert.AreEqual("", name.MiddleName);
            Assert.AreEqual("", name.LastName);
            Assert.AreEqual("", name.Suffix);
        }