ASP.Net is too slow - asp.net

Name: http://localhost:50692/bfea4cb4df42428dac17db20239d7d53/arterySignalR/poll?transport=longPolling&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAAY8r9H53SS0mPVZi%2BJaxhmgAAAAACAAAAAAADZgAAwAAAABAAAACxV1Yze0hqYW74IbMt%2F3ccAAAAAASAAACgAAAAEAAAANgm3EjRWVa2PG4Y0yKe170oAAAA3HRUEcQdeyzIzSRY1%2B88s1AWq3zAs3dVYKoE8nrk0XpbjrLFXenhzRQAAACtcSj%2FmTPLei2BFkjrPAqbbTphxA%3D%3D&messageId=d-90D2E0DD-B%2C0%7CC%2C9%7CD%2C0&requestUrl=http%3A%2F%2Flocalhost%3A53648%2F&browserName=Chrome&userAgent=Mozilla%2F5.0+(Windows+NT+6.1%3B+WOW64)+AppleWebKit%2F537.36+(KHTML%2C+like+Gecko)+Chrome%2F43.0.2357.132+Safari%2F537.36&tid=8&_=1436780235916
Status: 200
Type: xhr
Initiator: browserLink:37
Size: 336 B
Time: 6.0 seconds
From the Network tab in Inspect Element in Chrome.
It just does this over and over again without getting anywhere. I have no idea what parts of my code to give you, and I'd rather not swarm you with the whole project. Tell me what you need to see and I'll give you it.
When I click "copy as HAR" I get this: http://pastebin.com/tqqNGYpW
It's interesting that the 'log' at the top shows version 1.2, and I just uninstalled log4net version 1.2 and installed log4net version 2.x instead to fix another problem. The problem was related to some 32-bit 64-bit problems between LinqToExcel (it uses log4net).
This is almost certainly LinqToExcel-related. It only hangs sometimes. It continues doing the above even after I've stopped the loading process.
Further info:
The page that hangs displays Excel files from LinqToExcel. The page that does not use LinqToExcel does not hang. It doesn't matter if the page has Excel files to display, or not.
The hang occurs when I call the Index() method.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using steer.Models;
using LinqToExcel;
namespace steer.Controllers
{
public class FilesController : Controller
{
private UpFile.UpFileDBContext db = new UpFile.UpFileDBContext();
// GET: Upload
public ActionResult Index()
{
return View(db.UpFiles.ToList());
}
// GET: Upload/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
UpFile upFile = db.UpFiles.Find(id);
if (upFile == null)
{
return HttpNotFound();
}
var excel = new ExcelQueryFactory(AppDomain.CurrentDomain.BaseDirectory+"Uploaded\\"+upFile.Name);
var firstSheet = excel.GetWorksheetNames().First();
var excelRows = from c in excel.Worksheet(firstSheet)
select c;
ViewBag.excelRows = excelRows;
ViewBag.excelColumns = excel.GetColumnNames(firstSheet); ;
ViewBag.numberOfColumns = ViewBag.excelColumns.Count;
return View(upFile);
}
}
}

This is just a guess, but I'm assuming you have files you've uploaded in a database table and the page that is slow is the index which just shows the list of files.
If you have all the file details and the file contents in the same table then I suspect you're loading all those file contents for every single file every time you do an index.
Assuming this is the case you can either tell the linq to just select the info you want, or split out the data across 2 tables to make it so that you only end up with the data if you explicitly link it in.

Related

How do I parse specific data from a website within Codename One?

