private static string GetValueFromGXServices(GXServices services, string name)
        {
            string[] tokens = name.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
            if (tokens.Length < 2 || tokens.Length > 3)
            {
                return(null);
            }

            string key      = tokens[0];
            string property = tokens[1];

            if (tokens.Length == 3)
            {
                key      = $"{tokens[0]}:{tokens[1]}";
                property = tokens[2];
            }

            GXService service = services.Get(key);

            if (service == null)
            {
                return(null);
            }

            return(service.Properties[property]);
        }
Пример #2
0
        public ExternalProviderGoogle(GXService providerService)
        {
            GoogleCredential credentials;

            using (Stream stream = KeyStream(CryptoImpl.Decrypt(providerService.Properties.Get(KEY))))
            {
                credentials = GoogleCredential.FromStream(stream).CreateScoped(StorageService.Scope.CloudPlatform);
            }

            using (Stream stream = KeyStream(CryptoImpl.Decrypt(providerService.Properties.Get(KEY))))
            {
                Signer = UrlSigner.FromServiceAccountData(stream);
            }

            Client = StorageClient.Create(credentials);

            Service = new StorageService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credentials,
                ApplicationName       = providerService.Properties.Get(APPLICATION_NAME)
            });

            Project = providerService.Properties.Get(PROJECT_ID);
            Bucket  = CryptoImpl.Decrypt(providerService.Properties.Get(BUCKET));
            Folder  = providerService.Properties.Get(FOLDER);

            CreateBucket();
            CreateFolder(Folder);
        }
Пример #3
0
        public Redis()
        {
            GXService providerService = ServiceFactory.GetGXServices().Get(GXServices.CACHE_SERVICE);
            string    address, password;

            address  = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS");
            password = providerService.Properties.Get("CACHE_PROVIDER_PASSWORD");

            if (string.IsNullOrEmpty(address))
            {
                address = String.Format("localhost:{0}", REDIS_DEFAULT_PORT);
            }

            if (!string.IsNullOrEmpty(password))
            {
                if (!address.Contains(':'))
                {
                    address = $"{address}:{REDIS_DEFAULT_PORT}";
                }
                address = string.Format("{0},password={1}", address.Trim(), password.Trim());
                _redisConnectionOptions = ConfigurationOptions.Parse(address);
            }
            else
            {
                _redisConnectionOptions = ConfigurationOptions.Parse(address);
            }
            _redisConnectionOptions.AllowAdmin = true;
        }
Пример #4
0
 public ExternalStorage()
 {
     providerService = ServiceFactory.GetGXServices().Get(GXServices.STORAGE_APISERVICE);
     if (providerService == null)
     {
         providerService = ServiceFactory.GetGXServices().Get(GXServices.STORAGE_SERVICE);
     }
 }
Пример #5
0
        public bool Create(string name, GXProperties properties, ref GxStorageProvider storageProvider, ref GXBaseCollection <SdtMessages_Message> messages)
        {
            storageProvider = null;

            if (string.IsNullOrEmpty(name))
            {
                GXUtil.ErrorToMessages("Unsopported", "Provider cannot be empty", messages);
                return(false);
            }

            try
            {
                if (providerService == null || !string.Equals(providerService.Name, name, StringComparison.OrdinalIgnoreCase))
                {
                    providerService               = new GXService();
                    providerService.Type          = GXServices.STORAGE_SERVICE;
                    providerService.Name          = name;
                    providerService.AllowMultiple = false;
                    providerService.Properties    = new GXProperties();
                }

                preprocess(name, properties);

                GxKeyValuePair prop = properties.GetFirst();
                while (!properties.Eof())
                {
                    providerService.Properties.Set(prop.Key, prop.Value);
                    prop = properties.GetNext();
                }

                string typeFullName = providerService.ClassName;
                logger.Debug("Loading storage provider: " + typeFullName);
#if !NETCORE
                Type type = Type.GetType(typeFullName, true, true);
#else
                Type type = new AssemblyLoader(FileUtil.GetStartupDirectory()).GetType(typeFullName);
#endif
                this.provider = (ExternalProvider)Activator.CreateInstance(type, new object[] { providerService });
            }
            catch (Exception ex)
            {
                logger.Error("Couldn't connect to external storage provider. ", ex);
                StorageMessages(ex, messages);
                return(false);
            }

            storageProvider = this;
            return(true);
        }
