public void StorageFiresEventTest()
        {
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));

                using (IConfigurationChangeWatcher watcher = storage.CreateConfigurationChangeWatcher())
                {
                    watcher.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);

                    watcher.StartWatching();
                    Thread.Sleep(100);
                    ((IStorageProviderWriter)storage).Write(GetData());

                    for (int wait = 0; wait < 10 && eventFiredCount < 2; ++wait)
                    {
                        Thread.Sleep(500);
                    }

                    watcher.Dispose();
                }

                Assert.AreEqual(1, eventFiredCount);
            }
        }
Esempio n. 2
0
        public IHttpActionResult Get(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(BadRequest());
            }

            var storageProviderName       = ConfigurationManager.AppSettings["ITokenStorageProviderName"];
            ITokenStorageProvider storage = StorageProviderFactory.Create(storageProviderName);

            if (storage == null)
            {
                return(InternalServerError(new ArgumentException("Storage provider not found.")));
            }

            //try to get the item
            var value = storage.Read(token);

            if (string.IsNullOrWhiteSpace(value))
            {
                return(NotFound());
            }

            return(Ok(value));
        }
 public void NoPathReadWriteTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(NoPathXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create(applConfig1);
     }
 }
Esempio n. 4
0
 public void TypeDoesNotImplementTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
Esempio n. 5
0
 public void BadSectionTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("Foo");
     }
 }
Esempio n. 6
0
        private ITokenStorageProvider GetStorageProvider()
        {
            //get the storage provider, based on config setting
            //Note: more robust implementation would probably use Dependency Injection, for now using a factory
            var storageProviderName       = ConfigurationManager.AppSettings["ITokenStorageProviderName"];
            ITokenStorageProvider storage = StorageProviderFactory.Create(storageProviderName);

            return(storage);
        }
Esempio n. 7
0
        public async Task RevokePublishAsync(Storage storage, IMediaElement element)
        {
            IStorageProvider storageProvider = StorageProviderFactory.GetStorageProvider(
                _serviceProvider, storage.StorageType);

            await storageProvider.RemoveFileAsync(storage.PublishStorageId,
                                                  storage.PublishStorageAccessKey, StorageMode.External,
                                                  storage.PublishHost, element.FilePath, element.GetFileName());
        }
Esempio n. 8
0
 public void CreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(xmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create("ApplConfig1");
         Assert.IsNotNull(storage);
     }
 }
Esempio n. 9
0
        public string GetUrlCustom(Storage storage, string filePath, string fileName,
                                   MediaElementUrlType type, string customStyleProcessStr)
        {
            IStorageProvider storageProvider = StorageProviderFactory.GetStorageProvider(
                _serviceProvider, storage.StorageType);

            switch (type)
            {
            case MediaElementUrlType.DownloadUrl:
            {
                return(storageProvider.GetUrlCustom(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Intranet,
                        StorageAccessKey = storage.StorageAccessKey,
                        StorageId = storage.StorageId,
                        StorageHost = storage.DownloadHost,
                    }, type, filePath, fileName, customStyleProcessStr));
            }

            case MediaElementUrlType.OutputUrl:
            {
                return(storageProvider.GetUrlCustom(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Internet,
                        StorageAccessKey = storage.StorageAccessKey,
                        StorageId = storage.StorageId,
                        StorageHost = storage.OutputHost,
                    }, type, filePath, fileName, customStyleProcessStr));
            }

            case MediaElementUrlType.PublishDownloadUrl:
            {
                return(storageProvider.GetUrlCustom(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Intranet,
                        StorageAccessKey = storage.PublishStorageAccessKey,
                        StorageId = storage.PublishStorageId,
                        StorageHost = storage.PublishOutputHost,
                    }, type, filePath, fileName, customStyleProcessStr));
            }

            default:
            {
                return(storageProvider.GetUrlCustom(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Internet,
                        StorageAccessKey = storage.PublishStorageAccessKey,
                        StorageId = storage.PublishStorageId,
                        StorageHost = storage.PublishOutputHost,
                    }, type, filePath, fileName, customStyleProcessStr));
            }
            }
        }
