Пример #1
0
    private static string GetParameter(string action, string error, TranslationSubmissionInfo submissionInfo)
    {
        var submissionName = (submissionInfo != null) ? submissionInfo.SubmissionName : null;
        var submissionId   = (submissionInfo != null) ? submissionInfo.SubmissionID : 0;

        return(action + SEPARATOR + error + SEPARATOR + submissionName + SEPARATOR + submissionId);
    }
Пример #2
0
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        string err  = null;
        string info = null;

        // Check modify permission for all actions except for download ZIP
        if (!actionName.EqualsCSafe("downloadzip", true))
        {
            if (!modifyAllowed)
            {
                RedirectToAccessDenied("CMS.TranslationServices", "Modify");
            }
        }

        TranslationSubmissionInfo submissionInfo = TranslationSubmissionInfoProvider.GetTranslationSubmissionInfo(ValidationHelper.GetInteger(actionArgument, 0));

        if (submissionInfo != null)
        {
            switch (actionName.ToLowerCSafe())
            {
            case "downloadzip":
                TranslationServiceHelper.DownloadXLIFFinZIP(submissionInfo, Page.Response);
                break;

            case "resubmit":
                err  = TranslationServiceHelper.ResubmitSubmission(submissionInfo);
                info = GetString("translationservice.translationresubmitted");
                break;

            case "process":
                err  = TranslationServiceHelper.ProcessSubmission(submissionInfo);
                info = GetString("translationservice.translationsimported");
                break;

            case "cancel":
                err  = TranslationServiceHelper.CancelSubmission(submissionInfo);
                info = GetString("translationservice.submissioncanceled");
                break;

            case "delete":
                TranslationServiceHelper.CancelSubmission(submissionInfo);
                submissionInfo.Delete();
                info = GetString("translationservice.submissiondeleted");
                break;
            }
            if (!string.IsNullOrEmpty(err))
            {
                ShowError(err);
            }
            else if (!string.IsNullOrEmpty(info))
            {
                ShowConfirmation(info);
            }
        }
    }
    /// <summary>
    /// Processes the action asynchronously
    /// </summary>
    /// <param name="commandName">Command name</param>
    /// <param name="submission">Translation submission</param>
    private void ProcessActionAsync(string commandName, TranslationSubmissionInfo submission)
    {
        // Set flag
        submission.SubmissionStatus = string.Equals(commandName, RESUBMIT_ACTION, StringComparison.OrdinalIgnoreCase) ? TranslationStatusEnum.ResubmittingSubmission : TranslationStatusEnum.ProcessingSubmission;
        submission.Update();

        // Run action
        var parameter = new Tuple <string, TranslationSubmissionInfo>(commandName, submission);

        ctlAsync.Parameter = GetParameter(commandName, null, submission);
        ctlAsync.RunAsync(p => ProcessAction(parameter), WindowsIdentity.GetCurrent());
    }
Пример #4
0
    /// <summary>
    /// Checks Modify permissions for given translation submission.
    /// </summary>
    /// <param name="redirect">If true, redirects user to Access denied</param>
    private bool CheckModifyPermissions(bool redirect)
    {
        TranslationSubmissionInfo submission = EditedObject as TranslationSubmissionInfo;

        if (submission != null)
        {
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerObject(PermissionsEnum.Modify, submission, SiteInfoProvider.GetSiteName(submission.SubmissionSiteID)))
            {
                if (redirect)
                {
                    RedirectToAccessDenied("CMS.TranslationServices", "Modify");
                }
                return(false);
            }
        }
        return(true);
    }
