Thursday, November 29, 2018

Content Management System Structure



                              Fig: Structure of a Content Management System.



                                        Fig: Content Management System Layers.

C# MVC load the PDF without using Acrobat Reader, then send the PDF pages as images to the printer

C# code:

        private RasterImage PDFImage = null;
        private int currentPrintPageNumber;

        private void menuItem1_Click(object sender, EventArgs e)
        {
            using (RasterCodecs codecs = new RasterCodecs())
            {
                codecs.Options.Load.AllPages = true;

               // Load PDF as Image
               PDFImage = codecs.Load(@"Source.pdf");

               // Print
                using(PrintDocument document = new PrintDocument())
                {
                    currentPrintPageNumber = 1;
                    document.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
                    document.Print();
                }
                PDFImage.Dispose();
            }
        }

        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            PrintDocument document = sender as PrintDocument;
            RasterImagePrinter printer = new RasterImagePrinter();
            printer.PrintDocument = document;
            printer.SizeMode = RasterPaintSizeMode.FitAlways;
            printer.HorizontalAlignMode = RasterPaintAlignMode.Center;
            printer.VerticalAlignMode = RasterPaintAlignMode.Center;
            printer.PageRectangle = Rectangle.Empty;
            printer.ImageRectangle = Rectangle.Empty;
            printer.UseMargins = false;
            printer.Print(PDFImage, currentPrintPageNumber, e);
            currentPrintPageNumber++;
           
            if(currentPrintPageNumber <= PDFImage.PageCount)
                e.HasMorePages = true;
            else
                e.HasMorePages = false;
            printer.PrintDocument = null;
        }  

Wednesday, November 28, 2018

Best way to put SQL query result in a .NET chart control

Hi guys,
I am working on a web app using asp.net, c#. I am new to this charts control. I have a below SQL query and its result want to put in a pie chart? " SELECT A,B,C,(A+B+C) as Total FROM [dbo].[Data] " A B C Total 30 10 50 200 I'm tried linking with SQL query but it is having 4 columns. not sure how to connect. Thanks

Tuesday, November 27, 2018

For loop not necessary to add 2 element

