Example #1
0
        public IActionResult PascalRename([FromBody] GenerateOption input)
        {
            if (input.TableData != null)
            {
                foreach (var item in input.TableData)
                {
                    if (item.Alias.IsNullOrEmpty())
                    {
                        item.Alias = input.IsPascalCase?item.TableName.ToPascalCase():item.TableName;
                    }
                    else
                    {
                        item.Alias = input.IsPascalCase?item.Alias.ToPascalCase():item.TableName;
                    }

                    foreach (var x in item.Columns)
                    {
                        if (x.Alias.IsNullOrEmpty())
                        {
                            x.Alias = input.IsPascalCase?x.ColName.ToPascalCase():x.ColName;
                        }
                        else
                        {
                            x.Alias = input.IsPascalCase?x.Alias.ToPascalCase():x.ColName;
                        }
                    }
                }
            }
            var tables = input.TableData;

            return(Json(ExcutedResult.SuccessResult(tables)));
        }
        private void Initialize(IList <T> values, int lowerIndex, GenerateOption type)
        {
            this.myMetaCollectionType = type;
            this.myLowerIndex         = lowerIndex;
            this.myValues             = new List <T>();
            this.myValues.AddRange(values);
            List <bool> list = new List <bool>();

            if (type == GenerateOption.WithoutRepetition)
            {
                for (int i = 0; i < this.myValues.Count; i++)
                {
                    if (i >= this.myValues.Count - this.myLowerIndex)
                    {
                        list.Add(false);
                    }
                    else
                    {
                        list.Add(true);
                    }
                }
            }
            else
            {
                for (int j = 0; j < values.Count - 1; j++)
                {
                    list.Add(true);
                }
                for (int k = 0; k < this.myLowerIndex; k++)
                {
                    list.Add(false);
                }
            }
            this.myPermutations = new Permutations <bool>(list);
        }
Example #3
0
        /// <summary>
        /// Initialize the combinations by settings a copy of the values from the
        /// </summary>
        /// <param name="values">List of values to select combinations from.</param>
        /// <param name="lowerIndex">The size of each combination set to return.</param>
        /// <param name="type">The type of Combinations set to generate.</param>
        /// <remarks>
        /// Copies the array and parameters and then creates a map of booleans that will
        /// be used by a permutations object to refence the subset.  This map is slightly
        /// different based on whether the type is with or without repetition.
        ///
        /// When the type is WithoutRepetition, then a map of upper index elements is
        /// created with lower index false's.
        /// E.g. 8 choose 3 generates:
        /// Map: {1 1 1 1 1 0 0 0}
        /// Note: For sorting reasons, false denotes inclusion in output.
        ///
        /// When the type is WithRepetition, then a map of upper index - 1 + lower index
        /// elements is created with the falses indicating that the 'current' element should
        /// be included and the trues meaning to advance the 'current' element by one.
        /// E.g. 8 choose 3 generates:
        /// Map: {1 1 1 1 1 1 1 1 0 0 0} (7 trues, 3 falses).
        /// </remarks>
        private void Initialize(ICollection <T> values, Int32 lowerIndex, GenerateOption type)
        {
            Type       = type;
            LowerIndex = lowerIndex;
            _values    = new List <T>();
            _values.AddRange(values);
            List <Boolean> map = new List <Boolean>();

            if (type == GenerateOption.WithoutRepetition)
            {
                map.AddRange(_values.Select((t, i) => i < _values.Count - LowerIndex));
            }
            else
            {
                for (Int32 i = 0; i < values.Count - 1; ++i)
                {
                    map.Add(true);
                }

                for (Int32 i = 0; i < LowerIndex; ++i)
                {
                    map.Add(false);
                }
            }

            _permutations = new Permutations <Boolean>(map);
        }
Example #4
0
 /// <summary>
 /// Initialize the variations for constructors.
 /// </summary>
 /// <param name="values">List of values to select variations from.</param>
 /// <param name="lowerIndex">The size of each variation set to return.</param>
 /// <param name="type">The type of variations set to generate.</param>
 private void Initialize(IEnumerable <T> values, int lowerIndex, GenerateOption type)
 {
     myMetaCollectionType = type;
     myLowerIndex         = lowerIndex;
     myValues             = new List <T>();
     myValues.AddRange(values);
     if (type == GenerateOption.WithoutRepetition)
     {
         var myMap = new List <int>();
         var index = 0;
         for (var i = 0; i < myValues.Count; ++i)
         {
             if (i >= myValues.Count - myLowerIndex)
             {
                 myMap.Add(index++);
             }
             else
             {
                 myMap.Add(Int32.MaxValue);
             }
         }
         myPermutations = new Permutations <int>(myMap);
     }
     else
     {
         ; // myPermutations isn't used.
     }
 }
