Ejemplo n.º 1
0
        private FunctionResult <TRepo> TryGettingRepository <TRepo>(Type repositoryType)
            where TRepo : IRepository
        {
            var cachedRepo = _repos.SingleOrDefault(f => repositoryType.IsAssignableFrom(f.Key));
            var castedRepo = (TRepo)cachedRepo.Value;

            return(castedRepo == null?FunctionResult.CreateFailure <TRepo>() : FunctionResult.CreateSuccess(castedRepo));
        }
        public void Creating_BeingSuccess_MapsToSuccessTrue()
        {
            // Act
            var sut = FunctionResult.CreateSuccess(new object());

            // Assert
            sut.IsSuccess.Should().BeTrue();
        }
        public void Creating_BeingSuccess_MapsValueToPassedObjdect <T>(T value)
        {
            // Act
            var sut = FunctionResult.CreateSuccess(value);

            // Assert
            sut.Value.Should().Be(value);
        }
Ejemplo n.º 4
0
        public override FunctionResult <JsonElement> FindDeepestElement(string key)
        {
            if (key == Key)
            {
                FunctionResult.CreateSuccess(this);
            }

            return(FunctionResult.CreateFailure <JsonElement>());
        }
        public FunctionResult <ILocalizationService> TryGetService(string resourceKey)
        {
            var cacheResult = _chache.TryGetValue(resourceKey, out var service);

            if (cacheResult)
            {
                return(FunctionResult.CreateSuccess(service));
            }

            return(FunctionResult.CreateFailure <ILocalizationService>());
        }
Ejemplo n.º 6
0
 public override FunctionResult <JsonElement> FindDeepestElement(string objectElementKey)
 {
     if (objectElementKey.StartsWith(Key, StringComparison.OrdinalIgnoreCase))
     {
         var deeperChild = _children.Select(child => child.Value.FindDeepestElement(objectElementKey)).FirstOrDefault(f => f.IsSuccess);
         return(deeperChild ?? FunctionResult.CreateSuccess <JsonElement>(this));
     }
     else
     {
         return(FunctionResult.CreateFailure <JsonElement>());
     }
 }
Ejemplo n.º 7
0
 public FunctionResult <byte[]> TryDownloadingData(Uri uri)
 {
     try
     {
         var data = _webClient.DownloadData(uri);
         return(FunctionResult.CreateSuccess(data));
     }
     catch
     {
         return(FunctionResult.CreateFailure <byte[]>());
     }
 }
Ejemplo n.º 8
0
        private FunctionResult <string> TryCreatingDropboxPath(string environmentVariableName)
        {
            var envValue            = Environment.GetEnvironmentVariable(environmentVariableName);
            var dropboxInfoFullPath = _fileSystem.Path.Combine(envValue, DropboxInfoPath);

            if (_fileSystem.File.Exists(dropboxInfoFullPath))
            {
                return(FunctionResult.CreateSuccess(dropboxInfoFullPath));
            }

            return(FunctionResult.CreateFailure <string>());
        }
        internal static FunctionResult <string> LocateDropboxSettingsPath()
        {
            var dropboxBasePathResult = LocateDropboxBasePath();

            if (!dropboxBasePathResult.IsSuccess)
            {
                return(dropboxBasePathResult);
            }

            var relativePath = Path.Combine(dropboxBasePathResult.Value, @"Apps\MLS3\appsettings.json");

            if (!File.Exists(relativePath))
            {
                return(FunctionResult.CreateFailure <string>());
            }

            return(FunctionResult.CreateSuccess(relativePath));
        }
        private static FunctionResult <string> LocateDropboxBasePath()
        {
            const string DropboxInfoPath = @"Dropbox\info.json";
            var          jsonPath        = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), DropboxInfoPath);

            if (!File.Exists(jsonPath))
            {
                jsonPath = Path.Combine(Environment.GetEnvironmentVariable("AppData"), DropboxInfoPath);
            }

            if (!File.Exists(jsonPath))
            {
                return(FunctionResult.CreateFailure <string>());
            }

            var dropboxPath = File.ReadAllText(jsonPath).Split('\"')[5].Replace(@"\\", @"\", StringComparison.OrdinalIgnoreCase);

            return(FunctionResult.CreateSuccess(dropboxPath));
        }
        public static FunctionResult <string> TryProvidingSecret(string secretIdentifier)
        {
            try
            {
                var task = Task.Run(
                    async() =>
                {
                    var azureServiceTokenProvider = new AzureServiceTokenProvider();
                    var keyVaultClient            = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
                    var secret = await keyVaultClient.GetSecretAsync(secretIdentifier).ConfigureAwait(false);
                    return(secret.Value);
                });

                return(FunctionResult.CreateSuccess(task.Result));
            }
            catch (Exception)
            {
                return(FunctionResult.CreateFailure <string>());
            }
        }
Ejemplo n.º 12
0
        public FunctionResult <ModelClassInfo> TryCreatingFromFile(string filePath)
        {
            var fileContent = _fileSystem.File.ReadAllText(filePath);
            var tree        = CSharpSyntaxTree.ParseText(fileContent);
            var root        = tree.GetRoot();

            var classDeclaration = root.DescendantNodes().OfType <ClassDeclarationSyntax>().FirstOrDefault();

            if (classDeclaration == null)
            {
                return(FunctionResult.CreateFailure <ModelClassInfo>());
            }

            var fullNamespace = root
                                .DescendantNodes()
                                .OfType <NamespaceDeclarationSyntax>().First()
                                .Name
                                .ToString();
            var className = classDeclaration.Identifier.Text;

            var ctorDeclarations = root.DescendantNodes().OfType <ConstructorDeclarationSyntax>();
            var ctors            = ctorDeclarations.Select(
                ctorDecl =>
            {
                var ctorParams = ctorDecl.DescendantNodes()
                                 .OfType <PredefinedTypeSyntax>()
                                 .Select(f => new Parameter(f.Keyword.ToString(), f.Keyword.ToString()))
                                 .ToList();

                return(new Constructor(ctorParams));
            }).ToList();

            var classInfo = new ModelClassInfo(className, fullNamespace, ctors);

            return(FunctionResult.CreateSuccess(classInfo));
        }