Esempio n. 10
0
 public void SetStorageProvider()
 {
     foreach (var counterPoco in Counters)
     {
         counterPoco.StorageProvider = StorageProviderFactory.GetStorageProvider(
             false, StorageProvider, SerialNumber, DataStorePath,
             counterPoco.CounterId, Precision, counterPoco.StorageId);
     }
 }
Esempio n. 11
0
        public void WhenGettingWitDataStorehNullShouldThrowTest()
        {
            // arrange
            StorageProviderFactory.Register(StorageProvider.kWhStorage, typeof(kWhStorage), true);

            // act & assert
            Assert.Throws <ArgumentNullException>(
                () => StorageProviderFactory.GetStorageProvider(false, StorageProvider.kWhStorage, "00-00-000-000", null, 0, Precision.kWh));
        }
Esempio n. 12
0
 public void ExceptionConstructorCreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(exceptionConstructorTypeXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
         Assert.Fail("Should never reach here because we should get a ConfigurationException.");
     }
 }
 public void SectionNameTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreEqual(applConfig1, ((XmlFileStorageProvider)storage).CurrentSectionName);
     }
 }
Esempio n. 14
0
 public void BadTypeTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(badTypeXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
         Assert.Fail("Should not get here");
     }
 }
 public void WriteNonXmlNodeValueTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(new object());
     }
 }
 public void StorageBadFileTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlBadFileString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(GetData());
     }
 }
Esempio n. 17
0
        public void WhenRegisteringStorageProviderItShouldReturnTheInstanceOnGetProviderTest()
        {
            // arrange
            StorageProviderFactory.Register(StorageProvider.kWhStorage, typeof(kWhStorage), true);

            // act
            var storage = StorageProviderFactory.GetStorageProvider(false, StorageProvider.kWhStorage, "00-00-000-000", @".\Temp", 1, Precision.mWh);

            // assert
            Assert.IsNotNull(storage);
        }
 public void BadFilePathStorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlBadFilePathString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(GetData());
         Assert.Fail("Should never get here since the file is not specified in configuration.");
     }
 }
 public void NoSectionStorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(NoSectionXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Read();
         Assert.Fail("Should never get here since the section is not specified in the external configuration file.");
     }
 }
Esempio n. 20
0
        private bool EnsureStorageProvider()
        {
            if (StorageProvider == null)
            {
                Debug.Assert(Qbox.SerialNumber != null, "Qbox.SerialNumber != null");

                StorageProvider = StorageProviderFactory.GetStorageProvider(false, Qbox.Storageprovider, Qbox.SerialNumber, Qbox.DataStore.Path, CounterId, Qbox.Precision, StorageId);
                return(true);
            }
            return(false);
        }
 public void StorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         ((IStorageProviderWriter)storage).Write(GetData());
         XmlNode data = storage.Read() as XmlNode;
         Assert.AreEqual(GetData().OuterXml, data.OuterXml);
     }
 }
Esempio n. 22
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logFactory)
        {
            QboxNextLogProvider.LoggerFactory = logFactory;

            StorageProviderFactory.Register(StorageProvider.kWhStorage, typeof(kWhStorage));

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
        }
Esempio n. 23
0
        public async Task UploadFileAsync(Storage storage, IMediaElement element, Stream stream)
        {
            IStorageProvider storageProvider = StorageProviderFactory.GetStorageProvider(
                _serviceProvider, storage.StorageType);

            await storageProvider.UploadFileAsync(stream, storage.StorageId,
                                                  storage.StorageAccessKey, StorageMode.Internal, storage.DownloadHost,
                                                  element.FilePath, element.GetFileName());

            if (element.IsPublished)
            {
                await this.PublishAsync(storage, element);
            }
        }