list.Add(new Model{ Property = $"{infom.elmnt1} {infom.elmnt2}");
list.Add(new Model{ Property = String.Format("{0} {1}", infom.elmnt1, infom.elmnt2) };

Power Shell Unauthorized Error: 401

Power Shell Error




Sunday, November 25, 2018

Troubleshooting Azure for slow web app performance issues

Performance issues troubleshooting issues steps are like this:

Cause
This problem is often caused by application level issues, such as:
  • network requests taking a long time
  • application code or database queries being inefficient
  • application using high memory/CPU
  • application crashing due to an exception

Troubleshooting steps

A. Monitor your web app

This option enables you to find out if your application is having any issues. In your web app’s blade, click the Requests and errors tile. The Metric blade shows you all the metrics you can add.
Some of the metrics that you might want to monitor for your web app are
  • Average memory working set
  • Average response time
  • CPU time
  • Memory working set
  • Requests

B. Collect data

The Web Apps environment provides diagnostic functionality for logging information from both the web server and the web application. The information is separated into web server diagnostics and application diagnostics.

C. Mitigate the issue

Scale the web app

In Azure App Service, for increased performance and throughput, you can adjust the scale at which you are running your application. Scaling up a web app involves two related actions: changing your App Service plan to a higher pricing tier, and configuring certain settings after you have switched to the higher pricing tier.
For more information on scaling, see Scale a web app in Azure App Service.
Additionally, you can choose to run your application on more than one instance. Scaling out not only provides you with more processing capability, but also gives you some amount of fault tolerance. If the process goes down on one instance, the other instances continue to serve requests.
You can set the scaling to be Manual or Automatic.

Use AutoHeal

AutoHeal recycles the worker process for your app based on settings you choose (like configuration changes, requests, memory-based limits, or the time needed to execute a request). Most of the time, recycle the process is the fastest way to recover from a problem. Though you can always restart the web app from directly within the Azure portal, AutoHeal does it automatically for you. All you need to do is add some triggers in the root web.config for your web app. These settings would work in the same way even if your application is not a .Net app.
For more information, see Auto-Healing Azure Web Sites.

Restart the web app

Restarting is often the simplest way to recover from one-time issues. On the Azure portal, on your web app’s blade, you have the options to stop or restart your app.

You can feedback your opinion, whether its helpful or not

MVC GetData in Chart from WCF by using ViewModel

Hi guys,
I want to share getdata concept by accessing WCF. 
My ViewModel is MonthlyReportDto. 
public class MonthlyReportDto
{
public int Month { get; set; }
public int Year { get; set; }
public int NewWorkOrder { get; set; }
public int Goal { get; set; }
public int MonthlyClosedWO { get; set; }
}
public MonthlyReportDto[] getMonthlyData_noPM(int? categoryId)
{
List<MonthlyReportDto> rep = new List<MonthlyReportDto>();
DateTime currdate;
currdate = DateTime.Now;
int firstmonth = currdate.AddMonths(-36).Month; //Data for 3 years
int firstyear = currdate.AddMonths(-36).Year;
int[] chkMonthfirst = new int[(12 - firstmonth)+1];
int ix = 0;
for (int m = firstmonth; m <= 12; m++)
{
chkMonthfirst[ix] = m;
ix++;
}
int[] chkMonth = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
int currentMonth = currdate.Month;
int currentYear = currdate.Year;
// get first year and increment by 1 till i am on current year
List<int> totalyear = new List<int>();
for (int i = firstyear; i <= currentYear; i++)
{
totalyear.Add(i);
}
foreach (var t in totalyear)
{
if (t == firstyear)
{
foreach (var m in chkMonthfirst)
{
//calculates the total days in a month
int days = DateTime.DaysInMonth(t, m);
//gives the enddate for a month
string dateString = m + "/" + days + "/" + t + " 11:59:59 PM";
DateTime currentDate = DateTime.ParseExact(dateString, "M/d/yyyy h:mm:ss tt", System.Globalization.CultureInfo.CurrentCulture); //DateTime.Parse( DateTime.Parse(m + "/" + days + "/" + t + " 11:59:59 PM");
var goal = db.goal.Where(c => c.Month == m && c.Year == t).FirstOrDefault();
MonthlyReportDto r = new MonthlyReportDto();
// select all workorders closed in that month and year
#region
r.MonthlyClosedWO = db.fac_generalwork_request.Where(c => c.Status == "CLOSED" && c.ClosedDate.Value.Month == m && c.ClosedDate.Value.Year == t && c.PreventiveMaintenance == "N").Count();
//r.TotalOpenWorkOrder = db.fac_generalwork_request.Where(c => c.SubmittedDate.Value <= currentDate && c.Status != "CLOSED" && c.PreventiveMaintenance == "N").Count();
r.TotalOpenWorkOrder = db.fac_generalwork_request.Where(c => c.SubmittedDate.Value <= currentDate && c.PreventiveMaintenance == "N").ToList()
.Where(c => currentDate < Convert.ToDateTime(c.ClosedDate) || c.Status != "CLOSED").Count();
r.NewWorkOrder = db.fac_generalwork_request.Where(c => c.SubmittedDate.Value.Month == m && c.SubmittedDate.Value.Year == t && c.PreventiveMaintenance == "N").Count();

#endregion
r.Month = m;
r.Goal = goal == null ? 0 : goal.GoalNumber.Value;
r.Year = t;
if (r.Month == 1)
r.mont = "Jan";
else if (r.Month == 2)
r.mont = "Feb";
else if (r.Month == 3)
r.mont = "Mar";
else if (r.Month == 4)
r.mont = "Apr";
else if (r.Month == 5)
r.mont = "May";
else if (r.Month == 6)
r.mont = "Jun";
else if (r.Month == 7)
r.mont = "July";
else if (r.Month == 8)
r.mont = "Aug";
else if (r.Month == 9)
r.mont = "Sep";
else if (r.Month == 10)
r.mont = "Oct";
else if (r.Month == 11)
r.mont = "Nov";
else if (r.Month == 12)
r.mont = "Dec";
r.yearandmonth = r.mont + " " + r.Year;
rep.Add(r);
}
}
}
return rep.ToArray();
}
Then push your chart control.