Example #5
0
        /// <summary>
        /// Initialize the combinations by settings a copy of the values from the
        /// </summary>
        /// <param name="values">List of values to select combinations from.</param>
        /// <param name="lowerIndex">The size of each combination set to return.</param>
        /// <param name="type">The type of Combinations set to generate.</param>
        /// <remarks>
        /// Copies the array and parameters and then creates a map of booleans that will
        /// be used by a permutations object to refence the subset.  This map is slightly
        /// different based on whether the type is with or without repetition.
        ///
        /// When the type is WithoutRepetition, then a map of upper index elements is
        /// created with lower index false's.
        /// E.g. 8 choose 3 generates:
        /// Map: {1 1 1 1 1 0 0 0}
        /// Note: For sorting reasons, false denotes inclusion in output.
        ///
        /// When the type is WithRepetition, then a map of upper index - 1 + lower index
        /// elements is created with the falses indicating that the 'current' element should
        /// be included and the trues meaning to advance the 'current' element by one.
        /// E.g. 8 choose 3 generates:
        /// Map: {1 1 1 1 1 1 1 1 0 0 0} (7 trues, 3 falses).
        /// </remarks>
        private void Initialize(IEnumerable <T> values, int lowerIndex, GenerateOption type)
        {
            _myMetaCollectionType = type;
            _myLowerIndex         = lowerIndex;
            _myValues             = new List <T>();
            _myValues.AddRange(values);
            var myMap = new List <bool>();

            if (type == GenerateOption.WithoutRepetition)
            {
                myMap.AddRange(_myValues.Select((t, i) => i < _myValues.Count - _myLowerIndex));
            }
            else
            {
                for (var i = 0; i < values.Count() - 1; ++i)
                {
                    myMap.Add(true);
                }
                for (var i = 0; i < _myLowerIndex; ++i)
                {
                    myMap.Add(false);
                }
            }
            _myPermutations = new Permutations <bool>(myMap);
        }
Example #6
0
        /// <summary>
        /// Initialize the combinations by settings a copy of the values from the
        /// </summary>
        /// <param name="values">List of values to select combinations from.</param>
        /// <param name="lowerIndex">The size of each combination set to return.</param>
        /// <param name="type">The type of Combinations set to generate.</param>
        /// <remarks>
        /// Copies the array and parameters and then creates a map of booleans that will
        /// be used by a permutations object to refence the subset.  This map is slightly
        /// different based on whether the type is with or without repetition.
        ///
        /// When the type is WithoutRepetition, then a map of upper index elements is
        /// created with lower index false's.
        /// E.g. 8 choose 3 generates:
        /// Map: {1 1 1 1 1 0 0 0}
        /// Note: For sorting reasons, false denotes inclusion in output.
        ///
        /// When the type is WithRepetition, then a map of upper index - 1 + lower index
        /// elements is created with the falses indicating that the 'current' element should
        /// be included and the trues meaning to advance the 'current' element by one.
        /// E.g. 8 choose 3 generates:
        /// Map: {1 1 1 1 1 1 1 1 0 0 0} (7 trues, 3 falses).
        /// </remarks>
        private void Initialize(IList <T> values, int lowerIndex, GenerateOption type)
        {
            myMetaCollectionType = type;
            myLowerIndex         = lowerIndex;
            myValues             = new List <T>();
            myValues.AddRange(values);
            var myMap = new List <bool>();

            if (type == GenerateOption.WithoutRepetition)
            {
                for (var i = 0; i < myValues.Count; ++i)
                {
                    if (i >= myValues.Count - myLowerIndex)
                    {
                        myMap.Add(false);
                    }
                    else
                    {
                        myMap.Add(true);
                    }
                }
            }
            else
            {
                for (var i = 0; i < values.Count - 1; ++i)
                {
                    myMap.Add(true);
                }
                for (var i = 0; i < myLowerIndex; ++i)
                {
                    myMap.Add(false);
                }
            }
            myPermutations = new Permutations <bool>(myMap);
        }
Example #7
0
        private void Initialize(ICollection <T> values, int lowerIndex, GenerateOption type)
        {
            _myMetaCollectionType = type;
            LowerIndex            = lowerIndex;
            _myValues             = new List <T>();
            _myValues.AddRange(values);
            var myMap = new List <bool>();

            switch (type)
            {
            case GenerateOption.WithoutRepetition:
            {
                myMap.AddRange(_myValues.Select((t, i) => i < _myValues.Count - LowerIndex));
                break;
            }

            default:
            {
                for (var i = 0; i < values.Count - 1; ++i)
                {
                    myMap.Add(true);
                }

                for (var i = 0; i < LowerIndex; ++i)
                {
                    myMap.Add(false);
                }

                break;
            }
            }

            _myPermutations = new Permutations <bool>(myMap);
        }
