Beispiel #1
0
 private void SetupIsolated()
 {
     appdomain        = AppDomain.CreateDomain(connectionString);
     isolatedInstance = (AssemblyStore)appdomain.CreateInstanceFromAndUnwrap(
         typeof(AssemblyStore).Assembly.Location,
         typeof(AssemblyStore).FullName);
     isolatedInstance.Connect(connectionString, false);
 }
Beispiel #2
0
        public void DataSourceAdd(string name, string description, string handler = null, string remotename = null, string copyright = "",
                                  string uri = "", List <DataSourceMapping> addMapping = null, List <String> removeMapping           = null)
        {
            ushort?remoteID = null;
            string resolvedHandlerAssemblyQualifiedName = null;

            //if (string.IsNullOrEmpty(remotename) && !String.IsNullOrEmpty(handler))
            //    ExtractHandlerAssemblyAndTypeName(handler, out toLoad, out handlerType);

            if (!string.IsNullOrEmpty(remotename) && String.IsNullOrEmpty(handler)) //federated
            {
                IFetchConfiguration remoteConfig;
                try
                {
                    RemoteFetchClient client = new RemoteFetchClient(new Uri(uri));
                    remoteConfig = client.GetConfiguration(DateTime.MaxValue);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Failed to retrieve configuration of the remote service.\n Exception message: " + ex.Message);
                }
                if (!remoteConfig.DataSources.Any(ds => ds.Name == remotename))
                {
                    throw new ArgumentException("Data source with given name does not exist on the remote service.");
                }
                remoteID = remoteConfig.DataSources.Where(ds => ds.Name == remotename).FirstOrDefault().ID;
            }
            else if (string.IsNullOrEmpty(remotename) && !String.IsNullOrEmpty(handler))//local
            {
                AssemblyStore gac = null;
                if (isConnectedToCloud)
                {
                    gac = astore;
                }
                resolvedHandlerAssemblyQualifiedName = ExtractHandlerAssemblyAndTypeName(handler, gac);
            }
            else if (!string.IsNullOrEmpty(remotename) && !String.IsNullOrEmpty(handler))
            {
                throw new ArgumentException("Handler and remote name can not be specified simultaneously.");
            }

            var localDs = db.GetDataSources(DateTime.MaxValue).ToArray();

            if (localDs.All(x => x.Name != name))
            {
                db.AddDataSource(name, description, copyright, resolvedHandlerAssemblyQualifiedName, ParserHelper.AppendDataSetUriWithDimensions(uri), remoteID, remotename);
            }
            else
            {
                throw new ArgumentException("Data source with given name already exists.");
            }
            SetMappings(name, addMapping, null);
        }
