How to setup JsReport .NET to use current app folder - c#

Is there way to setup JsReport to use current application folder for storing temp files. Not using common folder C:\Windows\Temp\jsreport? If there are multiple applications running on common IIS, it produces Errors.
Error rendering report: A critical error occurred while trying to execute the render command: An error occurred while trying to start daemonized process: An error has occurred when trying to initialize jsreport (2). EBUSY: resource busy or locked, open 'C:\WINDOWS\TEMP\jsreport\compile\jsreport-2.2.0-r17qQMiI7\chrome\chrome.dll' (1). caused by error (2) -> stack = Error: at instance.init.then.catch ([eval]:43623:29) at tryCatcher (jsreportRuntime.js:146030:23) at Promise._settlePromiseFromHandler (jsreportRuntime.js:145723:31) at Promise._settlePromise (jsreportRuntime.js:145780:18) at Promise._settlePromise0 (jsreportRuntime.js:145825:10) at Promise._settlePromises (jsreportRuntime.js:145900:18) at Async._drainQueue (jsreportRuntime.js:41845:16) at Async._drainQueues (jsreportRuntime.js:41855:10) at Immediate.Async.drainQueues (jsreportRuntime.js:41729:14) at runCallback (timers.js:794:20) at tryOnImmediate (timers.js:752:5) at processImmediate [as _immediateCallback] (timers.js:729:5)caused by error (1) -> meta = {"errno":-4082,"code":"EBUSY","syscall":"open","path":"C:\WINDOWS\TEMP\jsreport\compile\jsreport-2.2.0-r17qQMiI7\chrome\chrome.dll"}, stack = Error: (1). caused by error (1) -> stack = Error: at exports.NsSocket.socket.dataOnce ([eval]:44008:13) at exports.NsSocket.listener ([eval]:16744:10) at exports.NsSocket.EventEmitter.emit ([eval]:16832:22) at exports.NsSocket._onData ([eval]:86359:8) at Lazy. ([eval]:51602:13) at Lazy. ([eval]:51584:19) at emitTwo (events.js:126:13) at Lazy.emit (events.js:214:7) at Lazy. ([eval]:51585:22) at emitOne (events.js:116:13) at Lazy.emit (events.js:211:7) at yieldTo ([eval]:51692:18) at Function. ([eval]:51730:27) at Lazy. ([eval]:51698:21) at emitOne (events.js:116:13) at Lazy.emit (events.js:211:7)

It needed to be configured in FilterConfig in RegisterGlobalFilters, so it creates jsreport folder in current app folder, so jsreport.exe do not interfere with other instances. Key property is TempDirectory, which define location for temporary folder. All files within this TempDirectory is created automatically.
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
var tempPath = Path.Combine(HttpRuntime.AppDomainAppPath, "jsreport");
filters.Add(new JsReportFilterAttribute(new LocalReporting()
.Configure(cfg =>
{
cfg.BaseUrlAsWorkingDirectory();
cfg.TempDirectory = tempPath;
return cfg;
})
.UseBinary(JsReportBinary.GetBinary())
.AsUtility()
.Create()));
}

Related

Bundle Optimization causing Invalid Invocation error in jquery-ui