I have run into a road block developing my Codename One app. One of my classes in my project parses 3 specific html "td" elements from a website and saves the text to a string where I then input that text data into a Codename One multibutton. I originally used jSoup for this operation but soon realized that Codename One doesn't support 3rd party jar files so I used this method as shown below.
public void showOilPrice() {
if (current != null) {
current.show();
return;
}
WebBrowser b = new WebBrowser() {
#Override
public void onLoad(String url) {
BrowserComponent c = (BrowserComponent) this.getInternal();
JavascriptContext ctx = new JavascriptContext(c);
String wtiLast = (String) ctx.get("document.getElementById('pair_8849').childNodes[4].innerText");
String wtiPrev = (String) ctx.get("document.getElementById('pair_8849').childNodes[5].innerText");
String wtiChange = (String) ctx.get("document.getElementById('pair_8849').childNodes[8].innerText");
Form op = new Form("Oil Prices", new BoxLayout(BoxLayout.Y_AXIS));
MultiButton wti = new MultiButton("West Texas Intermediate");
Image icon = null;
Image emblem = null;
wti.setEmblem(emblem);
wti.setTextLine2("Current Price: " + wtiLast);
wti.setTextLine3("Previous: " + wtiPrev);
wti.setTextLine4("Change: " + wtiChange);
op.add(wti);
op.show();
}
};
b.setURL("https://sslcomrates.forexprostools.com/index.php?force_lang=1&pairs_ids=8833;8849;954867;8988;8861;8862;&header-text-color=%23FFFFFF&curr-name-color=%230059b0&inner-text-color=%23000000&green-text-color=%232A8215&green-background=%23B7F4C2&red-text-color=%23DC0001&red-background=%23FFE2E2&inner-border-color=%23CBCBCB&border-color=%23cbcbcb&bg1=%23F6F6F6&bg2=%23ffffff&open=show&last_update=show");
}
This method works in the simulator (and gives a "depreciated API" warning), but does not run when I submit my build online after signing. I have imported the parse4cn1 and cn1JSON libraries and have gone through a series of obstacles but I still receive a build error when I submit. I want to start fresh and use an alternative method if one exists. Is there a way that I can rewrite this segment of code without having to use these libraries? Maybe by using the XMLParser class?
The deprecation is for the WebBrowser class. You can use BrowserComponent directly so WebBrowser is redundant in this case.
I used XMLParser for this use case in the past. It should work with HTML as it was originally designed to show HTML.
It might also be possible to port JSoup to Codename One although I'm not sure about the scope of effort involved.
It's very possible that onLoad isn't invoked for a site you don't actually see rendered so the question is what specifically failed on the device?

Angular SPA cannot open remote SSRS report