Пример #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!StopProcessing)
        {
            if (SubmissionID > 0)
            {
                Submission = TranslationSubmissionInfoProvider.GetTranslationSubmissionInfo(SubmissionID);

                if (CheckTranslationsPermissions && (Submission != null))
                {
                    if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerObject(PermissionsEnum.Modify, Submission, SiteInfoProvider.GetSiteName(Submission.SubmissionSiteID)))
                    {
                        RedirectToAccessDenied("CMS.TranslationServices", "Modify");
                    }
                }
            }

            if (Submission == null)
            {
                if (SubmissionItemID > 0)
                {
                    SubmissionItem = TranslationSubmissionItemInfoProvider.GetTranslationSubmissionItemInfo(SubmissionItemID);

                    if (CheckTranslationsPermissions && (SubmissionItem != null))
                    {
                        TranslationSubmissionInfo submission = TranslationSubmissionInfoProvider.GetTranslationSubmissionInfo(SubmissionItem.SubmissionItemSubmissionID);
                        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerObject(PermissionsEnum.Modify, submission, SiteInfoProvider.GetSiteName(submission.SubmissionSiteID)))
                        {
                            RedirectToAccessDenied("CMS.TranslationServices", "Modify");
                        }
                    }
                }
            }
            else
            {
                lblInfo.ResourceString = "translationservice.uploadzipinfo";
            }

            if ((SubmissionItem == null) && (Submission == null))
            {
                pnlContent.Visible = false;
                ShowError(GetString("general.objectnotfound"));
            }
        }
    }
    /// <summary>
    /// Submits submission to translation service.
    /// </summary>
    /// <param name="itemCount">Number of items</param>
    /// <param name="submission">Submission info object</param>
    /// <param name="charCount">Number of characters</param>
    /// <param name="wordCount">Number of words</param>
    /// <param name="submissionFileName">Submission file name</param>
    /// <param name="humanService">Translation service info</param>
    /// <param name="contactService">Indicates if service should be contacted</param>
    private void SubmitSubmissionToService(int itemCount, TranslationSubmissionInfo submission, int charCount, int wordCount, string submissionFileName, AbstractHumanTranslationService humanService, bool contactService)
    {
        submission.SubmissionCharCount = charCount;
        submission.SubmissionWordCount = wordCount;
        submission.SubmissionItemCount = itemCount;
        submission.SubmissionParameter = submissionFileName;

        AddLog(ResHelper.GetString("content.submitingtranslation"));

        if (contactService)
        {
            string error = humanService.CreateSubmission(submission);
            if (!string.IsNullOrEmpty(error))
            {
                AddError(LocalizationHelper.GetString("ContentRequest.TranslationFailed") + " \"" + error + "\"");
            }
        }

        // Update submission after submitting to service to save ticket
        submission.Update();
    }
