Esempio n. 1
0
        // interpreter for hershey fonts
        // see http://paulbourke.net/dataformats/hershey/
        // sends commands to an driver which can do the drawing
        public void interpret(string commands, IHersheyCommandDriver driver)
        {
            // translate a char to a value it encodes

            Func <char, float> translate = (char p) => {
                return((float)(p - 'R'));
            };

            Func <uint, float> readAndTranslate = (uint index) => {
                return(translate(commands[(int)index]));
            };

            Func <uint, bool> isRaiseCommand = (uint index) => {
                return(commands[(int)index] == ' ' && commands[(int)index + 1] == 'R');
            };

            float leftHandPosition  = readAndTranslate(8);
            float rightHandPosition = readAndTranslate(9);

            driver.setPositions(leftHandPosition, rightHandPosition);

            EnumCommandType commandType = EnumCommandType.MOVE;

            for (uint i = 0; ; i++)
            {
                uint i2 = 10 + i * 2;


                Debug.Assert(i2 <= commands.Length);
                if (i2 == commands.Length)
                {
                    break;
                }

                if (isRaiseCommand(i2))
                {
                    driver.raise();
                    commandType = EnumCommandType.MOVE;
                }
                else
                {
                    float x, y;

                    // C# implementation of readAndTranslateCoordinate(i2, /*out*/ x, /*out*/ y);
                    {
                        x = readAndTranslate(i2);
                        y = readAndTranslate(i2 + 1);
                    }

                    driver.command(commandType, x, y);
                    commandType = EnumCommandType.DRAW;
                }
            }
        }
        public static void CreateParametrs <T>(SqlCommand command, EnumCommandType ect, T entity)
        {
            PropertyInfo[] properties = typeof(T).GetProperties();
            foreach (PropertyInfo item in properties)
            {
                string name = item.Name;
                if (name == "Id" && ect == EnumCommandType.Insert)
                {
                    continue;
                }
                else if (name != "Id" && ect == EnumCommandType.Delete)
                {
                    continue;
                }
                else if ((name == "EntryTime" || name == "Active") && ect == EnumCommandType.Update)
                {
                    continue;
                }

                object value = item.GetValue(entity);
                command.Parameters.AddWithValue("@" + name, value);
            }
        }