Exemplo n.º 1
0
        public string GetDebugInformation()
        {
            String returnString = "Name : " + name + " (Key: " + Key + ")" +
                                  "\n" + "" +
                                  "\nTile Size : " + tileSize.ToString() +
                                  "\nState : " + State.ToString() +
                                  "\nIs Valid : " + IsValid.ToString() +
                                  "\nBaseScrPosition : " + BaseScreenPosition.ToString() +
                                  "\nScreenPosition : " + ScreenPosition.ToString() +
                                  "\nOrigin : " + BaseOrigin.ToString() +
                                  "\nShape Origin : " + ShapeOrigin.ToString() +
                                  "\nCursor Offset : " + CursorReturnOffset.ToString() +
                                  "\nRotation : " + rotation + " radians" +
                                  "\nRotation idx : " + currentRotationIdx +
                                  "\nCurrent Dimensions : " + CurrentMatrixDimensions.ToString() +
                                  "\n[Flipping : " + IsFlipping + "] [Rotating : " + IsRotating + "]" +
                                  "\n[FlippedX : " + isFlippedHorizontal + "] [FlippedY : " + isFlippedVertical + "]";

            returnString += "\n\nCurrent Matrix: ";

            returnString += "\n-----\n";

            for (int y = 0; y < CurrentMatrixDimensions.Y; y++)
            {
                for (int x = 0; x < CurrentMatrixDimensions.X; x++)
                {
                    returnString += CurrentMatrix[y][x] + " ";
                }

                returnString += "\n";
            }

            return(returnString);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Writes the contents of this spreadsheet to dest using an XML format.
 /// The XML elements should be structured as follows:
 ///
 /// <spreadsheet IsValid="IsValid regex goes here">
 ///   <cell name="cell name goes here" contents="cell contents go here"></cell>
 ///   <cell name="cell name goes here" contents="cell contents go here"></cell>
 ///   <cell name="cell name goes here" contents="cell contents go here"></cell>
 /// </spreadsheet>
 ///
 /// The value of the IsValid attribute should be IsValid.ToString()
 ///
 /// There should be one cell element for each non-empty cell in the spreadsheet.
 /// If the cell contains a string, the string (without surrounding double quotes) should be written as the contents.
 /// If the cell contains a double d, d.ToString() should be written as the contents.
 /// If the cell contains a Formula f, f.ToString() with "=" prepended should be written as the contents.
 ///
 /// If there are any problems writing to dest, the method should throw an IOException.
 /// </summary>
 /// <param name="dest">The desired filename</param>
 public override void Save(TextWriter dest)
 {
     using (XmlWriter writer = XmlWriter.Create(dest))
     {
         // Start the document off with an element called spreadsheet that has an attribute
         // IsValid, which is our regex expression.
         writer.WriteStartDocument();
         writer.WriteStartElement("spreadsheet");
         writer.WriteAttributeString("IsValid", IsValid.ToString());
         foreach (var cellName in GetNamesOfAllNonemptyCells())
         {
             // Create a new element for each cell in the spreadsheet.
             Cell currentCell = cells[cellName];
             writer.WriteStartElement("cell");
             writer.WriteAttributeString("name", cellName);
             if (cells[cellName].cellContents is Formula)
             {
                 // Formulas should be preceded by '=' so make sure and add that.
                 writer.WriteAttributeString("contents", "=" + currentCell.cellContents.ToString());
             }
             else
             {
                 // Otherwise just write the contents with the ToString method.
                 writer.WriteAttributeString("contents", currentCell.cellContents.ToString());
             }
             // End the element to indicate the end of a cell.
             writer.WriteEndElement();
         }
         // End our IsValid element and the document.
         writer.WriteEndElement();
         writer.WriteEndDocument();
     }
     // The document has now been saved, so Changed should be set to false.
     Changed = false;
 }
        /// <devdoc>
        /// <para>Evaluates validity and updates the <see cref='System.Web.UI.WebControls.BaseValidator.IsValid'/> property.</para>
        /// </devdoc>
        public void Validate()
        {
            IsValid = true;
            if (!Visible || !Enabled)
            {
                return;
            }
            propertiesChecked = false;
            if (!PropertiesValid)
            {
                return;
            }
            IsValid = EvaluateIsValid();
            Debug.Trace("BaseValidator.Validate", "id:" + ID + ", evaluateIsValid = " + IsValid.ToString());
            if (!IsValid)
            {
                Page page = Page;
                if (page != null && SetFocusOnError)
                {
                    // Dev10 584609 Need to render ClientID not control id for auto focus to work
                    string  validateId = ControlToValidate;
                    Control c          = NamingContainer.FindControl(validateId);
                    if (c != null)
                    {
                        validateId = c.ClientID;
                    }

                    Page.SetValidatorInvalidControlFocus(validateId);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// If name is null, throws an ArgumentNullException.
        ///
        /// Otherwise, if name isn't a valid cell name, throws an InvalidNameException.
        ///
        /// Otherwise, returns an enumeration, without duplicates, of the names of all cells whose
        /// values depend directly on the value of the named cell.  In other words, returns
        /// an enumeration, without duplicates, of the names of all cells that contain
        /// formulas containing name.
        ///
        /// For example, suppose that
        /// A1 contains 3
        /// B1 contains the formula A1 * A1
        /// C1 contains the formula B1 + A1
        /// D1 contains the formula B1 - C1
        /// The direct dependents of A1 are B1 and C1
        /// </summary>
        protected override IEnumerable <string> GetDirectDependents(string name)
        {
            // If name is null, throws an ArgumentNullException.
            if (name == null)
            {
                throw new ArgumentNullException();
            }
            // Otherwise, if name isn't a valid cell name, throws an InvalidNameException.
            if (!Regex.IsMatch(name, @"^[a-zA-Z_](?: [a-zA-Z_]|\d)*$") || !Regex.IsMatch(name, IsValid.ToString()))
            {
                throw new InvalidNameException();
            }


            return(dg.GetDependents(name.ToUpper()));
        }
Exemplo n.º 5
0
        /// <summary>
        /// If content is null, throws an ArgumentNullException.
        ///
        /// Otherwise, if name is null or invalid, throws an InvalidNameException.
        ///
        /// Otherwise, if content parses as a double, the contents of the named
        /// cell becomes that double.
        ///
        /// Otherwise, if content begins with the character '=', an attempt is made
        /// to parse the remainder of content into a Formula f using the Formula
        /// constructor with s => s.ToUpper() as the normalizer and a validator that
        /// checks that s is a valid cell name as defined in the AbstractSpreadsheet
        /// class comment.  There are then three possibilities:
        ///
        ///   (1) If the remainder of content cannot be parsed into a Formula, a
        ///       Formulas.FormulaFormatException is thrown.
        ///
        ///   (2) Otherwise, if changing the contents of the named cell to be f
        ///       would cause a circular dependency, a CircularException is thrown.
        ///
        ///   (3) Otherwise, the contents of the named cell becomes f.
        ///
        /// Otherwise, the contents of the named cell becomes content.
        ///
        /// If an exception is not thrown, the method returns a set consisting of
        /// name plus the names of all other cells whose value depends, directly
        /// or indirectly, on the named cell.
        ///
        /// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
        /// set {A1, B1, C1} is returned.
        /// </summary>

        public override ISet <string> SetContentsOfCell(string name, string content)
        {
            if (content == null)
            {
                throw new ArgumentNullException();
            }
            if (ReferenceEquals(name, null) || !Regex.IsMatch(name, @"^[a-zA-Z_](?: [a-zA-Z_]|\d)*$") || !Regex.IsMatch(name, IsValid.ToString()))
            {
                throw new InvalidNameException();
            }

            name = name.ToUpper();

            if (Regex.IsMatch(content, @"^(?:\d+\.\d*|\d*\.\d+|\d+)(?:e[\+-]?\d+)?$"))
            {
                Changed = true;
                return(SetCellContents(name, Double.Parse(content)));
            }
            else if (content.Length > 0 && content[0] == '=')
            {
                Formula f = new Formula(content.Substring(1, content.Length - 1), s => s.ToUpper(), s => Regex.IsMatch(s, IsValid.ToString()));


                Changed = true;
                return(SetCellContents(name, f));
            }
            else
            {
                Changed = true;
                return(SetCellContents(name, content));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Requires that all of the variables in formula are valid cell names.
        ///
        /// If name is null or invalid, throws an InvalidNameException.
        ///
        /// Otherwise, if changing the contents of the named cell to be the formula would cause a
        /// circular dependency, throws a CircularException.
        ///
        /// Otherwise, the contents of the named cell becomes formula.  The method returns a
        /// Set consisting of name plus the names of all other cells whose value depends,
        /// directly or indirectly, on the named cell.
        ///
        /// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
        /// set {A1, B1, C1} is returned.
        /// </summary>
        protected override ISet <string> SetCellContents(string name, Formula formula)
        {
            if (ReferenceEquals(name, null) || !Regex.IsMatch(name, @"^[a-zA-Z_](?: [a-zA-Z_]|\d)*$") || !Regex.IsMatch(name, IsValid.ToString()))
            {
                throw new InvalidNameException();
            }

            IEnumerable <String> old_dependees = dg.GetDependees(name);

            dg.ReplaceDependees(name, formula.GetVariables());

            try
            {
                HashSet <String> all_dependees = new HashSet <String>(GetCellsToRecalculate(name));

                Cell cell = new Cell(formula, FindVal);

                cell.value = formula;

                if (cellList.ContainsKey(name))
                {
                    cellList[name] = cell;
                }
                else
                {
                    cellList.Add(name, cell);
                }


                foreach (string values in all_dependees)
                {
                    if (cellList[values].contents is Formula)
                    {
                        Formula f = (Formula)(cellList[values].contents);
                        try
                        {
                            double value = f.Evaluate((Lookup)FindVal);

                            cellList[values].value = value;
                        }
                        catch (Exception e)
                        {
                            cellList[values].value = new FormulaError();
                        }
                    }
                    else
                    {
                        cell.value = formula.Evaluate((Lookup)FindVal);
                    }
                }

                return(all_dependees);
            }
            catch
            {
                dg.ReplaceDependees(name, old_dependees);
                throw new CircularException();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// If text is null, throws an ArgumentNullException.
        ///
        /// Otherwise, if name is null or invalid, throws an InvalidNameException.
        ///
        /// Otherwise, the contents of the named cell becomes text.  The method returns a
        /// set consisting of name plus the names of all other cells whose value depends,
        /// directly or indirectly, on the named cell.
        ///
        /// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
        /// set {A1, B1, C1} is returned.
        /// </summary>
        protected override ISet <string> SetCellContents(string name, string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException();
            }

            if (ReferenceEquals(name, null) || !Regex.IsMatch(name, @"^[a-zA-Z_](?: [a-zA-Z_]|\d)*$") || !Regex.IsMatch(name, IsValid.ToString()))
            {
                throw new InvalidNameException();
            }

            Cell cell = new Cell(text);

            cell.value = text;

            if (cellList.ContainsKey(name))
            {
                cellList[name] = cell;
            }


            else
            {
                cellList.Add(name, cell);
            }

            if (cellList[name].contents.Equals(""))
            {
                cellList.Remove(name);
            }

            dg.ReplaceDependees(name, new HashSet <string>());

            return(new HashSet <string>(GetCellsToRecalculate(name)));
        }
Exemplo n.º 8
0
        /// <summary>
        /// If name is null or invalid, throws an InvalidNameException.
        ///
        /// Otherwise, the contents of the named cell becomes number.  The method returns a
        /// set consisting of name plus the names of all other cells whose value depends,
        /// directly or indirectly, on the named cell.
        /// </summary>
        protected override ISet <string> SetCellContents(string name, double number)
        {
            if (ReferenceEquals(name, null) || !Regex.IsMatch(name, @"^[a-zA-Z_](?: [a-zA-Z_]|\d)*$") || !Regex.IsMatch(name, IsValid.ToString()))
            {
                throw new InvalidNameException();
            }

            Cell cell = new Cell(number);

            cell.value = number;



            if (cellList.ContainsKey(name))
            {
                cellList[name] = cell;
            }

            else
            {
                cellList.Add(name, cell);
            }


            dg.ReplaceDependees(name, new HashSet <string>());


            HashSet <String> ans = new HashSet <String>(GetCellsToRecalculate(name));

            foreach (String item in ans)
            {
                if (cellList[item].contents is Formula)
                {
                    Formula formula = (Formula)cellList[item].contents;
                    try
                    {
                        double num = formula.Evaluate((Lookup)FindVal);
                        cellList[item].value = item;
                    }
                    catch (Exception e)
                    {
                        cellList[item].value = new FormulaError();
                    }
                }
            }

            return(ans);
        }
Exemplo n.º 9
0
        /// <summary>
        /// If name is null or invalid, throws an InvalidNameException.
        ///
        /// Otherwise, returns the value (as opposed to the contents) of the named cell.  The return
        /// value should be either a string, a double, or a FormulaError.
        /// </summary>
        public override object GetCellValue(string name)
        {
            //done
            Cell cell;

            if (ReferenceEquals(name, null) || !Regex.IsMatch(name, @"^[a-zA-Z_](?: [a-zA-Z_]|\d)*$") || !Regex.IsMatch(name, IsValid.ToString()))
            {
                throw new InvalidNameException();
            }

            name = name.ToUpper();
            if (cellList.TryGetValue(name.ToUpper(), out cell))
            {
                return(cell.value);
            }

            else
            {
                return("");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// If name is null or invalid, throws an InvalidNameException.
        ///
        /// Otherwise, returns the contents (as opposed to the value) of the named cell.  The return
        /// value should be either a string, a double, or a Formula.
        /// </summary>
        public override object GetCellContents(string name)
        {
            Cell cell;

            if (ReferenceEquals(name, null) || !Regex.IsMatch(name, @"^[a-zA-Z]+[0-9]+$") || !Regex.IsMatch(name, IsValid.ToString()))
            {
                throw new InvalidNameException();
            }

            if (cellList.TryGetValue(name.ToUpper(), out cell))
            {
                return(cell.contents);
            }

            return("");
        }