Exemple #1
0
        /// <summary>
        /// Checks a record for nullness, type affinity, size overflow, and field count
        /// </summary>
        /// <param name="R">A record to check</param>
        /// <param name="FixAffinity">If true, the method will cast an invalid affinity cell</param>
        /// <returns>A boolean describing whether or not the check fails</returns>
        public bool Check(Record R, bool FixAffinity)
        {
            // Check length //
            if (R.Count != this.Count)
            {
                throw new Exception(String.Format("Record size {0} does not match schema size {1}", R.Count, this.Count));
            }

            // Check nullness and affinity //
            for (int i = 0; i < R.Count; i++)
            {
                // Check affinity //
                if (R[i].Affinity != this.ColumnAffinity(i) && this.ColumnAffinity(i) != CellAffinity.VARIANT && !FixAffinity)
                {
                    throw new Exception(String.Format("Column Affinities do not match {0} : {1} != {2}", i, R[i].Affinity, this.ColumnAffinity(i)));
                }
                else if (R[i].Affinity != this.ColumnAffinity(i) && this.ColumnAffinity(i) != CellAffinity.VARIANT)
                {
                    R[i] = CellConverter.Cast(R[i], this.ColumnAffinity(i));
                }

                // Check nullness //
                if (!this.ColumnNull(i) && R[i].IsNull)
                {
                    throw new Exception(String.Format("Column {0} is null", i));
                }
            }

            return(true);
        }
Exemple #2
0
            public override Cell Evaluate(SpoolSpace Memory)
            {
                this.CheckParameters();
                Cell         c = this._Children[0].Evaluate(Memory);
                Cell         d = this._Children[1].Evaluate(Memory);
                CellAffinity a = (CellAffinity)d.BYTE;

                return(CellConverter.Cast(c, a));
            }
        //Creates the grid with the GridX and GridY values
        private void CreateGrid()
        {
            CellConverter conv = new CellConverter();
            Cell          newCell;
            Binding       cellBinding = new Binding("Alive");

            cellBinding.Converter = conv;
            cellBinding.Mode      = BindingMode.TwoWay;
            Rectangle newRect;

            cells = new Cell[GridX, GridY];


            for (int y = 0; y < GridY; y++)
            {
                for (int x = 0; x < GridX; x++)
                {
                    newRect = new Rectangle();
                    newCell = new Cell();

                    newRect.DataContext = newCell;
                    newRect.Fill        = Brushes.Green;
                    newRect.SetBinding(Rectangle.FillProperty, cellBinding);
                    newRect.MouseDown += BoardRectangle_Click;

                    playGrid.Children.Add(newRect);

                    cells[x, y] = newCell;

                    if (x - 1 >= 0 && y - 1 >= 0 && x - 1 < GridX && y - 1 < GridY)
                    {
                        newCell.checks             += cells[x - 1, y - 1].UpdateFriends;
                        cells[x - 1, y - 1].checks += newCell.UpdateFriends;
                    }
                    if (x >= 0 && y - 1 >= 0 && x < GridX && y - 1 < GridY)
                    {
                        newCell.checks         += cells[x, y - 1].UpdateFriends;
                        cells[x, y - 1].checks += newCell.UpdateFriends;
                    }
                    if (x + 1 >= 0 && y - 1 >= 0 && x + 1 < GridX && y - 1 < GridY)
                    {
                        newCell.checks             += cells[x + 1, y - 1].UpdateFriends;
                        cells[x + 1, y - 1].checks += newCell.UpdateFriends;
                    }
                    if (x - 1 >= 0 && y >= 0 && x - 1 < GridX && y < GridY)
                    {
                        newCell.checks         += cells[x - 1, y].UpdateFriends;
                        cells[x - 1, y].checks += newCell.UpdateFriends;
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Fixing any affinity issues by auto casting the cell type to the correct type based on the column
        /// </summary>
        /// <param name="R">A record to check</param>
        /// <returns>A record</returns>
        public Record Fix(Record R)
        {
            // Check nullness and affinity //
            for (int i = 0; i < R.Count; i++)
            {
                // Cast to a new affinity if need by //
                if (R[i].Affinity != this.ColumnAffinity(i) && this.ColumnAffinity(i) != CellAffinity.VARIANT)
                {
                    R[i] = CellConverter.Cast(R[i], this.ColumnAffinity(i));
                }
            }

            return(R);
        }
Exemple #5
0
        static void TestCellTransformation()
        {
            TrinityConfig.CurrentRunningMode = RunningMode.Embedded;

            Console.WriteLine("Insert some cells for testing");

            for (int i = 0; i < 10000000; i++)
            {
                if (i % 256 == 1)
                {
                    Global.LocalStorage.SaveMyCellA(i, i);
                }
            }
            Console.WriteLine("Cell Count: {0}", Global.LocalStorage.CellCount);

            CellConverter <MyCellA, MyCellB> cc = new CellConverter <MyCellA, MyCellB>((oldCell) =>
            {
                MyCellB B = new MyCellB(oldCell.A, "Expanded Field");
                return(B);
            });

            Console.WriteLine("Start cell transformation ...");
            Global.LocalStorage.Transform(cc);
            Console.WriteLine("Transformation is done.");


            Console.WriteLine("Check transformed cells ");

            int count = 0;

            for (int i = 0; i < 10000000; i++)
            {
                if (i % 256 == 1)
                {
                    Console.WriteLine("CellId: {0} \t Name: {1}", i, Global.LocalStorage.LoadMyCellB(i).Name);
                    if (++count >= 10)
                    {
                        break;
                    }
                }
            }

            Console.WriteLine("Cell Count: {0}", Global.LocalStorage.CellCount);
        }
Exemple #6
0
            public override void Invoke(SpoolSpace Memory)
            {
                this.CheckParameters(1, 3);

                if (this._Parameters.Count == 2)
                {
                    throw new Exception("Inlining requires either one or three parameters");
                }

                Cell RawScripts = this._Parameters[0].Evaluate(Memory);

                string[] Scripts     = RawScripts.Affinity == CellAffinity.ARRAY ? new string[] { RawScripts.valueCSTRING } : CellConverter.ToCStringArray(RawScripts.valueARRAY);
                string[] SearchFor   = (this._Parameters.Count != 3 ? new string[] { } : CellConverter.ToCStringArray(this._Parameters[1].Evaluate(Memory)));
                string[] ReplaceWith = (this._Parameters.Count != 3 ? new string[] { } : CellConverter.ToCStringArray(this._Parameters[2].Evaluate(Memory)));

                for (int i = 0; i < Scripts.Length; i++)
                {
                    string Script = this.FixParameters(Scripts[i], SearchFor, ReplaceWith);
                    this._Host.Engine.Execute(Script);
                }
            }