Example #8
0
 /// <summary>
 /// Common intializer used by the multiple flavors of constructors.
 /// </summary>
 /// <remarks>
 /// Copies information provided and then creates a parellel int array of lexicographic
 /// orders that will be used for the actual permutation algorithm.  
 /// The input array is first sorted as required for WithoutRepetition and always just for consistency.
 /// This array is constructed one of two way depending on the type of the collection.
 ///
 /// When type is MetaCollectionType.WithRepetition, then all N! permutations are returned
 /// and the lexicographic orders are simply generated as 1, 2, ... N.  
 /// E.g.
 /// Input array:          {A A B C D E E}
 /// Lexicograhpic Orders: {1 2 3 4 5 6 7}
 /// 
 /// When type is MetaCollectionType.WithoutRepetition, then fewer are generated, with each
 /// identical element in the input array not repeated.  The lexicographic sort algorithm
 /// handles this natively as long as the repetition is repeated.
 /// E.g.
 /// Input array:          {A A B C D E E}
 /// Lexicograhpic Orders: {1 1 2 3 4 5 5}
 /// </remarks>
 private void Initialize(IList<T> values, GenerateOption type, IComparer<T> comparer) {
     myMetaCollectionType = type;
     myValues = new List<T>(values.Count);
     myValues.AddRange(values);
     myLexicographicOrders = new int[values.Count];
     if(type == GenerateOption.WithRepetition) {
         for(int i = 0; i < myLexicographicOrders.Length; ++i) {
             myLexicographicOrders[i] = i;
         }
     }
     else {
         if(comparer == null) {
             comparer = new SelfComparer<T>();
         }
         myValues.Sort(comparer);
         int j = 1;
         if(myLexicographicOrders.Length > 0) {
             myLexicographicOrders[0] = j;
         }
         for(int i = 1; i < myLexicographicOrders.Length; ++i) {
             if(comparer.Compare(myValues[i - 1], myValues[i]) != 0) {
                 ++j;
             }
             myLexicographicOrders[i] = j;
         }
     }
     myCount = GetCount();
 }
Example #9
0
        /// <summary>
        ///     Create a permutation set from the provided list of values.
        ///     The values will be compared using the supplied IComparer.
        ///     The repetition type defaults to MetaCollectionType.WithholdRepetitionSets
        /// </summary>
        /// <param name="values">List of values to permute.</param>
        /// <param name="type">The type of permutation set to calculate.</param>
        /// <param name="comparer">Comparer used for defining the lexigraphic order.</param>
        public Permutations(IList <T> values, GenerateOption type = GenerateOption.WithoutRepetition, IComparer <T>?comparer = null)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            ///     Copies information provided and then creates a parellel int array of lexicographic
            ///     orders that will be used for the actual permutation algorithm.
            ///     The input array is first sorted as required for WithoutRepetition and always just for consistency.
            ///     This array is constructed one of two way depending on the type of the collection.
            ///     When type is MetaCollectionType.WithRepetition, then all N! permutations are returned
            ///     and the lexicographic orders are simply generated as 1, 2, ... N.
            ///     E.g.
            ///     Input array:          {A A B C D E E}
            ///     Lexicograhpic Orders: {1 2 3 4 5 6 7}
            ///     When type is MetaCollectionType.WithoutRepetition, then fewer are generated, with each
            ///     identical element in the input array not repeated.  The lexicographic sort algorithm
            ///     handles this natively as long as the repetition is repeated.
            ///     E.g.
            ///     Input array:          {A A B C D E E}
            ///     Lexicograhpic Orders: {1 1 2 3 4 5 5}


            Type     = type;
            myValues = new List <T>(values.Count);
            myValues.AddRange(values);
            myLexicographicOrders = new int[values.Count];
            if (type == GenerateOption.WithRepetition)
            {
                for (var i = 0; i < myLexicographicOrders.Length; ++i)
                {
                    myLexicographicOrders[i] = i;
                }
            }
            else
            {
                if (comparer == null)
                {
                    comparer = new SelfComparer <T>();
                }
                myValues.Sort(comparer);
                var j = 1;
                if (myLexicographicOrders.Length > 0)
                {
                    myLexicographicOrders[0] = j;
                }
                for (var i = 1; i < myLexicographicOrders.Length; ++i)
                {
                    if (comparer.Compare(myValues[i - 1], myValues[i]) != 0)
                    {
                        ++j;
                    }
                    myLexicographicOrders[i] = j;
                }
            }

            Count = GetCount();
        }
