/// <summary>
 /// Print supported target langugaes
 /// </summary>
 static void GetSupportedLanguages()
 {
     foreach (CultureInfo item in TranslationJob.EnumerateSupportedLanguages(sc))
     {
         Console.Write(item.Name + " ");
     }
 }
        static void TestLanguageAndFileExtension()
        {
            Console.WriteLine("Print File Extensions");
            IEnumerable <string> fileExitems = TranslationJob.EnumerateSupportedFileExtensions(cc);

            cc.ExecuteQuery();
            foreach (string item in fileExitems)
            {
                Console.Write(item + ", ");
            }
            Console.WriteLine();
            Console.WriteLine("Print Supported Language");
            IEnumerable <string> langitems = TranslationJob.EnumerateSupportedLanguages(cc);

            cc.ExecuteQuery();
            foreach (string item in langitems)
            {
                Console.Write(item + ", ");
            }
            Console.WriteLine();

            TestIsFileExtensionSupported("docx");
            TestIsFileExtensionSupported("xlf");
            TestIsFileExtensionSupported("no");

            TestIsLanguageSupported("th-th");
            TestIsLanguageSupported("es");
            //invalid languages
            TestIsLanguageSupported("af-za");
            TestIsLanguageSupported("hi");

            TestGetMaximumFileSize("docx");
            TestGetMaximumFileSize("txt");
            TestGetMaximumFileSize("xlf");
        }
Exemplo n.º 3
0
        public ActionResult Index()
        {
            Uri hostWebUri = new Uri(Request.QueryString["SPHostUrl"]);
            Uri appWebUri  = new Uri(Request.QueryString["SPAppWebUrl"]);

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

            //Get supported cultures
            using (ClientContext ctx = TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWebUri, Request.LogonUserIdentity))
            {
                IEnumerable <string> cultures = TranslationJob.EnumerateSupportedLanguages(ctx);
                ctx.ExecuteQuery();

                foreach (string culture in cultures)
                {
                    languages.Add(new SupportedLanguage()
                    {
                        Culture     = culture,
                        DisplayName = CultureInfo.GetCultureInfo(culture).DisplayName,
                        Selected    = false
                    });
                }
            }

            //Get the app 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(),
                    });
                }
            }

            //Set up the ViewModel
            LanguagesViewModel viewModel = new LanguagesViewModel();

            viewModel.SelectedCulture = settings.Where <Setting>(s => s.Title == "Culture").FirstOrDefault().Value;
            viewModel.Destination     = settings.Where <Setting>(s => s.Title == "Destination").FirstOrDefault().Value;
            viewModel.Languages       = languages;
            viewModel.AppWebUrl       = Request.QueryString["SPAppWebUrl"]; //Save the AppWebUrl for future use
            return(View(viewModel));
        }
 private void CreateThreadForListAllLangs(object dummy)
 {
     try
     {
         string result = "";
         result += "Print Supported Languages \n";
         IEnumerable <string> langitems = TranslationJob.EnumerateSupportedLanguages(cc);
         cc.ExecuteQuery();
         foreach (string item in langitems)
         {
             result += item + ", ";
         }
         DispatcherOperation dop = Dispatcher.BeginInvoke(new Action <string>(PrintResult), result);
     }
     catch (Exception e)
     {
         DispatcherOperation dop = Dispatcher.BeginInvoke(new Action <string>(PrintResult), e.ToString());
     }
 }