Exemple #1
0
 public Guid GetUserId(string apiKey)
 {
     if (string.IsNullOrWhiteSpace(apiKey)) { throw new ArgumentNullException("apiKey"); }
     LocanDal dal = new LocanDal();
     User user = dal.GetUniqueUser(u => string.Compare(apiKey, u.ApiKey, StringComparison.OrdinalIgnoreCase) == 0, true);
     return user.Id;
 }
        public ActionResult Save(string isoCode, Guid fileId)
        {
            var dal = new LocanDal();
            var apiKey = dal.GetUserByFileId(fileId).ApiKey;
            ILocanTranslator bingTranslator = new BingLocanTranslator(apiKey);
            Language language = Language.GetLanguages(apiKey).SingleOrDefault(l => l.IsoCode.Equals(isoCode, StringComparison.OrdinalIgnoreCase));

            var phrases = dal.GetPhrases(p => p.FileId == fileId).ToList();
            IDictionary<string, string> result = new Dictionary<string, string>();

            foreach (string key in Request.Form)
            {
                var phrase = phrases.SingleOrDefault(p => p.TranslateKey == key);
                if (phrase != null)
                {
                    result.Add(phrase.StringToTranslate, Request.Form[key]);
                }
            }

            ILanguage sourceLanguage = bingTranslator.DetectLanguage(phrases.First().StringToTranslate);
            ILanguage destLanguage = new Locan.Translate.BaseLanguage(isoCode);

            bingTranslator.AddCustomTranslations(sourceLanguage, destLanguage, result);

            return View("Done");
        }
        public ViewResult Index(Guid fileId)
        {
            var dal = new LocanDal();
            var apiKey = dal.GetUserByFileId(fileId).ApiKey;

            return View(Language.GetLanguages(apiKey));
        }
        public static IEnumerable<TranslationItem> GetTranslationItems(string isoCode, Guid fileId)
        {
            var dal = new LocanDal();
            var apiKey = dal.GetUserByFileId(fileId).ApiKey;
            var phrases = dal.GetPhrases(p => p.FileId == fileId).ToList();

            return Convert(phrases, apiKey, isoCode);
        }
Exemple #5
0
        public Guid AddPhrasesForTranslation(HttpRequestMessage request)
        {
            // From the POST message we need to pick off the following properties
            //  UserId
            //  FileId
            //  Array of TranslateKey / StringToTranslate / Comment

            string fileContents = request.Content.ReadAsString();
            LocanWebFile webFile = LocanWebFile.BuildFrom(fileContents);
            LocanDal dal = new LocanDal();
            Guid fileId = dal.GetOrCreateIdForFile(webFile.UserId, webFile.Filename, webFile.ProjectName);

            // delete all old phrases
            dal.DeleteAllPhrasesfor(fileId);

            // now add the phrases
            dal.AddPhrasesToFile(fileId, webFile.Rows);

            return fileId;
        }
Exemple #6
0
        public Guid RegisterUser(string apiKey)
        {
            if (string.IsNullOrWhiteSpace(apiKey)) { throw new ArgumentNullException("apiKey"); }

            User newUser = new User {
                ApiKey = apiKey
            };

            // see if the user exists if so get that ID if not create a new one
            LocanDal dal = new LocanDal();

            User existingUser = dal.GetUniqueUser(user => user.ApiKey == apiKey, false);
            if (existingUser == null) {
                existingUser = dal.AddUser(newUser);
            }

            return existingUser.Id;
        }