Example #1
0
        private XliffFile GetXliffFile(GLExchange client, string documentTicket)
        {
            using (var translatedDocumentStream = client.downloadTarget(documentTicket))
            {
                var serializer = new XmlSerializer(typeof(XliffRoot));

                var xliff = (XliffRoot)serializer.Deserialize(translatedDocumentStream);
                return(xliff.Files[0]);
            }
        }
Example #2
0
        private GLExchange GetClient(ITranslationContext context)
        {
            GLExchange client;

            if (!context.TryGetItem <GLExchange>(CurrentClientKey, out client))
            {
                client = new GLExchange(this.ProjectDirectorConfig);
                context.Items[CurrentClientKey] = client;
            }

            return(client);
        }
Example #3
0
        /// <inheritdoc />
        protected override bool ProcessSendTranslationEvent(ISendTranslationTaskEvent evnt, ITranslationJobContext context, out string translationId)
        {
            GLExchange projectDirectorClient;

            if (!context.TryGetItem <GLExchange>(CurrentClientKey, out projectDirectorClient))
            {
                var submissionTicket = evnt.ProjectExternalId;

                projectDirectorClient = new GLExchange(this.ProjectDirectorConfig);
                if (!string.IsNullOrEmpty(submissionTicket))
                {
                    projectDirectorClient.getSubmission(submissionTicket);
                }

                context.Items[CurrentClientKey] = projectDirectorClient;
            }

            var translationsComDocument = new Document
            {
                fileformat = TranslationsComConnector.FileFormat,

                // Setting the translation id as the name of the document.
                name            = string.Format("{0}.xlf", evnt.TranslationId),
                sourceLanguage  = evnt.ActualSourceLanguage,
                targetLanguages = new string[] { evnt.TargetLanguage }
            };

            var xliffFile = evnt.GetXliffFile();

            this.ProcessXliffFile(xliffFile);
            var root = new XliffRoot();

            root.Files.Add(xliffFile);

            var xliffSerializer = new XmlSerializer(typeof(XliffRoot));

            using (var xliffStream = new MemoryStream())
            {
                xliffSerializer.Serialize(xliffStream, root);
                xliffStream.Seek(0, SeekOrigin.Begin);
                translationsComDocument.setDataFromMemoryStream(xliffStream);
                projectDirectorClient.uploadTranslatable(translationsComDocument);
            }

            // Setting a Boolean value indicating that we successfully uploaded at least one document in the current submission.
            context.Items[DocumentUploadedKey] = true;

            translationId = translationsComDocument.name;

            return(false);
        }
        private static void doRetrieve(string[] submissionTickets)
        {
            GLExchange pdClient  = new GLExchange(getPDConfig());
            string     shortcode = ConfigurationManager.AppSettings[CONFIG_PROJECT];

            if (string.IsNullOrEmpty(shortcode))
            {
                throw new Exception("Configuration option '" + CONFIG_PROJECT + "' is not set");
            }
            string report = "";


            foreach (string submissionTicket in submissionTickets)
            {
                Target[] completedTargets = pdClient.getCompletedTargets(submissionTicket, 999);

                for (int i = 0; i < completedTargets.Length; i++)
                {
                    try
                    {
                        System.Console.WriteLine("\n\nAttempting to retrieve target\nname=" + completedTargets[i].documentName + "\ntargetLocale =" + completedTargets[i].targetLocale + "\ndocumentTicket=" + completedTargets[i].documentTicket);
                        string       targetTicket   = completedTargets[i].ticket;
                        MemoryStream translatedText = pdClient.downloadCompletedTarget(targetTicket);
                        saveFile(completedTargets[i], translatedText);
                        // Do the processing that you need with the translated XML.
                        System.Console.WriteLine("Download success\n");
                        // On successful processing, send confirmation
                        pdClient.sendDownloadConfirmation(completedTargets[i].ticket);
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine("Problem processing " + completedTargets[i].documentName);
                        System.Console.WriteLine(e);
                    }
                }

                // Get Cancelled
                Target[] cancelledtargets = pdClient.getCancelledTargetsBySubmissions(new[] { submissionTicket }, 999);
            }


            // Re-Delivery Check .. gives you all targets from all submissions
            Target[] targets = pdClient.getCompletedTargets(999);
            for (int i = 0; i < targets.Length; i++)
            {
                System.Console.WriteLine("\nRedelivery to retrieve target\nname=" + targets[i].documentName + "\ntargetLocale =" + targets[i].targetLocale);
            }
            System.Console.WriteLine(report);
        }
