Build a Badge Service (Badge) Wheel, badgeservice

Source: Internet
Author: User

Build a Badge Service (Badge) Wheel, badgeservice
What is Badge Service?

Careful readers must have seen badges on many Github Repo and npm package pages. What are these badges?

The left side of the Badge I referenced above isDownloads,Build,DependencyIt is easy to guess that these Badge are used for statistics of some information and then displayed as an image. For example, a small project of mine, Delta, was written in js. I used Travis CI for continuous compilation and testing. Every time I checkin a new code, Travis CI will build the latest code, and then draw the build result into a vector image, put it inhttps://travis-ci.org/rebornix/delta.svg. So the students will be able to see the recent build of the project from my project homepage in a timely manner. If the build fails, they will be able to blow me up.

In fact, this is a gadget that turns numbers into an image.

Shield Badge

To make friends in the. NET world as cool as front-end friends, we decided to provide such services in Visual Studio Gallery. Soon I wrote a version to generate PNG. The effect is good, but the only drawback of PNG is that it cannot be scaled. It would be better to generate a vector image. Because. NET is inherently disabled in vector graph rendering, I try to find out if there are any ready-made solutions. So I found Sheild. io.

Shield provides a set of badge rendering solutions and open-source implementation methods for nodejs, php, go and other languages. They even provide a service Shield. io for your convenience. This is almost perfect.

Why am I building wheels?

The reason is also quite simple. shield may not provide SLA like Azure and AWS (nor should we ask them to provide SLA ). We should try our best to reduce this external dependency for our website. Since they are open-source, I simply wrote a. NET version, managed the Assembly through Nuget, and then ran the service on our own machine. I gave it a vulgar name called DotBadge. You can go to Github to view it.

How to Use

You can use nuget to download the dll for reference. In addition, I have written a small command line tool for better user experience.

Command line tool

Download

Open the command line, go to the DotBadge directory, and executeDotBadge.exe --help.

Example
DotBadge.exe -sb "Downloads" -st "1000" -c "Green" -sl 0

DotBadge.exe -sb "Build" -st "fail" -c "Red" -sl 0 

DotBadge.exe -sbhttps://github.com/rebornix/DotBadge/edit/master/Readme.md# "Star" -st "234" -c "#ddf" -sl 1 

How to put it in your own project

Run in the Nuget Package Manager Console

PM> Install-Package DotBadge

 Or use Nuget's UI tool to search for and download.

Example
using DotBadge;using System.IO;namespace Badge{    class Program    {        static void Main(string[] args)        {            var bp = new BadgePainter();            File.WriteAllText(@"C:\Users\peng\Desktop\nuget.svg", bp.DrawSVG("Badge", ".Net", ColorScheme.Red, Style.Flat));        }    }}
Making wheels fun

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.