Esempio n. 24
0
        public async Task PublishAsync(Storage storage, IMediaElement element)
        {
            IStorageProvider storageProvider = StorageProviderFactory.GetStorageProvider(
                _serviceProvider, storage.StorageType);

            using (Stream stream = storageProvider.GetStream(
                       storage.StorageId, storage.StorageAccessKey, StorageMode.Internal,
                       storage.DownloadHost, element.FilePath, element.GetFileName()))
            {
                if (stream == null)
                {
                    return;
                }
                await storageProvider.UploadFileAsync(
                    stream, storage.PublishStorageId, storage.PublishStorageAccessKey,
                    StorageMode.External, storage.PublishHost, element.FilePath, element.GetFileName());
            }
        }
        public void StorageTestChangeEncryption()
        {
            SaveKeyAlgorithmPair(XmlStringWithEncryption);

            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryption))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
                ((IStorageProviderWriter)storage).Write(GetData());

                configurationContext.GetMetaConfiguration().ConfigurationSections[0].Encrypt = false;
                factory = new StorageProviderFactory(configurationContext);
                IStorageProviderWriter storageWriter = factory.Create(applConfig1) as IStorageProviderWriter;
                storageWriter.Write(GetData());

                XmlNode data = storageWriter.Read() as XmlNode;
                Assert.AreEqual(GetData().OuterXml, data.OuterXml);
            }
        }
        public void StorageTestWithEncryption()
        {
            SaveKeyAlgorithmPair(XmlStringWithEncryption);
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryption))
            {
                using (FileStream s = new FileStream(Path.GetFullPath(testConfigFile), FileMode.Create))
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        byte b = 0;
                        s.WriteByte(b);
                    }
                }

                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
                ((IStorageProviderWriter)storage).Write(GetData());
                XmlNode data = storage.Read() as XmlNode;
                Assert.AreEqual(GetData().OuterXml, data.OuterXml);
            }
        }
Esempio n. 27
0
 public void WhenRegisteringInCorrectTypeItShouldThrowTest()
 {
     Assert.Throws <StorageException>(
         () => StorageProviderFactory.Register(StorageProvider.kWhStorage, typeof(int), true));
 }
Esempio n. 28
0
 public void WhenGettingWithNullShouldThrowTest()
 {
     Assert.Throws <ArgumentNullException>(
         () => StorageProviderFactory.GetStorageProvider(false, StorageProvider.kWhStorage, null, null, 0, Precision.kWh));
 }
 public void NoFileStorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlNoFileString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(GetData());
         Assert.Fail("Should never get here since the file is not specified in configuration.");
     }
 }
 public void NoPathReadWriteTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(NoPathXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create(applConfig1);
     }
 }
 public void TypeDoesNotImplementTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
 public void PrivateConstructorCreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(privateConstructorTypeXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
         Assert.Fail("Should never reach here because we should get a ConfigurationException.");
     }
 }
        public void StorageFiresEventTest()
        {
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));

                using (IConfigurationChangeWatcher watcher = storage.CreateConfigurationChangeWatcher())
                {
                    watcher.ConfigurationChanged += new ConfigurationChangedEventHandler(OnConfigurationChanged);

                    watcher.StartWatching();
                    Thread.Sleep(100);
                    ((IStorageProviderWriter)storage).Write(GetData());

                    for (int wait = 0; wait < 10 && eventFiredCount < 2; ++wait)
                    {
                        Thread.Sleep(500);
                    }

                    watcher.Dispose();
                }

                Assert.AreEqual(1, eventFiredCount);
            }
        }
 public void BadTypeTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(badTypeXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("ApplConfig1");
         Assert.Fail("Should not get here");
     }
 }
 public void BadSectionTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         factory.Create("Foo");
     }
 }
