示例#1
0
        private IList <ILocanRow> ReadResxFileTranslated(string filePath)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            List <ILocanRow> rowsToTranslate = null;

            using (ILocanReader reader = LocanReaderWriterFactory.Instance.GetReader(new { filepath = filePath })) {
                rowsToTranslate = reader.GetRowsTranslated().ToList();
            }

            return(rowsToTranslate);
        }
        private ILocanReader GetReaderForFilepath(string filepath)
        {
            if (string.IsNullOrEmpty(filepath))
            {
                throw new ArgumentNullException("filepath");
            }

            ILocanReader reader = null;

            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(Consts.ResxRegexPattern);
            if (r.IsMatch(filepath))
            {
                reader = new ResxFileLocanReader(filepath);
            }

            return(reader);
        }
        public ILocanReader GetReader(object properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            IDictionary <string, object> values = CollectionHelper.Instance.ConvertToDictionary(properties);
            ILocanReader reader = null;

            // get the file name
            string filepath = this.GetProperty(values, Consts.Filepath, true) as string;

            reader = this.GetReaderForFilepath(filepath);

            if (reader == null)
            {
                string message = string.Format("Couldn't find reader for filepath: [{0}]", filepath);
                throw new ReaderNotFoundException(message);
            }

            return(reader);
        }
示例#4
0
        internal LocanWebFile GetTranslationFile(string apiKey, string filename, Guid userId, string projectName)
        {
            if (string.IsNullOrWhiteSpace(apiKey))
            {
                throw new ArgumentNullException("apiKey");
            }
            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentNullException("filename");
            }
            if (string.IsNullOrWhiteSpace(projectName))
            {
                throw new ArgumentNullException("projectName");
            }
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("File passed to GetTranslationFile not found", filename);
            }

            List <LocanRow> rows = new List <LocanRow>();

            using (ILocanReader reader = LocanReaderWriterFactory.Instance.GetReader(new { filepath = filename })) {
                reader.GetRowsToBeTranslated().ToList().ForEach(row => {
                    rows.Add(row as LocanRow);
                });
            }

            LocanWebFile file = new LocanWebFile {
                ApiKey      = apiKey,
                Rows        = rows,
                Filename    = filename,
                UserId      = userId,
                ProjectName = projectName
            };

            return(file);
        }
示例#5
0
        public void TestReader_FromFactory()
        {
            string filepath = this.WriteTextToTempFile(Consts.ResxSample01, ".resx");

            using (ILocanReader reader = LocanReaderWriterFactory.Instance.GetReader(new { filepath = filepath })) {
                Dictionary <string, string> expectedValues = new Dictionary <string, string>();
                expectedValues.Add("Key01", "Value01");
                expectedValues.Add("Key02", "Value02");
                expectedValues.Add("Key03", "Value03");

                int currentIndex = 0;

                foreach (ILocanRow row in reader.GetRowsToBeTranslated())
                {
                    string expectedKey   = expectedValues.ElementAt(currentIndex).Key;
                    string expectedValue = expectedValues.ElementAt(currentIndex).Value as string;

                    Assert.AreEqual(expectedKey, row.Id);
                    Assert.AreEqual(expectedValue, row.StringToTranslate);

                    currentIndex++;
                }
            }
        }