private ResourceTranslation CreateTranslation(ResourceAssembly existingAssembly, ResourceBundle existingBundle, Resource existingResource, ResourceTranslation template)
 {
     ResourceTranslation translation = new ResourceTranslation();
     translation.BinaryValue = template.BinaryValue;
     translation.Locale = template.Locale;
     translation.ProjectID = existingAssembly.ProjectID;
     translation.Resource = existingResource;
     translation.ResourceAssemblyID = existingAssembly.ID;
     translation.ResourceBundleID = existingBundle.ID;
     translation.ResourceID = existingResource.ID;
     translation.StringValue = template.StringValue;
     translation.TranslationBy = template.TranslationBy;
     translation.TranslationDateTime = template.TranslationDateTime;
     translation.TranslationStatus = template.TranslationStatus;
     return translation;
 }
        private void SyncTranslation(Project project, ResourceAssembly existingAssembly, ResourceBundle existingBundle, ResourceTranslation translation)
        {
            // try find resource
            var existingResource = existingBundle.Resources.FirstOrDefault(r => r.Key == translation.Resource.Key);
            if (existingResource == null)
            {
                Statistics.ResourceNotFound++;
                return;
            }

            // compare resource
            if (existingResource.ResourceClass != translation.Resource.ResourceClass)
            {
                Statistics.ResourceMismatch++;
                return;
            }

            if (existingResource.StringValue == translation.StringValue &&
                existingResource.BinaryValue.SequenceEqual(translation.BinaryValue))
            {
                Statistics.UnchangedResource++;
                return;
            }

            // try find translation
            var existingTranslation = existingResource.Translations.FirstOrDefault(t => t.Locale == translation.Locale);
            if (existingTranslation != null &&
                (existingTranslation.StringValue == translation.StringValue &&
                existingTranslation.BinaryValue.SequenceEqual(translation.BinaryValue) ||
                existingTranslation.TranslationStatus >= translation.TranslationStatus))
            {
                Statistics.ExistingTranslations++;
                return;
            }

            // maybe delete old
            if (existingTranslation != null)
                translationRepository.DeleteTranslation(existingTranslation);

            // add new translation
            ResourceTranslation translationObj = CreateTranslation(existingAssembly, existingBundle, existingResource, translation);
            translationRepository.AddTranslation(translationObj);
            existingResource.Translations.Add(translationObj);
            Statistics.AddedTranslations++;

            // update resource translation status
            new TranslationStatusUtil().CalcResourceTranslationStatusFromTranslations(project.Translations, existingResource);
        }
 // TODO GetTranslations for TranslationSelection
 public void DeleteTranslation(ResourceTranslation translation)
 {
     context.ResourceTranslations.Remove(translation);
 }
        private void CollectTranslatedResource(string bundleName, IDictionaryEnumerator dict, ResourceReader reader, List<ResourceTranslation> translations)
        {
            Object dictValue = null;
            try
            {
                dictValue = dict.Value;
            }
            catch (Exception)
            {
                // wenn eine Assembly wie MeonaKernel gebraucht wird, um dict.Value aufzulösen
                return;
            }

            String key = dict.Key.ToString();
            if (key.StartsWith(">>"))
                return;

            String type;
            byte[] data;
            reader.GetResourceData(dict.Key.ToString(), out type, out data);

            ResourceTranslation translation = new ResourceTranslation();
            translation.BinaryValue = data;
            translation.StringValue = dict.Value != null ? dict.Value.ToString() : null;
            translation.TranslationDateTime = DateTime.UtcNow;
            translation.TranslationStatus = COLLECT_STATUS;
            translation.TranslationBy = TRANSLATION_IMPORTER;

            if (translation.StringValue != null || translation.BinaryValue != null)
            {
                translation.Locale = assembly.GetName().CultureInfo.Name;
                translation.Resource = new Resource();
                translation.Resource.Key = key;
                translation.Resource.ResourceClass = type;

                translations.Add(translation);
            }
        }
 public void AddTranslation(ResourceTranslation translation)
 {
     context.ResourceTranslations.Add(translation);
 }