Example #5
0
        /// <summary>
        /// TODOTR: document
        /// </summary>
        /// <param name="evnt">TODOTR: document event</param>
        /// <param name="context">TODOTR: document context</param>
        /// <param name="projectId">TODOTR: document projectId</param>
        /// <returns>TODOTR: document returns</returns>

        protected override bool ProcessStartProjectEvent(IStartProjectTaskEvent evnt, ITranslationJobContext context, out string projectId)
        {
            projectId = string.Empty;

            var projectDirectorClient = new GLExchange(this.ProjectDirectorConfig);

            var project = projectDirectorClient.getProject(this.TranslationsComProjectShortCode);

            Submission submission = new Submission();

            submission.name    = string.Format("{0}{1}-UCF-{2}", this.SubmissionNamePrefix, evnt.ProjectName, DateTime.Now.ToString("yyyy-MM-dd-hh-mm"));
            submission.project = project;
            submission.dueDate = evnt.DueDate;

            projectDirectorClient.initSubmission(submission);

            context.Items[CurrentClientKey]     = projectDirectorClient;
            context.Items[StartProjectEventKey] = evnt;

            return(false);
        }
        private static string[] doSend()
        {
            System.Console.WriteLine("Starting send");
            GLExchange pdClient = new GLExchange(getPDConfig());

            string sourceLanguage = ConfigurationManager.AppSettings[CONFIG_SOURCE_LANGUAGE];

            if (string.IsNullOrEmpty(sourceLanguage))
            {
                throw new Exception("Configuration option '" + CONFIG_SOURCE_LANGUAGE + "' is not set");
            }
            string targetLanguagesStr = ConfigurationManager.AppSettings[CONFIG_TARGET_LANGUAGES];

            if (string.IsNullOrEmpty(targetLanguagesStr))
            {
                throw new Exception("Configuration option '" + CONFIG_TARGET_LANGUAGES + "' is not set");
            }
            string fileFormat = ConfigurationManager.AppSettings[CONFIG_FILE_FORMAT];

            if (string.IsNullOrEmpty(fileFormat))
            {
                throw new Exception("Configuration option '" + CONFIG_FILE_FORMAT + "' is not set");
            }
            HashSet <String> targetLanguages = new HashSet <string>();

            if (targetLanguagesStr.IndexOf(CONFIG_SEPARATOR) > 0)
            {
                string[] langsArray = targetLanguagesStr.Split(new char[] { CONFIG_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
                if (langsArray.Length > 0)
                {
                    foreach (string lang in langsArray)
                    {
                        if (lang.Trim().Length > 1)
                        {
                            targetLanguages.Add(lang.Trim());
                        }
                    }
                }
            }
            else
            {
                if (targetLanguagesStr.Trim().Length > 1)
                {
                    targetLanguages.Add(targetLanguagesStr.Trim());
                }
            }
            if (targetLanguages.Count <= 0)
            {
                throw new Exception("Not able to find target languages");
            }

            string shortcode = ConfigurationManager.AppSettings[CONFIG_PROJECT];

            if (string.IsNullOrEmpty(shortcode))
            {
                throw new Exception("Configuration option '" + CONFIG_PROJECT + "' is not set");
            }
            Project project = pdClient.getProject(shortcode);

            DateTime   dt         = DateTime.Now;
            DateTime   dueDate    = dt.AddDays(5); // get this from the UI, i am hard coding to 5 days from now
            Submission submission = new Submission();

            submission.name    = "GLC_Sample_Code_" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm");
            submission.project = project;
            submission.dueDate = dueDate;

            pdClient.initSubmission(submission);

            string folder = SOURCE_ROOT_FOLDER + sourceLanguage;

            string[] filePaths;
            try
            {
                filePaths = Directory.GetFiles(folder);
            }
            catch (Exception ex)
            {
                throw new Exception("Directory '" + folder + "' not found." + ex.Message);
            }

            string report = "";

            foreach (string filePath in filePaths)
            {
                // read file into memory stream
                MemoryStream m          = new MemoryStream();
                FileStream   fileStream = File.OpenRead(filePath);
                m.SetLength(fileStream.Length);
                fileStream.Read(m.GetBuffer(), 0, (int)fileStream.Length);
                string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1);

                Document document = new Document();
                document.fileformat      = fileFormat;
                document.name            = filename;
                document.sourceLanguage  = sourceLanguage;
                document.targetLanguages = targetLanguages.ToArray <String>();
                document.setDataFromMemoryStream(m);

                string ticket = null;
                try
                {
                    ticket = pdClient.uploadTranslatable(document);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    m.Flush();
                    m.Close();
                    fileStream.Close();
                }
                if (ticket != null)
                {
                    report += filePath + " -> " + ticket + "\n";
                }
            }

            System.Console.WriteLine(report);

            string[] submissionTickets = pdClient.startSubmission();
            System.Console.WriteLine("Started Sub : " + submission.name + " [" + submissionTickets[0] + "]");

            return(submissionTickets);
        }