Example #1
0
        private void LoadDataSources(Dictionary <string, Dictionary <string, object> > configuration)
        {
            foreach (KeyValuePair <string, Dictionary <string, object> > sourceEntry in configuration)
            {
                string name = sourceEntry.Key;
                string type = (string)sourceEntry.Value["type"];

                if (type == "sql")
                {
                    _dataSources[name] = new SqlDataSource(_app, name, sourceEntry.Value);
                    Runtime.TraceInfo("Created sql data source named '%s'.", name);
                }
                else if (type == "tableStorage")
                {
                    _dataSources[name] = new TableDataSource(_app, name, sourceEntry.Value);
                    Runtime.TraceInfo("Created table storage data source named '%s'.", name);
                }
                else if (type == "inproc")
                {
                    _dataSources[name] = new InprocDataSource(_app, name, sourceEntry.Value);
                    Runtime.TraceInfo("Created local in-memory data source named '%s'.", name);
                }
                else
                {
                    Runtime.Abort("Missing or invalid type attribute for data source named '%s'.", name);
                }
            }
        }
Example #2
0
        public SqlDataSource(Application app, string name, Dictionary <string, object> configuration)
            : base(app, name, configuration)
        {
            _schemaName = (string)configuration["schemaName"];

            _connectionString = (string)configuration["connectionString"];
            if (String.IsNullOrEmpty(_connectionString))
            {
                Runtime.Abort("No connection string was specified in the configuration for the '%s' data source.", name);
            }

            _partitions = (Dictionary <string, string>)configuration["partitions"];

            if (Script.Boolean(configuration["localFile"]))
            {
                _localFile        = true;
                _connectionString = Path.Join(app.Options.Path, _connectionString);
                if (_partitions != null)
                {
                    Dictionary <string, string> resolvedPartitions = new Dictionary <string, string>();
                    foreach (KeyValuePair <string, string> partitionEntry in _partitions)
                    {
                        resolvedPartitions[partitionEntry.Key] = Path.Join(app.Options.Path, partitionEntry.Value);
                    }

                    _partitions = resolvedPartitions;
                }
            }
            else
            {
                _schemaName = Script.Or(_schemaName, "dbo");
            }
        }
Example #3
0
        public TableDataSource(Application app, string name, Dictionary <string, object> configuration)
            : base(app, name, configuration)
        {
            string storageAccount = (string)configuration["storageAccount"];

            if (String.IsNullOrEmpty(storageAccount))
            {
                Runtime.Abort("No storageAccount was specified in the configuration for the '%s' data source.", name);
            }

            string accessKey = (string)configuration["accessKey"];

            if (String.IsNullOrEmpty(accessKey))
            {
                Runtime.Abort("No accessKey was specified in the configuration for the '%s' data source.", name);
            }

            _tableService = Azure.CreateTableService(storageAccount, accessKey);
        }
Example #4
0
        private void LoadDataCollections()
        {
            string dataPath = Path.Join(_app.Options.Path, "data");

            // TODO: Also check if its a directory
            if (FileSystem.ExistsSync(dataPath) == false)
            {
                Runtime.TraceWarning("Data directory '%s' was not found. No data collections were loaded.", dataPath);
                return;
            }

            foreach (string name in FileSystem.ReadDirectorySync(dataPath))
            {
                string collectionPath       = Path.Join(dataPath, name);
                string collectionConfigPath = Path.Join(collectionPath, "config.json");

                Dictionary <string, object> collectionConfig = Configuration.Load(collectionConfigPath, /* createEmptyIfNeeded */ false);
                if (collectionConfig != null)
                {
                    string     sourceName = (string)collectionConfig["source"];
                    DataSource source     = _dataSources[sourceName];

                    if (source != null)
                    {
                        _dataCollections[name] = new DataCollection(name, collectionPath, collectionConfig, source);

                        Runtime.TraceInfo("Created data collection '%s' associated with data source named '%s'.", name, sourceName);
                    }
                    else
                    {
                        Runtime.Abort("Unable to find a data source named '%s' for '%s' data collection.", sourceName, name);
                    }
                }
                else
                {
                    Runtime.TraceError("Configuration not found in data collection directory named '%s'. Ignoring.", name);
                }
            }
        }