static void UploadFilesToProjectForLocale(OneSky.Project project, string[] files, string localeName) { foreach (var currentFile in files) { using (var fileStream = File.OpenRead(currentFile)) { // Read the BOM var bom = new byte[3]; fileStream.Read(bom, 0, 3); //We want to ignore the utf8 BOM if (bom[0] != 0xef || bom[1] != 0xbb || bom[2] != 0xbf) { fileStream.Position = 0; } Console.WriteLine("Uploading: " + currentFile + " Locale: " + localeName); var uploadedFile = project.Upload(Path.GetFileName(currentFile), fileStream, localeName).Result; if (uploadedFile == null) { Console.WriteLine("[FAILED] Uploading: " + currentFile + " Locale: " + localeName); } else { Console.WriteLine("[SUCCESS] Uploading: " + currentFile + " Locale: " + localeName); } } } }
static void UploadDirectoryToProject(OneSky.Project project, DirectoryInfo directory, string fileExtension) { foreach (var file in Directory.GetFiles(directory.FullName, fileExtension, SearchOption.AllDirectories)) { DirectoryInfo parentDirectory = Directory.GetParent(file); string localeName = parentDirectory.Name; string currentFile = file; using (var fileStream = File.OpenRead(currentFile)) { // Read the BOM var bom = new byte[3]; fileStream.Read(bom, 0, 3); //We want to ignore the utf8 BOM if (bom[0] != 0xef || bom[1] != 0xbb || bom[2] != 0xbf) { fileStream.Position = 0; } Console.WriteLine("Uploading: " + currentFile + " Locale: " + localeName); var uploadedFile = project.Upload(Path.GetFileName(currentFile), fileStream, new CultureInfo(OneSky.LocaleCodeHelper.ConvertFromLocaleCode(localeName))).Result; if (uploadedFile == null) { Console.WriteLine("[FAILED] Uploading: " + currentFile + " Locale: " + localeName); } else { Console.WriteLine("[SUCCESS] Uploading: " + currentFile + " Locale: " + localeName); } } } }
private UploadedFile UploadOneSkyTranslationWithRetry(OneSky.Project OneSkyProject, string OneSkyFileName, string Culture, FileStream FileStream) { const int MAX_COUNT = 3; long StartingFilePos = FileStream.Position; int Count = 0; for (;;) { try { return OneSkyProject.Upload(OneSkyFileName, FileStream, Culture).Result; } catch (Exception) { if (++Count < MAX_COUNT) { FileStream.Position = StartingFilePos; Console.WriteLine("UploadOneSkyTranslation attempt {0}/{1} failed. Retrying...", Count, MAX_COUNT); continue; } Console.WriteLine("UploadOneSkyTranslation attempt {0}/{1} failed.", Count, MAX_COUNT); break; } } return null; }