/// <summary>
    /// submit an async job to translate folder(s)
    /// </summary>
    /// <param name="culture">target langauge</param>
    /// <param name="inputFolder">Full URL of the input folder on SharePoint</param>
    /// <param name="outputFolder">Full URL of the output folder on SharePoint</param>
    static void AddAsyncFolder(string culture, string inputFolder, string outputFolder)
    {
        SPServiceContext sc  = SPServiceContext.GetContext(new SPSite(site));
        TranslationJob   job = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture));

        using (SPSite siteIn = new SPSite(inputFolder))
        {
            Console.WriteLine("In site: {0}", siteIn);
            using (SPWeb webIn = siteIn.OpenWeb())
            {
                Console.WriteLine("In web: {0}", webIn);
                using (SPSite siteOut = new SPSite(outputFolder))
                {
                    Console.WriteLine("Out site: {0}", siteOut);
                    using (SPWeb webOut = siteOut.OpenWeb())
                    {
                        Console.WriteLine("Out web: {0}", webOut);
                        SPFolder folderIn  = webIn.GetFolder(inputFolder);
                        SPFolder folderOut = webOut.GetFolder(outputFolder);
                        Console.WriteLine("Input: " + folderIn);
                        Console.WriteLine("Output: " + folderOut);
                        //true means to recursive all the sub folders
                        job.AddFolder(folderIn, folderOut, true);
                        Console.WriteLine("Submitting the job");
                        job.Start();
                        ListJobItemInfo(job);
                    }
                }
            }
        }
    }
    /// <summary>
    /// submit an async job to translate a document library
    /// </summary>
    /// <param name="culture">target langauge</param>
    /// <param name="inputList">Full URL of the input document library on SharePoint</param>
    /// <param name="outputList">Full URL of the output document library on SharePoint</param>
    static void AddAsyncLibrary(string culture, string inputList, string outputList)
    {
        SPServiceContext sc  = SPServiceContext.GetContext(new SPSite(site));
        TranslationJob   job = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture));

        using (SPSite siteIn = new SPSite(inputList))
        {
            Console.WriteLine("In site: {0}", siteIn);
            using (SPWeb webIn = siteIn.OpenWeb())
            {
                Console.WriteLine("In web: {0}", webIn);
                using (SPSite siteOut = new SPSite(outputList))
                {
                    Console.WriteLine("Out site: {0}", siteOut);
                    using (SPWeb webOut = siteOut.OpenWeb())
                    {
                        Console.WriteLine("Out web: {0}", webOut);
                        SPDocumentLibrary listIn  = (SPDocumentLibrary)webIn.GetList(inputList);
                        SPDocumentLibrary listOut = (SPDocumentLibrary)webOut.GetList(outputList);
                        Console.WriteLine("Input: " + listIn);
                        Console.WriteLine("Output: " + listOut);
                        job.AddLibrary(listIn, listOut);
                        Console.WriteLine("Submitting the job");
                        job.Start();
                        ListJobItemInfo(job);
                    }
                }
            }
        }
    }
 private void asyncLib_Click(object sender, RoutedEventArgs e)
 {
     CreateClientContext();
     List inList = cc.Web.Lists.GetByTitle(this.inputFile.Text);
     List outList = cc.Web.Lists.GetByTitle(this.outputFile.Text);
     TranslationJob job = new TranslationJob(cc, this.culture.Text);
     job.AddLibrary(inList, outList);
     job.Start();
     cc.Load(job);
     ThreadPool.QueueUserWorkItem(new WaitCallback(CreateThreadForAsync), job);
 }
 private void asyncFolder_Click(object sender, RoutedEventArgs e)
 {
     CreateClientContext();
     Folder folderIn = cc.Web.GetFolderByServerRelativeUrl(this.inputFile.Text);
     Folder folderOut = cc.Web.GetFolderByServerRelativeUrl(this.outputFile.Text);
     TranslationJob job = new TranslationJob(cc, this.culture.Text);
     job.AddFolder(folderIn, folderOut, true);
     job.Start();
     cc.Load(job);
     ThreadPool.QueueUserWorkItem(new WaitCallback(CreateThreadForAsync), job);
 }
        private void asyncLib_Click(object sender, RoutedEventArgs e)
        {
            CreateClientContext();
            List           inList  = cc.Web.Lists.GetByTitle(this.inputFile.Text);
            List           outList = cc.Web.Lists.GetByTitle(this.outputFile.Text);
            TranslationJob job     = new TranslationJob(cc, this.culture.Text);

            job.AddLibrary(inList, outList);
            job.Start();
            cc.Load(job);
            ThreadPool.QueueUserWorkItem(new WaitCallback(CreateThreadForAsync), job);
        }
        private void asyncFolder_Click(object sender, RoutedEventArgs e)
        {
            CreateClientContext();
            Folder         folderIn  = cc.Web.GetFolderByServerRelativeUrl(this.inputFile.Text);
            Folder         folderOut = cc.Web.GetFolderByServerRelativeUrl(this.outputFile.Text);
            TranslationJob job       = new TranslationJob(cc, this.culture.Text);

            job.AddFolder(folderIn, folderOut, true);
            job.Start();
            cc.Load(job);
            ThreadPool.QueueUserWorkItem(new WaitCallback(CreateThreadForAsync), job);
        }
 private void asyncFile_Click(object sender, RoutedEventArgs e)
 {
     CreateClientContext();
     TranslationJob job = new TranslationJob(cc, this.culture.Text);
     string input = this.inputFile.Text;
     string output = this.outputFile.Text;
     job.AddFile(input, output);
     job.Name = this.jobName.Text;
     job.Start();
     cc.Load(job);
     ThreadPool.QueueUserWorkItem(new WaitCallback(CreateThreadForAsync), job);
 }
        private void asyncFile_Click(object sender, RoutedEventArgs e)
        {
            CreateClientContext();
            TranslationJob job    = new TranslationJob(cc, this.culture.Text);
            string         input  = this.inputFile.Text;
            string         output = this.outputFile.Text;

            job.AddFile(input, output);
            job.Name = this.jobName.Text;
            job.Start();
            cc.Load(job);
            ThreadPool.QueueUserWorkItem(new WaitCallback(CreateThreadForAsync), job);
        }
 static void AsyncFolder(string culture, string inFolder, string outFolder, string name)
 {
     Folder folderIn = cc.Web.GetFolderByServerRelativeUrl(inFolder);
     Folder folderOut = cc.Web.GetFolderByServerRelativeUrl(outFolder);
     TranslationJob job = new TranslationJob(cc, culture);
     job.AddFolder(folderIn, folderOut, true);
     job.Name = name;
     job.Start();
     cc.Load(job);
     cc.ExecuteQuery();
     Console.WriteLine("JobId: " + job.JobId);
     Console.WriteLine("JobName: " + job.Name);
     Console.WriteLine("Done");
 }
 static void AsyncLib(string culture, string inputList, string outputList, string name)
 {
     List inList = cc.Web.Lists.GetByTitle(inputList);
     List outList = cc.Web.Lists.GetByTitle(outputList);
     TranslationJob job = new TranslationJob(cc, culture);
     job.AddLibrary(inList, outList);
     job.Name = name;
     job.Start();
     cc.Load(job);
     cc.ExecuteQuery();
     Console.WriteLine("JobId: " + job.JobId);
     Console.WriteLine("JobName: " + job.Name);
     Console.WriteLine("Done");
 }
        static void AsyncLib(string culture, string inputList, string outputList, string name)
        {
            List           inList  = cc.Web.Lists.GetByTitle(inputList);
            List           outList = cc.Web.Lists.GetByTitle(outputList);
            TranslationJob job     = new TranslationJob(cc, culture);

            job.AddLibrary(inList, outList);
            job.Name = name;
            job.Start();
            cc.Load(job);
            cc.ExecuteQuery();
            Console.WriteLine("JobId: " + job.JobId);
            Console.WriteLine("JobName: " + job.Name);
            Console.WriteLine("Done");
        }
        static void AsyncFolder(string culture, string inFolder, string outFolder, string name)
        {
            Folder         folderIn  = cc.Web.GetFolderByServerRelativeUrl(inFolder);
            Folder         folderOut = cc.Web.GetFolderByServerRelativeUrl(outFolder);
            TranslationJob job       = new TranslationJob(cc, culture);

            job.AddFolder(folderIn, folderOut, true);
            job.Name = name;
            job.Start();
            cc.Load(job);
            cc.ExecuteQuery();
            Console.WriteLine("JobId: " + job.JobId);
            Console.WriteLine("JobName: " + job.Name);
            Console.WriteLine("Done");
        }
 static void AsyncFile(string culture, string input, string output, string name)
 {
     TranslationJob job = new TranslationJob(cc, culture);
     Console.WriteLine("Adding files");
     Console.WriteLine("Input: " + input);
     Console.WriteLine("Output: " + output);
     job.AddFile(input, output);
     job.Name = name;
     //test
     job.Start();
     cc.Load(job);
     cc.ExecuteQuery();
     Console.WriteLine("JobId: " + job.JobId);
     Console.WriteLine("JobName: " + job.Name);
     Console.WriteLine("Done");
 }
        static void AsyncFile(string culture, string input, string output, string name)
        {
            TranslationJob job = new TranslationJob(cc, culture);

            Console.WriteLine("Adding files");
            Console.WriteLine("Input: " + input);
            Console.WriteLine("Output: " + output);
            job.AddFile(input, output);
            job.Name = name;
            //test
            job.Start();
            cc.Load(job);
            cc.ExecuteQuery();
            Console.WriteLine("JobId: " + job.JobId);
            Console.WriteLine("JobName: " + job.Name);
            Console.WriteLine("Done");
        }
    /// <summary>
    /// submit an async job to translate a file
    /// </summary>
    /// <param name="culture">target langauge</param>
    /// <param name="input">full URL of input file</param>
    /// <param name="output">full URL of output file</param>
    static void AddAsyncFile(string culture, string input, string output, string user)
    {
        SPServiceContext sc       = SPServiceContext.GetContext(new SPSite(site));
        TranslationJob   job      = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture));
        Encoding         encoding = new System.Text.UTF8Encoding();

        if (!String.IsNullOrEmpty(user))
        {
            job.UserToken = ConvertHexStringToByteArray(user);
            //job.UserToken = encoding.GetBytes(user);
        }
        Console.WriteLine("Input: " + input);
        Console.WriteLine("Output: " + output);
        Console.WriteLine("targetlang {0}:", job.TargetLanguage.Name);
        job.AddFile(input, output);
        Console.WriteLine("Submitting the job");
        job.Start();
        if (job.UserToken != null)
        {
            Console.WriteLine("User Token:" + encoding.GetString(job.UserToken));
        }
        ListJobItemInfo(job);
    }
 /// <summary>
 /// submit an async job to translate folder(s)
 /// </summary>
 /// <param name="culture">target langauge</param>
 /// <param name="inputFolder">Full URL of the input folder on SharePoint</param>
 /// <param name="outputFolder">Full URL of the output folder on SharePoint</param>
 static void AddAsyncFolder(string culture, string inputFolder, string outputFolder)
 {
     SPServiceContext sc = SPServiceContext.GetContext(new SPSite(site));
     TranslationJob job = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture));
     using (SPSite siteIn = new SPSite(inputFolder))
     {
         Console.WriteLine("In site: {0}", siteIn);
         using (SPWeb webIn = siteIn.OpenWeb())
         {
             Console.WriteLine("In web: {0}", webIn);
             using (SPSite siteOut = new SPSite(outputFolder))
             {
                 Console.WriteLine("Out site: {0}", siteOut);
                 using (SPWeb webOut = siteOut.OpenWeb())
                 {
                     Console.WriteLine("Out web: {0}", webOut);
                     SPFolder folderIn = webIn.GetFolder(inputFolder);
                     SPFolder folderOut = webOut.GetFolder(outputFolder);
                     Console.WriteLine("Input: " + folderIn);
                     Console.WriteLine("Output: " + folderOut);
                     //true means to recursive all the sub folders
                     job.AddFolder(folderIn, folderOut, true);
                     Console.WriteLine("Submitting the job");
                     job.Start();
                     ListJobItemInfo(job);
                 }
             }
         }
     }
 }
