示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="units"></param>
        /// <returns></returns>
        public IQuantity ConvertTo(params IDimension[] units)
        {
            //TODO: TBD: use cases like Time per Time (i.e. a ratio of time unit to potentially other time unit)
            //TODO: TBD: therefore, I think I must need to know the dimensions with precise Exponents as well ...
            //TODO: TBD: may then also replace none, some, or all, depending ...

            var destination = (from d in Dimensions select(IDimension) d.Clone()).ToList();

            destination.ReplaceUnits(units);

            /* Remember we want to yield a whole other Quantity and leave the original intact. Every single
             * operation we do during conversion will operate on the clones of the original dimensions. */

            var baseValue      = Dimensions.Aggregate(Value, (g, x) => x.ConvertToBase(g));
            var convertedValue = destination.Aggregate(baseValue, (g, x) => x.ConvertFromBase(g));

            return(new Quantity(convertedValue, destination.ToArray()));
        }
示例#2
0
 /// <summary>
 /// Get the number of tiles that exist within the game board.
 /// </summary>
 /// <returns>Number of tiles the board comprises of.</returns>
 public int GetLocationCount()
 {
     return(Dimensions.Aggregate(1, (x, y) => x * y));
 }
示例#3
0
        public void DoGenerate(object o)
        {
            var baseDim = Dimensions.FirstOrDefault(dim => { return(dim.Base); });

            if (baseDim == null || baseDim.DataTable.Rows.Count == 0)
            {
                MessageBox.Show("There must be at least one base dim with lines");
                return;
            }

            int totalCols = Dimensions.Aggregate(0, (total, next) => total += next.DataTable.Columns.Count);

            object[,] exportLines = new object[100, totalCols + 1];
            int exportLine = 0;

            DataTable baseDimTable = baseDim.DataTable;

            IRandomValue val;

            if (UseSimpleRandom)
            {
                val = new SimpleRandomValue(FromAmount, ToAmount);
            }
            else
            {
                val = new RandomValue(FromAmount, ToAmount, baseDim.DataTable.Rows.Count);
            }

            Random rnd = new Random(DateTime.Now.Millisecond);

            using (ExcelWrapper ex = new ExcelWrapper())
            {
                ex.Create();

                var wb    = ex.AddWorkbook();
                var sheet = wb.AddSheet();

                int  line      = 1;
                bool firstLine = true;

                var dropToExcel = new Action(() =>
                {
                    if (exportLine == 0)
                    {
                        return;
                    }

                    var r1 = sheet.Cells[line, 1];
                    var r2 = sheet.Cells[line + exportLine - 1, totalCols + 1];

                    NetOffice.ExcelApi.Range rg = sheet.Range(r1, r2);
                    rg.set_Value(NetOffice.ExcelApi.Enums.XlRangeValueDataType.xlRangeValueDefault, exportLines);

                    line      += exportLine;
                    exportLine = 0;
                });

                #region generation
                foreach (DataRow baseRow in baseDimTable.Rows)
                {
                    int totalLines;

                    if (TotalLinesFrom == TotalLinesTo)
                    {
                        totalLines = TotalLinesFrom;
                    }
                    else
                    {
                        totalLines = rnd.Next(TotalLinesFrom, TotalLinesTo);
                    }

                    val.NextStep(totalLines);

                    for (int r = 0; r < totalLines; ++r)
                    {
                        int col = 0;

                        foreach (Dimension dim in Dimensions)
                        {
                            if (dim == baseDim)
                            {
                                for (int c = 0; c < baseDimTable.Columns.Count; c++)
                                {
                                    exportLines[exportLine, col++] = firstLine ? baseDimTable.Columns[c].ColumnName : baseRow[c];
                                }
                            }
                            else
                            {
                                int rows    = dim.DataTable.Rows.Count;
                                int randRow = rnd.Next(0, rows);

                                DataRow dimRow = dim.DataTable.Rows[randRow];

                                for (int c = 0; c < dim.DataTable.Columns.Count; c++)
                                {
                                    exportLines[exportLine, col++] = firstLine ? dim.DataTable.Columns[c].ColumnName : dimRow[c];
                                }
                            }
                        }

                        //amounts

                        exportLines[exportLine, col++] = firstLine ? (object)"Amount" : (object)val.NextSubStep();

                        if (firstLine)
                        {
                            r--;
                            firstLine = false;
                        }

                        exportLine++;
                        if (exportLine == 100)
                        {
                            dropToExcel();
                        }
                    }
                }
                dropToExcel();

                #endregion


                ex.Show();
            }
        }