Example #1
0
        private static ITry <Unit, INonEmptyEnumerable <Validation.Error> > Run(Options options)
        {
            var storageClient = new StorageClient(
                containerUri: new Uri(options.StorageContainerUri),
                tenantId: options.ServicePrincipalTenantId,
                clientId: options.ServicePrincipalClientId,
                clientSecret: options.ServicePrincipalClientSecret
                );

            var version     = GenerateFreshVersion(StaticDateTimeProvider.NowUtc);
            var localData   = InputLocalizationData.Read(options.DataDirectory, options.SourceLanguage);
            var currentData = storageClient.ReadCurrentVersion();
            var errors      = currentData.FlatMap(data => Validator.Validate(localData, data, options.SourceLanguage, options.AllowKeyRemoval).AsNonEmpty());

            if (errors.IsEmpty)
            {
                var updatedData = new VersionedLocalizationData(
                    versionData: new VersionData(version, options.Commit),
                    localization: localData.Serialize(options.SourceLanguage)
                    );

                storageClient.Upload(updatedData);
                storageClient.Update(new Manifest(version, version));
            }

            return(errors.Match(
                       Try.Error <Unit, INonEmptyEnumerable <Validation.Error> >,
                       Try.Success <Unit, INonEmptyEnumerable <Validation.Error> >
                       ));
        }
Example #2
0
        public static IStrictEnumerable <Error> Validate(InputLocalizationData localData, VersionedLocalizationData storageData, string defaultLanguage, bool allowKeyRemoval)
        {
            var defaultLanguageLocalData = localData.Data.Single(p => p.Key.Code.SafeEquals(defaultLanguage)).Value;
            var keyRemovalErrors         = allowKeyRemoval.Match(
                t => StrictEnumerable.Empty <Error>(),
                f => CheckKeyRemovals(defaultLanguageLocalData, storageData)
                );

            return(keyRemovalErrors);
        }