Example #1
0
        public override void Collided(Model with, Displayable.CollisionStatus status)
        {
            if (status == Displayable.CollisionStatus.TOP) return; //lol???
            if (status == Displayable.CollisionStatus.BOTTOM)
            {
                DisableFreeFall();
                this.Velocity = new Velocity();
                return;
            }

            if (with.GetType() == typeof(Wall))
            {
                mBlockedWallId = with.ModelId;
                return;
            }

            if (with.GetType() != typeof(Character))
            {
                return;
            }

            if (mBlockedWallId != -1) return;

            if (status == Displayable.CollisionStatus.LEFT)
            {
                this.mPosition.X = with.Left - this.Origin.X;
            }
            else if (status == Displayable.CollisionStatus.RIGHT)
            {
                this.mPosition.X = with.Right + this.Origin.X;
            }
        }
 public static View.IDisplayItem produce(Model.IStoryContent storyContent)
 {
     if (storyContent.GetType().Equals(typeof(Model.RssStoryContent))) {
         Model.RssStoryContent rssStoryContent = (Model.RssStoryContent)storyContent;
         return new View.RssDisplayStory(rssStoryContent.Title, rssStoryContent.Description, rssStoryContent.Published, rssStoryContent.Link);
     }
     else if (storyContent.GetType().Equals(typeof(Model.AtomStoryContent))) {
         Model.AtomStoryContent atomStoryContent = (Model.AtomStoryContent)storyContent;
         return new View.AtomDisplayStory(atomStoryContent.Title, atomStoryContent.Summary, atomStoryContent.Updated, atomStoryContent.Link);
     }
     else
     {
         throw new Exception("Cannot display unsupported news content");
     }
 }
Example #3
0
        public override void NotColliding(Model with)
        {
            if (with.GetType() != typeof(Character)) return;
            Character chara = (Character)with;
            if (mPlayerIndex != (PlayerIndex)chara.Index) return;

            mDoorStatus = DoorStatus.CLOSED;
        }
        public IJobTaskWorker GetWorkerFor( Model.JobTask task )
        {
            var tt = task.GetType();
            var generic = typeof( IJobTaskWorker<> );
            var worker = generic.MakeGenericType( tt );

            return ( IJobTaskWorker )this.container.GetService( worker );
        }
        public Handlers.Tasks.IJobTaskRunner GetRunnerFor( Model.JobTask task )
        {
            var tt = task.GetType();
            var generic = typeof( IJobTaskRunner<> );
            var runner = generic.MakeGenericType( tt );

            return ( IJobTaskRunner )this.container.GetService( runner );
        }
        public IJobWorker GetWorkerFor( Model.Job job )
        {
            var jt = job.GetType();
            var generic = typeof( IJobWorker<> );
            var worker = generic.MakeGenericType( jt );

            return ( IJobWorker )this.container.GetService( worker );
        }
        public Handlers.Jobs.IJobRunner GetRunnerFor( Model.Job job )
        {
            var jt = job.GetType();
            var generic = typeof( IJobRunner<> );
            var runner = generic.MakeGenericType( jt );

            return ( IJobRunner )this.container.GetService( runner );
        }
Example #8
0
 // POST api/clientes
 public void Post(Model.Cidade model)
 {
     using (TextWriter textWriter = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(string.Format("~/XMLFiles/{0}.xml", ((Model.Cidade)model).Codigo.ToString()))))
     {
         XmlSerializer serializer = new XmlSerializer(model.GetType(), new XmlRootAttribute("Cidade"));
         serializer.Serialize(textWriter, model);
     }
 }
Example #9
0
        public override void Collided(Model with, Displayable.CollisionStatus status)
        {
            if (status == Displayable.CollisionStatus.TOP) return;
            if (with.GetType() != typeof(Character)) return;
            Character chara = (Character)with;
            if (mPlayerIndex != (PlayerIndex)chara.Index) return;

            mDoorStatus = DoorStatus.OPEN;
        }
