Disabling DHTMLX event_bar_date on ASP.net cs file - c#

I am using DHTMLX nuget package and I'm trying to disable or hide the value on event_bar_date through my aspx.cs
sched.Templates.event_header = #"<span class='event_date'
{start_date:date(%g:%s %A)}</span><br></div>";
sched.Templates.event_bar_header = ???????
I found something like this but this but using JS file which Im not familiar with, I want it to be directly on my cs file
scheduler.templates.event_bar_date = function(start,end,ev){
return "• <b class ='disp_none'>"+scheduler.templates.event_date(start)+"</b> ";
};

You can do the same config in c#:
var scheduler = new DHXScheduler();
...
scheduler.Templates.event_bar_date = "• ";
http://scheduler-net.com/docs/options-and-templates.html#using_javascript_configuration_with_the_scheduler

You can wrap JS configuration into some function and tell DHXScheduler to call it to initialization on the client side, e.g.
JS:
window.app = {
configure: function () {
scheduler.attachEvent("onSchedulerReady", function () {
scheduler.templates.event_bar_date = function (start, end, ev) {
return "• ";
};
});
}
};
C#
var scheduler = new DHXScheduler();
scheduler.BeforeInit.Add("app.configure();");
Here is a complete demo, you might need to update nuget package of DHTMLX Scheduler in order to run it
https://s3.amazonaws.com/uploads.hipchat.com/15721/63476/GFsBPty6TaIz13o/schedulernetmonthdatetemplate.zip
Server-side configuration ( scheduler.Templates.event_bar_date = "• "; ) should also work, however seems like this particular template gets rewrited during initialization, that is a reason why i've put it definition into onSchedulerReady handler
http://docs.dhtmlx.com/scheduler/api__scheduler_onschedulerready_event.html

Related

Blazor - Drag and Drop uploads file

I'm facing an issue with uploading a file via the Drag'n Drop API.
Here the following blazor component:
<InputTextArea
#ondrop="HandleDrop"
#ondragenter="HandleDragEnter"
#ondragleave="HandleDragLeave"/>
</InputTextArea>
#code {
private async Task HandleDrop(DragEventArgs args)
{
var files = args.DataTransfer.Files;
// Do something to upload the file and get the content
}
I want to upload the file and display it in the textarea. Now since .NET6 the DragEventArgs will list all files (if any) associated with the Drag'n Drop event.
Natively there seems to be no way to get the content of those files.
Therefore I tried to achieve this with JavaScript interop:
private async Task HandleDrop(DragEventArgs args)
{
var content = await jsRuntime.InvokeAsync<string>("getContentFromFile", args);
}
With the following JavaScript function (which is referenced in the _Layout.cshtml):
async function getContentFromFile(args) {
// Use some API here? File Upload API? Didn't work as args is only a data object and not the "real" DragEventArgs from JavaScript
// I also tried FileReader
const fileName = args.Files[0]; // Let's assume we always have one file
let content = await new Promise((resolve) => {
let fileReader = new FileReader();
fileReader.onload = (e) => resolve(fileReader.result);
fileReader.readAsText(fileName);
});
console.log(content);
return content;
}
This approach let to other issues and exceptions, like that the FileReader threw:
parameter is not of type 'Blob'
Is this with this approach with the current version of blazor (.net6) possible at all? Any tips are welcome.

How to using CEFSharp JavascriptObjectRepository in WPF