Example #10
0
        /// <summary>
        ///     Create a combination set from the provided list of values.
        ///     The upper index is calculated as values.Count, the lower index is specified.
        /// </summary>
        /// <param name="values">List of values to select combinations from.</param>
        /// <param name="lowerIndex">The size of each combination set to return.</param>
        /// <param name="type">The type of Combinations set to generate.</param>
        public Combinations(IList <T> values, int lowerIndex, GenerateOption type)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            ///     Copies the array and parameters and then creates a map of booleans that will
            ///     be used by a permutations object to refence the subset.  This map is slightly
            ///     different based on whether the type is with or without repetition.
            ///     When the type is WithoutRepetition, then a map of upper index elements is
            ///     created with lower index false's.
            ///     E.g. 8 choose 3 generates:
            ///     Map: {1 1 1 1 1 0 0 0}
            ///     Note: For sorting reasons, false denotes inclusion in output.
            ///     When the type is WithRepetition, then a map of upper index - 1 + lower index
            ///     elements is created with the falses indicating that the 'current' element should
            ///     be included and the trues meaning to advance the 'current' element by one.
            ///     E.g. 8 choose 3 generates:
            ///     Map: {1 1 1 1 1 1 1 1 0 0 0} (7 trues, 3 falses).

            Type       = type;
            LowerIndex = lowerIndex;
            myValues   = new List <T>();
            myValues.AddRange(values);
            var myMap = new List <bool>();

            if (type == GenerateOption.WithoutRepetition)
            {
                for (var i = 0; i < myValues.Count; ++i)
                {
                    if (i >= myValues.Count - LowerIndex)
                    {
                        myMap.Add(false);
                    }
                    else
                    {
                        myMap.Add(true);
                    }
                }
            }
            else
            {
                for (var i = 0; i < values.Count - 1; ++i)
                {
                    myMap.Add(true);
                }
                for (var i = 0; i < LowerIndex; ++i)
                {
                    myMap.Add(false);
                }
            }

            myPermutations = new Permutations <bool>(myMap);
        }
Example #11
0
        private void Initialize(IList <T> values, GenerateOption type, IComparer <T> comparer)
        {
            _myMetaCollectionType = type;
            _myValues             = new List <T>(values.Count);
            _myValues.AddRange(values);
            _myLexicographicOrders = new int[values.Count];

            switch (type)
            {
            case GenerateOption.WithRepetition:
            {
                for (var i = 0; i < _myLexicographicOrders.Length; ++i)
                {
                    _myLexicographicOrders[i] = i;
                }

                break;
            }

            default:
            {
                if (comparer == null)
                {
                    comparer = new SelfComparer <T>();
                }

                _myValues.Sort(comparer);
                var j = 1;

                if (_myLexicographicOrders.Length > 0)
                {
                    _myLexicographicOrders[0] = j;
                }

                for (var i = 1; i < _myLexicographicOrders.Length; ++i)
                {
                    if (comparer.Compare(_myValues[i - 1], _myValues[i]) != 0)
                    {
                        ++j;
                    }

                    _myLexicographicOrders[i] = j;
                }
                break;
            }
            }

            Count = GetCount();
        }
Example #12
0
        public string GenerateNumber(int length, GenerateOption generateOption = GenerateOption.Default)
        {
            switch (generateOption)
            {
            case GenerateOption.Default:
                return(Random(length, NUMERIC_CHARS));

            case GenerateOption.NoLeadingZero:
                var firstChar = Random(1, NUMERIC_NoZero_CHARS);
                return(firstChar + Random(length - 1, NUMERIC_CHARS));

            default:
                throw new ArgumentOutOfRangeException(nameof(generateOption), generateOption, null);
            }
        }
Example #13
0
        public IActionResult Preview(int index, [FromBody] GenerateOption option)
        {
            var generator = new CodeGenerator(option);

            var table = option.TableData[index];

            generator.Generate(new List <DbTable>()
            {
                table
            }, true);
            var tableName = table.TableName;
            var className = table.Alias.IsNullOrEmpty() ? tableName : table.Alias;

            return(Json(ExcutedResult.SuccessResult(new
            {
                table = tableName,
                model = new
                {
                    content = generator.ReadFile("Models", tableName + ".cs"),
                    name = tableName + ".cs"
                },
                irepository = new
                {
                    content = generator.ReadFile("IRepositories", $"I{className}Repository.cs"),
                    name = $"I{className}Repository.cs"
                },
                repository = new
                {
                    content = generator.ReadFile("Repositories", $"{className}Repository.cs"),
                    name = $"{className}Repository.cs"
                },
                iservice = new
                {
                    content = generator.ReadFile("IServices", $"I{className}Service.cs"),
                    name = $"I{className}Service.cs"
                },
                service = new
                {
                    content = generator.ReadFile("Services", $"{className}Service.cs"),
                    name = $"{className}Service.cs"
                },
                controller = new
                {
                    content = generator.ReadFile("Controllers", $"{className}Controller.cs"),
                    name = $"{className}Controller.cs"
                }
            })));
        }