Example #10
0
        /// <summary>
        /// 生成插入语句
        /// </summary>
        /// <param name="model">模型对象</param>
        /// <returns></returns>
        public virtual string BuildInsertSQL(Model.Model model)
        {
            List<string> fileds = new List<string>();
            List<string> values = new List<string>();
            var propertys = model.GetType().GetProperties();
            var identity = model.getIdentify();
            foreach (var p in propertys)
            {
                if (!Magic.Mvc.Equals.IsNull(identity) && identity.Name == p.Name) continue;

                var notmaps = p.GetCustomAttributes(typeof(Model.NotMapingAttribute), false);
                if (notmaps != null && notmaps.Length > 0) continue;

                fileds.Add(string.Format("[{0}]", p.Name));
                values.Add(string.Format("@{0}", p.Name));
            }

            return string.Format(" INSERT INTO [{0}]({1}) VALUES({2}) ", model.GetType().Name, string.Join(",", fileds.ToArray()), string.Join(",", values.ToArray()));
        }
Example #11
0
        /// <summary>
        /// 获取sql参数
        /// </summary>
        /// <returns></returns>
        public virtual IDataParameter[] GetParameters(Model.Model model)
        {
            var propertys = model.GetType().GetProperties();

            List<IDataParameter> listSQLParamter = new List<IDataParameter>();
            foreach (var p in propertys)
            {
                listSQLParamter.Add(new SqlParameter() { ParameterName = p.Name, Value = model.Property(p.Name) });
            }
            return listSQLParamter.ToArray();
        }
        public void Label_from_property_should_return_the_example()
        {
            Model m = new Model() { Enum = Foo.Bar };
            var pi = m.GetType().GetProperty("Enum");
            //arrange

            //act
            var result = _conventions.LabelForPropertyConvention(pi);

            //assert
            Assert.AreEqual("label", result);
        }
        public void Label_from_property_should_return_the_property_name()
        {
            Model m = new Model() { String = "foo" };
            var pi = m.GetType().GetProperty("String");
            //arrange

            //act
            var result = _conventions.LabelForPropertyConvention(pi);

            //assert
            Assert.AreEqual("String", result);
        }
Example #14
0
 public override void Collided(Model with, Displayable.CollisionStatus status)
 {
     if (ProjectHelper.IsDebugNoKill) return;
     if (status != Displayable.CollisionStatus.BOTTOM) return;
     if (with.IsDestroyed) return;
     if (with.GetType() != typeof(Character)) return;
     Character chara = (Character)with;
     if (chara.CharacterPlayerIndex == mPlayerIndex || mPlayerIndex == PlayerIndex.Three)
     {
         with.Destroy();
     }
 }
        public void Example_from_property_should_return_an_empty_string()
        {
            Model m = new Model() { String = "foo" };
            var pi = m.GetType().GetProperty("String");
            //arrange

            //act
            var result = _conventions.ExampleForPropertyConvention(pi);

            //assert
            Assert.AreEqual("", result);
        }
        public void Model_is_invalid_should_return_true()
        {
            Model m = new Model() { String = "foo" };
            var pi = m.GetType().GetProperty("String");
            //arrange
            var helper = InputModelPropertyFactoryTester.CreateHelper(m);
            helper.ViewData.ModelState.AddModelError("String","foo bar");
            //act
            var result = _conventions.ModelIsInvalidConvention(pi, helper);

            //assert
            Assert.IsTrue(result);
        }
Example #17
0
        /// <summary>
        /// 生成删除语句
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual string BuildDeleteSQL(Model.Model model)
        {
            List<string> wheres = new List<string>();
            var primarys = model.getPrimaryKeys();
            foreach (var p in primarys)
            {
                var notmaps = p.GetCustomAttributes(typeof(Model.NotMapingAttribute), false);
                if (notmaps != null && notmaps.Length > 0) continue;

                wheres.Add(string.Format("[{0}][email protected]{0}", p.Name));
            }

            return string.Format(" DELETE FROM [{0}]  WHERE {1}", model.GetType().Name, string.Join(" and ", wheres.ToArray()));
        }