thanks to all for your time and efforts trying to help me solve this.
Now lets get to it... I have an AngularJS SPA. I would like to provide links on my view page, that when clicked, open a new tab and launch pre-existing SSRS reports in PDF format. Technically what I am trying to do: Render an SSRS report in my Repository, pass that through my WEB API then on to my SPA for display in a new tab.
One important note before I go any further: This setup, method, approach works flawlessly on my local machine within Visual Studio. It's when I move my SPA to a remote Web server (the same server that hosts SSRS) that I have a problem.
My Landscape:
Local Development Machine (Windows 7 Pro, VS2015 Pro)
Server1 (Win Server 2012R2): Hosts IIS (8), SPA, SQL (2014) and SSRS
Server2 (Win Server 2012R2). Hosts SSRS (SQL 2012) source of data (happens to be SSAS cubes, but I don't think that matters).
On My Local Development Machine:
As stated above the solution works fine through Visual Studio. The only part of the solution on my local machine is the SPA. The SSRS and SQL portion are located remotely. I can launch my SPA, click on a link and new tab opens containing the PDF report. I can also make a call directly to the web API and display a PDF report (http://localhost:3040/api/dataservice/ProductivityReportH/)
Problem 1
Browsing to the deployed version of my SPA on Server1, the application displays fine. But, if I click on a report hyperlink I get a the following message:
Do you want to open or save ProductivityReportH/ (3.28KB) from Server1?
No matter what I click (Open, Save, Cancel) nothing happens.
If I try and launch the report directly through the API, I get the same message. There are no errors displayed in the console window. I could find no errors in the Server1 log files.
On Server1: I can display the report via the SSRS report viewer.
Problem 1A
Using a browser on Server1, I can display the application just fine. But, if I click on a report hyperlink I get the same message as Problem 1. If I try to launch the report directly through the web API (http://Server1/projecttracker/api/dataservice/ProductivityReportH/)
on Server1, I get the same message.
Any ideas would be greatly appreciated
My SPA Setup:
View Page:
<div class="view indent">
<div class="container">
<h2>Productivity Reports Method 1</h2>
<a ng-href='#here' ng-click="hproductivityreport()">Launch</a><br>
</div>
My Controller:
(function () {
var ProjectsController = function ($scope, $window) {
$scope.hproductivityreport = function () {
$window.open('api/dataservice/ProductivityReportH/', '_blank');
};
}
ProjectsController.$inject = ['$scope', '$window'];
angular.module('ReportTracker').controller('ProjectsController', ProjectsController)
}());
The WEB API:
using ProjectTracker.Repository;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using System.Web.Http;
namespace ProjectTracker.Model
{
[Authorize]
public class DataServiceController : ApiController
{
IProjectTracker _ProjectTrackerRepository;
public DataServiceController()
: this(null)
{
}
public DataServiceController(IProjectTracker Repo)
{
_ProjectTrackerRepository = Repo ?? new ProjectTrackerRepository ();
}
[HttpGet]
public HttpResponseMessage ProductivityReportH()
{
var result = new HttpResponseMessage(HttpStatusCode.OK);
byte[] bytes = _ProjectTrackerRepository.RenderProductivityReport("Hibble, Norman");
Stream stream = new MemoryStream(bytes);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return result;
}
}
}
The Respository:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
namespace ProjectTracker.Repository
{
public class ProjectTrackerRepository : RepositoryBase<ProjectTrackerContext>, IProjectTracker
{
ProjectTrackerContext _Context;
public ProjectTrackerRepository()
{
_Context = new ProjectTrackerContext();
}
public Byte[] RenderProductivityReport(string _sManager)
{
Server1.ReportExecutionService rs = new Server1.ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://Server1/reportserver/ReportExecution2005.asmx";
// Render arguments
byte[] result = null;
string reportPath = "/Staff Client Services/StaffProductivity";
string format = "PDF";
string historyID = null;
string devInfo = #"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
//Create the list of parameters that will be passed to the report
List<Server1.ParameterValue> lstParameterValues = new List<Server1.ParameterValue>();
Server1.ParameterValue aParameter = new Server1.ParameterValue();
aParameter.Name = "SupervisorSupervisorName";
aParameter.Value = "[Supervisor].[Supervisor Name].&[" + _sManager + "]";
lstParameterValues.Add(aParameter);
Server1.ParameterValue bParameter = new Server1.ParameterValue();
bParameter.Name = "PayPeriodPayPeriodYear";
bParameter.Value = "[Pay Period].[Pay Period Year].&[2015]";
lstParameterValues.Add(bParameter);
int index = 0;
Server1.ParameterValue[] parameterValues = new Server1.ParameterValue[lstParameterValues.Count];
foreach (Server1.ParameterValue parameterValue in lstParameterValues)
{
parameterValues[index] = parameterValue;
index++;
}
string encoding;
string mimeType;
string extension;
Server1.Warning[] warnings = null;
string[] streamIDs = null;
Server1.ExecutionInfo execInfo = new Server1.ExecutionInfo();
Server1.ExecutionHeader execHeader = new Server1.ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);
rs.SetExecutionParameters(parameterValues, "en-us");
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
try
{
result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
execInfo = rs.GetExecutionInfo();
}
catch (Exception e)
{
Exception Errr = e.InnerException;
}
return result;
}
}
}
Finally! For those that are interested...
Found this from nearly two years ago.
AppPool Permission Issue with Accessing Report Server
In particular the comment below:
Almost the same situation here except IIS and Report Server running on Windows Server 2008 R2. I used to have the asp.net application running with it's own application pool and everything worked. When I changed the application to the DefaultAppPool (due to a different problem), I got the permissions problem. I changed the Identity of the DefaultAppPool from ApplicationPoolIdentity to LocalSystem (in IIS, Advanced Settings) and it worked again.
Changed web server default app pool to LocalSystem and wha-la, I am rendering PDF reports from an SSAS cube through my AngularJS SPA.

excel data from asp

i have made a list of folders from my directory, to show as html.
What i want is to be able to read and write in excel.
now what am strugleing to do is put this code to get it as .xlsx. i have a excel file in my computer and want all the directories to go in that file..
I have been told EPPlus is the best solution. but am not sure how to implement this in the above code so my directories comes in excel rather than html.
any ideas/direction would be really helpful
If you want to go the route of EPPlus, first thing you need to do is add the EPPlus package to your solution. This can be achieved by doing one of the following:
Opening up NuGet, searching for EPPlus in the gallery and installing it
Opening up your Package Manager Console and typing Install-Package EPPlus
Downloading the dll file and manually adding a reference to it in your project.
Then, in your code:
using OfficeOpenXml;
using System.IO;
using System.Linq;
namespace TestConsole {
class Program {
static void Main(string[] args) {
string[] directoryList = System.IO.Directory.GetDirectories(#"C:\Users\bblack\Temp\TestDirectories\");
using (Stream file = new FileStream(#"C:\Users\bblack\Temp\testexcelfile.xlsx", FileMode.Create))
using (ExcelPackage xl = new ExcelPackage(file)) {
ExcelWorksheet sheet = xl.Workbook.Worksheets.Add("Sheet1");
for (int i = 1; i < directoryList.Count(); i++)
sheet.Cells[i, 1].Value = directoryList[i];
xl.Save();
}
}
}
}
This
Gets all the directories in the address provided to it.
Creates a new FileStream where you want your Excel file to be
Creates a new ExcelPackage based off of the FileStream
Adds a new worksheet (there are zero by default) to the workbook in the ExcelPackage
Iterates through directoryList, and for each string in there puts the value in a new cell
it is important to note, that worksheet cell indexes are not zero-based, they start with a base index of 1
edit Woops, forgot to close the stream, use this updated answer.

Calling R-UDF's from Excel

I want to have functions in Excel (Taking Excel-Arguments) that call R-Functions and return the results back to Excel. RExcel does not seem to be on CRAN (anymore) and I have not yet found an alternative. Does anyone know of a way to achieve this?
One constraint is that the solution should work even without administrator privileges on Windows Vista.
Edit:
Thanks for the comment. We have tried R.Net, but with little success. We went for:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExcelDna.Integration;
using System.Windows.Forms;
using RDotNet;
using RDotNet.NativeLibrary;
public static class MyFunctions
{
[ExcelFunction(Description = "Test R connection")]
public static double MyRTest(double x)
{
var envPath = Environment.GetEnvironmentVariable("PATH");
var rBinPath = #"D:\Programme\R\R-2.15.1\bin\i386";
Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath);
// using (REngine engine = REngine.CreateInstance("RDotNet"))
// {
// }
// REngine rengine = REngine.CreateInstance("RDotNet");
return (2*x);
} // End Function
[ExcelFunction(Description="Multiplies two numbers", Category="Useful functions")]
public static double MultiplyThem(double x, double y)
{
return x * y;
}
}
The function MultiplyThem() can be Called in Excel and it works. As is, so does MyRTest. But as soon as I try to instanciate R using either of the methods commented out, it returns the #Value error in Excel. Trying to make sense of it, we went for a Command Line application and just copied the example from here (v1.5). However at the line engine.Initialize(); the debugger just terminated, without error or exception. We use R12.15.1 (32 Bit), Windows Vista (32 Bit), Visual Studio 2010 Professional and RdotNet 1.5.0. What could have gone wrong?

Javascript permission denied error when using Atalasoft DotImage

Have a real puzzler here. I'm using Atalasoft DotImage to allow the user to add some annotations to an image. When I add two annotations of the same type that contain text that have the same name, I get a javascript permission denied error in the Atalasoft's compressed js. The error is accessing the style member of a rule:
In the debugger (Visual Studio 2010 .Net 4.0) I can access
h._rule
but not
h._rule.style
What in javascript would cause permission denied when accessing a membere of an object?
Just wondering if anyone else has encountered this. I see several people using Atalasoft on SO and I even saw a response from someone with Atalasoft. And yes, I'm talking to them, but it never hurts to throw it out to the crowd. This only happens in IE8, not FireFox.
Thanks, Brian
Updates: Yes, using latest version: 9.0.2.43666
By same name (see comment below) I mean, I created default annotations and they are named so they can be added with javascript later.
// create a default annotation
TextData text = new TextData();
text.Name = "DefaultTextAnnotation";
text.Text = "Default Text Annotation:\n double-click to edit";
//text.Font = new AnnotationFont("Arial", 12f);
text.Font = new AnnotationFont(_strAnnotationFontName, _fltAnnotationFontSize);
text.Font.Bold = true;
text.FontBrush = new AnnotationBrush(Color.Black);
text.Fill = new AnnotationBrush(Color.Ivory);
text.Outline = new AnnotationPen(new AnnotationBrush(Color.White), 2);
WebAnnotationViewer1.Annotations.DefaultAnnotations.Add(text);
In javascript:
CreateAnnotation('TextData', 'DefaultTextAnnotation');
function CreateAnnotation(type, name) {
SetAnnotationModified(true);
WebAnnotationViewer1.DeselectAll();
var ann = WebAnnotationViewer1.CreateAnnotation(type, name);
WebThumbnailViewer1.Update();
}
There was a bug in an earlier version that allowed annotations to be saved with the same unique id's. This generally doesn't cause problems for any annotations except for TextAnnotations, since they use the unique id to create a CSS class for the text editor. CSS doesn't like having two or more classes defined by the same name, this is what causes the "Permission denied" error.
You can remove the unique id's from the annotations without it causing problems. I have provided a few code snippets below that demonstrate how this can be done. Calling ResetUniques() after you load the annotation data (on the server side) should make everything run smoothly.
-Dave C. from Atalasoft
protected void ResetUniques()
{
foreach (LayerAnnotation layerAnn in WebAnnotationViewer1.Annotations.Layers)
{
ResetLayer(layerAnn.Data as LayerData);
}
}
protected void ResetLayer(LayerData layer)
{
ResetUniqueID(layer);
foreach (AnnotationData data in layer.Items)
{
LayerData group = data as LayerData;
if (group != null)
{
ResetLayer(data as LayerData);
}
else
{
ResetUniqueID(data);
}
}
}
protected void ResetUniqueID(AnnotationData data)
{
data.SetExtraProperty("_atalaUniqueIndex", null);
}

Resources