Ayuda con chart ASP .NET

Tengo la siguiente grafica en ASP .NET usando chart, en la cual se muestran dos valores diferentes, y necesito que la mitad donde est $ 0 sea de un color y la otra mitad de otro color la otra mitad, se que se necesitan dos series pero nose como añadirlo a mi codigo

introducir la descripción de la imagen aquí

<div class="grafica form-inline my-2 my-lg-0"> <asp:Chart ID="chart1" runat="server"> <Titles><asp:Title Text="%ABONO" /></Titles> <Series> <asp:Series Name="" IsValueShownAsLabel="true" IsVisibleInLegend="False" LabelFormat="{0:C0}" ></asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea2"></asp:ChartArea> </ChartAreas> </asp:Chart>  </div>

string[] ax = { "Importe", "Descuento" }; decimal[] ay={totalImporte, totalDescuento};//variables ya calculadas  chart1.Series[0].Color = Color.Blue; chart1.Series[0].Points.DataBindXY(ax, ay); chart1.Series[0].ChartType = SeriesChartType.Pie;  System.Web.UI.DataVisualization.Charting.Grid agd = new System.Web.UI.DataVisualization.Charting.Grid(); agd.LineWidth = 0; System.Web.UI.DataVisualization.Charting.Grid agd1 = new System.Web.UI.DataVisualization.Charting.Grid(); agd1.LineWidth = 0;  chart1.ChartAreas[0].AxisX.MajorGrid = agd; chart1.ChartAreas[0].AxisY.MajorGrid = agd1;             chart1.ChartAreas["ChartArea2"].AxisY.LabelStyle.Enabled = false; chart1.Legends[0].Enabled = true;

Mono view supported .net frameworks

Is there any way of viewing which .Net frameworks are currently installed/supported by my installation of mono? Currently using a Ubuntu Server 18.04 system.

Using the command # mono -V tells me the Mono JIT compiler version is, which doesn’t really help me much.

My end goal is to try and use mod_mono for Apache to run an ASP.Net web app using .Net framework 4.5.2

Why do I define my Queries, Data, and Mutation as Singleton when using GraphQL in .NET Core?

Why do I define my Queries, Data, and Mutation as Singleton when using GraphQL in .NET Core?

From the doc’s dependency injection page:

public void ConfigureServices(IServiceCollection services) {   services.AddSingleton<IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));    services.AddSingleton<IDocumentExecuter, DocumentExecuter>();   services.AddSingleton<IDocumentWriter, DocumentWriter>();    services.AddSingleton<StarWarsData>();   services.AddSingleton<StarWarsQuery>();   services.AddSingleton<StarWarsMutation>();   services.AddSingleton<HumanType>();   services.AddSingleton<HumanInputType>();   services.AddSingleton<DroidType>();   services.AddSingleton<CharacterInterface>();   services.AddSingleton<EpisodeEnum>();   services.AddSingleton<ISchema, StarWarsSchema>(); } 

At the beginning of the docs:

The library resolves a GraphType only once and caches that type for the lifetime of the Schema.

While I understand that these are more like DTOs in which they hold values or their class content doesn’t change at all… Why do I specify them as singleton instead of just letting them get instantiated?

Web Api hosting with database using .Net

I have scenario:

  1. Using .Net Framework or .Net Core and develop web api
  2. It has database too for storing data , ie: SQL Server
  3. It needs to install on client side


  1. How to protect my code or what can be right way to deliver solution to client so license should work
  2. Client can have Windows or Linux(so solution should be OS independent)

I prefer to use .Net Core and SQL Server but do not have any idea on packaging with securing my code and deployment on client side with database.

My effort: I have worked with .Net Core, I know it can help me to get web api working on Linux & Windows but I am not sure what is better approach for packaging? How to make package in a way so one installer can install on needed on both OS(Wibdows & Linux) Please advise.

Thank you 🙂

How to convert this .NET cryptography code to openssl command?

how to sign the message with the private key of the signer using openssl command line tool to get the same result as the code below?

using System.Security.Cryptography.Pkcs; using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography;  static public byte[] SignMe(X509Certificate2 rsa_cert, Byte[] message) {     ContentInfo ci = new ContentInfo(message);     SignedCms scms = new SignedCms(ci, true);     CmsSigner signer = new CmsSigner(rsa_cert);     scms.ComputeSignature(signer, false);     return Convert.ToBase64String(scms.Encode()); } 

C# .Net Core API design – interfaces vs DTOs

I’m designing a relatively simple web application using .net core. I’ve mostly done desktop development in my career so far, so I’m a bit new to the nuances between desktop and web development.

In this application there is a business logic layer and a presentation logic layer which takes the business logic and transforms the properties into marked up output server-side and then returns the data to the client through a web API.

Due to the controls I’m using and the structure of the application, it makes sense to have this “presentation logic” layer on the server side, since some aspects of the presentation are actual business logic requirements (most of the presentation is handled in views, partial views and view components).

Currently the way that I am handling this is by injecting the business logic classes into presentation logic classes, then having the api controller return an interface to the presentation logic class.

A simplified example of the approach:

public class BusinessLogic {   public string PropertyA { get; set; }    public string PropertyB { get; set; }    public void DoSomeLogic() { // some code here } }  public class PresentationLogic : IPresented {   private BusinessLogic businessLogic;    public PresentationLogic(BusinessLogic businessLogic)   {     this.businessLogic = businessLogic;   }    public string PresentationPropertyA   {     get     {       return "<span class='businesslogicspecificclass'>" + this.businessLogic.PropertyA + "</span>";     }   } }  public interface IPresented {   string PresentationPropertyA { get; } }  [Route("api/[controller]")] public class MyController {   [HttpGet]   public IPresented Get()   {     var businessLogic = new BusinessLogic();     // manipulate businessLogic     return new PresentationLogic(businessLogic);   } } 

The API exposes interfaces which are implemented by the PresentationLogic classes. As I understand it, these interfaces are then serialised into JSON and returned to the page to use within its controls.

A different approach to solving the same problem would be to create a DTO, and have the PresentationLogic class take the business logic and spit out the DTO, adding the extra markup to the properties during the creation of the DTO. For example:

public class PresentationLogic {   public Dto GetDtoFromBusinessLogic(BusinessLogic businessLogic)   {     return new Dto { PresentationPropertyA = "<span class='businesslogicspecificclass'>" + this.businessLogic.PropertyA + "</span>" };   } }  public class Dto {   public PresentationPropertyA { get; set; } }  [Route("api/[controller]")] public class MyController {   [HttpGet]   public Dto Get()   {     var businessLogic = new BusinessLogic();     // manipulate businessLogic     var presentationLogic = new PresentationLogic();     return presentationLogic.GetDtoFromBusinessLogic(businessLogic);   } } 

What I want to know is what the advantages or disadvantages to each approach is.

As I understand it, both controller methods will return effectively the same JSON to the calling page.

The first approach feels more natural to me for the following reasons:

  • I do not like DTOs unless they’re absolutely necessary since I believe that they tend to encourage anaemic domain models
  • The presentation logic class becomes an adapter class that sits between the business logic and the view. It has a clearly defined responsibility.
  • I have not created any classes purely for the purpose of acting as a return type – it feels like less wasted code.
  • I could potentially add new properties to the PresentationLogic class and implement a new interface if version 2 called for changes.
  • Interfaces feel like the natural tool for abstraction for C# code.

I was discussing this with other developers and they were suggesting that returning a DTO was the more standard way of approaching this problem. I have come up with a couple of reasons why this might be a better approach:

  • DTOs are clearly marked as such and nobody is tempted to add breaking logic to them.
  • If it’s the standard way then it will help new developers to get up to speed.
  • Adding a new version forces the use of a new DTO class, which means that there’s less potential to introduce breaking changes (though this could also be done with the other approach if needed)

Note that this question is generally about layered web architecture than specifically about my needs on this project. If no presentation logic needed to be added server-side, this question could easily be about business logic and persistence logic classes.

So which is better – using DTOs in a web API or using interfaces on complex objects in a web API?

Ler vários arquivos de texto usando o System.IO e o Visual C# .NET e escrevendo nestes arquivos

Meu problema é o seguinte. Tenho vários arquivos .txt em um diretorio do pc. Esses arquivos tem informacoes em cada linha e possuem linhas em branco.

O que eu precisaria fazer é ler todos os arquivos do diretorio, abrir um a um, ler as informacoes de cada, e adicionar um index numérico em cada, seguido de um ponto e vírgula e apagando as linhas em branco ou com espaço.

Voilà, consegui parcialmente.

Meu programa le o diretorio, lista os arquivos, abre e lê as informacoes neles, mas quando vai gravar as informacoes, ele replica as informacoes do primeiro arquivo no segundo.

Ex.: Se num arquivo tenho a disposicao

joao  legal

o resultado no primeiro arquivo é

0;joao 1;legal

no segundo arquivo tenho as informacoes:

marcelo  medeiros

mas, depois de executar o programa, o resultado no segundo arquivo é:

0;joao 1;legal 2;marcelo 3;medeiros

Logo, se houverem varios e varios arquivos, voces imaginam como ficaria o arquivo final.

Alguém consegue me auxiliar em encontrar onde está o erro no meu programa?

Segue o código:

static void Main(string[] args)     {         List<string> lines = new List<string>();          string path3;         int counter = 0;           path3 = @"C:\Users\msant\Desktop\New folder\";          string[] files = Directory.GetFiles(path3);          foreach (var file in files)         {              if (File.Exists(file))             {                 try                 {                     //ABRE E LÊ O ARQUIVO TXT                      using (StreamReader reader = new StreamReader(file))                     {                         while (!reader.EndOfStream)                         {                              string line = reader.ReadLine();                              if (!string.IsNullOrWhiteSpace(line))                             {                                 var lineOutput = counter++ + ";";                                 lines.Add(lineOutput + line);                             }                          }                         reader.Close();                         reader.Dispose();                     }                      foreach (var line in lines)                     {                          Console.WriteLine(line);                     }                       //ESCREVE NOS ARQUIVOS TXT                      using (StreamWriter writer = new StreamWriter(file))                     {                         foreach (var item in lines)                         {                             writer.WriteLine(item);                         }                          writer.Close();                     }                   }                 catch (Exception e)                 {                     Console.WriteLine(e.Message);                     Console.ReadKey();                 }             }              else             {                 Console.WriteLine("ALERTA: O ARQUIVO LOCALIZADO EM <-- " + path3+ " --> NAO EXISTE.");             }               Console.ReadKey();         }     } 

Which CMS is more flexible and robus in .NET Platform?

I have an ASP.NET Core web application with SQL Server Database. I want to integrate it with an existing CMS. Which CMS will be best in this scenario.

It should have

  1. Design Independence
  2. Easy Administration
  3. WYSIWYG Editor
  4. Media Libraries
  5. Image Gallery
  6. News Feed
  7. Social Media Integration
  8. Simple Form Builder
  9. RESTful API call
  10. Payment Gateway Integration
  11. Responsive UI (with mobile devices support)

I am preferring .NET Core CMS, but as .NET Core is pretty new, I will try to incorporate with .NET Framework base CMS if I find too much better support.

If the CMS can be configured with custom API from which it will take data that will be a Great Advantage. The source code should be open and well organized so that if I want to change or add any feature I can do that easily.