Beispiel #3
0
 /// <summary>
 /// extracts the assembly and type for the data hanfler from supplied string which can be either a type name or a dll name
 /// </summary>
 /// <param name="handler">a type name or a dll name</param>
 /// <param name="toLoad"></param>
 /// <param name="handlerType"></param>
 private static string ExtractHandlerAssemblyAndTypeName(string handler, AssemblyStore gac)
 {
     if (handler.EndsWith("dll", true, CultureInfo.InvariantCulture))
     {
         try
         {
             var toLoad = System.Reflection.Assembly.LoadFrom(handler);
             var types  = toLoad.GetExportedTypes().Where(t => t.IsSubclassOf(typeof(Microsoft.Research.Science.FetchClimate2.DataSourceHandler))).ToArray();
             if (types.Length == 0)
             {
                 throw new Exception("Specifed dll doesn't contain classes inheried from Microsoft.Research.Science.FetchClimate2.DataSourceHandler");
             }
             else if (types.Length > 1)
             {
                 throw new Exception("Specifed dll contains more than one class specification inheried from Microsoft.Research.Science.FetchClimate2.DataSourceHandler. You can specify FullTypeName of the handler instead");
             }
             else
             {
                 return(types[0].AssemblyQualifiedName);
             }
         }
         catch (Exception ex)
         {
             throw new Exception("Failed to load data handler from " + handler + "\n Exception message: " + ex.Message);
         }
     }
     else
     {
         if (gac != null)
         {
             var result = gac.TryLoadType(handler);
             if (result.Item1)
             {
                 return(result.Item2);
             }
             else
             {
                 throw new Exception(result.Item2);
             }
         }
         else
         {
             return(Type.GetType(handler).AssemblyQualifiedName);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="localSqlConnString">SQL connection string to configuration data base (null for automatic extraction from blob)</param>
        /// <param name="storageConnStr">An azure storage to work with (null for in-process operation)</param>
        /// <param name="isWorkingWithCloud">identifies whether the configurator works with cloud deployment of FetchClimate or with "in-process" deployment</param>
        /// <remarks>This constructor is invoked by "use command".
        /// use cloud accountkey=... accountname=... sqlconnstr=... invokes FetchConfigurator(storageconnstr, sqlconnstr, true),
        /// use local sqlconnstr=... invokes FetchConfigurator(null, sqlconnstr, false)</remarks>
        public FetchConfigurator(string storageConnStr, string sqlConnectionStr, bool isWorkingWithCloud)
        {
            this.storageConnectionString = storageConnStr;
            this.isConnectedToCloud      = isWorkingWithCloud;

            if (!string.IsNullOrEmpty(storageConnectionString) && sqlConnectionStr == null) //extracting sql connection string from the azure storage
            {
                sqlConnectionStr = ExtractSqlConnectionString(sqlConnectionStr);
            }
            sqlConnStringIncludingPassword = sqlConnectionStr;
            db = new FetchConfigurationDataClassesDataContext(sqlConnectionStr);

            //caching sql conn string to blob storage
            if (!string.IsNullOrEmpty(storageConnStr))
            {
                var csa        = CloudStorageAccount.Parse(storageConnectionString);
                var client     = csa.CreateCloudBlobClient();
                var contatiner = client.GetContainerReference(ConfigurationContainerName);
                contatiner.CreateIfNotExist();
                var blob = contatiner.GetBlobReference(SqlConnectionStringBlobName);
                blob.UploadText(sqlConnStringIncludingPassword);
                astore = new AssemblyStore(storageConnectionString, true);
            }
        }
Beispiel #5
0
        public void DataSourceSet(string name, string handler         = null, string remotename = null, string uri = null, string copyright = null, string description = null,
                                  List <DataSourceMapping> addMapping = null, List <String> removeMapping = null)
        {
            var localDs = db.GetDataSources(DateTime.MaxValue).ToArray();

            if (localDs.All(x => x.Name != name))
            {
                throw new ArgumentException("Specified data source does not exist.");
            }

            ushort?remoteID = null;

            if (!String.IsNullOrEmpty(handler) && String.IsNullOrEmpty(remotename))
            {
                AssemblyStore gac = null;
                if (isConnectedToCloud)
                {
                    gac = new AssemblyStore(storageConnectionString);
                }
                var resolvedHandlerAssemblyQualifiedName = ExtractHandlerAssemblyAndTypeName(handler, gac);
                db.SetDataSourceProcessor(name, resolvedHandlerAssemblyQualifiedName, null, null);
            }
            else if (String.IsNullOrEmpty(handler) && !String.IsNullOrEmpty(remotename))
            {
                IFetchConfiguration remoteConfig;
                try
                {
                    RemoteFetchClient client = new RemoteFetchClient(new Uri(uri));
                    remoteConfig = client.GetConfiguration(DateTime.MaxValue);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Failed to retrieve configuration of the remote service.\n Exception message: " + ex.Message);
                }
                if (!remoteConfig.DataSources.Any(ds => ds.Name == remotename))
                {
                    throw new ArgumentException("Data source with given name does not exist on the remote service.");
                }
                remoteID = remoteConfig.DataSources.Where(ds => ds.Name == remotename).FirstOrDefault().ID;
                db.SetDataSourceProcessor(name, null, remoteID, remotename);
            }
            if (!string.IsNullOrEmpty(remotename) && !String.IsNullOrEmpty(handler))
            {
                throw new ArgumentException("Handler and remote name can not be specified simultaneously.");
            }

            if (!String.IsNullOrEmpty(uri))
            {
                db.SetDataSourceUri(name, ParserHelper.AppendDataSetUriWithDimensions(uri));
            }

            //if (isHidden != null)
            //    db.SetDataSourceHidden(name, isHidden);

            if (copyright != null)
            {
                db.SetDataSourceCopyright(name, copyright);
            }

            if (description != null)
            {
                db.SetDataSourceDescription(name, description);
            }

            SetMappings(name, addMapping, removeMapping);
        }