Пример #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int submissionId = QueryHelper.GetInteger("submissionid", 0);
        int itemId       = QueryHelper.GetInteger("itemid", 0);

        if (submissionId > 0)
        {
            TranslationSubmissionInfo info = TranslationSubmissionInfoProvider.GetTranslationSubmissionInfo(submissionId);
            if (info != null)
            {
                TranslationServiceHelper.DownloadXLIFFinZIP(info, HttpContext.Current.Response);
            }
        }
        else if (itemId > 0)
        {
            TranslationSubmissionItemInfo info = TranslationSubmissionItemInfoProvider.GetTranslationSubmissionItemInfo(itemId);
            if (info != null)
            {
                TranslationServiceHelper.DownloadXLIFF(info, Response);
            }
        }
    }
    /// <summary>
    /// Submits the node for translation. Does not check the permissions, you need to chek it before calling this method.
    /// </summary>
    public string SubmitToTranslation()
    {
        string err = ValidateData();

        if (!string.IsNullOrEmpty(err))
        {
            return(err);
        }

        TranslationSettings settings = TranslationSettings ?? new TranslationSettings();

        if (string.IsNullOrEmpty(settings.TargetLanguage))
        {
            settings.TargetLanguage = CMSContext.PreferredCultureCode;
        }
        settings.TranslateWebpartProperties = SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSTranslateWebpartProperties");
        settings.SourceLanguage             = FromLanguage;
        settings.Instructions           = Instructions;
        settings.Priority               = Priority;
        settings.ProcessBinary          = ProcessBinary;
        settings.TranslateAttachments   = ProcessBinary;
        settings.TranslationDeadline    = Deadline;
        settings.TranslationServiceName = hdnSelectedName.Value;
        settings.GenerateTargetTag      = ValidationHelper.GetBoolean(hdnGenerateTarget.Value, false);

        TreeProvider tree = TreeProvider;

        if (tree == null)
        {
            tree = new TreeProvider();
        }
        TreeNode node = DocumentHelper.GetDocument(NodeID, settings.SourceLanguage, true, tree); //tree.SelectSingleNode(NodeID, settings.SourceLanguage, true, settings.TranslateDocCoupledData);

        TranslationSubmissionInfo submissionInfo = null;

        return(TranslationServiceHelper.SubmitToTranslation(settings, node, out submissionInfo));
    }
    /// <summary>
    /// Translates document(s).
    /// </summary>
    private void Translate(object parameter)
    {
        var parameters = parameter as AsyncParameters;

        if ((parameters == null) || nodeIds.Count < 1)
        {
            return;
        }

        AbstractMachineTranslationService machineService = null;
        AbstractHumanTranslationService   humanService   = null;
        TranslationSubmissionInfo         submission     = null;
        string submissionFileName        = "";
        int    charCount                 = 0;
        int    wordCount                 = 0;
        int    refreshId                 = 0;
        int    itemCount                 = 0;
        int    pageCount                 = 0;
        bool   oneSubmission             = translationElem.CreateSeparateSubmission;
        bool   success                   = false;
        bool   separateSubmissionCreated = false;

        TreeProvider tree = new TreeProvider();

        tree.AllowAsyncActions = false;

        try
        {
            // Begin log
            AddLog(ResHelper.GetString("contentrequest.starttranslate", parameters.UICulture));

            // Prepare translation settings
            var settings = PrepareTranslationSettings();

            // Check selected service
            var service = TranslationServiceInfoProvider.GetTranslationServiceInfo(translationElem.SelectedService);
            if (service == null)
            {
                return;
            }

            // Set if we need target tag (Translations.com workaround)
            settings.GenerateTargetTag = service.TranslationServiceGenerateTargetTag;

            if (service.TranslationServiceIsMachine)
            {
                machineService = AbstractMachineTranslationService.GetTranslationService(service, CurrentSiteName);
            }
            else
            {
                humanService = AbstractHumanTranslationService.GetTranslationService(service, CurrentSiteName);
            }


            bool langSupported = (humanService == null) || CheckLanguageSupport(humanService, settings);
            if (!langSupported)
            {
                return;
            }

            if ((machineService != null) || (humanService != null))
            {
                var data = tree.SelectNodes()
                           .CombineWithDefaultCulture(false)
                           .Published(false)
                           .Culture(settings.SourceLanguage)
                           .WhereIn("NodeID", nodeIds)
                           .OnSite(CurrentSiteName)
                           .OrderBy("NodeLevel, NodeAliasPath")
                           .Column("NodeID");

                if (!DataHelper.DataSourceIsEmpty(data))
                {
                    var processedNodes = new List <int>();

                    // Translate the documents
                    foreach (DataRow dr in data.Tables[0].Rows)
                    {
                        int nodeId = ValidationHelper.GetInteger(dr["NodeID"], 0);

                        // Get document in source language
                        var node = DocumentHelper.GetDocument(nodeId, settings.SourceLanguage, false, tree);
                        if (node == null)
                        {
                            // Document doesn't exist in source culture, skip it
                            continue;
                        }

                        var targetLanguages = GetTargetLanguages(settings.TargetLanguages, node).ToList();
                        if (!targetLanguages.Any())
                        {
                            continue;
                        }

                        if ((submission == null) && (humanService != null))
                        {
                            // Create new submission if not exists for human translation service
                            submission = TranslationServiceHelper.CreateSubmissionInfo(settings, service, MembershipContext.AuthenticatedUser.UserID, SiteInfoProvider.GetSiteID(CurrentSiteName), node.GetDocumentName());
                        }

                        // Handle duplicities
                        if (processedNodes.Contains(nodeId))
                        {
                            continue;
                        }

                        processedNodes.Add(nodeId);
                        bool   targetLanguageVersionCreated = false;
                        bool   logged      = false;
                        string encodedPath = HTMLHelper.HTMLEncode(node.NodeAliasPath);

                        foreach (var targetLanguage in targetLanguages)
                        {
                            // Log only once per document
                            if (!logged)
                            {
                                AddLog(String.Format(ResHelper.GetString("content.translating"), encodedPath, settings.SourceLanguage));
                                logged = true;
                            }

                            itemCount++;
                            targetLanguageVersionCreated = true;

                            if (humanService != null)
                            {
                                if (String.IsNullOrEmpty(submissionFileName))
                                {
                                    submissionFileName = node.NodeAlias;
                                }

                                var targetNode = TranslationServiceHelper.CreateTargetCultureNode(node, targetLanguage, true, false, !settings.TranslateAttachments);

                                TranslationSubmissionItemInfo submissionItem;
                                using (new CMSActionContext {
                                    TouchParent = false
                                })
                                {
                                    // Do not touch parent because all updated information are saved after last item
                                    submissionItem = TranslationServiceHelper.CreateSubmissionItemInfo(settings, submission, node, targetNode.DocumentID, targetLanguage);
                                }

                                charCount += submissionItem.SubmissionItemCharCount;
                                wordCount += submissionItem.SubmissionItemWordCount;
                            }
                            else
                            {
                                // Prepare local settings to translate per one target language
                                var localSettings = settings.Clone();
                                localSettings.TargetLanguages.Clear();
                                localSettings.TargetLanguages.Add(targetLanguage);

                                // Translate page via machine translator
                                TranslationServiceHelper.Translate(machineService, localSettings, node);
                            }
                        }

                        // Each page has own submission if human service is used
                        if (!oneSubmission && (humanService != null))
                        {
                            if (itemCount > 0)
                            {
                                SubmitSubmissionToService(itemCount, submission, charCount, wordCount, submissionFileName, humanService, true);

                                // Reset counters
                                itemCount = 0;
                                charCount = 0;
                                wordCount = 0;

                                // Reset submission file name
                                submissionFileName = null;

                                // At least one submission was created
                                separateSubmissionCreated = true;
                            }
                            else
                            {
                                // No documents were submitted to translation delete empty submission
                                TranslationSubmissionInfoProvider.DeleteTranslationSubmissionInfo(submission);
                            }

                            // Reset submission to create new for next page
                            submission = null;
                        }

                        if (targetLanguageVersionCreated)
                        {
                            // Check if at least one target language version was created
                            pageCount++;
                        }

                        // Store parent ID to refresh UI
                        refreshId = node.NodeParentID;
                    }

                    success = true;
                }
                else
                {
                    AddError(ResHelper.GetString("TranslateDocument.NoSourceDocuments", parameters.UICulture));
                }
            }
            else
            {
                AddError(ResHelper.GetString("TranslateDocument.TranslationServiceNotFound", parameters.UICulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            if (CMSThread.Stopped(ex))
            {
                // When canceled
                AddError(ResHelper.GetString("TranslateDocument.TranslationCanceled", parameters.UICulture));
            }
            else
            {
                // Log error
                LogExceptionToEventLog(ex, parameters.UICulture);
            }
        }
        catch (Exception ex)
        {
            // Log error
            LogExceptionToEventLog(ex, parameters.UICulture);
        }
        finally
        {
            var showAllAlreadyTranslatedError = false;
            if (itemCount > 0)
            {
                // All pages are submitted via only one submission or using machine service
                if ((humanService != null) && (submission != null))
                {
                    // Set submission name if more pages are translated
                    if (pageCount > 1)
                    {
                        submission.SubmissionName += " " + string.Format(GetString("translationservices.submissionnamesuffix"), pageCount - 1);
                        // Do not localize the file name
                        submissionFileName += string.Format(" (and {0} more)", pageCount - 1);
                    }

                    SubmitSubmissionToService(itemCount, submission, charCount, wordCount, submissionFileName, humanService, success);
                }
            }
            else if (oneSubmission)
            {
                TranslationSubmissionInfoProvider.DeleteTranslationSubmissionInfo(submission);

                // Log error only if the translation was successfully processed
                if (success)
                {
                    showAllAlreadyTranslatedError = true;
                }
            }
            else if (!separateSubmissionCreated)
            {
                // Separate submissions were used and no one was created
                showAllAlreadyTranslatedError = true;
            }

            if (showAllAlreadyTranslatedError)
            {
                AddError(ResHelper.GetString("TranslateDocument.DocumentsAlreadyTranslated", parameters.UICulture));
            }

            if (parameters.IsDialog)
            {
                ctlAsyncLog.Parameter = "wopener.location.replace(wopener.location); CloseDialog(); if (wopener.RefreshTree) { wopener.RefreshTree(null, null);}";
            }
            else
            {
                if (string.IsNullOrEmpty(CurrentError))
                {
                    // Overwrite refreshId variable if sub-levels are visible
                    if (parameters.AllLevels && Parameters.ContainsKey("refreshnodeid"))
                    {
                        refreshId = ValidationHelper.GetInteger(Parameters["refreshnodeid"], 0);
                    }

                    // Refresh tree
                    ctlAsyncLog.Parameter = "RefreshTree(" + refreshId + ", " + refreshId + "); \n" + "SelectNode(" + refreshId + ");";
                }
                else
                {
                    ctlAsyncLog.Parameter = "RefreshTree(null, null);";
                }
            }
        }
    }
Пример #10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check the license
        if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, "") != "")
        {
            LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.TranslationServices);
        }

        if (!QueryHelper.ValidateHash("hash", null, new HashSettings("")))
        {
            ShowError(GetString("general.badhashtext"));
            uploadElem.StopProcessing = true;
            uploadElem.Visible        = false;
            return;
        }

        int submissionID = QueryHelper.GetInteger("submissionid", 0);

        TranslationSubmissionInfo submissionInfo = TranslationSubmissionInfoProvider.GetTranslationSubmissionInfo(submissionID);

        if (submissionInfo != null)
        {
            EditedObject = submissionInfo;
            bool allowUpload = true;

            // Show information about submission status
            switch (submissionInfo.SubmissionStatus)
            {
            case TranslationStatusEnum.TranslationCanceled:
                ShowInformation(String.Format(GetString("translationservice.submit.submissioncanceled"), submissionInfo.SubmissionName));
                allowUpload = false;
                break;

            case TranslationStatusEnum.TranslationCompleted:
                ShowInformation(String.Format(GetString("translationservice.submissioncompleted"), submissionInfo.SubmissionName));
                allowUpload = false;
                break;

            case TranslationStatusEnum.ResubmittingSubmission:
            case TranslationStatusEnum.ProcessingSubmission:
                ShowInformation(String.Format(GetString("translationservice.submissionactive"), submissionInfo.SubmissionName));
                allowUpload = false;
                break;
            }

            if (!allowUpload)
            {
                // Disable uploader
                uploadElem.Visible        = false;
                uploadElem.StopProcessing = true;
                btnUpload.Visible         = false;
            }
            else
            {
                // Initialize uploader
                uploadElem.SubmissionID     = QueryHelper.GetInteger("submissionid", 0);
                uploadElem.SubmissionItemID = QueryHelper.GetInteger("itemid", 0);
                btnUpload.Click            += btnUpload_Click;
            }
        }
        else
        {
            ShowInformation(GetString("translationservice.submit.submissiondeleted"));
            // Disable uploader
            uploadElem.Visible        = false;
            uploadElem.StopProcessing = true;
            btnUpload.Visible         = false;
        }
    }
    /// <summary>
    /// Translates document(s).
    /// </summary>
    private void Translate(object parameter)
    {
        if (parameter == null || nodeIds.Count < 1)
        {
            return;
        }

        int refreshId = 0;

        TreeProvider tree = new TreeProvider(currentUser);

        tree.AllowAsyncActions = false;

        try
        {
            // Begin log
            AddLog(ResHelper.GetString("contentrequest.starttranslate", currentCulture));

            bool oneSubmission = chkSeparateSubmissions.Checked;

            // Prepare translation settings
            TranslationSettings settings = new TranslationSettings();
            settings.TargetLanguage             = targetCulture;
            settings.TranslateWebpartProperties = SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSTranslateWebpartProperties");
            settings.SourceLanguage             = translationElem.FromLanguage;
            settings.Instructions           = translationElem.Instructions;
            settings.Priority               = translationElem.Priority;
            settings.TranslateAttachments   = translationElem.ProcessBinary;
            settings.ProcessBinary          = translationElem.ProcessBinary;
            settings.TranslationDeadline    = translationElem.Deadline;
            settings.TranslationServiceName = translationElem.SelectedService;

            using (CMSTransactionScope tr = new CMSTransactionScope())
            {
                // Get the translation provider
                AbstractMachineTranslationService machineService = null;
                AbstractHumanTranslationService   humanService   = null;
                TranslationSubmissionInfo         submission     = null;
                TranslationServiceInfo            ti             = TranslationServiceInfoProvider.GetTranslationServiceInfo(translationElem.SelectedService);
                if (ti != null)
                {
                    if (oneSubmission)
                    {
                        if (ti.TranslationServiceIsMachine)
                        {
                            machineService = AbstractMachineTranslationService.GetTranslationService(ti, CurrentSiteName);
                        }
                        else
                        {
                            humanService = AbstractHumanTranslationService.GetTranslationService(ti, CurrentSiteName);

                            if (oneSubmission)
                            {
                                submission = TranslationServiceHelper.CreateSubmissionInfo(settings, ti, CMSContext.CurrentUser.UserID, CMSContext.CurrentSiteID, "Document submission " + DateTime.Now);
                            }
                        }
                    }

                    bool langSupported = true;
                    if (humanService != null)
                    {
                        if (!humanService.IsLanguageSupported(settings.TargetLanguage))
                        {
                            AddError(ResHelper.GetString("translationservice.targetlanguagenotsupported"));
                            langSupported = false;
                        }
                    }

                    if (langSupported)
                    {
                        if (!oneSubmission || (machineService != null) || (humanService != null))
                        {
                            // Prepare the where condition
                            string where = SqlHelperClass.GetWhereCondition("NodeID", (int[])nodeIds.ToArray(typeof(int)));
                            string columns = "NodeID, NodeAliasPath, DocumentCulture, NodeParentID";

                            string submissionFileName = "";
                            string submissionName     = "";
                            int    charCount          = 0;
                            int    wordCount          = 0;

                            int docCount = 0;

                            // Get the documents in target culture to be able to check if "Skip already translated" option is on
                            // Combine both, source and target culture (at least one hit has to be found - to find the source of translation)
                            where = SqlHelperClass.AddWhereCondition(where, "DocumentCulture = N'" + settings.SourceLanguage + "' OR DocumentCulture = N'" + settings.TargetLanguage + "'");

                            DataSet ds = tree.SelectNodes(CMSContext.CurrentSiteName, "/%", TreeProvider.ALL_CULTURES, true, null, where, "NodeAliasPath DESC", TreeProvider.ALL_LEVELS, false, 0, columns);
                            if (!DataHelper.DataSourceIsEmpty(ds))
                            {
                                List <int> processedNodes = new List <int>();

                                // Translate the documents
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    refreshId = ValidationHelper.GetInteger(dr["NodeParentID"], 0);
                                    int nodeId = ValidationHelper.GetInteger(dr["NodeID"], 0);

                                    if (!processedNodes.Contains(nodeId))
                                    {
                                        processedNodes.Add(nodeId);

                                        string aliasPath = ValidationHelper.GetString(dr["NodeAliasPath"], "");
                                        string culture   = ValidationHelper.GetString(dr["DocumentCulture"], "");

                                        if (chkSkipTranslated.Checked)
                                        {
                                            if (culture == settings.TargetLanguage)
                                            {
                                                // Document already exists in requested culture, skip it
                                                AddLog(string.Format(ResHelper.GetString("content.translatedalready"), HTMLHelper.HTMLEncode(aliasPath + " (" + culture + ")")));
                                                continue;
                                            }
                                        }

                                        AddLog(string.Format(ResHelper.GetString("content.translating"), HTMLHelper.HTMLEncode(aliasPath + " (" + culture + ")")));

                                        TreeNode node = DocumentHelper.GetDocument(nodeId, settings.SourceLanguage, true, null);

                                        // Save the first document as a base for submission name
                                        if (string.IsNullOrEmpty(submissionName))
                                        {
                                            submissionName = node.GetDocumentName();
                                        }
                                        if (string.IsNullOrEmpty(submissionFileName))
                                        {
                                            submissionFileName = node.NodeAlias;
                                        }

                                        docCount++;

                                        // Submit the document
                                        if (machineService != null)
                                        {
                                            TranslationServiceHelper.Translate(machineService, settings, node);
                                        }
                                        else
                                        {
                                            if (oneSubmission && (humanService != null))
                                            {
                                                TreeNode targetNode = TranslationServiceHelper.CreateTargetCultureNode(node, settings.TargetLanguage, true, false);
                                                TranslationSubmissionItemInfo submissionItem = TranslationServiceHelper.CreateSubmissionItemInfo(settings, submission, node, targetNode.DocumentID);

                                                charCount += submissionItem.SubmissionItemCharCount;
                                                wordCount += submissionItem.SubmissionItemWordCount;
                                            }
                                            else
                                            {
                                                TranslationServiceHelper.SubmitToTranslation(settings, node, out submission);
                                            }
                                        }
                                    }
                                }

                                if (docCount > 0)
                                {
                                    if (oneSubmission && (humanService != null))
                                    {
                                        AddLog(ResHelper.GetString("content.submitingtranslation"));

                                        // Set submission name
                                        int itemCount = processedNodes.Count;
                                        if (itemCount > 1)
                                        {
                                            submissionName += " " + string.Format(GetString("translationservices.submissionnamesuffix"), itemCount - 1);
                                        }
                                        submission.SubmissionName      = submissionName;
                                        submission.SubmissionCharCount = charCount;
                                        submission.SubmissionWordCount = wordCount;
                                        submission.SubmissionItemCount = itemCount;
                                        submission.SubmissionParameter = submissionFileName;

                                        string err = humanService.CreateSubmission(submission);
                                        if (!string.IsNullOrEmpty(err))
                                        {
                                            AddError(err);
                                        }

                                        // Save submission with ticket
                                        TranslationSubmissionInfoProvider.SetTranslationSubmissionInfo(submission);
                                    }
                                }
                                else
                                {
                                    TranslationSubmissionInfoProvider.DeleteTranslationSubmissionInfo(submission);
                                    AddError(ResHelper.GetString("TranslateDocument.DocumentsAlreadyTranslated", currentCulture));
                                }
                            }
                        }
                        else
                        {
                            AddError(ResHelper.GetString("TranslateDocument.TranslationServiceNotFound", currentCulture));
                        }
                    }
                }

                tr.Commit();
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state == CMSThread.ABORT_REASON_STOP)
            {
                // When canceled
                AddError(ResHelper.GetString("TranslateDocument.TranslationCanceled", currentCulture));
            }
            else
            {
                // Log error
                LogExceptionToEventLog(ex);
            }
        }
        catch (Exception ex)
        {
            // Log error
            LogExceptionToEventLog(ex);
        }
        finally
        {
            if (isModal)
            {
                ctlAsync.Parameter = "wopener.location.replace(wopener.location); CloseDialog();";
            }
            else
            {
                if (string.IsNullOrEmpty(CurrentError))
                {
                    // Refresh tree
                    ctlAsync.Parameter = "RefreshTree(" + refreshId + ", " + refreshId + "); \n" + "SelectNode(" + refreshId + ");";
                }
                else
                {
                    ctlAsync.Parameter = "RefreshTree(null, null);";
                }
            }
        }
    }
    /// <summary>
    /// Submits submission to translation service.
    /// </summary>
    /// <param name="itemCount">Number of items</param>
    /// <param name="submission">Submission info object</param>
    /// <param name="charCount">Number of characters</param>
    /// <param name="wordCount">Number of words</param>
    /// <param name="submissionFileName">Submission file name</param>
    /// <param name="humanService">Translation service info</param>
    /// <param name="contactService">Indicates if service should be contacted</param>
    private void SubmitSubmissionToService(int itemCount, TranslationSubmissionInfo submission, int charCount, int wordCount, string submissionFileName, AbstractHumanTranslationService humanService, bool contactService)
    {
        submission.SubmissionCharCount = charCount;
        submission.SubmissionWordCount = wordCount;
        submission.SubmissionItemCount = itemCount;
        submission.SubmissionParameter = submissionFileName;

        AddLog(ResHelper.GetString("content.submitingtranslation"));

        if (contactService)
        {
            string error = humanService.CreateSubmission(submission);
            if (!string.IsNullOrEmpty(error))
            {
                AddError(LocalizationHelper.GetString("ContentRequest.TranslationFailed") + " \"" + error + "\"");
            }
        }

        // Update submission after submitting to service to save ticket
        submission.Update();
    }
