public void It_Should_Return_None_Where_A_Field_Is_Missing()
        {
            // Arrange
            var array = CreateArray();
            var field = "field2";

            var dictionaryValues = array.ArrValue.Select(x => x.Value).Cast<DictionaryValue>().ToList();
            dictionaryValues[1].DictValue.Remove(field);
            //array.ArrValue[1].Value.ValueAs<DictionaryValue>().DictValue.Remove(field);
            //((DictionaryValue) array.ArrValue[1]).DictValue.Remove(field);
            var mapFilter = new MapFilter(new StringValue(field));

            // Act
            var result = (mapFilter.Apply(new TemplateContext(), array).SuccessValue<ArrayValue>()).ToList();


            // Assert
            //IEnumerable<String> expected = dictionaryValues.Select(x => x.DictValue[field].;
//            var expected = array.ArrValue.Select(x => x.Value.ValueAs<DictionaryValue>().DictValue)
//                .Select(x => x.ContainsKey(field) ? x[field].Value.ToString() : "");
                

//            var expected = array.ArrValue.Cast<DictionaryValue>().Select(
//                x => x.DictValue.ContainsKey(field) ?
//                    x.DictValue[field].Value.ToString() :
//                    UndefinedMessage(field)).ToList();

            //Logger.Log("EXPECTED: " + String.Join(",", expected));
            Assert.That(result.Count(x => !x.HasValue), Is.EqualTo(1));
            //var actual = result.Select(x => x.Value.ToString());

            //Logger.Log("ACTUAL: " + String.Join(",", actual));
            //Assert.That(actual, Is.EquivalentTo(expected));

        }
		public MapViewController (IntPtr handle) : base (handle)
		{
			houseService = new HouseService ();
			imageCacheRepo = new HouseImageCacheRepository ();
			this.mapFilter = MapFilter.All;
			this.NavigationItem.BackBarButtonItem = new UIBarButtonItem ("Back", UIBarButtonItemStyle.Plain,null);
			isAdmin =  NSBundle.MainBundle.ObjectForInfoDictionary("AllowAddNew").ToString() == "1";
		}
        public void It_Should_Return_An_Error_When_Trying_To_Map_A_Non_Dictionary()
        {
            // Arrange
            var mapFilter = new MapFilter(new StringValue("field1"));
            IList<IExpressionConstant> objlist = new List<IExpressionConstant>
            {
                NumericValue.Create(123),
                new StringValue("Test")
            };
            // Act
            var result = mapFilter.Apply(new TemplateContext(), new ArrayValue(objlist)).SuccessValue<ArrayValue>();

            // Assert
            Assert.That(result.ArrValue.Count, Is.EqualTo(objlist.Count()));
            Assert.That(result.ArrValue[0].HasValue, Is.False);
            Assert.That(result.ArrValue[1].HasValue, Is.False);
        }
        public void It_Should_Extract_The_Property_From_Each_Element()
        {
            // Arrange
            var array = CreateArray();
            var field = "field1";
            var mapFilter = new MapFilter(new StringValue(field));

            // Act
            var result = mapFilter.Apply(new TemplateContext(), array).SuccessValue<ArrayValue>();

            // Assert
            var dictionaryValues = array.ArrValue.Select(x => x.Value).Cast<DictionaryValue>();

            IEnumerable<String> expected = dictionaryValues.Select(x => x.DictValue[field].Value.Value.ToString());
            //var expected = array.ArrValue.Cast<DictionaryValue>().Select(x => x.DictValue[field].Value.ToString());
            IEnumerable<String> actual = result.Select(x => x.Value.Value.ToString());
            Assert.That(actual, Is.EquivalentTo(expected));
        }
		public async Task<IEnumerable<House>> GetHousesAsync(MapFilter mapFilter)
		{
			var query = new ParseQuery<House>();

//
//			if (mapFilter == MapFilter.RecentlyAdded) {
//				query = query.WhereGreaterThanOrEqualTo("createdAt",DateTime.Today.AddDays(-3));
//			}
			if (mapFilter == MapFilter.Top5) {
				var houses = await  query.FindAsync ();
				return houses.GroupBy (x => x.Likes).OrderByDescending(x=>x.Key).Take (5).SelectMany (x => x);
			}


			var results = await  query.FindAsync ();

			return results;
		}
