Esempio n. 1
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);
            }
        }
    }
Esempio n. 2
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"));
            }
        }
    }
Esempio n. 3
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);
            }
        }
    }
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        // There is already a running thread
        if (IsRunningThread())
        {
            return;
        }

        string err  = null;
        string info = null;

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

        // Get submission
        var submissionInfo = TranslationSubmissionInfoProvider.GetTranslationSubmissionInfo(ValidationHelper.GetInteger(actionArgument, 0));

        if (submissionInfo == null)
        {
            return;
        }

        switch (actionName.ToLowerInvariant())
        {
        case "downloadzip":
            TranslationServiceHelper.DownloadXLIFFinZIP(submissionInfo, Page.Response);
            break;

        case RESUBMIT_ACTION:
            ProcessActionAsync(actionName, submissionInfo);
            break;

        case PROCESS_ACTION:
            ProcessActionAsync(actionName, submissionInfo);
            break;

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

        case "delete":
            var serviceInfo = TranslationServiceInfoProvider.GetTranslationServiceInfo(submissionInfo.SubmissionServiceID);
            if (serviceInfo.TranslationServiceSupportsCancel)
            {
                err = TranslationServiceHelper.CancelSubmission(submissionInfo);
            }

            if (String.IsNullOrEmpty(err))
            {
                submissionInfo.Delete();
            }
            info = GetString("translationservice.submissiondeleted");
            break;
        }

        if (!string.IsNullOrEmpty(err))
        {
            ShowError(err);
        }
        else if (!string.IsNullOrEmpty(info))
        {
            ShowConfirmation(info);
        }
    }
Esempio n. 5
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;
        }
    }
Esempio n. 6
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);
    }