public SettingsService(
            ISiteService siteService,
            IDbConnectionAccessor dbConnectionAccessor,
            IStore store
            )
        {
            _dbConnectionAccessor = dbConnectionAccessor;
            _store = store;

            using (MiniProfiler.Current.Step("Common Settings Setup")) {
                var result = siteService.GetSiteSettingsAsync().Result;
                Settings = result.As <TransformalizeSettings>();

                if (Settings.CommonArrangement == string.Empty)
                {
                    Process       = new Process();
                    ProcessFacade = new Transformalize.ConfigurationFacade.Process();
                }
                else
                {
                    Process       = new Process(Settings.CommonArrangement);
                    ProcessFacade = new Transformalize.ConfigurationFacade.Process(Settings.CommonArrangement);
                }

                // parameters
                foreach (var parameter in Process.Parameters)
                {
                    Parameters.Add(parameter.Name, parameter);
                }
                foreach (var parameter in ProcessFacade.Parameters)
                {
                    ParametersFacade.Add(parameter.Name, parameter);
                }

                // maps
                foreach (var map in Process.Maps)
                {
                    Maps.Add(map.Name, map);
                }
                foreach (var map in ProcessFacade.Maps)
                {
                    MapsFacade.Add(map.Name, map);
                }

                // actions
                foreach (var action in Process.Actions)
                {
                    Actions.Add(action.Name, action);
                }
                foreach (var action in ProcessFacade.Actions)
                {
                    ActionsFacade.Add(action.Name, action);
                }

                // connections
                foreach (var connection in Process.Connections)
                {
                    Connections.Add(connection.Name, connection);
                }
                foreach (var connection in ProcessFacade.Connections)
                {
                    ConnectionsFacade.Add(connection.Name, connection);
                }

                // fields
                if (Process.Entities.Any())
                {
                    foreach (var field in Process.Entities.First().Fields)
                    {
                        Fields.Add(field.Name, field);
                    }
                }
                if (ProcessFacade.Entities.Any())
                {
                    foreach (var field in ProcessFacade.Entities.First().Fields)
                    {
                        FieldsFacade.Add(field.Name, field);
                    }
                }
            }
        }
        /// <summary>
        /// This copies common arrangement settings into current process facade.
        /// All facade properties are strings without defaults, so they will be null if not provided.
        /// </summary>
        /// <param name="process">the transformalize report process</param>
        public void ApplyCommonSettings(Transformalize.ConfigurationFacade.Process process)
        {
            // common parameters
            for (int i = 0; i < process.Parameters.Count; i++)
            {
                var parameter = process.Parameters[i];
                if (parameter.Value == null && parameter.Name != null && ParametersFacade.ContainsKey(parameter.Name) && parameter.T == null && !parameter.Transforms.Any() && parameter.V == null && !parameter.Validators.Any())
                {
                    process.Parameters[0] = ParametersFacade[parameter.Name];
                }
            }

            // common maps
            for (int i = 0; i < process.Maps.Count; i++)
            {
                var map = process.Maps[i];
                if (map.Query == null && !map.Items.Any() && MapsFacade.ContainsKey(map.Name))
                {
                    process.Maps[i] = MapsFacade[map.Name];
                }
            }

            // common actions
            for (int i = 0; i < process.Actions.Count; i++)
            {
                var action = process.Actions[i];
                if (action.Type == null && action.Name != null && ActionsFacade.ContainsKey(action.Name))
                {
                    process.Actions[i] = ActionsFacade[action.Name];
                }
            }

            // common connections
            for (int i = 0; i < process.Connections.Count; i++)
            {
                var connection = process.Connections[i];
                if (connection.Provider == null)
                {
                    if (ConnectionsFacade.ContainsKey(connection.Name))
                    {
                        var table = connection.Table;
                        process.Connections[i]       = ConnectionsFacade[connection.Name];
                        process.Connections[i].Table = table;
                    }
                    else if (connection.Name == "orchard")
                    {
                        using (var cn = _dbConnectionAccessor.CreateConnection()) {
                            connection.ConnectionString = cn.ConnectionString;
                            connection.Provider         = _store.Dialect.Name.ToLower();
                        }
                    }
                }
            }

            // common fields
            if (FieldsFacade.Any() && process.Entities.Any())
            {
                for (int x = 0; x < process.Entities.Count; x++)
                {
                    var entity = process.Entities[x];

                    for (int y = 0; y < entity.Fields.Count; y++)
                    {
                        var field = process.Entities[x].Fields[y];

                        if (FieldsFacade.ContainsKey(field.Name) && field.System != "true" && field.Input != "true" && !field.Transforms.Any() && !field.Validators.Any())
                        {
                            process.Entities[x].Fields[y] = FieldsFacade[field.Name];
                        }
                    }

                    for (int y = 0; y < entity.CalculatedFields.Count; y++)
                    {
                        var field = process.Entities[x].CalculatedFields[y];

                        if (FieldsFacade.ContainsKey(field.Name) && field.System != "true" && field.Input != "true" && !field.Transforms.Any() && !field.Validators.Any())
                        {
                            process.Entities[x].CalculatedFields[y] = FieldsFacade[field.Name];
                        }
                    }
                }
            }
        }