示例#17
0
        public ActionResult Library()
        {
            try
            {
                Uri hostWebUri = new Uri(Request.QueryString["SPHostUrl"]);
                Uri appWebUri  = new Uri(Request.QueryString["SPAppWebUrl"]);

                string listId     = Request.QueryString["SPListId"];
                string listItemId = Request.QueryString["SPListItemId"];

                string culture     = string.Empty;
                string destination = string.Empty;

                List <Setting> settings = new List <Setting>();

                //Get the settings
                using (ClientContext ctx = TokenHelper.GetS2SClientContextWithWindowsIdentity(appWebUri, Request.LogonUserIdentity))
                {
                    List settingsList = ctx.Web.Lists.GetByTitle("Settings");
                    ctx.Load(settingsList);

                    ListItemCollection settingItems = settingsList.GetItems(CamlQuery.CreateAllItemsQuery());
                    ctx.Load(settingItems);

                    ctx.ExecuteQuery();

                    foreach (ListItem settingItem in settingItems)
                    {
                        settings.Add(new Setting()
                        {
                            Title = settingItem["Title"].ToString(),
                            Value = settingItem["Value"].ToString(),
                        });
                    }
                }

                culture     = settings.Where <Setting>(s => s.Title == "Culture").FirstOrDefault().Value;
                destination = settings.Where <Setting>(s => s.Title == "Destination").FirstOrDefault().Value;

                //Translate library asynchronously
                using (ClientContext ctx = TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWebUri, Request.LogonUserIdentity))
                {
                    //Get library to translate
                    Folder rootFolder = ctx.Web.Lists.GetById(new Guid(listId)).RootFolder;
                    ctx.Load(rootFolder, f => f.ServerRelativeUrl);

                    //Get destination library
                    Folder destinationFolder = ctx.Web.Lists.GetByTitle(destination).RootFolder;
                    ctx.Load(destinationFolder, f => f.ServerRelativeUrl);
                    ctx.ExecuteQuery();


                    TranslationJob job = new TranslationJob(ctx, culture);
                    job.AddFolder(rootFolder, destinationFolder, true);
                    job.Name = "LibraryTranslation";
                    job.Start();
                    ctx.Load(job);
                    ctx.ExecuteQuery();

                    string returnPath = hostWebUri.Scheme + "://" + hostWebUri.Authority + ":" + hostWebUri.Port + destinationFolder.ServerRelativeUrl;
                    ViewBag.ReturnPath = returnPath;
                    ViewBag.Message    = "The translation job has been scheduled.";
                }
            }
            catch (Exception x)
            {
                ViewBag.Message = x.Message;
            }

            return(View());
        }
 /// <summary>
 /// submit an async job to translate a document library
 /// </summary>
 /// <param name="culture">target langauge</param>
 /// <param name="inputList">Full URL of the input document library on SharePoint</param>
 /// <param name="outputList">Full URL of the output document library on SharePoint</param>
 static void AddAsyncLibrary(string culture, string inputList, string outputList)
 {
     SPServiceContext sc = SPServiceContext.GetContext(new SPSite(site));
     TranslationJob job = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture));
     using (SPSite siteIn = new SPSite(inputList))
     {
         Console.WriteLine("In site: {0}", siteIn);
         using (SPWeb webIn = siteIn.OpenWeb())
         {
             Console.WriteLine("In web: {0}", webIn);
             using (SPSite siteOut = new SPSite(outputList))
             {
                 Console.WriteLine("Out site: {0}", siteOut);
                 using (SPWeb webOut = siteOut.OpenWeb())
                 {
                     Console.WriteLine("Out web: {0}", webOut);
                     SPDocumentLibrary listIn = (SPDocumentLibrary)webIn.GetList(inputList);
                     SPDocumentLibrary listOut = (SPDocumentLibrary)webOut.GetList(outputList);
                     Console.WriteLine("Input: " + listIn);
                     Console.WriteLine("Output: " + listOut);
                     job.AddLibrary(listIn, listOut);
                     Console.WriteLine("Submitting the job");
                     job.Start();
                     ListJobItemInfo(job);
                 }
             }
         }
     }
 }
 /// <summary>
 /// submit an async job to translate a file
 /// </summary>
 /// <param name="culture">target langauge</param>
 /// <param name="input">full URL of input file</param>
 /// <param name="output">full URL of output file</param>
 static void AddAsyncFile(string culture, string input, string output, string user)
 {
     SPServiceContext sc = SPServiceContext.GetContext(new SPSite(site));
     TranslationJob job = new TranslationJob(sc, CultureInfo.GetCultureInfo(culture));
     Encoding encoding = new System.Text.UTF8Encoding();
     if (!String.IsNullOrEmpty(user))
     {
         job.UserToken = ConvertHexStringToByteArray(user);
         //job.UserToken = encoding.GetBytes(user);
     }
     Console.WriteLine("Input: " + input);
     Console.WriteLine("Output: " + output);
     Console.WriteLine("targetlang {0}:", job.TargetLanguage.Name);
     job.AddFile(input, output);
     Console.WriteLine("Submitting the job");
     job.Start();
     if (job.UserToken != null)
     {
         Console.WriteLine("User Token:" + encoding.GetString(job.UserToken));
     }
     ListJobItemInfo(job);
 }