示例#6
0
        /// <summary>
        /// 查找指定预期服务类型的实际服务类型。
        /// </summary>
        /// <param name="expectType">预期服务类型。</param>
        /// <returns>找到匹配的实际服务类型,或一个 null 值。</returns>
        internal Type FindActualType(Type expectType)
        {
            var defaultMappingAttr = expectType.GetAttribute <DefaultMappingAttribute>();

            if (defaultMappingAttr != null)
            {
                return(defaultMappingAttr.ActualType);
            }

            //- 不支持基类或值类型
            if ((expectType.IsClass && expectType.IsAbstract) || expectType.IsValueType)
            {
                return(null);
            }
            //- 是一个普通类
            if (!expectType.IsInterface)
            {
                return(expectType);
            }
            //- 否则就是一个接口

            //- 获取通过接口名称智能分析出来的所有名称限定符
            var fullNames = this.Get <IActualTypeFactory>().GetAllActualType(expectType);

            //- 从智能映射表中获取(当前程序集)
            foreach (var fullName in fullNames)
            {
                var actualType = expectType.Assembly.GetType(fullName, false);
                if (actualType != null)
                {
                    return(actualType);
                }
            }

            //- 从智能映射表中获取(所有程序集)
            return(MapFilter.FindActualType(ObjectFactory.AllTypes, expectType, fullNames));
        }
示例#7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="bounds"></param>
        public TreeLoader2D(PagedGeometry geom, TBounds bounds)
        {
            //Calculate grid size
            mGeom = geom;
            mPageSize = mGeom.PageSize;

            //Reset height function
            mHeightFunction = null;
            mHeightFunctionUserData = null;

            //Make sure the bounds are aligned with PagedGeometry's grid, so the TreeLoader's grid tiles will have a 1:1 relationship
            mActualBounds = bounds;
            mGridBounds = bounds;

            mGridBounds.Left = (float)(mPageSize * System.Math.Floor((mGridBounds.Left - mGeom.Bounds.Left) / mPageSize) + mGeom.Bounds.Left);
            mGridBounds.Top = (float)(mPageSize * System.Math.Floor((mGridBounds.Top - mGeom.Bounds.Top) / mPageSize) + mGeom.Bounds.Top);
            mGridBounds.Right = (float)(mPageSize * System.Math.Ceiling((mGridBounds.Right - mGeom.Bounds.Left) / mPageSize) + mGeom.Bounds.Left);
            mGridBounds.Bottom = (float)(mPageSize * System.Math.Ceiling((mGridBounds.Bottom - mGeom.Bounds.Top) / mPageSize) + mGeom.Bounds.Top);

            //Calculate page grid size
            mPageGridX = (int)(System.Math.Ceiling(mGridBounds.Width / mPageSize) + 1);
            mPageGridZ = (int)(System.Math.Ceiling(mGridBounds.Height / mPageSize) + 1);

            //Reset color map
            mColorMap = null;
            mColorMapFilter = MapFilter.None;

            //Default scale range
            mMaximumScale = 2.0f;
            mMinimumScale = 0.0f;
        }
示例#8
0
 public IEnumerable <string> GetAllActualType(Type expectType) => MapFilter.GetAllActualType(expectType);
示例#9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="geom"></param>
 /// <param name="ldr"></param>
 internal GrassLayer(PagedGeometry geom, GrassLoader ldr)
 {
     mGeom = geom;
     mParent = ldr;
     mDensity = 1.0f;
     mMinWidth = 1.0f;
     mMinHeight = 1.0f;
     mMaxWidth = 1.0f;
     mMaxHeight = 1.0f;
     mRenderTechnique = GrassTechnique.Quad;
     mFadeTechnique = FadeTechnique.Alpha;
     mAnimMag = 1.0f;
     mAnimSpeed = 1.0f;
     mAnimFreq = 1.0f;
     mWaveCount = 0.0f;
     mAnimate = false;
     mShaderNeedsUpdate = true;
     mDensityMap = null;
     mDensityMapFilter = MapFilter.Bilinear;
     mColorMap = null;
     mColorMapFilter = MapFilter.Bilinear;
 }
示例#10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="channel"></param>
        private DensityMap(Texture texture, MapChannel channel)
        {
            Debug.Assert(texture != null);
            mFilter = MapFilter.Bilinear;

            //Add self to selfList
            mSelfKey = texture.Name + (int)channel;
            mSelfList.Add(mSelfKey, this);
            mRefCount = 0;

            //Get the texture buffer
            HardwarePixelBuffer buff = texture.GetBuffer();

            //Prepare a PixelBox (8-bit greyscale) to receive the density values
            mPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.BYTE_L);
            byte[] pixelData = new byte[mPixels.ConsecutiveSize];
            mPixelPtr = Memory.PinObject(pixelData);
            mPixels.Data = mPixelPtr;

            if (channel == MapChannel.Color)
            {
                //Copy to the greyscale density map directly if no channel extraction is necessary
                buff.BlitToMemory(mPixels);
            }
            else
            {
                unsafe
                {
                    //If channel extraction is necessary, first convert to a PF_R8G8B8A8 format PixelBox
                    //This is necessary for the code below to properly extract the desired channel
                    PixelBox tmpPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.R8G8B8A8);
                    byte[] tmpPix = new byte[tmpPixels.ConsecutiveSize];
                    byte* pixPtr = (byte*)Memory.PinObject(tmpPix);
                    tmpPixels.Data = (IntPtr)pixPtr;
                    buff.BlitToMemory(tmpPixels);

                    //Pick out a channel from the pixel buffer
                    int channelOffset = 0;
                    switch (channel)
                    {
                        case MapChannel.Red:
                            channelOffset = 3;
                            break;
                        case MapChannel.Green:
                            channelOffset = 2;
                            break;
                        case MapChannel.Blue:
                            channelOffset = 1;
                            break;
                        case MapChannel.Alpha:
                            channelOffset = 0;
                            break;
                        default:
                            //should never happen
                            throw new Exception("Invalid channel");
                    }

                    //And copy that channel into the density map
                    byte* inputPtr = (byte*)pixPtr + channelOffset;
                    byte* outputPtr = (byte*)pixPtr + channelOffset;
                    byte* outputEndPtr = outputPtr + mPixels.ConsecutiveSize;
                    while (outputPtr != outputEndPtr)
                    {
                        *outputPtr++ = *inputPtr++;
                        inputPtr += 4;
                    }

                    //Finally, delete the temporary PF_R8G8B8A8 pixel buffer
                    Memory.UnpinObject(tmpPix);
                    tmpPixels = null;
                }
            }
        }