Example #14
0
        /// <summary>
        /// Initialize the variations for constructors.
        /// </summary>
        /// <param name="values">List of values to select variations from.</param>
        /// <param name="lowerIndex">The size of each variation set to return.</param>
        /// <param name="type">The type of variations set to generate.</param>
        private void Initialize(IEnumerable <T> values, Int32 lowerIndex, GenerateOption type)
        {
            Type       = type;
            LowerIndex = lowerIndex;
            _values    = new List <T>();
            _values.AddRange(values);
            if (type != GenerateOption.WithoutRepetition)
            {
                return;
            }

            Int32        index = 0;
            List <Int32> map   = _values.Select((t, i) => i >= _values.Count - LowerIndex ? index++ : Int32.MaxValue).ToList();

            _permutations = new Permutations <Int32>(map);
        }
Example #15
0
        public IActionResult GetDataTables([FromBody] GenerateOption input)
        {
            try
            {
                var option = new DbContextOption()
                {
                    ConnectionString = input.ConnectionString,
                    IsOutputSql      = true
                };
                var dbContext = GetDbContext(input.DbType, option);
                var tables    = dbContext.GetCurrentDatabaseTableList().Where(m => m.Columns.Any(n => n.IsPrimaryKey)).ToList();

                tables?.ForEach(x =>
                {
                    if (!input.KeepPrefix && !input.Prefixes.IsNullOrWhiteSpace())
                    {
                        var prefixes = input.Prefixes.Split(',');
                        foreach (var prefix in prefixes)
                        {
                            if (x.TableName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
                            {
                                x.Alias = x.TableName.Replace(prefix, "", StringComparison.OrdinalIgnoreCase);
                                break;
                            }
                        }
                    }

                    if (input.IsPascalCase)
                    {
                        x.Alias = (x.Alias.IsNullOrEmpty() ? x.TableName : x.Alias).ToPascalCase();
                    }

                    foreach (var column in x.Columns)
                    {
                        column.Alias = input.IsPascalCase ? column.ColName.ToPascalCase() : column.ColName;
                    }
                });
                return(Json(ExcutedResult.SuccessResult(tables)));
            }
            catch (Exception e)
            {
                Log4NetHelper.WriteError(GetType(), e);
                return(Json(ExcutedResult.FailedResult($"数据库连接失败,具体原因如下:{e.Message}")));
            }
        }
Example #16
0
        public IActionResult Generate([FromBody] GenerateOption input)
        {
            if (ModelState.IsValid)
            {
                var generator = new CodeGenerator(input);

                var tables = input.TableData;
                generator.Generate(tables, true);

                var zipFileName = GetZipFile();
                //var file =new FileInfo(zipFileName);
                //var bytes = new byte[file.Length];
                //var stream = file.OpenRead();
                //stream.Read(bytes, 0, Convert.ToInt32(file.Length));
                //stream.Close();
                //return File(bytes, "application/x-zip-compressed");
                return(Json(ExcutedResult.SuccessResult(rows: "/zips/" + Path.GetFileName(zipFileName))));
            }
            return(Json(ExcutedResult.SuccessResult("数据验证失败,请检查后重试")));
        }
Example #17
0
        /// <summary>
        /// Create a variation set from the indicated list of values.
        /// The upper index is calculated as values.Count, the lower index is specified.
        /// </summary>
        /// <param name="values">List of values to select variations from.</param>
        /// <param name="lowerIndex">The size of each variation set to return.</param>
        /// <param name="type">Type indicates whether to use repetition in set generation.</param>
        public Variations(IEnumerable <T> values, int lowerIndex, GenerateOption type)
        {
            Type       = type;
            LowerIndex = lowerIndex;
            _myValues  = values.ToList();

            if (type != GenerateOption.WithoutRepetition)
            {
                return;
            }

            var myMap = new List <int>(_myValues.Count);
            var index = 0;

            for (var i = 0; i < _myValues.Count; ++i)
            {
                myMap.Add(i >= _myValues.Count - LowerIndex ? index++ : int.MaxValue);
            }

            _myPermutations = new Permutations <int>(myMap);
        }
        /// ------------------------------------------------------------------------------------
        public override void GenerateOralAnnotationFile(Control parentOfProgressPopup,
                                                        GenerateOption option)
        {
            var eafFile = AssociatedComponentFile.GetAnnotationFile();

            if (eafFile == null)
            {
                return;                 // nothing we can do.
            }
            if (option == GenerateOption.GenerateIfNeeded)
            {
                var oralAnnotationFilename = GetPathToSourceMediaFile() + Settings.Default.OralAnnotationGeneratedFileSuffix;
                var finfo = new FileInfo(oralAnnotationFilename);
                if (!finfo.Exists || finfo.Length == 0)
                {
                    option = GenerateOption.RegenerateNow;
                }
            }

            AssociatedComponentFile.GenerateOralAnnotationFile(eafFile.Tiers, parentOfProgressPopup, option);
        }
Example #19
0
 /// <summary>
 /// Initialize the variations for constructors.
 /// </summary>
 /// <param name="values">List of values to select variations from.</param>
 /// <param name="lowerIndex">The size of each variation set to return.</param>
 /// <param name="type">The type of variations set to generate.</param>
 private void Initialize(IEnumerable <T> values, int lowerIndex, GenerateOption type)
 {
     if (values == null)
     {
         throw new ArgumentNullException("values");
     }
     myMetaCollectionType = type;
     myLowerIndex         = lowerIndex;
     myValues             = new List <T>();
     myValues.AddRange(values);
     if (type == GenerateOption.WithoutRepetition)
     {
         int        index = 0;
         List <int> myMap = myValues.Select((t, i) => i >= myValues.Count - myLowerIndex ? index++ : Int32.MaxValue).ToList();
         myPermutations = new Permutations <int>(myMap);
     }
     else
     {
         ; // myPermutations isn't used.
     }
 }
Example #20
0
        /// <summary>
        /// Common intializer used by the multiple flavors of constructors.
        /// </summary>
        /// <remarks>
        /// Copies information provided and then creates a parellel int array of lexicographic
        /// orders that will be used for the actual permutation algorithm.
        /// The input array is first sorted as required for WithoutRepetition and always just for consistency.
        /// This array is constructed one of two way depending on the type of the collection.
        ///
        /// When type is MetaCollectionType.WithRepetition, then all N! permutations are returned
        /// and the lexicographic orders are simply generated as 1, 2, ... N.
        /// E.g.
        /// Input array:          {A A B C D E E}
        /// Lexicograhpic Orders: {1 2 3 4 5 6 7}
        ///
        /// When type is MetaCollectionType.WithoutRepetition, then fewer are generated, with each
        /// identical element in the input array not repeated.  The lexicographic sort algorithm
        /// handles this natively as long as the repetition is repeated.
        /// E.g.
        /// Input array:          {A A B C D E E}
        /// Lexicograhpic Orders: {1 1 2 3 4 5 5}
        /// </remarks>
        private void Initialize(ICollection <T> values, GenerateOption type, IComparer <T> comparer)
        {
            Type    = type;
            _values = new List <T>(values.Count);
            _values.AddRange(values);
            _lexicographicOrders = new Int32[values.Count];
            if (type == GenerateOption.WithRepetition)
            {
                for (Int32 i = 0; i < _lexicographicOrders.Length; ++i)
                {
                    _lexicographicOrders[i] = i;
                }
            }
            else
            {
                if (comparer == null)
                {
                    comparer = new SelfComparer <T>();
                }

                _values.Sort(comparer);
                Int32 j = 1;
                if (_lexicographicOrders.Length > 0)
                {
                    _lexicographicOrders[0] = j;
                }

                for (Int32 i = 1; i < _lexicographicOrders.Length; ++i)
                {
                    if (comparer.Compare(_values[i - 1], _values[i]) != 0)
                    {
                        ++j;
                    }

                    _lexicographicOrders[i] = j;
                }
            }

            Count = GetCount();
        }
Example #21
0
        /// <summary>
        /// Initialize the variations for constructors.
        /// </summary>
        /// <param name="values">List of values to select variations from.</param>
        /// <param name="lowerIndex">The size of each variation set to return.</param>
        /// <param name="type">The type of variations set to generate.</param>
        private void Initialize(IEnumerable <T> values, int lowerIndex, GenerateOption type)
        {
            Type       = type;
            LowerIndex = lowerIndex;
            _myValues  = new List <T>();
            _myValues.AddRange(values);

            if (type != GenerateOption.WithoutRepetition)
            {
                return;
            }

            var myMap = new List <int>();
            var index = 0;

            for (var i = 0; i < _myValues.Count; ++i)
            {
                myMap.Add(i >= _myValues.Count - LowerIndex ? index++ : int.MaxValue);
            }

            _myPermutations = new Permutations <int>(myMap);
        }
Example #22
0
 /// <summary>
 ///     Initialize the variations for constructors.
 /// </summary>
 /// <param name="values">List of values to select variations from.</param>
 /// <param name="lowerIndex">The size of each variation set to return.</param>
 /// <param name="type">The type of variations set to generate.</param>
 private void Initialize(IList <T> values, int lowerIndex, GenerateOption type)
 {
     Type       = type;
     LowerIndex = lowerIndex;
     myValues   = new List <T>();
     myValues.AddRange(values);
     if (type == GenerateOption.WithoutRepetition)
     {
         var myMap = new List <int>();
         var index = 0;
         for (var i = 0; i < myValues.Count; ++i)
         {
             if (i >= myValues.Count - LowerIndex)
             {
                 myMap.Add(index++);
             }
             else
             {
                 myMap.Add(int.MaxValue);
             }
         }
         myPermutations = new Permutations <int>(myMap);
     }
 }
Example #23
0
 private void Initialize(IList <T> values, GenerateOption type, IComparer <T> comparer)
 {
     this.myMetaCollectionType = type;
     this.myValues             = new List <T>(values.Count);
     this.myValues.AddRange(values);
     this.myLexicographicOrders = new int[values.Count];
     if (type == GenerateOption.WithRepetition)
     {
         for (int i = 0; i < this.myLexicographicOrders.Length; i++)
         {
             this.myLexicographicOrders[i] = i;
         }
     }
     else
     {
         if (comparer == null)
         {
             comparer = new SelfComparer <T>();
         }
         this.myValues.Sort(comparer);
         int num = 1;
         if (this.myLexicographicOrders.Length != 0)
         {
             this.myLexicographicOrders[0] = num;
         }
         for (int j = 1; j < this.myLexicographicOrders.Length; j++)
         {
             if (comparer.Compare(this.myValues[j - 1], this.myValues[j]) != 0)
             {
                 num++;
             }
             this.myLexicographicOrders[j] = num;
         }
     }
     this.myCount = this.GetCount();
 }
Example #24
0
 private void Initialize(IList <T> values, int lowerIndex, GenerateOption type)
 {
     this.myMetaCollectionType = type;
     this.myLowerIndex         = lowerIndex;
     this.myValues             = new List <T>();
     this.myValues.AddRange(values);
     if (type == GenerateOption.WithoutRepetition)
     {
         List <int> list = new List <int>();
         int        num  = 0;
         for (int i = 0; i < this.myValues.Count; i++)
         {
             if (i >= this.myValues.Count - this.myLowerIndex)
             {
                 list.Add(num++);
             }
             else
             {
                 list.Add(2147483647);
             }
         }
         this.myPermutations = new Permutations <int>(list);
     }
 }
Example #25
0
 /// <summary>
 /// Create a combination set from the provided list of values.
 /// The upper index is calculated as values.Count, the lower index is specified.
 /// </summary>
 /// <param name="values">List of values to select combinations from.</param>
 /// <param name="lowerIndex">The size of each combination set to return.</param>
 /// <param name="type">The type of Combinations set to generate.</param>
 public Combinations(IList <T> values, int lowerIndex, GenerateOption type)
 {
     Initialize(values, lowerIndex, type);
 }
Example #26
0
 /// <summary>
 /// Create a permutation set from the provided list of values.
 /// If type is MetaCollectionType.WithholdRepetitionSets, then values (T) must implement IComparable.
 /// If T does not implement IComparable use a constructor with an explict IComparer.
 /// </summary>
 /// <param name="values">List of values to permute.</param>
 /// <param name="type">The type of permutation set to calculate.</param>
 public Permutations(IList <T> values, GenerateOption type)
 {
     Initialize(values, type, null);
 }
 public static void Generate(string inputFileContent, System.CodeDom.CodeCompileUnit compileUnit, System.CodeDom.CodeNamespace mainNamespace, System.CodeDom.Compiler.CodeDomProvider codeProvider, System.Collections.Hashtable customDBProviders, GenerateOption option, string dataSetNamespace)
 {
 }
 /// <summary>
 /// Create a permutation set from the provided list of values.
 /// If type is MetaCollectionType.WithholdRepetitionSets, then values (T) must implement IComparable.
 /// If T does not implement IComparable use a constructor with an explicit IComparer.
 /// </summary>
 /// <param name="values">List of values to permute.</param>
 /// <param name="type">The type of permutation set to calculate.</param>
 public Permutations(IEnumerable <T> values, GenerateOption type)
     : this(values, type, null)
 {
 }
 /// <summary>
 /// Create a permutation set from the provided list of values.
 /// If type is MetaCollectionType.WithholdRepetitionSets, then the values will be compared using the supplied IComparer.
 /// </summary>
 /// <param name="values">List of values to permute.</param>
 /// <param name="type">The type of permutation set to calculate.</param>
 /// <param name="comparer">Comparer used for defining the lexicographic order.</param>
 public Permutations(IEnumerable <T> values, GenerateOption type, IComparer <T>?comparer)
     : this(values, type == GenerateOption.WithRepetition ? GenerateOptions.WithRepetition : GenerateOptions.None, comparer)
 {
 }
 public static string Generate(string inputFileContent, System.CodeDom.CodeCompileUnit compileUnit, System.CodeDom.CodeNamespace mainNamespace, System.CodeDom.Compiler.CodeDomProvider codeProvider, GenerateOption option, string dataSetNamespace)
 {
 }
Example #31
0
 /// <summary>
 /// Create a variation set from the indicated list of values.
 /// The upper index is calculated as values.Count, the lower index is specified.
 /// </summary>
 /// <param name="values">List of values to select variations from.</param>
 /// <param name="lowerIndex">The size of each vatiation set to return.</param>
 /// <param name="type">Type indicates whether to use repetition in set generation.</param>
 public Variations(IEnumerable <T> values, int lowerIndex, GenerateOption type)
 {
     Initialize(values, lowerIndex, type);
 }
 public static string Generate(string inputFileContent, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, GenerateOption option, string dataSetNamespace, string basePath)
 {
     if ((inputFileContent == null) || (inputFileContent.Length == 0))
     {
         throw new ArgumentException(System.Design.SR.GetString("CG_DataSetGeneratorFail_InputFileEmpty"));
     }
     if (mainNamespace == null)
     {
         throw new ArgumentException(System.Design.SR.GetString("CG_DataSetGeneratorFail_CodeNamespaceNull"));
     }
     if (codeProvider == null)
     {
         throw new ArgumentNullException("codeProvider");
     }
     StringReader textReader = new StringReader(inputFileContent);
     DesignDataSource designDS = new DesignDataSource();
     try
     {
         designDS.ReadXmlSchema(textReader, basePath);
     }
     catch (Exception exception)
     {
         throw new Exception(System.Design.SR.GetString("CG_DataSetGeneratorFail_UnableToConvertToDataSet", new object[] { CreateExceptionMessage(exception) }), exception);
     }
     return GenerateInternal(designDS, compileUnit, mainNamespace, codeProvider, option, dataSetNamespace);
 }
Example #33
0
 public static string Generate(string inputFileContent, System.CodeDom.CodeCompileUnit compileUnit, System.CodeDom.CodeNamespace mainNamespace, System.CodeDom.Compiler.CodeDomProvider codeProvider, GenerateOption option, string dataSetNamespace)
 {
 }
 public static void Generate(string inputFileContent, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, Hashtable customDBProviders, GenerateOption option, string dataSetNamespace, string basePath)
 {
     if (customDBProviders != null)
     {
         ProviderManager.CustomDBProviders = customDBProviders;
     }
     try
     {
         Generate(inputFileContent, compileUnit, mainNamespace, codeProvider, option, dataSetNamespace, basePath);
     }
     finally
     {
         ProviderManager.CustomDBProviders = null;
     }
 }
 internal static string GenerateInternal(DesignDataSource designDS, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, GenerateOption generateOption, string dataSetNamespace)
 {
     if (StringUtil.Empty(designDS.Name))
     {
         designDS.Name = "DataSet1";
     }
     try
     {
         TypedDataSourceCodeGenerator generator = new TypedDataSourceCodeGenerator {
             CodeProvider = codeProvider,
             GenerateSingleNamespace = false
         };
         if (mainNamespace == null)
         {
             mainNamespace = new CodeNamespace();
         }
         if (compileUnit == null)
         {
             compileUnit = new CodeCompileUnit();
             compileUnit.Namespaces.Add(mainNamespace);
         }
         generator.GenerateDataSource(designDS, compileUnit, mainNamespace, dataSetNamespace, generateOption);
         foreach (string str in imports)
         {
             mainNamespace.Imports.Add(new CodeNamespaceImport(str));
         }
     }
     catch (Exception exception)
     {
         throw new Exception(System.Design.SR.GetString("CG_DataSetGeneratorFail_FailToGenerateCode", new object[] { CreateExceptionMessage(exception) }), exception);
     }
     ArrayList list = new ArrayList(fixedReferences);
     list.AddRange(TypedDataSourceCodeGenerator.GetProviderAssemblies(designDS));
     if ((generateOption & GenerateOption.LinqOverTypedDatasets) == GenerateOption.LinqOverTypedDatasets)
     {
         Assembly entityAssembly = EntityAssembly;
         if (entityAssembly != null)
         {
             list.Add(entityAssembly);
         }
     }
     referencedAssemblies = (Assembly[]) list.ToArray(typeof(Assembly));
     foreach (Assembly assembly2 in referencedAssemblies)
     {
         compileUnit.ReferencedAssemblies.Add(assembly2.GetName().Name + ".dll");
     }
     return designDS.GeneratorDataSetName;
 }
 public static string Generate(string inputFileContent, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, GenerateOption option, string dataSetNamespace)
 {
     return Generate(inputFileContent, compileUnit, mainNamespace, codeProvider, option, dataSetNamespace, null);
 }
 public static void Generate(string inputFileContent, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, Hashtable customDBProviders, GenerateOption option, string dataSetNamespace)
 {
     Generate(inputFileContent, compileUnit, mainNamespace, codeProvider, customDBProviders, option, dataSetNamespace, null);
 }
Example #38
0
		public static void Generate (string inputFileContent, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider, Hashtable customDBProviders, GenerateOption option)
		{
			throw new NotImplementedException ();
		}