I am having the strangest error and it's driving me up the wall. At the moment I have the following two bundles...
var jquery = new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"
, "~/Scripts/jquery-ui-{version}.js"
, "~/Scripts/materialize/materialize.js"
, "~/Scripts/knockout-{version}.debug.js"
, "~/Scripts/knockout-{version}.js"
, "~/Scripts/jquery.signalR-{version}.js");
var jsfiles = new ScriptBundle("~/bundles/Assets/js")
.IncludeDirectory("~/Assets/js", "*.js", true);
bundles.IgnoreList.Ignore("~/Scripts/knockout-{version}.js", OptimizationMode.WhenDisabled);
Within the ASSETS folder there is the following file
jquery-ui-1.10.3.custom.min.js"
When I debug and run locally everything is fine. However when I turn on following
BundleTable.EnableOptimizations = true;
The jquery-ui file mentioned is throwing the following error...
Uncaught TypeError: Illegal invocation
Which relates to this block of code
return u?n.isFunction(u[e])&&"_"!==e.charAt(0)?(i=u[e].apply(u,o),i!==u&&i!==t?(s=i&&i.jquery?s.pushStack(i.get()):i,!1):t):n.error("no such method '"+e+"' for "+r+" widget instance")
:n.error("cannot call methods on "+r+" prior to initialization; attempted to call method '"+e+"'")})
:this.each(function(){var t=n.data(this,f);});
I don't even know where to start debugging it? Could the minification engine be doing something?
From memory, javascript resourced with .min in the filename are automatically excluded from bundling, so referencing the unminified version of the JQuery UI document should fix it (or alternatively, but not recommended - remove the .min from your existing filename.

Sikuli Integrator C# errors

I try to use Sikuli Integrator for C#.
I create new project in Visual Studio 2015, and I Install SikuliIntegrator.
After the installation JSikuliModule.jar, it will be part of my solution, together with some additional files. After that Properties to set “Copy to Output Directory” property to “Copy always” of JSikuliModule.jar
and then I try my code :
class Program
{
static void Main(string[] args)
{
String pattern = #"C:\\Users\\amin-\\Documents\\Visual Studio 2015\\Projects\\SikuliTest\\SikuliTest\\img\\logo.png";
SikuliAction.Click(pattern);
//if (SikuliAction.Exists(pattern).IsEmpty)
//{
// Console.WriteLine("Nope! It's gone...");
//}
//else
//{
// Console.WriteLine("Yep! It's there...");
//}
}
}
If I run the code, this is the errors shows :
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll Additional information: Access to the path 'C:\SikuliOutputLog.txt' is denied.
If I run the code as an administrator, this is the errors shows :
An unhandled exception of type 'System.Exception' occurred in SikuliModule.dl Additional information: ###FAILURE
Manually create a text file 'C:\SikuliOutputLog.txt' then run the code.
It works for me.
In Windows10 besides manually adding C:\SikuliOutputLog.txt you need also to make sure current user have the 'Write' control to this file.

CS-Script persistent cache for better performance when loading scripts

Is there a way to persist CS-Script internal assembly cache between subsequent application's runs?
Used component: http://www.csscript.net/
The desired behavior is:
when I compile an assembly form a script string and I close the application, the next time I run the application the compiled assembly with matching script string is found and no recompilation is needed.
This question is follow-up of another question:
Is there a way to call C# script files with better performance results?
Here is my code, but every script string requires recompilation with every restart of parent .NET application.
public interface ICalculateScript
{
Exception Calculate(QSift qsift, QSExamParams exam);
}
...
void Calculate(string script)
{
CSScript.CacheEnabled = true;
//Can following command use built-in cache to load assembly, compiled by this line of code, but by another instance of this app which run in the past and has been meanwhile closed?
Assembly assembly = = CSScript.LoadCode(script, null);
AsmHelper asmHelper = new AsmHelper(assembly);
ICalculateScript calcScript = (ICalculateScript)asmHelper.CreateObject("Script");
calcScript.Calculate(this, exam);
}
Related problem:
The folder of temp scripts created by Cache in CS Script C:\Users\vdohnal\AppData\Local\Temp\CSSCRIPT\Cache\2015108000 has 41 MB and growing with files few months old.
In the output window of WPF App there are first chance exceptions:
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
'ESClient.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\vdohnal\AppData\Local\Temp\CSSCRIPT\Cache\2015108000\af621e10-d711-40d7-9b77-0a8e7de28831.tmp.compiled'
C:\Users\vdohnal\AppData\Local\Temp\CSSCRIPT\Cache\2015108000
I got an answer fom Oleg Shilo which pointed me in the right direction:
The cache folder indeed grows as new scripts are compiled/loaded. This
is the nature of the caching. It seems that it "grows without control"
though it is not. Once cache is created for a given script file it is
never duplicated and the new cache update is always written over the
existing one.
The problem in your case is that every time you load the file you give
it a unique name thus you are creating a new unique cache. To fix it
you need to start using the same name for the script file every time
you load/execute it.
Alternatively you can completely take over the caching location and
specify what ever cache name you want. It is that second parameter
that you pass null for:
Assembly assembly = CSScript.LoadCode(script, null);
I used following code:
if (assemblyFileName == null)
assembly = CSScript.LoadCode(script, null); //In case there is no name specified - when my custom temp folder cannot be created etc.
else
assembly = CSScript.LoadCode(script, assemblyFileName, false, null); //Specify full path and file name with extension
Thanks to this I have complete control over cached assembly name and location.
If cached assembly with appropriate script already exists, I can simply load it instead of compiling a new one:
Assembly assembly = Assembly.LoadFrom(assemblyFileName);
AsmHelper asmHelper = new AsmHelper(assembly)
The speed of initial loading is better and there is no uncontrollably growing cache.

Cassette.AssetReferenceException being fired when removing a file from folder

I used to have a .js file in /Public/javascripts/jquery1.1js.
Everything was working perfectly but then I needed to delete this file from my project, so I just removed it from the solution in Visual Studio.
Now when I visit my application, I get:
Reference error in "~/Public/javascripts/jquery.unobtrusive-ajax.js",
line 1. Cannot find "~/Public/javascripts/jquery-1.5.1.js". Reference
error in "~/Public/javascripts/jquery.validate.unobtrusive.js", line
1. Cannot find "~/Public/javascripts/jquery-1.5.1.js".
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: Cassette.AssetReferenceException: Reference error
in "~/Public/javascripts/jquery.unobtrusive-ajax.js", line 1. Cannot
find "~/Public/javascripts/jquery-1.5.1.js". Reference error in
"~/Public/javascripts/jquery.validate.unobtrusive.js", line 1. Cannot
find "~/Public/javascripts/jquery-1.5.1.js".
Here's a stacktrace:
[AssetReferenceException: Reference error in "~/Public/javascripts/jquery.unobtrusive-ajax.js", line 1. Cannot find "~/Public/javascripts/jquery-1.5.1.js".
Reference error in "~/Public/javascripts/jquery.validate.unobtrusive.js", line 1. Cannot find "~/Public/javascripts/jquery-1.5.1.js".]
Cassette.BundleContainer.ValidateAssetReferences() +387
Cassette.BundleContainer..ctor(IEnumerable`1 bundles) +41
Granted, I know why this is happening, Cassette is still trying to find the deleted file, but I'm not sure how to tell Cassette: "Hey, this file is no longer relevant. Scan the folder again and rebuild a list of files you need to work with."
But I just don't know how to accomplish this.
The documentation has no mention of this and just implies that it should do this automatically for me.
Here's my Configuration class:
using Cassette.Configuration;
using Cassette.Scripts;
using Cassette.Stylesheets;
namespace XXX.WebUI
{
/// <summary>
/// Configures the Cassette asset modules for the web application.
/// </summary>
public class CassetteConfiguration : ICassetteConfiguration
{
public void Configure(BundleCollection bundles, CassetteSettings settings)
{
bundles.AddPerIndividualFile<ScriptBundle>("Public/javascripts/");
bundles.AddPerIndividualFile<StylesheetBundle>("Public/stylesheets/");
}
}
}
And in my _Layout.cshtml file:
#{
Bundles.Reference("Public/javascripts/site.js");
Bundles.Reference("Public/javascripts/jquery.validate.unobtrusive.js");
Bundles.Reference("Public/stylesheets/site.less");
}
<!DOCTYPE html>
...
<head>
<title>#ViewBag.Title</title>
#Bundles.RenderStylesheets()
...
#Bundles.RenderScripts()
</body>
Does the jquery.validate.unobtrusive.js file contain a JavaScript reference at the top to jquery-1.5.1.js?
The line would look like:
/// <reference path="jquery-1.5.1.js" />
If so, remove that line. Cassette uses those references to determine build order.
ref: http://getcassette.net/documentation/scripts
This can also happen if you reference files with the same root
e.g. easyXDM.js and easyXDM.debug.js
When you reference easyXMD.js it gives the exception and the solution seems to be use a different naming convention that ensures the roots are different such as easyXMDdebug.js.

How to create resource manager in ASP.NET

I would like to create resource manager on my page and use some data stored in my resource files. (default.aspx.resx and default.aspx.en.resx)
The code looks like this:
System.Resources.ResourceManager myResourceManager = System.Resources.ResourceManager.CreateFileBasedResourceManager("resource",
Server.MapPath("App_LocalResources") + Path.DirectorySeparatorChar, null);
if (User.Identity.IsAuthenticated)
{
Welcome.Text = myResourceManager.GetString("LoggedInWelcomeText");
}
else
{
Welcome.Text = myResourceManager.GetString("LoggedOutWelcomeText");
}
but when i compile and run it on my local server i get this type of error:
Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.
baseName: resource locationInfo: fileName: resource.resources
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.
baseName: resource locationInfo: fileName: resource.resources
Source Error:
Line 89: else
Line 90: {
Line 91: Welcome.Text = myResourceManager.GetString("LoggedOutWelcomeText");
Line 92: }
Line 93:
can you please assist me with this issue?
Use GetLocalResourceObject() which is part of a System.Web.Page's base.
If you wish to access global resources use GetGlobalResourceObject().
keep it simple ;-)
According to MSDN, CreateFileBasedResourceManager is expecting compiled resource files. Usually, one puts .resx files in App_LocalResources. Do you have files in this directory named resource.XXX.resources (where XXX is the current culture id) in this directory.
I don't have a VS handy in order to check this in an ASP.NET project, but the usual way to handle resource strings is to go the project properties, Resources tab and create strings there. This generates a strongly-typed wrapper around your resources, avoiding the need to explicitly create your own ResourceManager.

Categories