Пример #13
0
    /// <summary>
    /// Processes the action asynchronously
    /// </summary>
    /// <param name="commandName">Command name</param>
    /// <param name="submission">Translation submission</param>
    private void ProcessActionAsync(string commandName, TranslationSubmissionInfo submission)
    {
        // Set flag
        submission.SubmissionStatus = commandName.EqualsCSafe(RESUBMIT_ACTION, true) ? TranslationStatusEnum.ResubmittingSubmission : TranslationStatusEnum.ProcessingSubmission;
        submission.Update();

        // Run action
        var parameter = new Tuple<string, TranslationSubmissionInfo>(commandName, submission);

        ctlAsync.Parameter = GetParameter(commandName, null, submission);
        ctlAsync.RunAsync(p => ProcessAction(parameter), WindowsIdentity.GetCurrent());
    }
Пример #14
0
    private static string GetParameter(string action, string error, TranslationSubmissionInfo submissionInfo)
    {
        var submissionName = (submissionInfo != null) ? submissionInfo.SubmissionName : null;

        return action + SEPARATOR + error + SEPARATOR + submissionName;
    }
Пример #15
0
    /// <summary>
    /// Uploads the translations submitted.
    /// </summary>
    /// <returns>Zero if upload was not sucessful. Positive number if upload was sucessful (one if whole translation was uploaded and status can be therefore changed, two if only part of submission was uploaded).</returns>
    public bool UploadTranslation()
    {
        // Check permissions
        if (CheckContentPermissions)
        {
            CurrentUserInfo user = CMSContext.CurrentUser;
            if (!user.IsAuthorizedPerResource("CMS.Content", "Read"))
            {
                RedirectToAccessDenied("CMS.Content", "Read");
            }
            if (!user.IsAuthorizedPerResource("CMS.Content", "Create"))
            {
                RedirectToAccessDenied("CMS.Content", "Create");
            }
        }

        try
        {
            if ((uploadElem.PostedFile == null) || string.IsNullOrEmpty(uploadElem.PostedFile.FileName))
            {
                ShowError(GetString("newfile.errorempty"));
                return(false);
            }

            if (SubmissionItem != null)
            {
                if (!FileInfo.New(uploadElem.PostedFile.FileName).Extension.TrimStart('.').EqualsCSafe(TranslationServiceHelper.XLIFFEXTENSION, true))
                {
                    ShowError(GetString("translationservice.xliffallowed"));
                    return(false);
                }

                byte[] xliffBytes = uploadElem.FileBytes;
                if (xliffBytes != null)
                {
                    SubmissionItem.SubmissionItemTargetXLIFF = Encoding.UTF8.GetString(xliffBytes);
                    TranslationSubmissionItemInfoProvider.SetTranslationSubmissionItemInfo(SubmissionItem);

                    TranslationSubmissionInfo submission = TranslationSubmissionInfoProvider.GetTranslationSubmissionInfo(SubmissionItem.SubmissionItemSubmissionID);
                    if (submission != null)
                    {
                        if (submission.SubmissionItemCount == 1)
                        {
                            // Update submission status
                            submission.SubmissionStatus = TranslationStatusEnum.TranslationReady;
                            TranslationSubmissionInfoProvider.SetTranslationSubmissionInfo(submission);
                        }
                    }

                    return(true);
                }
            }
            else if (Submission != null)
            {
                if (uploadElem.PostedFile.FileName.EndsWith(".zip"))
                {
                    string badFiles = TranslationServiceHelper.ImportXLIFFfromZIP(Submission, StreamWrapper.New(uploadElem.PostedFile.InputStream));
                    if (string.IsNullOrEmpty(badFiles))
                    {
                        // Update status of the submission to "Translation ready"
                        Submission.SubmissionStatus = TranslationStatusEnum.TranslationReady;
                        TranslationSubmissionInfoProvider.SetTranslationSubmissionInfo(Submission);

                        if (AutoImport)
                        {
                            // Handle auto import
                            string importErr = TranslationServiceHelper.AutoImportSubmission(Submission);
                            if (!string.IsNullOrEmpty(importErr))
                            {
                                ShowError(importErr);
                                return(false);
                            }
                        }

                        return(true);
                    }
                    else
                    {
                        ShowError(string.Format(GetString("translationservice.badfilesinzip"), badFiles));
                    }
                }
                else
                {
                    ShowError(GetString("translationservice.zipfileexpected"));
                }
            }
        }
        catch (Exception ex)
        {
            TranslationServiceHelper.LogEvent(ex);
            ShowError(ex.Message);
        }

        return(false);
    }