I want get javascript response,
and follow cef document to do,
this is my step,
first create a html file
...
<button onclick='test()'>click</button>
...
<script>
function test(){
alert('123');
callbackObj.getMessage('123');
}
</script>
and then I register javascript response method
CefSharpSettings.LegacyJavascriptBindingEnabled = true;
this.MyBrowser.JavascriptObjectRepository.Register("callbackObj", new PagaJavaScriptResponse(), true);
and create class to do PagaJavaScriptResponse
public class PagaJavaScriptResponse
{
public void getMessage(string s)
{
....
}
}
next step to check the register is bound
var isBound = this.MyBrowser.JavascriptObjectRepository.IsBound("callbackObj");
the result is true,
last step to url http://127.0.0.1/index.html
this.MyBrowser.Address = #"http://127.0.0.1:8887/test.html";
here I think when I click button it should be return 123 to my method in C#, but not,
hot it's correct?
I try a solution
just when page loaded excute this javascript
this.MyBrowser.WebBrowser.ExecuteScriptAsyncWhenPageLoaded(#"(async function() {await CefSharp.BindObjectAsync('callbackObj', 'bound');})();");
it's will work

C#.Net ClearsScript V8 enable modules

Is there a way to enable "import <module>.js;" statements in an embedded V8 Runtime using Microsoft ClearScript?
I couldn't find any examples and makes me think I'd have to parse the script file myself first to enable this.
Yes there is. See answer to this question as the basic approach. That question was about enabling CommonJS Require. For ES6 modules approach you will want something like this:
using System;
using Microsoft.ClearScript;
using Microsoft.ClearScript.JavaScript;
using Microsoft.ClearScript.V8;
namespace ConsoleApp1
{
class Program
{
static void Main()
{
V8ScriptEngine engine = new V8ScriptEngine();
engine.DocumentSettings.SearchPath = #"c:\temp\js\";
engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading;
engine.AddHostType(typeof(Console));
Console.WriteLine("Hello from C#");
engine.Execute(new DocumentInfo() { Category = ModuleCategory.Standard }, #"
Console.WriteLine('Hello from Javascript');
import {print} from 'a.js';
import {add} from 'b.js';
print(add(30, 12));
Console.WriteLine('Javascript signing off...');
");
Console.ReadKey();
}
}
}
Where the JS looks like this:
// File c:\temp\js\a.js
export function print(txt) {
Console.WriteLine('The answer to Life etc is ... ' + txt);
}
// File c:\temp\js\b.js
export function add(var1, var2) {
return var1 + var2;
}
Result is:
This example is reading files from the local file system as indicated by the AccessFlags = EnableFileLoading setting, with the SearchPath setting giving the path, or paths if given a comma-separated list of paths.
It is the 'ModuleCategory.Standard' option that enables ES6-stylee module loading.
You could also use a roll-your-own require() function similar to node.js. I wrote a blog article here and there's a working CodePen to illustrate the approach which was inspired by an article by Michele Nasti which was itself based on the ideas in chapter 10 of the book Eloquent JavaScript by Marijn Haverbeke.
Here is my coded example:
const myCode1 = `
let utils = function (){
this.say = function(x){
log('utils: says = ' + x)
};
return this;
}
exports.utils = utils;
`;
const myCode2 = `
let customer = function (){
this.say = function(x){
log('Customer: says = ' + x)
};
return this;
}
exports.customer = customer;
`;
/*
*/
// I am loading simple source code strings into an array - in the real solution
// you would use some kind of source code fetch / load to string process.
let sourceCode = {c1: myCode1, c2: myCode2};
myRequire.cache = Object.create(null);
function myRequire(name) {
log(`myRequire: You require file ${name}`)
if (!(name in myRequire.cache)) {
log(`myRequire: ${name} is not in cache; reading from disk`)
let code = sourceCode[name]; // load the code - this is bespoke to your env
let module = {exports: {}};
myRequire.cache[name] = module;
let wrapper = Function("require, exports, module", code);
wrapper(myRequire, module.exports, module);
}
log(`myRequire: ${name} is in cache. Returning it...`)
return myRequire.cache[name].exports;
}
// myRequire() produces an object from the 'exports' object in the loaded code.
//let myExports = new myRequire('c1');
// we can then refer to these as
// let util = myExports.utils();
// or just use
// let util = new myRequire('c1').utils();
// So...Require c1 will create an object with exports.
let util = new myRequire('c1').utils();
util.say('I am alive!')
log("");
// Require c2 will create an object with exports.
let cust = new myRequire('c2').customer();
cust.say('I am alive too!')
function log(msg){
$('#log').html($('#log').html() + "<br />" + msg);
}
The output is
myRequire: You require file c1
myRequire: c1 is not in cache; reading from disk
myRequire: c1 is in cache. Returning it...
utils: says = I am alive!
myRequire: You require file c2
myRequire: c2 is not in cache; reading from disk
myRequire: c2 is in cache. Returning it...
Customer: says = I am alive too!

Modify programatically csproj files with Microsoft.Build.Evaluation (instead of Engine)

I would like to read, modify and write back csproj files.
I've found this code, but unfortunately Engine class is depreciated.
Engine engine = new Engine()
Project project = new Project(engine);
project.Load("myproject.csproj");
project.SetProperty("SignAssembly", "true");
project.Save("myproject.csproj");
So I've continued based on the hint I should use Evaluation.ProjectCollection instead of Engine:
var collection = new ProjectCollection();
collection.DefaultToolsVersion = "4.0";
var project = new Project(collection);
// project.Load("myproject.csproj") There is NO Load method :-(
project.FullPath = "myproject.csproj"; // Instead of load? Does nothing...
// ... modify the project
project.Save(); // Interestingly there is a Save() method
There is no Load method anymore. I've tried to set the property FullPath, but the project still seems empty. Missed I something?
(Please note I do know that the .csproj file is a standard XML file with XSD schema and I know that we could read/write it by using XDocument or XmlDocument. That's a backup plan. Just seeing the .Save() method on the Project class I think I missed something if I can not load an existing .csproj. thx)
I've actually found the answer, hopefully will help others:
Instead of creating a new Project(...) and trying to .Load(...) it, we should use a factory method of the ProjectCollection class.
// Instead of:
// var project = new Project(collection);
// project.FullPath = "myproject.csproj"; // Instead of load? Does nothing...
// use this:
var project = collection.LoadProject("myproject.csproj")
Since i can't comment:
This won't work in .net core without first setting the MSBuild.exe path variable. The code to do so can be found here
https://blog.rsuter.com/missing-sdk-when-using-the-microsoft-build-package-in-net-core/
and is written here
private static void SetMsBuildExePath()
{
try
{
var startInfo = new ProcessStartInfo("dotnet", "--list-sdks")
{
RedirectStandardOutput = true
};
var process = Process.Start(startInfo);
process.WaitForExit(1000);
var output = process.StandardOutput.ReadToEnd();
var sdkPaths = Regex.Matches(output, "([0-9]+.[0-9]+.[0-9]+) \\[(.*)\\]")
.OfType<Match>()
.Select(m => System.IO.Path.Combine(m.Groups[2].Value, m.Groups[1].Value, "MSBuild.dll"));
var sdkPath = sdkPaths.Last();
Environment.SetEnvironmentVariable("MSBUILD_EXE_PATH", sdkPath);
}
catch (Exception exception)
{
Console.Write("Could not set MSBUILD_EXE_PATH: " + exception);
}
}

how to pass arguments in EMR job to use in bootstrap script

I have a bootstrap script which runs with my EMR job.
I need to pass a parameter to this script so I can configure a path for different environments
The following line in my script needs to use it
path=OVA/{EnvironmentName}/Scripts/UniqueUsers
I am using C# to invoke a streaming EMR job. how do I pass this argument while I create the job?
HadoopJarStepConfig config = new StreamingStep()
.WithInputs(input)
.WithOutput(output)
.WithMapper(configMapperLocation)
.WithReducer(configReducerLocation)
.ToHadoopJarStepConfig();
string configName = string.Format("Unique_Users_config_{0}", outputFolder);
StepConfig uniqueUsersDaily = new StepConfig()
.WithName(configName)
.WithActionOnFailure("TERMINATE_JOB_FLOW")
.WithHadoopJarStep(config);
ScriptBootstrapActionConfig bootstrapActionScript = new ScriptBootstrapActionConfig()
.WithPath(configBootStrapScriptLocation);
BootstrapActionConfig bootstrapAction = new BootstrapActionConfig()
.WithName("CustomAction")
.WithScriptBootstrapAction(bootstrapActionScript);
string jobName = string.Format("Unique_User_DailyJob_{0}", outputFolder);
RunJobFlowRequest jobRequest = new RunJobFlowRequest()
.WithName(jobName)
.WithBootstrapActions(bootstrapAction)
.WithSteps(uniqueUsersDaily)
.WithLogUri(configHadoopLogLocation)
.WithInstances(new JobFlowInstancesConfig()
.WithHadoopVersion(configHadoopVersion)
.WithInstanceCount(2)
.WithKeepJobFlowAliveWhenNoSteps(false)
.WithMasterInstanceType(configMasterInstanceType)
.WithSlaveInstanceType(configSlaveInstanceType));
You can use withArgs() of ScriptBootstrapActionConfig, in Java you can do as follows, I am sure there is a similar method for C#:
ScriptBootstrapActionConfig bootstrapActionScript = new ScriptBootstrapActionConfig()
.WithPath(configBootStrapScriptLocation)
.WithArgs(List<String> args);

Categories

Resources