示例#1
0
        public ProjectTaskSegment PostDqfProjectTaskSegment(ProjectTaskSegment projectTaskSegment)
        {
            //System.Web.HttpContext.Current.Server.UrlEncode



            var url = Configuration.DqfServerRoot + Configuration.DqfApiVersion;

            url += "productivityProject/" + projectTaskSegment.Projectid + "/task/" + projectTaskSegment.Taskid + "/segment?";
            url += "source_segment=" + Uri.EscapeDataString(projectTaskSegment.SourceSegment);
            url += "&target_segment=" + Uri.EscapeDataString(projectTaskSegment.TargetSegment);
            url += "&new_target_segment=" + Uri.EscapeDataString(projectTaskSegment.NewTargetSegment);
            url += "&time=" + projectTaskSegment.Time;
            url += "&tm_match=" + projectTaskSegment.TmMatch;
            url += "&cattool=" + projectTaskSegment.Cattool;
            url += "&mtengine=" + projectTaskSegment.Mtengine;
            url += "&mt_engine_version=" + "";

            var uri = new Uri(url);


            //Headers	{Access-Control-Allow-Headers: Content-Type, api_key, Authorization
            //Access-Control-Allow-Methods: GET, POST, DELETE, PUT
            //Access-Control-Allow-Origin: *
            //task_id: 3737
            //Connection: close
            //Content-Length: 76
            //Content-Type: application/json
            //Date: Sat, 30 May 2015 21:57:38 GMT
            //Server: Apache

            //}	System.Net.WebHeaderCollection


            var webRequest = (HttpWebRequest)WebRequest.Create(uri);

            webRequest.KeepAlive     = false;
            webRequest.Method        = @"POST";
            webRequest.ContentLength = 0;
            webRequest.Proxy         = null;
            //webRequest.Headers.Add("DQF_PMANAGER_KEY", productivityProjectTask.DQF_PMANAGER_KEY);
            webRequest.Headers.Add("DQF_TRANSLATOR_KEY", projectTaskSegment.DqfTranslatorKey);
            webRequest.Headers.Add("DQF_PROJECT_KEY", projectTaskSegment.DqfProjectKey);


            webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; .NET CLR 3.5.30729;)";
            using (var webResponse = webRequest.GetResponse() as HttpWebResponse)
            {
                if (webResponse == null)
                {
                    return(projectTaskSegment);
                }
                projectTaskSegment.Segmentid = webResponse.Headers["segment_id"];

                var reader = new StreamReader(webResponse.GetResponseStream());
                reader.ReadToEnd();
            }

            return(projectTaskSegment);
        }
