public string Receipt(Format format) { var totalAmount = 0d; var reportLines = new TupleList<Line, string>(); foreach (var line in _lines) { var thisAmount = 0d; thisAmount += CalculateAmountPlusDiscount(line.Bike, line.Quantity); reportLines.Add(line, thisAmount.ToString("C")); totalAmount += thisAmount; } var tax = totalAmount * TaxRate; var data = new ReceiptData(Company, totalAmount.ToString("C"), reportLines, tax.ToString("C"), (totalAmount + tax).ToString("C")); if (format == Format.Text) return new TextReceipt(data).TransformText(); else if (format == Format.HTML) return new HtmlReceipt(data).TransformText(); else if (format == Format.PDF) { return new PdfReceipt(data).TransformText(); } else throw new Exception("Unsupported format type!"); }
/// <summary> /// Convert position name to coordinates. /// /// Example: /// format(8, 12) /// "12" -> Point(0,11) /// "13" -> Point(1,0) /// "52" -> Point(4,3) /// </summary> /// <param name="pos">The position.</param> /// <param name="format">Arbitrary format of the <see cref="Plate"/></param> /// <returns><see cref="Point"/> of given coordinates</returns> public Point GetCoords(int pos, Format format) { if (pos > 0) { var point = new Point(); if (pos >= format.Width * format.Height) { point.X = format.Height - 1; point.Y = format.Width - 1; } else { point.X = pos / format.Width; point.Y = pos % format.Width; if (point.Y == 0) { point.Y = format.Width; point.X = point.X > 0 ? point.X - 1 : point.X; } point.X = point.X >= format.Height ? (format.Height - 1) : point.X; point.Y = point.Y >= format.Width ? (format.Width - 1) : (point.Y - 1); } return point; } return new Point(0, 0); }
/// <summary> /// Provides an interface to the /api/v2/movie_details yify API. /// </summary> /// <param name="movieId">Sets the id of the movie details which are to be queried.</param> /// <param name="withImages">Sets wether the response should hold images.</param> /// <param name="withCast">Sets wether the response should hold information about the cast.</param> /// <param name="format">Sets the format in which to display the results in. DO NOT USE ANYTHING OTHER THAN JSON! (Experimental)</param> /// <returns>The ApiResponse representing the query result.</returns> public static ApiResponse<MovieDetailsData> GetMovieDetails(int movieId, bool withImages = false, bool withCast = false, Format format = Format.JSON) { string apiReq = string.Format("movie_id={0}&with_images={1}&with_cast={2}", movieId, withImages, withCast); // Getting the response Stream stream; try { stream = WebRequest.Create(string.Format("https://yts.to/api/v2/movie_details.{0}?{1}", ParseFormat(format), apiReq)) .GetResponse() .GetResponseStream(); using (StreamReader sr = new StreamReader(stream)) { // Parsing the response and returning it return new ApiResponse<MovieDetailsData>(JsonConvert.DeserializeObject<ApiResponseRaw>(sr.ReadToEnd())); } } catch (WebException) { // No internet connection throw new Exception("No internet connection."); } }
public PrintCmd(Format format, string expression, Action<object> callback, GDBSubProcess gdbProc) : base(gdbProc) { _format = format; _expression = expression; _rh = new PrintRH(format, callback, _gdbProc); }
public DX11RenderTexture3D(DX11RenderContext context, int w, int h, int d, Format format) : base(context) { Texture3DDescription desc = new Texture3DDescription() { BindFlags = BindFlags.UnorderedAccess | BindFlags.ShaderResource | BindFlags.RenderTarget, CpuAccessFlags = CpuAccessFlags.None, Depth = d, Format = format, Height = h, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default, Width = w }; RenderTargetViewDescription rtvd = new RenderTargetViewDescription(); rtvd.Dimension = RenderTargetViewDimension.Texture3D; rtvd.MipSlice = 0; rtvd.FirstDepthSlice = 0; rtvd.DepthSliceCount = d; this.Resource = new Texture3D(context.Device, desc); this.SRV = new ShaderResourceView(context.Device, this.Resource); this.UAV = new UnorderedAccessView(context.Device, this.Resource); this.RTV = new RenderTargetView(context.Device, this.Resource, rtvd); this.Width = desc.Width; this.Height = desc.Height; this.Format = desc.Format; this.Depth = desc.Depth; }
public SoundResource(ResourceManager mgr, string fullName, Stream stream, Format fmt) { _manager = mgr; FullName = fullName; switch (fmt) { case Format.MP3: { Mp3FileReader mp3 = new Mp3FileReader(stream); _reader = mp3; break; } case Format.WAV: { WaveFileReader wav = new WaveFileReader(stream); _reader = wav; break; } default: throw new InvalidOperationException("Unsupported extension."); } _stream = new WaveChannel32(_reader); _stream.PadWithZeroes = false; _wavDevice.PlaybackStopped += _wavDevice_PlaybackStopped; }
public RenderTarget(Device device, int width, int height, int sampleCount, int sampleQuality, Format format) : this() { Texture = _disposer.Add(new Texture2D(device, new Texture2DDescription { Format = format, Width = width, Height = height, ArraySize = 1, MipLevels = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default, SampleDescription = new SampleDescription(sampleCount, sampleQuality), })); RenderTargetView = _disposer.Add(new RenderTargetView(device, Texture, new RenderTargetViewDescription { Format = format, Dimension = RenderTargetViewDimension.Texture2DMultisampled, //MipSlice = 0, })); ShaderResourceView = _disposer.Add(new ShaderResourceView(device, Texture)); Viewport = new Viewport(0, 0, width, height, 0.0f, 1.0f); }
internal static OpenGL.PixelInternalFormat GetInternalFormat(Format format) { if (!FormatTranslator.ContainsKey(format) || FormatTranslator[format] == null) { throw new NotImplementedException("The InternalFormat '" + format + "' is not currently supported."); } return FormatTranslator[format].InternalFormat; }
public static Imaging.PixelFormat GetPixelFormat(Format format) { if (!FormatTranslator.ContainsKey(format) || FormatTranslator[format] == null) { throw new NotImplementedException("The PixelFormat '" + format + "' is not currently supported."); } return FormatTranslator[format].PixelFormat; }
public Direct2DRenderTarget(DeviceContext10_1 deviceContext10, Surface surface, Format format = Format.B8G8R8A8_UNorm) { m_deviceContext10 = deviceContext10; m_surface = surface; m_format = format; InitializeResources(surface); }
public Raw(string path, Size3i size, Format format) { using (var stream = File.OpenRead(path)) { Load(stream, size, format); } }
public void Save(string Path, JSONObject JSON, Format Format) { Serializer s = new Serializer(); string text = s.GetText(JSON); text = s.FormatText(text, Format); File.WriteAllText(Path, text); }
public void Bind(ProgramAttribute attribute, GraphicsBuffer buffer, int offsetInBytes, Format format, int stride) { if (attribute == null) throw new ArgumentNullException("attribute"); throw new NotImplementedException(); //GLExt.VertexAttribFormat(attribute.Index, format.ComponentCount, format.VertexAttribPonterType, format.IsNormalized, offsetInBytes); }
public static bool TryFormat(this DateTime value, Span<byte> buffer, Format.Parsed format, EncodingData formattingData, out int bytesWritten) { if (format.IsDefault) { format.Symbol = 'G'; } Precondition.Require(format.Symbol == 'R' || format.Symbol == 'O' || format.Symbol == 'G'); switch (format.Symbol) { case 'R': var utc = value.ToUniversalTime(); if (formattingData.IsUtf16) { return TryFormatDateTimeRfc1123(utc, buffer, EncodingData.InvariantUtf16, out bytesWritten); } else { return TryFormatDateTimeRfc1123(utc, buffer, EncodingData.InvariantUtf8, out bytesWritten); } case 'O': if (formattingData.IsUtf16) { return TryFormatDateTimeFormatO(value, true, buffer, EncodingData.InvariantUtf16, out bytesWritten); } else { return TryFormatDateTimeFormatO(value, true, buffer, EncodingData.InvariantUtf8, out bytesWritten); } case 'G': return TryFormatDateTimeFormagG(value, buffer, formattingData, out bytesWritten); default: throw new NotImplementedException(); } }
public DX11RenderMip3D(DX11RenderContext context, int w, int h,int d, Format format) : base(context) { int levels = this.CountMipLevels(w,h,d); var texBufferDesc = new Texture3DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = h, Width = w, Depth = d, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default, MipLevels = levels, }; this.Resource = new Texture3D(context.Device, texBufferDesc); this.Width = w; this.Height = h; this.Depth = d; this.SRV = new ShaderResourceView(context.Device, this.Resource); this.Slices = new DX11MipSliceRenderTarget[levels]; int sw = w; int sh = h; int sd = d; for (int i = 0; i < levels; i++) { this.Slices[i] = new DX11MipSliceRenderTarget(this.context, this, i, w, h,d); w /= 2; h /= 2; d /= 2; } }
internal static bool TryFormatUInt64(ulong value, byte numberOfBytes, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten) { if(format.Symbol == 'g') { format.Symbol = 'G'; } if (format.IsHexadecimal && formattingData.IsUtf16) { return TryFormatHexadecimalInvariantCultureUtf16(value, buffer, format, out bytesWritten); } if (format.IsHexadecimal && formattingData.IsUtf8) { return TryFormatHexadecimalInvariantCultureUtf8(value, buffer, format, out bytesWritten); } if ((formattingData.IsInvariantUtf16) && (format.Symbol == 'D' || format.Symbol == 'G')) { return TryFormatDecimalInvariantCultureUtf16(value, buffer, format, out bytesWritten); } if ((formattingData.IsInvariantUtf8) && (format.Symbol == 'D' || format.Symbol == 'G')) { return TryFormatDecimalInvariantCultureUtf8(value, buffer, format, out bytesWritten); } return TryFormatDecimal(value, buffer, format, formattingData, out bytesWritten); }
/// <summary> /// Document: http://dev.twitter.com/doc/get/search /// Supported formats: json, atom /// Supported request methods: GET /// Requires Authentication: false /// Rate Limited: true /// Required Parameters: q /// </summary> /// <param name="extension">atomに対応</param> /// <param name="options">Documentを参照してください</param> /// <returns></returns> public static IEnumerable<Status> Execute(Format extension, params string[] options) { string query = TwitterUtility.GetQuery(ApiSelector.Search, extension, options); switch (extension) { case Format.Atom: using (XmlReader reader = XmlReader.Create(query)) { SyndicationFeed feed = SyndicationFeed.Load(reader); foreach (var e in feed.Items) { yield return new Status(e); } } break; case Format.Json: // まだ途中 string context = ModelUtility.DownloadContext(query); var serializer = new JavaScriptSerializer(); var results = serializer.Deserialize<Dictionary<string, object>>(context)["results"]; foreach (Dictionary<string, object> status in results as ArrayList) { yield return new Status(status, CreatedAtFormatType.Search); } break; default: throw new NotImplementedException(); } }
public LayerTerrainComponent(PlanarTerrain terrain, Format format) : base(terrain) { if (format == null) throw new ArgumentNullException("format"); Format = format; }
internal static bool TryFormatInt64(long value, byte numberOfBytes, Span<byte> buffer, Format.Parsed format, FormattingData formattingData, out int bytesWritten) { Precondition.Require(numberOfBytes <= sizeof(long)); if (value >= 0) { return TryFormatUInt64(unchecked((ulong)value), numberOfBytes, buffer, format, formattingData, out bytesWritten); } else if (format.IsHexadecimal) { ulong bitMask = GetBitMask(numberOfBytes); return TryFormatUInt64(unchecked((ulong)value) & bitMask, numberOfBytes, buffer, format, formattingData, out bytesWritten); } else { int minusSignBytes = 0; if(!formattingData.TryWriteSymbol(FormattingData.Symbol.MinusSign, buffer, out minusSignBytes)) { bytesWritten = 0; return false; } int digitBytes = 0; if(!TryFormatUInt64(unchecked((ulong)-value), numberOfBytes, buffer.Slice(minusSignBytes), format, formattingData, out digitBytes)) { bytesWritten = 0; return false; } bytesWritten = digitBytes + minusSignBytes; return true; } }
protected Plot(string title, long slice, Dictionary<string, List<PointF>> seriesPoints, int height, int width, Format format) { _title = title; _slice = slice; _seriesPoints = seriesPoints; _imageFormat = format; }
public DX11SwapChain(DX11RenderContext context, IntPtr handle, Format format, SampleDescription sampledesc) { this.context = context; this.handle = handle; SwapChainDescription sd = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), format), IsWindowed = true, OutputHandle = handle, SampleDescription = sampledesc, SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput | Usage.ShaderInput, Flags = SwapChainFlags.None }; if (sd.SampleDescription.Count == 1 && context.IsFeatureLevel11) { sd.Usage |= Usage.UnorderedAccess; this.allowuav = true; } this.swapchain = new SwapChain(context.Device.Factory, context.Device, sd); this.Resource = Texture2D.FromSwapChain<Texture2D>(this.swapchain, 0); this.context.Factory.SetWindowAssociation(handle, WindowAssociationFlags.IgnoreAltEnter); this.RTV = new RenderTargetView(context.Device, this.Resource); this.SRV = new ShaderResourceView(context.Device, this.Resource); if (this.allowuav) { this.UAV = new UnorderedAccessView(context.Device, this.Resource); } this.desc = this.Resource.Description; }
public DX11CubeDepthStencil(DX11RenderContext context, int size, SampleDescription sd, Format format) { this.context = context; var texBufferDesc = new Texture2DDescription { ArraySize = 6, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = DepthFormatsHelper.GetGenericTextureFormat(format), Height = size, Width = size, OptionFlags = ResourceOptionFlags.TextureCube, SampleDescription = sd, Usage = ResourceUsage.Default, MipLevels = 1 }; this.Resource = new Texture2D(context.Device, texBufferDesc); this.desc = texBufferDesc; //Create faces SRV/RTV this.SliceDSV = new DX11SliceDepthStencil[6]; ShaderResourceViewDescription svd = new ShaderResourceViewDescription() { Dimension = ShaderResourceViewDimension.TextureCube, Format = DepthFormatsHelper.GetSRVFormat(format), MipLevels = 1, MostDetailedMip = 0, First2DArrayFace = 0 }; DepthStencilViewDescription dsvd = new DepthStencilViewDescription() { ArraySize= 6, Dimension = DepthStencilViewDimension.Texture2DArray, FirstArraySlice = 0, Format = DepthFormatsHelper.GetDepthFormat(format), MipSlice = 0 }; this.DSV = new DepthStencilView(context.Device, this.Resource, dsvd); if (context.IsFeatureLevel11) { dsvd.Flags = DepthStencilViewFlags.ReadOnlyDepth; if (format == Format.D24_UNorm_S8_UInt) { dsvd.Flags |= DepthStencilViewFlags.ReadOnlyStencil; } this.ReadOnlyDSV = new DepthStencilView(context.Device, this.Resource, dsvd); } this.SRV = new ShaderResourceView(context.Device, this.Resource, svd); for (int i = 0; i < 6; i++) { this.SliceDSV[i] = new DX11SliceDepthStencil(context, this, i, DepthFormatsHelper.GetDepthFormat(format)); } }
public DX11RenderMip2D(DX11RenderContext context, int w, int h, Format format) { this.context = context; int levels = this.CountMipLevels(w,h); var texBufferDesc = new Texture2DDescription { ArraySize = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = h, Width = w, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, MipLevels = levels, }; this.Resource = new Texture2D(context.Device, texBufferDesc); this.desc = this.Resource.Description; this.SRV = new ShaderResourceView(context.Device, this.Resource); this.Slices = new DX11MipSliceRenderTarget[levels]; int sw = w; int sh = h; for (int i = 0; i < levels; i++) { this.Slices[i] = new DX11MipSliceRenderTarget(this.context, this, i, w, h); w /= 2; h /= 2; } }
public ReadTexture(int width, int height, uint handle, EnumEntry formatEnum, EnumEntry usageEnum) { Format format; if (formatEnum.Name == "INTZ") format = D3DX.MakeFourCC((byte)'I', (byte)'N', (byte)'T', (byte)'Z'); else if (formatEnum.Name == "RAWZ") format = D3DX.MakeFourCC((byte)'R', (byte)'A', (byte)'W', (byte)'Z'); else if (formatEnum.Name == "RESZ") format = D3DX.MakeFourCC((byte)'R', (byte)'E', (byte)'S', (byte)'Z'); else if (formatEnum.Name == "No Specific") throw (new Exception("Texture mode not supported")); else format = (Format)Enum.Parse(typeof(Format), formatEnum, true); var usage = Usage.Dynamic; if (usageEnum.Index == (int)(TextureType.RenderTarget)) usage = Usage.RenderTarget; else if (usageEnum.Index == (int)(TextureType.DepthStencil)) usage = Usage.DepthStencil; this.FWidth = width; this.FHeight = height; this.FHandle = (IntPtr)unchecked((int)handle); this.FFormat = format; this.FUsage = usage; Initialise(); }
public DX11RenderTextureArray(DX11RenderContext context, int w, int h, int elemcnt, Format format) { this.context = context; var texBufferDesc = new Texture2DDescription { ArraySize = elemcnt, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = h, Width = w, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1,0), Usage = ResourceUsage.Default, }; this.Resource = new Texture2D(context.Device, texBufferDesc); RenderTargetViewDescription rtd = new RenderTargetViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Dimension = RenderTargetViewDimension.Texture2DArray, Format = format }; ShaderResourceViewDescription srvd = new ShaderResourceViewDescription() { ArraySize = elemcnt, FirstArraySlice = 0, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = format, MipLevels = 1, MostDetailedMip = 0 }; this.SRV = new ShaderResourceView(context.Device, this.Resource, srvd); this.RTV = new RenderTargetView(context.Device, this.Resource, rtd); this.SRVArray = new ShaderResourceView[elemcnt]; ShaderResourceViewDescription srvad = new ShaderResourceViewDescription() { ArraySize = 1, Dimension = ShaderResourceViewDimension.Texture2DArray, Format = format, MipLevels = 1, MostDetailedMip = 0 }; for (int i = 0; i < elemcnt; i++) { srvad.FirstArraySlice = i; this.SRVArray[i] = new ShaderResourceView(context.Device, this.Resource, srvad); } this.desc = texBufferDesc; }
public void RegisterTexture(string textureName, int width, int height, Format format, MyCatalogTextureType type) { m_textureKeysCatalog.Add(textureName, new MyTextureKeyIdentity() { Type = type, Key = new MyBorrowedTextureKey() { Width = width, Height = height, Format = format } }); }
protected override void ReplaceRawRange(IRange range, string replacement, Format format) { System.Diagnostics.Trace.Assert(range.Start >= 0); System.Diagnostics.Trace.Assert(range.End <= TextBox.TextLength); SelectRawRange(range, format); TextBox.SelectedText = replacement; }
/// <summary> /// Row name index starting with 1. Returns 1 for all negative integers. /// </summary> /// <param name="row">Internal row index starting with 0.</param> /// <param name="format">Arbitrary format of the <see cref="Plate"/></param> /// <returns> /// Row name string. /// </returns> public virtual string GetRowName(int row, Format format) { return row <= 0 ? "1" : row >= format.Height ? (format.Height - 1).ToString(CultureInfo.InvariantCulture) : (row + 1).ToString(CultureInfo.InvariantCulture); }
/// <summary> /// Column name for given position naming. /// </summary> /// <param name="col">Internal column index starting with 0.</param> /// <param name="format">Arbitrary format of the <see cref="Plate"/></param> /// <returns> /// Column name string /// </returns> public virtual string GetColName(int col, Format format) { return col <= 0 ? "1" : col >= format.Width ? (format.Width - 1).ToString(CultureInfo.InvariantCulture) : (col + 1).ToString(CultureInfo.InvariantCulture); }
public StagingTexture(Device device, int width, int height, Format format = Format.B8G8R8A8_UNorm, ResourceOptionFlags optionFlags = ResourceOptionFlags.None) : base(new Texture2D(device, CreateTextureDescription(width, height, format, optionFlags))) { }
public static bool TryFormat(this float value, Span <byte> buffer, Span <char> format, EncodingData formattingData, out int bytesWritten) { Format.Parsed parsedFormat = Format.Parse(format); return(TryFormat(value, buffer, parsedFormat, formattingData, out bytesWritten)); }