I'm trying to define individual business hours for the kendo scheduler. The kendo scheduler only uses a single start/end time for each work day. I want to define start/end times for each day specifically (ie. monday has different times than tuesday).
Someone recently asked this question on
http://www.telerik.com/forums/set-business-hours-for-individual-days
I'm wondering if someone has extended a view to add similar functionality.
I don't have access to the non-minified version of the views (kendo.ui.DayView, kendo.ui.WeekView). Based on the kendo.scheduler.dayview.min.js file, I'd assume I'd have to extend the DayView, and override the _content function, however I just can't copy the minified version of the function into the extending view.
I'm currently using jQuery to loop through the timeslots to add a css class for this on the data-bound event, however, the performance can be pretty bad if you're on the weekly view and have the major tick set to 5.
The code to loop through the timeslots is similar to
http://www.telerik.com/forums/color-code-resource-unavailable-days-hours
dataBound: function (e) {
var scheduler = this;
var view = scheduler.view();
view.table.find("td[role=gridcell]").each(function () {
var element = $(this);
var slot = scheduler.slotByElement(element);
//your custom logic based on the slot object
if (true) {
element.addClass("customClass");
}
})
}
To define start/end times for each day specifically, use the "schedulerInstance.options" property in "Navigation" method of scheduler.e.g.
navigate: function (e) {
var schedulerInstance = $("#schedulerInterface").data('kendoScheduler');
var options = schedulerInstance.options;
switch (new Date().getDay())
{
case 0:
options.startTime = // Your start time;
options.endTime = //Your end time;
break;
case 1:
options.startTime = // Your start time;
options.endTime = //Your end time;
break;
case 2:
options.startTime = // Your start time;
options.endTime = //Your end time;
break;
case 3:
options.startTime = // Your start time;
options.endTime = //Your end time;
break;
case 4:
options.startTime = // Your start time;
options.endTime = //Your end time;
break;
case 5:
options.startTime = // Your start time;
options.endTime = //Your end time;
break;
case 6:
options.startTime = // Your start time;
options.endTime = //Your end time;
break;
}
}
Hope it helps.
Related
when i write a listview in xamarin forms this icon is auto added to IOS and this is not present in Android
i tried removing this using custom renderer by rendering viewrenderer but this this view renderer never gets call
here is the code which i used for custom renderering
[assembly: ExportRenderer(typeof(ViewCell),
typeof(StandardViewCellRenderer))]
namespace Sample.iOS.Renderers.RevisedRenderer
{
public class StandardViewCellRenderer : ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell(Cell item,
UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
switch (item.StyleId)
{
case "none":
cell.Accessory = UIKit.UITableViewCellAccessory.None;
break;
case "checkmark":
cell.Accessory = UIKit.UITableViewCellAccessory.Checkmark;
break;
case "detail-button":
cell.Accessory =
UIKit.UITableViewCellAccessory.DetailButton;
break;
case "detail-disclosure-button":
cell.Accessory =
UIKit.UITableViewCellAccessory.DetailDisclosureButton;
break;
case "disclosure":
default:
cell.Accessory =
UIKit.UITableViewCellAccessory.DisclosureIndicator;
break;
}
return cell;
}
}
}
let me know what need to be modified or add to make it work
remove your switch, and leave the code like this:
var cell = base.GetCell (item, reusableCell, tv);
cell .Accessory = UITableViewCellAccessory.DisclosureIndicator;
You can get more details at:
https://forums.xamarin.com/discussion/88286/xamarin-viewcell-how-to-turn-off-right-arrow-meant-for-touch-action
Cause:
i tried removing this using custom renderer by rendering viewrenderer
but this this view renderer never gets call
The view renderer did get call in your project while the code inside Switch statement never executed, because item.StyleId is always null. You can add a breakpoint to check it.
Solution:
If you want to remove the arrow, just set cell.Accessory = UIKit.UITableViewCellAccessory.None; will work.
class StandardViewCellRenderer : ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell(Cell item,
UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
Console.WriteLine(item.StyleId);
cell.Accessory = UIKit.UITableViewCellAccessory.None;
// switch (item.StyleId)
// {
// case "none":
// cell.Accessory = UIKit.UITableViewCellAccessory.None;
// break;
// case "checkmark":
// cell.Accessory = UIKit.UITableViewCellAccessory.Checkmark;
// break;
// case "detail-button":
// cell.Accessory =
// UIKit.UITableViewCellAccessory.DetailButton;
// break;
// case "detail-disclosure-button":
// cell.Accessory =
//UIKit.UITableViewCellAccessory.DetailDisclosureButton;
// break;
// case "disclosure":
// default:
// cell.Accessory =
// UIKit.UITableViewCellAccessory.DisclosureIndicator;
// break;
// }
return cell;
}
}
If you want to show cells with different cell.Accessory style, you can create a custom property instead of using StyleId.
I also uploaded a demo here.
I have created application using Lync client side SDK 2013 and UCMA 4.0 . Now I test my application with large number of users. How can I simulate large number of client using UCMA or Lync client side SDK?
It depends on what exactly what you want to "simulate".
If you just want call traffic there is sipp, but that is just simple sip calls and doesn't really reflect an actual Microsoft Lync Client.
As far as I know, Microsoft doesn't provide any load testing tools in Lync. You will have to generate them yourself base on what exactly you want to "simulate".
With a UCMA trusted application, you should be able to startup and use a large number of user endpoints to "simulate" common lync services (like randomly changing presence, making calls, send IM's, etc). You would have to create such an app yourself.
I created a tool in UCMA to do my stress test for all my applications than I have made.
It is simple to make, and it is composed of two parts.
This example is a stress tester for calls. Of course, you can easily make a different one by using this example.
We create our platform, follow our Set-CsTrustedApplication.
var platformSettings = new ProvisionedApplicationPlatformSettings("InnixiTester", "urn:application:innixitester");
var collabPlatform = new CollaborationPlatform(platformSettings);
collabPlatform.EndStartup(collabPlatform.BeginStartup(null, null));
Ok, I know what I am doing here is a wrong chaining together, the Begin and the End into one line of code. However, this is just a code exemple. I invite you to read the article of Tom Morgan, he explains why it is not good to do it like me.
We use here a Parallel loop to create all our users-endpoint. In that way, it goes faster.
/*
* Proprieties of the class
*/
private AutoResetEvent _waitForStressTestToFinish = new AutoResetEvent(false);
private List<UserEndpoint> _listUserEndpoints = new List<UserEndpoint>();
private int _maxUsers = 200;
private int _tickTotal;
private int _tickCount;
private int _nbrCallsByIntervall;
/*
* End
*/
_maxUsers = 200; // Nbr max of users
const var callsTotal = 200; // Nbr of total call
const var timeToTest = 30; // Total time to test
const var intervalOfCalls = 5; // We want to make our calls between specific intervals
Parallel.For(0, _maxUsers, i =>
{
CreateUserEndpoint(collabPlatform, i.ToString());
});
You simply create your UserEndpoint here. The scenario is that my users in the active directory are stressuser0 to stressuser200. With extension starting from +14250 to +1425200
private void CreateUserEndpoint(CollaborationPlatform cp, string iteration)
{
try
{
UserEndpointSettings settingsUser = new UserEndpointSettings($"sip:stressuser{iteration}#pferde.net", "pool2010.pferde.net", 5061);
settingsUser = InitializePublishAlwaysOnlineSettings(settingsUser);
var userEndpoint = new UserEndpoint(cp, settingsUser);
userEndpoint.EndEstablish(userEndpoint.BeginEstablish(null, null));
PublishOnline(userEndpoint);
_listUserEndpoints.Add(userEndpoint);
Console.WriteLine($"The User Endpoint owned by URI: {userEndpoint.OwnerUri} was created\n");
}
catch (Exception)
{
Console.WriteLine($"failed to create for --> sip:stressuser{iteration}#pferde.net");
throw;
}
}
private UserEndpointSettings InitializePublishAlwaysOnlineSettings(UserEndpointSettings settings)
{
settings.AutomaticPresencePublicationEnabled = true;
settings.Presence.PreferredServiceCapabilities.AudioSupport = CapabilitySupport.Supported;
return (settings);
}
Now time to place the calls! We are going to code a simple algorithm with a timer. Is going to calculate how many calls it needs to make for X time and for Y Calls and for Z intervals.
Console.WriteLine("Tape a key to place calls...");
Console.ReadKey();
PlaceCalls(callsTotal, timeToTest, intervalOfCalls);
_waitForStressTestToFinish.WaitOne();
}
catch (Exception ex)
{
Console.WriteLine($"Shutting down platform due to error {ex}");
ShutdownPlatform(collabPlatform);
}
ShutdownPlatform(collabPlatform);
}
private void PlaceCalls(int callsMax, int timeMax, int timeIntervall)
{
_tickTotal = timeMax / timeIntervall;
_nbrCallsByIntervall= callsMax / _tickTotal;
Console.WriteLine($"_nbrCallsByIntervall --> {_nbrCallsByIntervall}");
var timeIntervalTimespan = new TimeSpan(0, 0, 0, timeIntervall);
_timer = new Timer(timeIntervalTimespan.TotalMilliseconds);
_timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
_timer.Enabled = true;
}
void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (_tickCount < _tickTotal)
{
Console.WriteLine($"\n Pause Timer | On {_tickCount} to {_tickTotal}\n");
_timer.Enabled = false;
for (var i = 0; i <= _nbrCallsByIntervall - 1; ++i)
{
ConversationSettings convSettings = new ConversationSettings();
Conversation conversation = new Conversation(_listUserEndpoints[generateNumber(0, _listUserEndpoints.Count)], convSettings);
var audioVideoCall = new AudioVideoCall(conversation);
CallEstablishOptions options = new CallEstablishOptions();
var gNbr = generateNumber(0, _listUserEndpoints.Count);
try
{
// Here I'm calling a single phone number. You can use GenerateNumber to call stressusers each others. But you have to extend your code to accept the calls coming.
audioVideoCall.BeginEstablish($"3322", options, null, audioVideoCall);
}
catch (Exception)
{
Console.WriteLine("Fail to Call the remote user...");
throw;
}
Console.WriteLine($"Call--> +1425{gNbr}.Counter--> {_tickCount} Ticket--> {_tickTotal} and thread id {Thread.CurrentThread.ManagedThreadId}");
}
_tickCount++;
_timer.Enabled = true;
Console.WriteLine("\n reStart Timer \n");
}
else
{
Console.WriteLine("\n!!! END Stress test !!!\n");
_timer.Enabled = false;
_waitForCallToEstablish.Set();
}
}
private int generateNumber(int min, int max)
{
var r = new Random();
Thread.Sleep(200);
return (r.Next(min, max));
}
Need to get sounds duration into memory.
var sound = new Sound(this);
function getSoundDuration(soundName:String):Number
{
var dur = 0;
sound.onLoad = function (success:Boolean) {
if (success) {
dur = this.duration;
}
};
sound.loadSound(soundName, false);
return dur;
}
var DoS1 = getSoundDuration("sound1.mp3");
var DoS2 = getSoundDuration("sound2.mp3");
trace(DoS2);
trace(DoS2);
is that possible without wait onLoad to finish ?
It is not, the sound needs to be loaded in order to read the metadata. If you are using static sound files, you could hard code those values.
public function SeedsAndPots()
{
startpage = new StartPage();
addChild(startpage);
buttonPage = new ButtonPage();
addChild(buttonPage);
buttonPage.addEventListener(MouseEvent.CLICK, GoToGame);
}
public function GoToGame(e:MouseEvent):void
{
removeChild(startpage);
buttonPage.removeEventListener(MouseEvent.CLICK, GoToGame);
removeChild(buttonPage);
gamePage = new GamePage();
addChild(gamePage);
}
// I wanna do a function that says that if time is 0 i should go to my GameOver-Page.
}
}
Create a countdown variable to reflect time in seconds.
Instantiate a timer when you load your game page to countdown every second.
When time has reached 0, apply the logic to end the current level and display your game over page.
// store time remaining in a countdown timer
protected var countdown:uint = 60;
// create a timer, counting down every second
protected var timer:Timer;
// in your go to game, or when you want to start the timer
public function GoToGame(e:MouseEvent):void
{
// ... your go to game function
// start your countdown timer.
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
protected function timerHandler(event:TimerEvent):void
{
// countdown a second
--countdown;
// update any counter time text field display here...
// if you've reached 0 seconds left
if(countdown == 0)
{
// stop the timer
timer.removeEventListener(TimerEvent.TIMER, timerHandler);
timer.reset();
// remove current gamePage
// addChild to your game over page.
}
}
Is there a way to run a piece of JavaScript code only ONCE, without using boolean flag variables to remember whether it has already been ran or not?
Specifically not something like:
var alreadyRan = false;
function runOnce() {
if (alreadyRan) {
return;
}
alreadyRan = true;
/* do stuff here */
}
I'm going to have a lot of these types of functions and keeping all booleans would be messy...
An alternative way that overwrites a function when executed so it will be executed only once.
function useThisFunctionOnce(){
// overwrite this function, so it will be executed only once
useThisFunctionOnce = Function("");
// real code below
alert("Hi!");
}
// displays "Hi!"
useThisFunctionOnce();
// does nothing
useThisFunctionOnce();
'Useful' example:
var preferences = {};
function read_preferences(){
// read preferences once
read_preferences = Function("");
// load preferences from storage and save it in 'preferences'
}
function readPreference(pref_name){
read_prefences();
return preferences.hasOwnProperty(pref_name) ? preferences[pref_name] : '';
}
if(readPreference('like_javascript') != 'yes'){
alert("What's wrong wth you?!");
}
alert(readPreference('is_stupid') ? "Stupid!" : ":)");
Edit: as CMS pointed out, just overwriting the old function with function(){} will create a closure in which old variables still exist. To work around that problem, function(){} is replaced by Function(""). This will create an empty function in the global scope, avoiding a closure.
I like Lekensteyn's implementation, but you could also just have one variable to store what functions have run. The code below should run "runOnce", and "runAgain" both one time. It's still booleans, but it sounds like you just don't want lots of variables.
var runFunctions = {};
function runOnce() {
if(!hasRun(arguments.callee)) {
/* do stuff here */
console.log("once");
}
}
function runAgain() {
if(!hasRun(arguments.callee)) {
/* do stuff here */
console.log("again");
}
}
function hasRun(functionName) {
functionName = functionName.toString();
functionName = functionName.substr('function '.length);
functionName = functionName.substr(0, functionName.indexOf('('));
if(runFunctions[functionName]) {
return true;
} else {
runFunctions[functionName] = true;
return false;
}
}
runOnce();
runAgain();
runAgain();
A problem with quite a few of these approaches is that they depend on function names to work: Mike's approach will fail if you create a function with "x = function() ..." and Lekensteyn's approach will fail if you set x = useThisFunctionOnce before useThisFunctionOnce is called.
I would recommend using Russ's closure approach if you want it run right away or the approach taken by Underscore.js if you want to delay execution:
function once(func) {
var ran = false, memo;
return function() {
if (ran) return memo;
ran = true;
return memo = func.apply(this, arguments);
};
}
var myFunction = once(function() {
return new Date().toString();
});
setInterval(function() {console.log(myFunction());}, 1000);
On the first execution, the inner function is executed and the results are returned. On subsequent runs, the original result object is returned.
What about an immediately invoked anonymous function?
(function () {
// code in here to run once
})();
the code will execute immediately and leave no trace in the global namespace.
If this code is going to need to be called from elsewhere, then a closure can be used to ensure that the contents of a function are run only once. Personally, I prefer this to a function that rewrites itself as I feel doing so can cause confusion, but to each their own :) This particular implementation takes advantage of the fact that 0 is a falsy value.
var once = (function() {
var hasRun = 0;
return function () {
if (!hasRun) {
hasRun++;
// body to run only once
// log to the console for a test
console.log("only ran once");
}
}
})();
// test that the body of the function executes only once
for (var i = 0; i < 5; i++)
once();
Elegant solution from Douglas Crockford, spent some time to understand how it works and stumbled upon this thread.
So the wrapper once return function which is just invokes parameter's function you passed. And taking advantage of closures this construction replaced passed function to empty function, or null in original source, after the first call, so all the next calls will be useless.
This is something very close to all other answers, but it is kinda self containing code and you could use it independently, which is good. I am still trying to grasp all the entire mechanism of replacement, but practically it just works perfectly.
function once (func) {
return function () {
var f = func;
func = null;
return f.apply(this, arguments);
};
}
function hi(name) {
console.log("Hi %s", name);
}
sayonce = once(hi);
sayonce("Vasya");
sayonce("Petya");
for those who are curious here is jsbin transformations
(function (){
var run = (function (){
var func, blank = function () {};
func = function () {
func = blank;
// following code executes only once
console.log('run once !');
};
return function(){
func.call();
};
})();
run();
run();
run();
run();
})();
I just ran into this problem, and ended up doing something like the following:
function runOnce () {
if (!this.alreadyRan) {
// put all your functionality here
console.log('running my function!');
// set a property on the function itself to prevent it being run again
this.alreadyRan = true;
}
}
This takes advantage of the fact that Javascript properties are undefined by default.
In addition, the nature of what happens in the "/* do stuff here */" may leave something around that, when present, must mean that the function has run e.g.
var counter = null;
function initCounter() {
if (counter === null) {
counter = 0;
}
}
If not bound to an event, code is usually ran once