Esempio n. 36
0
        public string GetUrlByFormatSizeQuality(Storage storage, string filePath, string fileName,
                                                MediaElementUrlType type, string format, int maxWidthHeight, int percentage)
        {
            IStorageProvider storageProvider = StorageProviderFactory.GetStorageProvider(
                _serviceProvider, storage.StorageType);

            switch (type)
            {
            case MediaElementUrlType.DownloadUrl:
            {
                return(storageProvider.GetUrlByFormatSizeQuality(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Intranet,
                        StorageAccessKey = storage.StorageAccessKey,
                        StorageId = storage.StorageId,
                        StorageHost = storage.DownloadHost,
                    }, type, filePath, fileName, format,
                           maxWidthHeight, percentage));
            }

            case MediaElementUrlType.OutputUrl:
            {
                return(storageProvider.GetUrlByFormatSizeQuality(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Internet,
                        StorageAccessKey = storage.StorageAccessKey,
                        StorageId = storage.StorageId,
                        StorageHost = storage.OutputHost,
                    }, type, filePath, fileName, format,
                           maxWidthHeight, percentage));
            }

            case MediaElementUrlType.PublishDownloadUrl:
            {
                return(storageProvider.GetUrlByFormatSizeQuality(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Intranet,
                        StorageAccessKey = storage.PublishStorageAccessKey,
                        StorageId = storage.PublishStorageId,
                        StorageHost = storage.PublishOutputHost,
                    }, type, filePath, fileName, format,
                           maxWidthHeight, percentage));
            }

            default:
            {
                return(storageProvider.GetUrlByFormatSizeQuality(
                           new DefaultStorageInfoImpl()
                    {
                        NetType = NetType.Internet,
                        StorageAccessKey = storage.PublishStorageAccessKey,
                        StorageId = storage.PublishStorageId,
                        StorageHost = storage.PublishOutputHost,
                    }, type, filePath, fileName, format,
                           maxWidthHeight, percentage));
            }
            }
        }
 public void WriteNullValueTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Write(null);
     }
 }
 public void NoSectionStorageTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(NoSectionXmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         storage.Read();
         Assert.Fail("Should never get here since the section is not specified in the external configuration file.");
     }
 }
        public void StorageTestWithEncryption()
        {
            SaveKeyAlgorithmPair(XmlStringWithEncryption);
            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryption))
            {
                using( FileStream s = new FileStream(Path.GetFullPath(testConfigFile), FileMode.Create) )
                {
                    for (int i=0; i<1000; i++)
                    {
                        byte b = 0;
                        s.WriteByte(b);
                    }
                }

                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
                ((IStorageProviderWriter)storage).Write(GetData());
                XmlNode data = storage.Read() as XmlNode;
                Assert.AreEqual(GetData().OuterXml, data.OuterXml);
            }
        }
        public void StorageTestChangeEncryption()
        {
            SaveKeyAlgorithmPair(XmlStringWithEncryption);

            using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryption))
            {
                StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
                IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
                Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
                ((IStorageProviderWriter)storage).Write(GetData());

                configurationContext.GetMetaConfiguration().ConfigurationSections[0].Encrypt = false;
                factory = new StorageProviderFactory(configurationContext);
                IStorageProviderWriter storageWriter = factory.Create(applConfig1) as IStorageProviderWriter;
                storageWriter.Write(GetData());

                XmlNode data = storageWriter.Read() as XmlNode;
                Assert.AreEqual(GetData().OuterXml, data.OuterXml);
            }
        }
 public void CreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(xmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create("ApplConfig1");
         Assert.IsNotNull(storage);
     }
 }
 public void StorageTestWithEncryptionAndDpapi()
 {
     SaveKeyAlgorithmPair(XmlStringWithEncryptionAndDpapi);
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlStringWithEncryptionAndDpapi))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderReader storage = factory.Create(applConfig1) as IStorageProviderReader;
         Assert.AreSame(storage.GetType(), typeof(XmlFileStorageProvider));
         ((IStorageProviderWriter)storage).Write(GetData());
         XmlNode data = storage.Read() as XmlNode;
         Assert.AreEqual(GetData().OuterXml, data.OuterXml);
     }
 }
 public void SectionNameTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(XmlString))
     {
         StorageProviderFactory factory = new StorageProviderFactory(configurationContext);
         IStorageProviderWriter storage = factory.Create(applConfig1) as IStorageProviderWriter;
         Assert.AreEqual(applConfig1, ((XmlFileStorageProvider)storage).CurrentSectionName);
     }
 }