示例#2
0
        private void show_panel(bool back)
        {
            switch (IndexCurrent)
            {
            case 0:
            {
                Text = PluginResources.DQF_Project_Task_Wizard_Title;
                panel_information.BringToFront();
            } break;

            case 1:
            {
                Text = PluginResources.DQF_Project_Task_Step_1_of_3;
                panel_dqf_project.BringToFront();
            } break;

            case 2:
            {
                Text = PluginResources.DQF_Project_Task_Step_2_of_3;

                panel_dqf_documents.BringToFront();
            } break;

            case 3:
            {
                Text = PluginResources.DQF_Project_Task_Step_3_of_3;

                panel_processing_the_upload.BringToFront();
                Application.DoEvents();

                var currentString = string.Empty;
                try
                {
                    progressBar_import_progress.Value   = 0;
                    progressBar_import_progress.Maximum = 100;
                    label_progress_message.Text         = string.Format(PluginResources._0_entries_processed, 0);
                    label_progress_percentage.Text      = "0%";

                    Application.DoEvents();
                    Cursor = Cursors.WaitCursor;

                    var processor = new Processor();
                    if (treeView_dqf_projects.SelectedNode != null)
                    {
                        var dqfProject = treeView_dqf_projects.SelectedNode.Tag as DqfProject;
                        if (dqfProject != null && dqfProject.DqfProjectId > -1)
                        {
                            #region  |  get the working list  |


                            var documentActivitiesUploadList = new List <DocumentActivity>();
                            var targetLanguages = new List <string>();

                            foreach (ListViewItem item in listView_documents.Items)
                            {
                                if (!item.Checked)
                                {
                                    continue;
                                }
                                var da = item.Tag as DocumentActivity;
                                documentActivitiesUploadList.Add(da);

                                if (da != null && !targetLanguages.Contains(da.TranslatableDocument.TargetLanguage))
                                {
                                    targetLanguages.Add(da.TranslatableDocument.TargetLanguage);
                                }
                            }

                            progressBar_import_progress.Maximum = GetTotalDocumentRecords(documentActivitiesUploadList);

                            #endregion


                            var documentActivitiesDictionary = new Dictionary <string, List <DocumentActivity> >();

                            foreach (var documentActivity in documentActivitiesUploadList)
                            {
                                if (!documentActivitiesDictionary.ContainsKey(documentActivity.DocumentId))
                                {
                                    documentActivitiesDictionary.Add(documentActivity.DocumentId, new List <DocumentActivity> {
                                            documentActivity
                                        });
                                }
                                else
                                {
                                    documentActivitiesDictionary[documentActivity.DocumentId].Add(documentActivity);
                                }
                            }


                            var tcc = new TextComparer {
                                Type = TextComparer.ComparisonType.Words
                            };


                            var query = new Query();

                            foreach (var targetLanguage in targetLanguages)
                            {
                                foreach (var kvp in documentActivitiesDictionary)
                                {
                                    if (kvp.Value[0].TranslatableDocument.TargetLanguage != targetLanguage)
                                    {
                                        continue;
                                    }
                                    var mergedDocuments = new MergedDocuments(kvp.Value, Activity, tcc, null);

                                    var productivityProjectTask = new ProductivityProjectTask
                                    {
                                        DqfProjectKey    = dqfProject.DqfProjectKey,
                                        Projectid        = dqfProject.DqfProjectId,
                                        DqfPmanagerKey   = Tracked.Settings.DqfSettings.UserKey,
                                        DqfTranslatorKey = Tracked.Settings.DqfSettings.TranslatorKey,
                                        TargetLanguage   = mergedDocuments.DocumentTargetLanguage,
                                        FileName         = mergedDocuments.DocumentName
                                    };
                                    productivityProjectTask = processor.PostDqfProjectTask(productivityProjectTask);


                                    if (productivityProjectTask.ProjectTaskId <= -1)
                                    {
                                        continue;
                                    }

                                    #region  |  create ProjectTaskSegment list  |

                                    var ptss = new List <ProjectTaskSegment>();

                                    foreach (var record in mergedDocuments.RecordsDictionary.Values)
                                    {
                                        var pts = new ProjectTaskSegment
                                        {
                                            Segmentid        = record.SegmentId,
                                            DqfProjectKey    = dqfProject.DqfProjectKey,
                                            DqfTranslatorKey = Tracked.Settings.DqfSettings.TranslatorKey,
                                            Projectid        = dqfProject.DqfProjectId,
                                            Taskid           = productivityProjectTask.ProjectTaskId,
                                            SourceSegment    =
                                                Helper.GetCompiledSegmentText(
                                                    record.ContentSections.SourceSections, true)
                                        };
                                        if (pts.SourceSegment == string.Empty)
                                        {
                                            pts.SourceSegment = " ";
                                        }
                                        pts.TargetSegment = Helper.GetCompiledSegmentText(record.ContentSections.TargetOriginalSections, true);
                                        if (pts.TargetSegment == string.Empty)
                                        {
                                            pts.TargetSegment = " ";
                                        }
                                        pts.NewTargetSegment = Helper.GetCompiledSegmentText(record.ContentSections.TargetUpdatedSections, true);
                                        if (pts.NewTargetSegment == string.Empty)
                                        {
                                            pts.NewTargetSegment = " ";
                                        }
                                        pts.Time     = new TimeSpan(record.TicksElapsed).Milliseconds;
                                        pts.TmMatch  = GetMatchPercentage(record.TranslationOrigins.Updated.TranslationStatus, record.TranslationOrigins.Updated.OriginType);
                                        pts.Cattool  = 23;        //Trados Studio
                                        pts.Mtengine = 1;
                                        if (record.TranslationOrigins.Updated.OriginType.ToLower().Trim() == "mt" ||
                                            record.TranslationOrigins.Updated.OriginType.ToLower().Trim() == "amt")
                                        {
                                            #region  |  get MT engine  |

                                            if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("APERTIUM", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 2;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("APERTIUM-MOSES", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 3;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("ASIA ONLINE", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 4;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("BING", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 5;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("CAPITA", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 6;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("CARABAO", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 7;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("CCID", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 8;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("CROSSLANG", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 9;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("LINDEN", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 10;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("FIRMA8", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 11;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("FREET", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 12;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("GOOGLE", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 13;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("ICONIC", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 14;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("KANTAN", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 15;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("KODENSHA", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 16;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("LDS TRANSLATOR", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 17;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("LINGUASYS", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 18;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("LUCY", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 19;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("MICROSOFT", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 20;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("MOSES", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 21;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("MYMEMORY", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 22;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("MYMT", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 23;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("OPENTRAD", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 24;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("PANGEAMT", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 25;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("PRAGMA", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 26;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("PROMT", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 27;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("REVERSO", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 28;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("SAFABA", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 29;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("SDL", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 30;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("SOVEE", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 31;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("SYSTRAN", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 32;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("T-TEXT", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 33;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("TAUYOU", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 34;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("TOSHIBA", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 35;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("TRANSSPHERE", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 36;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("WEBLIO", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 37;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("WEBTRANCE", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 38;
                                            }
                                            else if (record.TranslationOrigins.Updated.OriginSystem.ToUpper().IndexOf("WEMT", StringComparison.Ordinal) > -1)
                                            {
                                                pts.Mtengine = 39;
                                            }
                                            else         //other
                                            {
                                                pts.Mtengine = 40;
                                            }

                                            #endregion
                                        }
                                        ptss.Add(pts);
                                    }

                                    #endregion


                                    foreach (var pts in ptss)
                                    {
                                        label_progress_message.Text = string.Format(PluginResources._0_entries_processed, progressBar_import_progress.Value);

                                        if (progressBar_import_progress.Value + 1 <= progressBar_import_progress.Maximum)
                                        {
                                            progressBar_import_progress.Value = ++progressBar_import_progress.Value;

                                            var perc = Convert.ToDouble(progressBar_import_progress.Value) / Convert.ToDouble(progressBar_import_progress.Maximum);
                                            label_progress_percentage.Text = Convert.ToString(Math.Round(perc * 100, 0), CultureInfo.InvariantCulture) + "%";

                                            Application.DoEvents();
                                            Cursor = Cursors.WaitCursor;
                                        }


                                        processor.PostDqfProjectTaskSegment(pts);
                                    }


                                    #region  |  create DQFProjectTask  |

                                    var dqfProjectTask = new DqfProjectTask
                                    {
                                        TableTausdqfprojectsId = dqfProject.Id,
                                        ProjectActivityId      = Activity.Id,
                                        DocumentId             = kvp.Key,
                                        DocumentName           = mergedDocuments.DocumentName,
                                        DqfTranslatorKey       = Tracked.Settings.DqfSettings.TranslatorKey,
                                        DqfProjectKey          = dqfProject.DqfProjectKey,
                                        DqfProjectId           = dqfProject.DqfProjectId,
                                        DqfTaskId      = productivityProjectTask.ProjectTaskId,
                                        Uploaded       = DateTime.Now,
                                        TargetLanguage = mergedDocuments.DocumentTargetLanguage,
                                        CatTool        = 23,
                                        TotalSegments  = mergedDocuments.RecordsDictionary.Values.Count()
                                    };



                                    #endregion

                                    dqfProjectTask.Id = query.CreateDqfProjectTask(Tracked.Settings.ApplicationPaths.ApplicationMyDocumentsDatabaseProjectsPath, dqfProjectTask);

                                    dqfProject.DqfTasks.Add(dqfProjectTask);
                                }
                            }

                            progressBar_import_progress.Value = progressBar_import_progress.Maximum;
                            label_progress_message.Text       = string.Format(PluginResources._0_entries_processed, progressBar_import_progress.Maximum);
                            label_progress_percentage.Text    = "100%";
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message + "\r\n\r\n" + currentString, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            } break;
            }
            check_enabled();
        }