Пример #6
0
        MemcachedClient InitCache()
        {
            GXService providerService = ServiceFactory.GetGXServices().Get(GXServices.CACHE_SERVICE);
            String    address         = providerService.Properties.Get("CACHE_PROVIDER_ADDRESS");

            if (!String.IsNullOrEmpty(address))
            {
                MemcachedClient.Setup("instance", address.Split(',', ';', ' '));
            }
            else
            {
                MemcachedClient.Setup("instance", new string[] { "127.0.0.1:11211" });
            }
            return(MemcachedClient.GetInstance("instance"));
        }
        public AzureStorageExternalProvider(GXService providerService)
        {
            Account = CryptoImpl.Decrypt(providerService.Properties.Get(ACCOUNT_NAME));
            Key     = CryptoImpl.Decrypt(providerService.Properties.Get(ACCESS_KEY));

            string publicContainer  = CryptoImpl.Decrypt(providerService.Properties.Get(PUBLIC_CONTAINER));
            string privateContainer = CryptoImpl.Decrypt(providerService.Properties.Get(PRIVATE_CONTAINER));

            StorageCredentials  credentials    = new StorageCredentials(Account, Key);
            CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);

            Client = storageAccount.CreateCloudBlobClient();

            PublicContainer  = GetContainer(publicContainer, BlobContainerPublicAccessType.Blob);
            PrivateContainer = GetContainer(privateContainer, BlobContainerPublicAccessType.Off);
        }
Пример #8
0
        public ExternalProviderS3(GXService providerService)
        {
            string         keyId       = CryptoImpl.Decrypt(providerService.Properties.Get(ACCESS_KEY_ID));
            string         keySecret   = CryptoImpl.Decrypt(providerService.Properties.Get(SECRET_ACCESS_KEY));
            AWSCredentials credentials = null;

            if (!string.IsNullOrEmpty(keyId) && !string.IsNullOrEmpty(keySecret))
            {
                credentials = new BasicAWSCredentials(keyId, keySecret);
            }

            var region = Amazon.RegionEndpoint.GetBySystemName(providerService.Properties.Get(REGION));

            Endpoint = providerService.Properties.Get(ENDPOINT);

            AmazonS3Config config = new AmazonS3Config()
            {
                ServiceURL     = Endpoint,
                RegionEndpoint = region
            };

#if NETCORE
            if (credentials != null)
            {
                Client = new AmazonS3ClientExtended(credentials, config);
            }
            else
            {
                Client = new AmazonS3ClientExtended(config);
            }
#else
            if (credentials != null)
            {
                Client = new AmazonS3Client(credentials, config);
            }
            else
            {
                Client = new AmazonS3Client(config);
            }
#endif
            Bucket = CryptoImpl.Decrypt(providerService.Properties.Get(BUCKET));
            Folder = providerService.Properties.Get(FOLDER);

            CreateBucket();
            CreateFolder(Folder);
        }
Пример #9
0
        private String GetHandlerClassName(HandlerType hType)
        {
            string handlerClassName = string.Empty;

            if (!handlerCache.TryGetValue(hType, out handlerClassName))
            {
                String    type    = GetPtyTypeName(hType);
                GXService service = GXServices.Instance.Get(GXServices.WEBNOTIFICATIONS_SERVICE);
                if (service != null && service.Properties != null)
                {
                    String className = service.Properties.Get(type);
                    if (!string.IsNullOrWhiteSpace(className))
                    {
                        handlerCache[hType] = className.ToLower();
                        handlerClassName    = handlerCache[hType];
                    }
                }
            }
            return(handlerClassName);
        }
Пример #10
0
        public ExternalProviderOpenStack(GXService providerService)
        {
            var identityEndpoint = new Uri(providerService.Properties.Get("SERVER_URL"));
            var identity         = new CloudIdentityWithProject
            {
                Username    = CryptoImpl.Decrypt(providerService.Properties.Get("STORAGE_PROVIDER_USER")),
                Password    = CryptoImpl.Decrypt(providerService.Properties.Get("STORAGE_PROVIDER_PASSWORD")),
                ProjectName = providerService.Properties.Get("TENANT_NAME"),
            };

            OpenStackIdentityProvider identityProvider = new OpenStackIdentityProvider(identityEndpoint, identity);

            GetStorageEndpoint(identityProvider, identity);

            openstackFilesProvider = new CloudFilesProvider(null, "regionOne", identityProvider, null);
            publicBucketName       = CryptoImpl.Decrypt(providerService.Properties.Get("PUBLIC_BUCKET_NAME"));
            privateBucketName      = CryptoImpl.Decrypt(providerService.Properties.Get("PRIVATE_BUCKET_NAME"));
            folderName             = providerService.Properties.Get("FOLDER_NAME");
            serverUrl = providerService.Properties.Get("SERVER_URL");

            CreateBuckets();
            CreateFolder(folderName);
        }