Example #18
0
        /// <summary>
        /// Gets the cache associated with a type derived from the abstract class Model.
        /// If the cache hasn't been accessed yet, this creates one for the type.
        /// </summary>
        public static ModelCache Get(Model instance)
        {
            Type type = instance.GetType();

            return Get(type);
        }
        public void verify_logic_with_context()
        {
            var now = DateTime.Now;
            var model = new Model
            {
                NDate = now,
                Date = now,
                NSpan = now - new DateTime(1999, 1, 1),
                Span = new TimeSpan(0),
                Number = 0,
                Flag = true,
                Text = "hello world",
                PoliticalStability = Utility.Stability.High,
                SbyteNumber = SbyteEnum.First,
                ByteNumber = ByteEnum.First,
                ShortNumber = ShortEnum.First,
                UshortNumber = UshortEnum.First,
                IntNumber = IntEnum.First,
                UintNumber = UintEnum.First,
                LongNumber = LongEnum.First,
                UlongNumber = UlongEnum.First,
                Guid1 = Guid.NewGuid(),
                Guid2 = Guid.Empty,
                SubModel = new Model
                {
                    NDate = now.AddDays(1),
                    Date = now.AddDays(1),
                    Number = 1,
                    Flag = false,
                    Text = " hello world ",
                    PoliticalStability = null,
                }
            };

            var parser = new Parser();
            parser.RegisterMethods();

            Assert.IsTrue(parser.Parse(model.GetType(), "Number < 1").Invoke(model));
            Assert.IsTrue(parser.Parse(model.GetType(), "Number == 0").Invoke(model));
            Assert.IsTrue(parser.Parse(model.GetType(), "Number != null").Invoke(model));
            Assert.IsTrue(parser.Parse(model.GetType(), "SubModel.Number / 2 == 0.5").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("SbyteNumber / SbyteEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("ByteNumber / ByteEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("ShortNumber / ShortEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("UshortNumber / UshortEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("IntNumber / IntEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("UintNumber / UintEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("LongNumber / LongEnum.Second == 0.5").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("UlongNumber / UlongEnum.Second == 0.5").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("PoliticalStability == 0").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("PoliticalStability == Utility.Stability.High").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("PoliticalStability < Utility.Stability.Low").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("SubModel.PoliticalStability == null").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("SubModel.PoliticalStability != Utility.Stability.High").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("Const != Utility.Const").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("Flag").Invoke(model));
            Assert.IsFalse(parser.Parse<Model>("!Flag").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Flag && true").Invoke(model));

            Assert.IsFalse(parser.Parse<Model>("SubModel.Flag").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("!SubModel.Flag").Invoke(model));
            Assert.IsFalse(parser.Parse<Model>("SubModel.Flag && true").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("Number < SubModel.Number").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Date <= NDate").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("NDate != null").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Span <= NSpan").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("NSpan != null").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("SubModel.Date < NextWeek()").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("IncNumber(0) == SubModel.Number").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("IncNumber(Number) == SubModel.Number").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Today() - Today() == Span").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Today() - Today() == Date - Date").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Today() - Today() == Span - Span").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Today() - Today() == NSpan - NSpan").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Span + NSpan == NSpan + Span").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Now() - Span > Date - NSpan").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("DecNumber(SubModel.Number) == Number").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("DecNumber(Number) == 0").Invoke(model.SubModel));

            Assert.IsTrue(parser.Parse<Model>("SubModel.Date > Today()").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("'hello world' == Trim(SubModel.Text)").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("CompareOrdinal(Text, Trim(SubModel.Text)) == 0").Invoke(model));

            Assert.IsTrue(parser.Parse<Model>("Guid1 != Guid('00000000-0000-0000-0000-000000000000')").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Guid2 == Guid('00000000-0000-0000-0000-000000000000')").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("Guid1 != Guid2").Invoke(model));

            model.NDate = null;
            model.NSpan = null;
            Assert.IsTrue(parser.Parse<Model>("NDate == null && Date != NDate").Invoke(model));
            Assert.IsTrue(parser.Parse<Model>("NSpan == null && Span != NSpan").Invoke(model));

            var subModel = new Model();
            var newModel = new Model {SubModel = subModel, SubModelObject = subModel};
            Assert.IsTrue(parser.Parse<Model>("SubModel == SubModelObject").Invoke(newModel));

            const string expression =
                @"Flag == !false
                      && (
                             (Text != 'hello world' && Date < SubModel.Date)
                             || (
                                    (Number >= 0 && Number < 1) && PoliticalStability == Utility.Stability.High
                                )
                         )
                      && Const + Utility.Const == 'insideoutside'";
            var func = parser.Parse(model.GetType(), expression);
            Assert.IsTrue(func(model));

            parser.GetFields()["Flag"] = null; // try to mess up with internal fields - original data should not be affected
            var parsedFields = parser.GetFields();
            var expectedFields = new Dictionary<string, Type>
            {
                {"Flag", typeof (bool)},
                {"Text", typeof (string)},
                {"Date", typeof (DateTime)},
                {"SubModel.Date", typeof (DateTime)},
                {"Number", typeof (int?)},
                {"PoliticalStability", typeof (Utility.Stability?)}
            };
            Assert.AreEqual(expectedFields.Count, parsedFields.Count);
            Assert.IsTrue(
                expectedFields.Keys.All(
                    key => parsedFields.ContainsKey(key) &&
                           EqualityComparer<Type>.Default.Equals(expectedFields[key], parsedFields[key])));

            parser.GetConsts()["Const"] = null; // try to mess up with internal fields - original data should not be affected
            var parsedConsts = parser.GetConsts();
            var expectedConsts = new Dictionary<string, object>
            {
                {"Utility.Stability.High", Utility.Stability.High},
                {"Const", Model.Const},
                {"Utility.Const", Utility.Const}
            };
            Assert.AreEqual(expectedConsts.Count, parsedConsts.Count);
            Assert.IsTrue(
                expectedConsts.Keys.All(
                    key => parsedConsts.ContainsKey(key) &&
                           EqualityComparer<object>.Default.Equals(expectedConsts[key], parsedConsts[key])));
        }
Example #20
0
 /// <summary>Get the scripts parameters as a returned xmlElement.</summary>
 /// <param name="script">The script.</param>
 /// <returns></returns>
 private XmlElement GetParametersInObject(Model script)
 {
     XmlDocument doc = new XmlDocument();
     doc.AppendChild(doc.CreateElement("Script"));
     foreach (PropertyInfo property in script.GetType().GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
     {
         if (property.CanRead && property.CanWrite &&
             ReflectionUtilities.GetAttribute(property, typeof(XmlIgnoreAttribute), false) == null)
         {
             object value = property.GetValue(script, null);
             if (value == null)
                 value = "";
             XmlUtilities.SetValue(doc.DocumentElement, property.Name,
                                  ReflectionUtilities.ObjectToString(value));
         }
     }
     return doc.DocumentElement;
 }
Example #21
0
 //Move the selected barricade to a location.
 public Boolean moveBarricade(Model.Field field)
 {
     if (field.Pawn == null &&
         field.Barricade == null &&
         (field.GetType() == typeof(Model.Field) ||
         field.GetType() == typeof(Model.Barricade)))
     {
         //If the row is in the array it can not contain a barricade
         if (!level.ANoBarricades.Contains(field.Y))
         {
             barricade.setLocation(field);
             barricade = null;
             level.setCursor("arrow", field);
             nextPlayer();
             return true;
         }
     }
     return false;
 }
        public void Model_property_builder_should_return_a_model_of_datetime()
        {
            Model m = new Model(){timestamp = DateTime.Today};
            var pi = m.GetType().GetProperty("timestamp");
            //arrange

            //act
            var result = _conventions.ModelPropertyBuilder(pi, m.timestamp);

            //assert
            Assert.IsInstanceOf(typeof(PropertyViewModel<DateTime>),result);

            Assert.AreEqual(((PropertyViewModel<DateTime>) result).Value, DateTime.Today);
        }
        public void Partial_Name_should_return_the_datatype()
        {
            Model m = new Model() { DataType = "foo" };
            var pi = m.GetType().GetProperty("DataType");
            //arrange

            //act
            var result = _conventions.PartialNameConvention(pi);

            //assert
            Assert.AreEqual("EmailAddress", result);
        }
Example #24
0
        /// <summary>
        /// 生成更新语句
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual string BuildUpdateSQL(Model.Model model)
        {
            List<string> fileds = new List<string>();
            List<string> wheres = new List<string>();
            var propertys = model.GetType().GetProperties();
            var primarys = model.getPrimaryKeys();
            var identity = model.getIdentify();
            foreach (var p in propertys)
            {
                var notmaps = p.GetCustomAttributes(typeof(Model.NotMapingAttribute), false);
                if (notmaps != null && notmaps.Length > 0) continue;

                if (primarys.Any(m => m.Name == p.Name))
                {
                    wheres.Add(string.Format("[{0}][email protected]{0}", p.Name));
                }
                if (!Magic.Mvc.Equals.IsNull(identity) && identity.Name == p.Name) continue;

                fileds.Add(string.Format("[{0}][email protected]{0}", p.Name));

            }

            return string.Format(" UPDATE [{0}] SET {1} WHERE {2}", model.GetType().Name, string.Join(",", fileds.ToArray()), string.Join(" and ", wheres.ToArray()));
        }
        public void Partial_Name_should_return_the_property()
        {
            Model m = new Model() { String = "foo" };
            var pi = m.GetType().GetProperty("String");
            //arrange

            //act
            var result = _conventions.PartialNameConvention(pi);

            //assert
            Assert.AreEqual("String", result);
        }
        public void Partial_Name_should_return_the_enum_name()
        {
            Model m = new Model() { Enum = Foo.Bar };
            var pi = m.GetType().GetProperty("Enum");
            //arrange

            //act
            var result = _conventions.PartialNameConvention(pi);

            //assert
            Assert.AreEqual("Enum", result);
        }
        public void Partial_Name_should_return_the_uihint()
        {
            Model m = new Model() { UiHintProperty = "foo"};
            var pi = m.GetType().GetProperty("UiHintProperty");
            //arrange

            //act
            var result = _conventions.PartialNameConvention(pi);

            //assert
            Assert.AreEqual("theview", result);
        }
        public void Model_property_builder_should_return_a_model_of_select_items_for_an_enum()
        {
            Model m = new Model() { Enum=Foo.Bar };
            var pi = m.GetType().GetProperty("Enum");
            //arrange

            //act
            var result = _conventions.ModelPropertyBuilder(pi, m.Enum);

            //assert
            Assert.IsInstanceOf(typeof(PropertyViewModel<IEnumerable<SelectListItem>>), result);

            Assert.AreEqual(((PropertyViewModel<IEnumerable<SelectListItem>>)result).Value.Count(), 2);
        }
Example #29
0
        /// <summary>
        /// Find all properties from the model and fill this.properties.
        /// </summary>
        /// <param name="model">The model to search for properties</param>
        /// <param name="properties">The list of properties to fill</param>
        private static void FindAllProperties(Model model, List<VariableProperty> properties)
        {
            if (model != null)
            {
                foreach (PropertyInfo property in model.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy))
                {
                    // Properties must have a [Summary] attribute
                    bool includeProperty = property.IsDefined(typeof(SummaryAttribute), false);

                    if (includeProperty)
                    {
                        properties.Add(new VariableProperty(model, property));
                    }
                }
            }
        }
        public void Value_from_model_should_return_the_enum_name()
        {
            Model m = new Model() { Enum = Foo.Bar };
            var pi = m.GetType().GetProperty("Enum");
            //arrange

            //act
            var result = _conventions.ValueFromModelPropertyConvention(pi,m);

            //assert
            Assert.AreEqual(Foo.Bar, result);
        }