internal SubmittedJob(JObject json) : base(json)
        {
            long createdRaw;

            if (Int64.TryParse(json.Value<string>("ctime"), out createdRaw))
            {
                _created = createdRaw.ToDateFromTimestamp();
            }

            JToken mt;
            
            if (json.TryGetValue("mt", out mt))
            {
                _isMachineTranslation = mt.ToString() == "1";
            }

            Decimal.TryParse(
                json.Value<string>("credits"),
                NumberStyles.Any,
                CultureInfo.InvariantCulture,
                out _credits);

            Int32.TryParse(json.Value<string>("job_id"), out _jobId);
            Int32.TryParse(json.Value<string>("unit_count"), out _unitCount);

            _currency = json.Value<string>("currency");
            _bodyTranslated = json.Value<string>("body_tgt");

            double eta = -1;

            if (Double.TryParse(
                json.Value<string>("eta"),
                NumberStyles.Integer,
                CultureInfo.InvariantCulture,
                out eta) && eta > -1)
            {
                _eta = TimeSpan.FromSeconds(eta);
            }

            _status = json.Value<string>("status").ToTranslationStatus();

            var captchaUrl = json.Value<string>("captcha_url");

            Uri.TryCreate(captchaUrl, UriKind.Absolute, out _captchaUrl);
        }
        private void UpdateStatus()
        {
            TranslationStatus newStatus = TranslationStatus.Ok;
            string newStatusText = "";

            if (string.IsNullOrEmpty(Target)) // Includes inherited text
            {
                if (!string.IsNullOrEmpty(source))
                {
                    newStatusText = "Missing translation.";
                    newStatus = TranslationStatus.Error;
                }
            }
            else if (!string.IsNullOrEmpty(target)) // Only translations at this level.
            {

                if (!StringIsMultiline(source) && StringIsMultiline(target))
                {
                    newStatusText = "Newlines might not be valid in this text.";
                    newStatus = TranslationStatus.Warning;
                }
                if (trailingSpacesRegex.Match(source).Value != trailingSpacesRegex.Match(target).Value)
                {
                    newStatusText = "Trailing spaces do not match.";
                    newStatus = TranslationStatus.Warning;
                }
                if (prefixSpacesRegex.Match(source).Value != prefixSpacesRegex.Match(target).Value)
                {
                    newStatusText = "Initial spaces do not match.";
                    newStatus = TranslationStatus.Warning;
                }
                if (!string.IsNullOrEmpty(translatedSource) && translatedSource != Source)
                {
                    newStatusText = "Source text has changed after translation.";
                    newStatus = TranslationStatus.Warning;
                }
            }

            if (newStatus != status)
            {
                status = newStatus;
                RaisePropertyChanged("Status");
            }
            if (newStatusText != statusText)
            {
                statusText = newStatusText;
                RaisePropertyChanged("StatusText");
            }
        }
Exemple #3
0
        private async Task<TimestampedId> GetJobWithStatus(TranslationStatus status)
        {
            var items = await _client.Jobs.GetRecentJobs(status: status);

            if (items.Length == 0)
            {
                Assert.Inconclusive("Could not find job with status " + status);
            }

            return items[0];
        }
Exemple #4
0
 public Translation UpdateTranslation(int phraseId, string languageCode, string translationText, TranslationStatus status, string updatedBy)
 {
     throw new NotImplementedException();
 }
Exemple #5
0
 internal static string ToStatusString(this TranslationStatus status)
 {
     return(status.ToString().ToLowerInvariant());
 }
 public List <string> GetStatus()
 {
     return(TranslationStatus.GetTraslationStatus());
 }
        /// <summary>
        /// Gets the ID of recent jobs matching optional filter criterias
        /// </summary>
        /// <param name="status">Status of jobs to get (optional)</param>
        /// <param name="afterDateTime">
        /// Oldest allowed age of jobs to get (optional)
        /// </param>
        /// <param name="maxCount">Max number of jobs to retrive</param>
        /// <returns>Task yielding array of job IDs</returns>
        public async Task<TimestampedId[]> GetRecentJobs(
            TranslationStatus? status = null,
            DateTime? afterDateTime = null,
            int maxCount = 10
            )
        {
            var args = new Dictionary<string, string>();

            if (status.HasValue &&
                status.Value == TranslationStatus.Unknown)
            {
                throw new ArgumentException(
                    Resources.CannotRequestJobsWithUnknownStatus,
                    "status");
            }
            else if (status.HasValue)
            {
                args["status"] = status.Value.ToStatusString(); 
            }

            if (afterDateTime.HasValue)
            {
                var ts = afterDateTime.Value.ToTimeStamp();

                if (ts <= 0)
                {
                    throw new ArgumentException(
                        Resources.CannotRequestJobsWithPreUnixTime,
                        "afterDateTime");
                }

                args["timestamp_after"] = ts.ToString();
            }

            if (maxCount <= 0)
            {
                return new TimestampedId[] { };
            }
            else
            {
                args["count"] = maxCount.ToString();
            }

            var json = await _client.GetJsonAsync<JArray>(UriPartJobsEndpoint, args, true);

            return json.Values<JObject>().Select(o =>
                new TimestampedId(o, "job_id", "ctime")).ToArray();
        }