internal EffectParameterUpdaterDefinition(IEnumerable <ParameterKey> keys, IEnumerable <ParameterDependency> dependencies)
        {
            SortedKeys      = keys.OrderBy(x => x.HashCode).ToArray();
            SortedKeyHashes = SortedKeys.Select(x => x.HashCode).ToArray();

            // Sort dependencies
            dependencies = BuildDependencies(dependencies).ToArray();

            // Build dependencies (with indices instead of keys)
            var dependenciesIndex = new List <ParameterDependencyIndex>();

            foreach (var dependency in dependencies)
            {
                var destinationIndex = Array.IndexOf(SortedKeys, dependency.Destination);
                if (destinationIndex == -1)
                {
                    throw new InvalidOperationException();
                }
                var sourceIndices = dependency.Sources.Select(x => Array.IndexOf(SortedKeys, x)).ToArray();
                if (sourceIndices.Any(x => x == -1))
                {
                    throw new InvalidOperationException();
                }
                dependenciesIndex.Add(new ParameterDependencyIndex
                {
                    Destination = destinationIndex,
                    Sources     = sourceIndices,
                    Dynamic     = dependency.Dynamic,
                    //Parameters = new ParameterCollection.InternalValueReference[dependency.Sources.Length],
                });
            }

            this.Dependencies = dependenciesIndex.ToArray();

            ThreadLocalDynamicValues = new ParameterCollection.InternalValue[GraphicsDevice.ThreadCount][];
            for (int i = 0; i < ThreadLocalDynamicValues.Length; ++i)
            {
                ThreadLocalDynamicValues[i] = Dependencies.Select(x => ParameterCollection.CreateInternalValue(SortedKeys[x.Destination])).ToArray();
            }
        }
        internal static void SaveSortOrder(PetaPocoUnitOfWork unitOfWork, SortedKeys sortedKeys)
        {
            try
            {
                foreach (var key in sortedKeys.Keys)
                {
                    var sql = @"
                        UPDATE G42SecureSettings
                        SET 
                            sortOrder = @0,
                            categoryId = @1
                        WHERE id = @2
                    ";

                    unitOfWork.Database.Execute(sql, key.SortOrder, key.CategoryId, key.Id);
                }

                SecureSettingsService.Clear();
            }
            catch (Exception ex)
            {
                LogHelper.Error<Exception>(ex.Message, ex);
            }
        }
Пример #3
0
        /// <summary>
        /// Generates JSON formatted file whose contents are of form and fit to many-to-one nodes of an hbm.xml file.
        /// This is the second of the three hbm sorting cmdlets that should
        /// be called.
        ///
        /// The effort of this cmdlet is to determine, of all
        /// tables having a primary key, what this tables foreign keys
        /// are which were not already accounted for as part of a
        /// composite-id primary key by the former cmdlet.
        /// </summary>
        /// <param name="sortedKeys">The output of GetHbmDbPkData</param>
        /// <returns></returns>
        public static SortedOneToMany GetHbmDbFkData(SortedKeys sortedKeys)
        {
            var pkItems = sortedKeys.Data;

            //get load/re-load psobjects to have output paths matching current settings
            Settings.LoadOutputPathCurrentSettings();

            //get needed json
            var cnJson  = DbContainers.Fks.Data;
            var pkJson  = DbContainers.Pks.Data;
            var akJson  = DbContainers.AllKeys.Data;
            var aiJson  = DbContainers.AllIndex.Data;
            var colJson = DbContainers.AllColumns.Data;

            //get a list of all the tables having a primary key
            var fks       = new Dictionary <string, FkItem>();
            var allTables = pkJson.Select(x => x.table_name).Distinct();

            //proceed through each table
            foreach (var tbl in allTables)
            {
                var fkManifold  = GetHbmDistinctFks(tbl);
                var iFkManifold = GetHbmFksNoRelToPks(fkManifold, pkItems, tbl);

                //produce output that is not already represented in the pk json hash
                if (iFkManifold == null || iFkManifold.Keys.Count <= 0)
                {
                    continue;
                }
                foreach (var iFkKeyValue in iFkManifold.Keys)
                {
                    //by constraint_name find the json entry for this table
                    var residentTableJsonData =
                        cnJson.First(
                            x => string.Equals(x.table_name, tbl, C) && string.Equals(x.constraint_name, iFkKeyValue, C));
                    //from json data entry discover the matching unique_constraint_name
                    var fkConstraintName = residentTableJsonData.unique_constraint_name;

                    //find the table-name this FK's unique_constraint_name is referring to
                    var matchedTable = akJson.FirstOrDefault(x => string.Equals(x.constraint_name, fkConstraintName)) ??
                                       aiJson.First(x => string.Equals(x.constraint_name, fkConstraintName));
                    var matchedTableName = matchedTable.table_name;

                    //get all the columns, not just first
                    var matchedFkColumns =
                        cnJson.Where(
                            x => string.Equals(x.table_name, tbl, C) && string.Equals(x.constraint_name, iFkKeyValue, C))
                        .ToList();

                    foreach (var matchCol in matchedFkColumns)
                    {
                        matchCol.CopyFromDataSrc(colJson);
                    }

                    if (!fks.ContainsKey(tbl))
                    {
                        var fkItem = new FkItem
                        {
                            ManyToOne = new Dictionary <string, List <ColumnMetadata> >
                            {
                                { matchedTableName, matchedFkColumns }
                            }
                        };
                        fks.Add(tbl, fkItem);
                    }
                    else if (!fks[tbl].ManyToOne.ContainsKey(matchedTableName))
                    {
                        fks[tbl].ManyToOne.Add(matchedTableName, matchedFkColumns);
                    }
                    else
                    {
                        fks[tbl].ManyToOne[matchedTableName].AddRange(matchedFkColumns);
                    }
                }
            }
            return(new SortedOneToMany()
            {
                Data = fks
            });
        }