示例#11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="channel"></param>
        private ColorMap(Texture texture, MapChannel channel)
        {
            Debug.Assert(texture != null);
            mFilter = MapFilter.Bilinear;
            //Add self to selfList
            mSelfKey = texture.Name + (int)channel;
            mSelfList.Add(mSelfKey, this);
            mRefCount = 0;

            //Get the texture buffer
            HardwarePixelBuffer buff = texture.GetBuffer();

            #warning Root::getSingleton().getRenderSystem()->getColourVertexElementType();

            //Prepare a PixelBox (24-bit RGB) to receive the color values
            VertexElementType format = VertexElementType.Color_ARGB;
            switch (format)
            {
                case VertexElementType.Color_ARGB:
                    //DirectX9
                    mPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.A8B8G8R8);
                    break;
                case VertexElementType.Color_ABGR:
                    //OpenGL
                    mPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.A8B8G8R8);
                    //Patch for Ogre's incorrect blitToMemory() when copying from PF_L8 in OpenGL
                    if (buff.Format == PixelFormat.L8)
                        channel = MapChannel.Red;
                    break;
                default:
                    throw new Exception("Unknown RenderSystem color format");
            }

            byte[] pixelData = new byte[mPixels.ConsecutiveSize];
            mPixelPtr = Memory.PinObject(pixelData);
            mPixels.Data = mPixelPtr;

            if (channel == MapChannel.Color)
            {
                //Copy to the color map directly if no channel extraction is necessary
                buff.BlitToMemory(mPixels);
            }
            else
            {
                unsafe
                {
                    //If channel extraction is necessary, first convert to a PF_R8G8B8A8 format PixelBox
                    //This is necessary for the code below to properly extract the desired channel
                    PixelBox tmpPixels = new PixelBox(new BasicBox(0, 0, buff.Width, buff.Height), PixelFormat.R8G8B8A8);
                    byte[] tmpPix = new byte[tmpPixels.ConsecutiveSize];
                    byte* pixPtr = (byte*)Memory.PinObject(tmpPix);
                    tmpPixels.Data = (IntPtr)pixPtr;
                    buff.BlitToMemory(tmpPixels);

                    //Pick out a channel from the pixel buffer
                    int channelOffset = 0;
                    switch (channel)
                    {
                        case MapChannel.Red:
                            channelOffset = 3;
                            break;
                        case MapChannel.Green:
                            channelOffset = 2;
                            break;
                        case MapChannel.Blue:
                            channelOffset = 1;
                            break;
                        case MapChannel.Alpha:
                            channelOffset = 0;
                            break;
                        default:
                            //should never happen
                            throw new Exception("Invalid channel");
                    }

                    //And copy that channel into the density map
                    byte* inputPtr = (byte*)pixPtr + channelOffset;
                    byte* outputPtr = (byte*)pixPtr + channelOffset;
                    byte* outputEndPtr = outputPtr + mPixels.ConsecutiveSize;
                    while (outputPtr != outputEndPtr)
                    {
                        *outputPtr++ = *inputPtr;
                        *outputPtr++ = *inputPtr;
                        *outputPtr++ = *inputPtr;
                        *outputPtr++ = 0xFF;	//Full alpha
                        inputPtr += 4;
                    }

                    //Finally, delete the temporary PF_R8G8B8A8 pixel buffer
                    Memory.UnpinObject(tmpPix);
                    tmpPixels = null;
                    tmpPix = null;
                }
            }
        }
示例#12
0
        public void It_Should_Do_The_Same_As_Lookup_When_Dictionary()
        {
            // Arrange
            var dict = DataFixtures.CreateDictionary(1, "Value 1 A", "Value 1 B");
            var field = "field1";
            var mapFilter = new MapFilter(new StringValue(field));

            // Act
            var result = mapFilter.Apply(new TemplateContext(), dict).SuccessValue<StringValue>();

            // Assert
            Assert.That(result, Is.EquivalentTo("Value 1 A"));
        }