/// <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); }