/// <summary> ///To Update the device Lock Status (Lock/unlock) /// </summary> /// <param name="Ar"></param> /// <returns></returns> public HttpResponseMessage updateDeviceLockStatus(DeviceLock DL) { ar = new WebApiResponse(); try { string qry = "select * from MDM_DeviceMaster where DeviceID='" + DL.uuid + "'"; dr = databaseHelper.getDataReader(qry); if (dr.Read()) { if (!dr.IsClosed) { dr.Close(); } qry = "delete from MDM_PushNotification where DeviceID='" + DL.uuid + "'"; string qry1 = "update MDM_DeviceMaster set"; if (DL.status == false)//successfully unlocked { // SendSmsOrMail(DL.uuid); //to inform that device is unlocked qry += " and Command ='Unlocked'"; qry1 += " Status=2 "; } else if (DL.status == true)//successfully locked { // SendLockDeviceDetails(DL.uuid);//To send unlock details of locked device by sms/email qry += " and Command ='Locked'"; qry1 += " Status=1 "; } rcnt = databaseHelper.ExecuteQuery(qry); qry1 += " where DeviceID='" + DL.uuid + "'"; rcnt = databaseHelper.ExecuteQuery(qry1); ar.response = true; response = Request.CreateResponse(HttpStatusCode.Created, ar); return(response); } else { ar.errorCode = "Authentication Failed"; ar.response = false; response = Request.CreateResponse(HttpStatusCode.BadRequest, ar); return(response); } } catch (Exception ex) { linfo.LogFile(enLogType.EXCEPTION, ex.Message, null); ar.errorCode = "Device Lock Status Failed"; ar.response = false; response = Request.CreateResponse(HttpStatusCode.BadRequest, ar); } finally { if (dr != null && !dr.IsClosed) { dr.Close(); } } return(response); }
void RenderContents() { // 1) We first lock them. // 2) We process layouting. if (rootObject is IWidget) { // We simply apply bounding rect to it and trigger further processing. (rootObject as IWidget).ApplyBoundingRect(canvas, new Vector2f(0, 0), canvas.CanvasUnitSize); } // 3) We call prerender event. using (DeviceLock l = canvas.Device.Lock()) { Action <GuiManager> t = onPreRender; if (t != null) { t(this); } canvas.Begin(CanvasRenderFlags.None); try { // 4) We render them if (rootObject is IDisplayObject) { RenderObject(rootObject as IDisplayObject); } foreach (IDisplayObject obj in auxilaryObjects) { RenderObject(obj); } } finally { canvas.End(); } // 5) We call rendered event. t = onRendered; if (t != null) { t(this); } } // 6) We unlock them. }
public void PenVG(GraphicsDevice device) { ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f)); // We first create all needed fills. SolidFill solidFill = new SolidFill(Colour.Red); Pen pen = new Pen(solidFill, 0.003f, 0.0f, OutlineEnd.Square); Bezier2f line = new Bezier2f(new Vector2f(0.1f, 0.5f), new Vector2f(0.3f, 1.0f), new Vector2f(0.9f, 0.5f)); Bezier2f line2 = new Bezier2f(new Vector2f(0.1f, 0.5f), new Vector2f(0.3f, 0.0f), new Vector2f(0.9f, 0.5f)); LineSegment2f seg = new LineSegment2f(new Vector2f(0, 0.5f), new Vector2f(0.7f, 0.6f)); bool exit = false; device.SwapChain.Window.Closed += delegate(Window w) { exit = true; }; float a = 0; while (!exit) { device.SwapChain.Window.DoEvents(); using (DeviceLock l = device.Lock()) { device.Clear(device.SwapChain, Colour.Green); device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height)); line.A = 0.5f * new Vector2f(1, 1) + new Vector2f(1, 1) * 0.5f * MathHelper.Cos(a); line2.B = 0.5f * new Vector2f(1, 1) + new Vector2f(1, 1) * 0.5f * MathHelper.Sin(a); // We render. canvas.Begin(CanvasRenderFlags.None); canvas.DrawShape(pen, line, null); canvas.DrawShape(pen, seg, null); canvas.DrawShape(pen, line2, null); canvas.End(); } device.SwapChain.Present(); a += 0.01f; } }
/// <summary> ///To Update the device Lock Status (Lock/unlock) /// </summary> /// <param name="Ar"></param> /// <returns></returns> public HttpResponseMessage updateDeviceLockStatus(DeviceLock DL) { ar = new WebApiResponse(); try { string qry = "select * from MDM_DeviceMaster where DeviceID='" + DL.uuid + "'"; dr = databaseHelper.getDataReader(qry); if (dr.Read()) { if (!dr.IsClosed) dr.Close(); qry = "delete from MDM_PushNotification where DeviceID='" + DL.uuid + "'"; string qry1 = "update MDM_DeviceMaster set"; if (DL.status == false)//successfully unlocked { // SendSmsOrMail(DL.uuid); //to inform that device is unlocked qry += " and Command ='Unlocked'"; qry1 += " Status=2 "; } else if (DL.status == true)//successfully locked { // SendLockDeviceDetails(DL.uuid);//To send unlock details of locked device by sms/email qry += " and Command ='Locked'"; qry1 += " Status=1 "; } rcnt = databaseHelper.ExecuteQuery(qry); qry1 += " where DeviceID='" + DL.uuid + "'"; rcnt = databaseHelper.ExecuteQuery(qry1); ar.response = true; response = Request.CreateResponse(HttpStatusCode.Created, ar); return response; } else { ar.errorCode = "Authentication Failed"; ar.response = false; response = Request.CreateResponse(HttpStatusCode.BadRequest, ar); return response; } } catch (Exception ex) { linfo.LogFile(enLogType.EXCEPTION, ex.Message, null); ar.errorCode = "Device Lock Status Failed"; ar.response = false; response = Request.CreateResponse(HttpStatusCode.BadRequest, ar); } finally { if (dr != null && !dr.IsClosed) dr.Close(); } return response; }
/// <summary> /// Rendering code, forces rendering. /// </summary> public void Render() { lock (syncRoot) { // We do not render if everything is synced. if (!isDirty) { return; } using (DeviceLock l = device.Lock()) { // 1) First fire pre-rendering the event. Action <IWindowManager> t = onPreRendering; if (t != null) { t(this); } // 2) Fullscreen rendering or not if (fullscreenWindow != null) { lock (fullscreenWindow.syncRoot) { // We copy the window's target to ours. compositor.Push(fullscreenWindow.renderData); // We resize (a null operation in most cases). compositor.Resize(renderTarget.Width, renderTarget.Height); // We copy fullscreen application. compositor.CopyTo(renderTarget); } return; } else { // 3) We render background (desktop). desktopManager.Render(); // 4) We render windows in z-order. for (int i = 0; i < windows.Count; i++) { DefaultWindow window = windows[i] as DefaultWindow; lock (window.syncRoot) { // Renders window by compositing image. RenderWindow(window); // We also render title bar. RenderWindowTitleBar(window); } } } // 5) We fire post-rendering event. t = onPostRendering; if (t != null) { t(this); } } } }
unsafe void Flush(bool rebatch) { if (batch.VertexCount == 0) { if (!rebatch) { batch.EndBatch(); } return; } // We flush the buffer, first end batch. batch.EndBatch(); // We update vertex constants. vertexConstants.Map(MapOptions.Write); try { DataTransform vtransform = positionTransforms.Peek(); if (!vtransform.ProcessCPU) { vertexConstants.SetConstant("PositionTransform", Matrix4x4f.CreateTranslate(new Vector3f(-unitSize.X, -unitSize.Y, 0)) * Matrix4x4f.CreateScale(new Vector3f(2.0f, 2.0f, 2.0f)) * vtransform.Transform.RuntimeForm); } else { vertexConstants.SetConstant("PositionTransform", Matrix4x4f.Identity); } DataTransform ttransform = textureTransforms.Peek(); if (!ttransform.ProcessCPU) { vertexConstants.SetConstant("TextureTransform", ttransform.Transform.RuntimeForm); } else { vertexConstants.SetConstant("TextureTransform", Matrix4x4f.Identity); } } finally { vertexConstants.UnMap(); } // Vertex Shader: FixedShaderParameters vparams = vertexShaderCode.FixedParameters; vparams.AddLayout(0, vertexConstants.Layout); VShader vshader = vertexShaderCode.Compile(device, vparams) as VShader; // Pixel Shaders: FixedShaderParameters pparams = pixelShaderCode.FixedParameters; // We set interfaces. pparams.SetInterfaceArray("Fills", fills); // We now set per parameter data. ConstantBufferLayoutBuilder builder = new ConstantBufferLayoutBuilder(); List <TextureView> textures = new List <TextureView>(); List <SamplerState> samplers = new List <SamplerState>(); // We add per-fill data. for (int i = 0; i < fills.Count; i++) { IFill fill = fills[i]; string prefix = string.Format("Fills[{0}]", i); InterfaceHelper.ApplyInterfaceConstants(prefix, fill, builder, pparams, textures, samplers, fill.ParameterValues); } // We create view and fill data. ConstantBufferLayout layout = builder.CreateLayout(); ConstantBufferView pixelConstantsView = pixelConstants.CreateConstantBuffer(layout); pparams.AddLayout(0, layout); // TODO: this may not be needed for optimized setting. pixelConstantsView.Map(MapOptions.Write); try { for (int i = 0; i < fills.Count; i++) { IFill fill = fills[i]; string prefix = string.Format("Fills[{0}]", i); InterfaceHelper.FillInterfaceConstants(prefix, fill, pixelConstantsView, fill.ParameterValues); } } finally { pixelConstantsView.UnMap(); } // Finally compile. PShader pshader = pixelShaderCode.Compile(device, pparams) as PShader; using (DeviceLock devLock = device.Lock()) { // We now draw using data, set all states. device.SetBlendState(blendState, Colour.Black, 0xFFFFFFFF); device.SetDepthStencilState(depthStencilState, 0); device.SetRasterizationState(rasterizationState); if (viewport.Width == viewport.Height && viewport.Height == 0) { device.Viewport = new Region2i(new Vector2i(0, 0), new Vector2i((int)renderTarget.Width, (int)renderTarget.Height)); } else { device.Viewport = viewport; } // We bind stages. device.SetVertexShader(vshader, batch, null, null, new ConstantBufferView[] { vertexConstants }); device.SetPixelShader(pshader, samplers.ToArray(), textures.ToArray(), new ConstantBufferView[] { pixelConstantsView }, new RenderTargetView[] { renderTarget }, null); device.SetGeometryShader(null, null, null, null, null); // We now draw. device.DrawIndexed(0, batch.IndexCount, 0); // We clear state. device.SetVertexShader(null, null, null, null, null); device.SetPixelShader(null, null, null, null, null, null); } pixelConstantsView.Dispose(); // Fills and data is irrelavant. fills.Clear(); // We rebatch if not completelly ended. if (rebatch) { batch.BeginBatch(); } }
/// <summary> /// Composites to source. /// </summary> /// <param name="compositeOperation"></param> public void CompositeToSource(ICompositingOperation compositeOperation, BlendState blendOverwrite, Colour blendColour, Region2i viewport, RenderTargetView target) { // 1) We first prepare the providers. List <ICompositingOperation> relavantOperations = new List <ICompositingOperation>(); ListOperations(compositeOperation, relavantOperations); // 2) We extract processors. List <ICompositeInterface> processors = new List <ICompositeInterface>(relavantOperations.Count); for (int i = 0; i < relavantOperations.Count; i++) { processors.Add(relavantOperations[i].Interface); } // 3) We prepare the shader. ShaderCode pshader = PixelShader; ShaderCode vshader = VertexShader; States.BlendState bstate = blendOverwrite != null ? blendOverwrite : DefaultBlendState; States.DepthStencilState dstate = DefaultDepthStencilState; States.RasterizationState rstate = DefaultRasterizationState; FixedShaderParameters pparams = pshader.FixedParameters; FixedShaderParameters vparams = vshader.FixedParameters; ConstantBufferLayoutBuilder builder = new ConstantBufferLayoutBuilder(); List <TextureView> textures = new List <TextureView>(); List <States.SamplerState> samplers = new List <States.SamplerState>(); // We set interface array. pparams.SetInterfaceArray("Composite", processors); builder.AppendElement("Offset", PinFormat.Floatx2); // 4) We fill parameters and builder. for (int i = 0; i < processors.Count; i++) { string name = string.Format("Composite[{0}]", i); InterfaceHelper.ApplyInterfaceConstants(name, processors[i], builder, pparams, textures, samplers, processors[i].ParameterValues); } // 5) We obtain layout big enough. ConstantBufferLayout layout = builder.CreateLayout(); pparams.AddLayout(0, layout); ConstantBufferView constantBuffer = pixelTypelessConstantBuffer.CreateConstantBuffer(layout); // 6) We fill buffer. constantBuffer.Map(MapOptions.Write); try { constantBuffer.SetConstant("Offset", new Vector2f((float)viewport.X, (float)viewport.Y)); for (int i = 0; i < processors.Count; i++) { InterfaceHelper.FillInterfaceConstants(string.Format("Composite[{0}]", i), processors[i], constantBuffer, processors[i].ParameterValues); } } finally { constantBuffer.UnMap(); } // 7) We prepare geometry. // We get quad geometry Geometry geometry = alignedQuad; // ) We render the composition. GraphicsDevice device = Device; using (DeviceLock l = device.Lock()) { // We set our state objects. device.SetBlendState(bstate, blendColour, 0xFFFFFFFF); device.SetDepthStencilState(dstate, 0); device.SetRasterizationState(rstate); device.Viewport = viewport; // We prepare to render. device.SetVertexShader(vshader.Compile(device, vparams) as VShader, geometry, null, null, null); device.SetGeometryShader(null, null, null, null, null); device.SetPixelShader(pshader.Compile(device, pparams) as PShader, samplers.ToArray(), textures.ToArray(), new ConstantBufferView[] { constantBuffer }, new RenderTargetView[] { target }, null); // We render it. if (geometry.IndexBuffer != null) { device.DrawIndexed(0, 6, 0); } else { device.Draw(0, 6); } device.SetPixelShader(null, null, null, null, null, null); } // We do not use constant buffer anymore. constantBuffer.Dispose(); }
/// <summary> /// Composites to source 2. /// </summary> /// <param name="compositeOperation"></param> public void CompositeToSource2(IBinaryOperation compositeOperation, BlendState blendOverwrite, Vector2f minCoord, Vector2f maxCoord) { // 1) We first prepare the providers. List <IOperation> relavantOperations = CompositionHelper.RelavantOperations(compositeOperation); // 2) We extract processors. List <ICompositeInterface> processors = new List <ICompositeInterface>(relavantOperations.Count + 1); for (int i = 0; i < relavantOperations.Count; i++) { processors.Add(relavantOperations[i].PixelProcessor); } processors.Add(compositeOperation.PixelProcessor); // 3) We prepare the shader. ShaderCode pshader = PixelShader; ShaderCode vshader = VertexShader; States.BlendState bstate = blendOverwrite != null ? blendOverwrite : DefaultBlendState; States.DepthStencilState dstate = DefaultDepthStencilState; States.RasterizationState rstate = DefaultRasterizationState; FixedShaderParameters pparams = pshader.FixedParameters; FixedShaderParameters vparams = vshader.FixedParameters; ConstantBufferLayoutBuilder builder = new ConstantBufferLayoutBuilder(); List <TextureView> textures = new List <TextureView>(); List <States.SamplerState> samplers = new List <States.SamplerState>(); // We set interface array. pparams.SetInterfaceArray("Composite", processors); // 4) We fill parameters and builder. for (int i = 0; i < processors.Count; i++) { string name = string.Format("Composite[{0}]", i); InterfaceHelper.ApplyInterfaceConstants(name, processors[i], builder, pparams, textures, samplers, processors[i].ParameterValues); } // 5) We obtain layout big enough. ConstantBufferLayout layout = builder.CreateLayout(); pparams.AddLayout(0, layout); ConstantBufferView constantBuffer = ResourceProvider.Provide(layout.MinimumBufferSizeInBytes).CreateConstantBuffer(layout); // 6) We fill buffer. constantBuffer.Map(MapOptions.Write); try { for (int i = 0; i < processors.Count; i++) { InterfaceHelper.FillInterfaceConstants(string.Format("Composite[{i}]", i), processors[i], constantBuffer, processors[i].ParameterValues); } } finally { constantBuffer.UnMap(); } // 7) We prepare geometry. // We create quad geometry Geometry geometry = CreateQuadGeometry(minCoord, maxCoord); // ) We render the composition. GraphicsDevice device = Device; using (DeviceLock l = device.Lock()) { // We set our state objects. device.SetBlendState(bstate, Colour.White, 0xFFFFFFFF); device.SetDepthStencilState(dstate, 0); device.SetRasterizationState(rstate); // We prepare to render. device.SetVertexShader(vshader.Compile(device, vparams) as VShader, geometry, null, null, null); device.SetGeometryShader(null, null, null, null, null); device.SetPixelShader(pshader.Compile(device, pparams) as PShader, samplers.ToArray(), textures.ToArray(), new ConstantBufferView[] { constantBuffer }, new RenderTargetView[] { compositeOperation.Source2.DestinationView }, null); // We render it. if (geometry.IndexBuffer != null) { device.DrawIndexed(0, 6, 0); } else { device.Draw(0, 6); } } // We do not use constant buffer anymore. ResourceProvider.Unused(constantBuffer.TypelessResource as TypelessBuffer); }
public void SimpleVG(GraphicsDevice device) { ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f)); // We first create all needed fills. SolidFill solidFill = new SolidFill(); solidFill.Colour = Colour.LightBlue; GradientFill graFill = GradientFill.CreateGradient( new Colour[] { new Colour(13, 185, 242, 255), new Colour(191, 234, 21, 255), new Colour(112, 62, 193, 255), new Colour(255, 242, 81, 255) }, new float[] { 0.30f, 0.60f }, new Vector2f(1, 1)); TextureFill texFill = new TextureFill(CreateSampleTexture()); RadialFill radFill = new RadialFill(new Vector2f(0.75f, 0.75f), 0.15f, Colour.White, Colour.Black); Quad2f rect = new Quad2f(Vector2f.Zero, new Vector2f(0.5f, 0), new Vector2f(0.5f, 0.5f), new Vector2f(0.0f, 0.5f)); Quad2f rect2 = new Quad2f(new Vector2f(0.5f, 0.5f), new Vector2f(1, 0.5f), new Vector2f(1, 1), new Vector2f(0.5f, 1.0f)); bool exit = false; device.SwapChain.Window.Closed += delegate(Window w) { exit = true; }; float a = 0; while (!exit) { device.SwapChain.Window.DoEvents(); using (DeviceLock l = device.Lock()) { device.Clear(device.SwapChain, Colour.Green); device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height)); // We render. canvas.Begin(CanvasRenderFlags.None); canvas.FillShape(solidFill, rect, null); canvas.FillShape(radFill, rect2, null); canvas.Transform = new LinearTransform( new Math.Matrix.Matrix4x4f(Math.MathHelper.Cos(a), -Math.MathHelper.Sin(a), 0, 0, Math.MathHelper.Sin(a), Math.MathHelper.Cos(a), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)); canvas.FillShape(graFill, rect, null); canvas.FillShape(texFill, rect2, null); canvas.End(); } Console.WriteLine("FPS: {0}\nTrig Count: {1}", device.DevicePerformance.CurrentFPS, device.DevicePerformance.MaxTrianglesPerFrame); a += 0.003f; device.SwapChain.Present(); } texFill.Texture.Dispose(); }
public void FontRendering2(GraphicsDevice device) { using (ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f))) { // We first create all needed fills. //RadialFill solidFill = new RadialFill(new Vector2f(0.2f, 0.3f), .4f, Colour.Blue, Colour.LightBlue); SolidFill solidFill = new SolidFill(Colour.Black); Font font = new Font(SVGFontProvider.ImportSVG("vera.svg")); Pen pen = new Pen(solidFill, 0.007f, 0.0f, OutlineEnd.Square); bool exit = false; device.SwapChain.Window.Closed += delegate(Window w) { exit = true; }; string txt = "ABC�DEFGHIJKLMNOPRS�TUVZ�abc�defghijklmnoprs�tuvz�123456789!?";//"CFGHIJKLMNSTUVZ��cfhklijmnstuvz��12357"; float a = 0, b = 0; while (!exit) { device.SwapChain.Window.DoEvents(); using (DeviceLock l = device.Lock()) { device.Clear(device.SwapChain, Colour.White); device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height)); DateTime time = DateTime.Now; // We render. canvas.Begin(CanvasRenderFlags.None); font.Render(pen.Fill, canvas, txt, 0.1f, TextOptions.UseCanvasUnits | TextOptions.Top, 1.5f, new Vector2f(0, 0), new Vector2f(1, 1)); canvas.End(); span += DateTime.Now - time; Console.WriteLine("Span 1: {0}", span.TotalSeconds); } device.SwapChain.Present(); Console.WriteLine("FPS: {0}\nTrig Count: {1}", device.DevicePerformance.CurrentFPS, device.DevicePerformance.MaxTrianglesPerFrame); a += 0.002f; b += 0.01f; /* * if (a > 0.005f) * { * txt += (char)(txt[txt.Length - 1] + 1); * a = 0; * }*/ } } }
public void FontRendering(GraphicsDevice device) { ICanvas canvas = new GraphicsCanvas(device, device.SwapChain, new Vector2f(1.0f, 1.0f)); // We first create all needed fills. RadialFill solidFill = new RadialFill(new Vector2f(0.2f, 0.3f), .4f, Colour.Blue, Colour.LightBlue); Font font = new Font(SVGFontProvider.ImportSVG("vera.svg")); Pen pen = new Pen(solidFill, 0.01f, 0.0f, OutlineEnd.Square); bool exit = false; device.SwapChain.Window.Closed += delegate(Window w) { exit = true; }; float a = 0; while (!exit) { device.SwapChain.Window.DoEvents(); using (DeviceLock l = device.Lock()) { device.Clear(device.SwapChain, Colour.Green); device.SetViewports(new Region2i(0, 0, (int)device.SwapChain.Width, (int)device.SwapChain.Height)); // We render. canvas.Begin(CanvasRenderFlags.None); canvas.PixelErrorTolerance = 0.01f + 0.001f * a; Vector2f[] polygon1 = new Vector2f[] { new Vector2f(0.1f, 0.1f), new Vector2f(0.9f, 0.1f), new Vector2f(0.9f, 0.9f), new Vector2f(0.15f, 0.9f), new Vector2f(0.5f, 0.5f), new Vector2f(0.2f, 0.5f), new Vector2f(0.1f, 0.9f) }; Vector2f[] polygon2 = new Vector2f[] { new Vector2f(0, 0), new Vector2f(0.1f, 0f), new Vector2f(0.2f, 0.2f), new Vector2f(0.54f, 0.2f), new Vector2f(0.61f, 0.0f), new Vector2f(0.72f, 0.0f), new Vector2f(0.42f, 0.8f), new Vector2f(0.37f, 0.7f), new Vector2f(0.51f, 0.29f), new Vector2f(0.22f, 0.3f), new Vector2f(0.37f, 0.71f), new Vector2f(0.42f, 0.81f), new Vector2f(0.3f, 0.8f) }; canvas.FillShape(solidFill, new Polygon2f(polygon2), null); //canvas.FillShape(solidFill, polygon2); //canvas.DrawShape(pen, outline); canvas.End(); } device.SwapChain.Present(); a += 0.01f; } }