I am trying to parse recurrence rule string to telerik object but it does not work for me at all. The result is always null even though the string pattern seems to be right (passed from Kendo Recurrence control). Thank you for any thoughts on this.
Update: I tried another case to prove if the parse is working or not, here is the result:
As per this post http://www.telerik.com/forums/parsing-recurrencerule-server-side recurrence rule works when INTERVAL is specified.
As to the exceptions thrown by RecurrenceRule.TryParse, I noticed that
it is caused when INTERVAL rule is missing. If you want to use the
RecurrenceRule.TryParse method, you will need to add it manually.
here is the modified code that was originally uploaded by jonno
var today = DateTime.Now.Date;
var start = today.AddDays(-14).AddHours(19);
var end = start.AddHours(2.5);
// Create a few recurring events using Kendo Web Scheduler and use the recurrence rules
var patterns = new[]
{
"FREQ=DAILY;UNTIL=20140227T130000Z",
"FREQ=DAILY;INTERVAL=3;UNTIL=20140227T130000Z",
"FREQ=DAILY;INTERVAL=3;COUNT=4",
"FREQ=DAILY;INTERVAL=5",
"FREQ=WEEKLY;BYDAY=WE;INTERVAL=1",
"FREQ=WEEKLY;COUNT=5;BYDAY=TU,WE;INTERVAL=1",
"FREQ=WEEKLY;INTERVAL=4;COUNT=5;BYDAY=WE,TH,SA",
"FREQ=WEEKLY;INTERVAL=3;UNTIL=20140331T090000Z;BYDAY=WE,TH,SA",
"FREQ=MONTHLY;BYMONTHDAY=13;INTERVAL=1",
"FREQ=MONTHLY;COUNT=7;BYDAY=1FR;INTERVAL=1",
"FREQ=MONTHLY;UNTIL=20150212T130000Z;BYDAY=SU,SA;BYSETPOS=-1;INTERVAL=1",
"FREQ=YEARLY;BYMONTH=12;BYMONTHDAY=25",
"FREQ=YEARLY;COUNT=3;BYMONTH=2;BYMONTHDAY=28",
"FREQ=YEARLY;UNTIL=20200306T130000Z;BYMONTH=8;BYDAY=3WE",
"FREQ=WEEKLY;COUNT=5;BYDAY=MO;INTERVAL=4",
"FREQ=WEEKLY;COUNT=2;BYDAY=MO;INTERVAL=1",
};
// Now figure out which events will trigger in the next week - server side only - using Telerik.Web.UI.dll RecurrenceRule class.
foreach (var expr in patterns)
{
var rrule = string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}\r\nDTEND:{1:yyyyMMddTHHmmssZ}\r\nRRULE:{2}", start, end, expr);
try
{
RecurrenceRule recRule = null;
var b = RecurrenceRule.TryParse(rrule, out recRule);
if (recRule == null)
{
Console.WriteLine("PARSE ERROR: " + expr);
continue;
}
}
catch (Exception)
{
Console.WriteLine("PARSE ERROR: " + expr);
}
}
Related
I've tried a few different ways to do this and each way has a piece of code I am just not getting right. I need to update a custom field UsrCustomerShipAccount in Customer Locations if it is updated in the Customer Delivery Tab. I tried SetValueExt and creating a graph instance. Sorry about the dumb question.
The way that seemed to get me the closest is below:
protected void LocationExtAddress_UsrCustomerShipAccnt_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (LocationExtAddress)e.Row;
if (row == null) return;
PXSelectBase<Location> locationObj = new PXSelect<Location, Where<Location.bAccountID, Equal<Required<Location.bAccountID>>>>(Base);
Location deliveryLocation = locationObj.Select(row.LocationBAccountID);
var locationExt = PXCache<Location>.GetExtension<LocationExt>(location); <-- This generates error that there is no LocationExt.
deliveryLocation.Cache.SetValueExt(deliveryLocation, "UsrCustomerShipAccount", -->This needs to be the value that changed LocationExtAddress.UsrCustomerShipAccount but I don't see how to get this<--);
deliveryLocation.Cache.IsDirty = true;
deliveryLocation.Update(deliveryLocation); <--I don't know if this doesn't work because it is wrong or if it is because "UsrCustomerShipAccount" is not in deliverLocation.
}
You have
var locationExt = PXCache<Location>.GetExtension<LocationExt>(location);
shouldn't this be
var locationExt = PXCache<Location>.GetExtension<LocationExt>(deliveryLocation );
?
I'm using the Bing Maps API to generate images from certain locations using the BotFramework-Location NuGet package. (Which code can be found here)
Sometimes it works, but sometimes the images are not loaded due to an error in the Rest call (which is called by the BotFramework, not by me)
This is my code:
IGeoSpatialService geoService = new AzureMapsSpatialService(this.azureApiKey);
List < Location > concreteLocations = new List < Location > ();
foreach(String location in locations) {
LocationSet locationSet = await geoService.GetLocationsByQueryAsync(location);
concreteLocations.AddRange(locationSet ? .Locations);
}
// Filter out duplicates
var seenKeys = new HashSet < String > ();
var uniqueLocations = new List < Location > ();
foreach(Location location in concreteLocations) {
if (seenKeys.Add(location.Address.AddressLine)) {
uniqueLocations.Add(location);
}
}
concreteLocations = new List < Location > (uniqueLocations.Take(5));
if (concreteLocations.Count == 0) {
await context.PostAsync("No dealers found.");
context.Done(true);
} else {
var locationsCardReply = context.MakeMessage();
locationsCardReply.Attachments = new LocationCardBuilder(this.bingApiKey, new LocationResourceManager()).CreateHeroCards(concreteLocations).Select(card => card.ToAttachment()).ToList();
locationsCardReply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
await context.PostAsync(locationsCardReply);
}
Which responds this:
The reason not all images are shown is because the Rest call to the Bing Maps API returns this:
mapArea: This parameter value is out of range.
Here is one of the image uris that fail (I removed my key):
https://dev.virtualearth.net/REST/V1/Imagery/Map/Road?form=BTCTRL&mapArea=49.5737,5.53792,49.57348,5.53744&mapSize=500,280&pp=49.5737,5.53744;1;1&dpi=1&logo=always&key=NOT_REAL_12758FDLKJLDKJO8769KLJDLKJF
Anyone know what I've been doing wrong?
I think I understood why you got that error. I tried to get this map and got the same result as yours, as you said:
mapArea: This parameter value is out of range.
If you look at the sample url you provided, the mapArea is equal to 49.5737,5.53792,49.57348,5.53744
So I just inverted the coordinates of the 2 points defining this area, putting the one with the smaller latitude value first, I got a reply:
EDIT:
As you commented, this call is made inside BotBuilder-Location code, not on yours. I had a look to it, this is the method to generate the map, called inside LocationCardBuilder class that you are instantiating:
public string GetLocationMapImageUrl(Location location, int? index = null)
{
if (location == null)
{
throw new ArgumentNullException(nameof(location));
}
var point = location.Point;
if (point == null)
{
throw new ArgumentNullException(nameof(point));
}
if (location.BoundaryBox != null && location.BoundaryBox.Count >= 4)
{
return string.Format(
CultureInfo.InvariantCulture,
ImageUrlByBBox,
location.BoundaryBox[0],
location.BoundaryBox[1],
location.BoundaryBox[2],
location.BoundaryBox[3],
point.Coordinates[0],
point.Coordinates[1],
index,
this.apiKey);
}
else
{
return string.Format(
CultureInfo.InvariantCulture,
ImageUrlByPoint,
point.Coordinates[0],
point.Coordinates[1],
index,
apiKey);
}
}
As you can see, there is no restriction on the format of the BoundaryBox item. But if you look at the documentation about location data here:
BoundingBox: A geographic area that contains the location. A bounding box contains SouthLatitude, WestLongitude, NorthLatitude, and EastLongitude values in units of degrees.
As you may know, in code, SouthLatitude is smaller that NorthLatitude (as it expressed with positive and negative values in code depending on the location compared to Ecuador: 43N is 43, 43S is -43). So the problem seems to be here.
I made a quick test to see if I got the error base on the call you are doing before (to GetLocationsByQueryAsync), I wasn't able to reproduce this case. Can you share the query you did that linked to this problem?
I've followed this tutorial to create a custom dynamic backend configuration with serialized data, and everything is working as expected. yay
But now I want to take another step and only show some inputs when a specific value is selected in a select box. I know that I can use when doing this with system.xml, but how can I accomplish the same thing via code with dynamics serialized tables?
I ended up doing some kind of Javascript workaround to enable/disable a certain input.
function togleSelect(element)
{
var val = element.value;
var name = element.name;
if (val == 0) // select value to be triggered
{
name = name.substr(0, name.lastIndexOf("[")) + "[name_of_my_input]";
var target = document.getElementsByName(name);
target[0].disabled = false;
}
else
{
name = name.substr(0, name.lastIndexOf("[")) + "[name_of_my_input]";
var target = document.getElementsByName(name);
target[0].disabled = true;
}
}
It's not the best solution but it's working.
I am using EF4/LINQ for the first time and have run into an issue. I am looping thru the results of a LINQ query using a foreach loop as follows:
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
CallOutcomeSubmission los = new CallOutcomeSubmission();
client = connectToService();
try
{
using (var context = new CallOutcomeContext())
{
// List of available actions
private static string ACTION_CALL_ATTEMPT = "Call Attempt";
DateTime oneDayAgo = DateTime.Now.AddHours(-24);
var query = from co in context.T_MMCallOutcome
join ca in context.T_Call on co.CallID equals ca.CallID
join lv in context.T_LeadVendorEmailHeader on co.LeadVendorEmailID equals lv.LeadVendorEmailID
where co.EnteredOn > oneDayAgo && co.MMLeadActionID == null
select new
{
co.CallOutcomeID,
co.CallID,
co.LeadVendorEmailID,
MMLeadID = lv.email_text,
ca.OutcomeID,
lv.FranchiseNumber,
co.MMLeadActionID,
co.LeadAction
};
// if any results found for query
if (query.Any())
{
foreach (var call in query.ToList())
{
// if the franchise exists
if (client.FranchiseExists(int.Parse(call.FranchiseNumber)))
{
switch (call.OutcomeID)
{
case 39: // Not Answered
call.LeadAction = ACTION_CALL_ATTEMPT;
break;
case 43: // Remove from Call List
break;
default: // If the OutcomeID is not identified in the case statement
break;
} // switch
}
else
{
los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent: No franchise found with franchise ID " + call.FranchiseNumber);
}
// Save any changes currently on context
context.SaveChanges();
} // foreach
}
// if no results found from query write system log stating such
else
{
los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent: No new entries found");
}
} // using
client.Close();
}
catch (System.TimeoutException exception)
{
los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent:" + exception.ToString());
client.Abort();
}
catch (System.ServiceModel.CommunicationException exception)
{
los.eventLog.WriteEntry("CallOutcomeSubmission.OnTimedEvent:" + exception.ToString());
client.Abort();
}
}
When I try to do the assignment:
call.LeadAction = ACTION_CALL_ATTEMPT;
I get a build error of
Property or indexer 'AnonymousType#2.LeadAction' cannot be assigned to -- it is read only
I can't seem to find anything on this specific error doing a Google search and am not sure what I am doing wrong. Is it because the original query contains a join?
How can I do the assignment of call.LeadAction within the foreach loop?
I would also like to know if there are design issue withe way I have written the query or performed any of the operations since this is my first foray into EF/LINQ.
You're creating a new anonymous type - with the Linq joins and then trying to set that value. What you're really wanting to do, is update the call's LeadAction correct?
How would EF know to translate your new query back to an entity so it can go back to the database? It would have to go through alot of hoops, and it's not capable of that.
What you could do, is retrieve the Call from your database and set the LeadAction that way - I'm using Find, assuming that CallID is your PK:
case 39: // Not Answered
var thisCall = context.T_Call.Find(call.CallID)
thisCall.LeadAction = ACTION_CALL_ATTEMPT;
break;
I'm using WatIn to create an automated test for a Web App that uses Telerik controls: my first challenge is to drive a Telerik date control - a RadDatePicker.
Simply entering the text in the likeliest input field doesn't work: the value is reset to blank as the form is posted. So I imagine I need a more complex set of automated interactions -- for example, I found this thread on the Telerik site discussing how to automated a selection from a Telerik combo box.
Can anyone supply the magic combination of interactions I need?
(I'm sure that the answer would help anyone using any automated test tool, hence I've also flagged this question with a couple of other test frameworks too :-))
I'm using Selenium RC and had a similar problem few days ago. It took me ages to find the right way of doing it so I thought I will share the solution that worked for me:
(NOTE: I couldn't use $find)
The javascript to set the date on the RadDatePicker is:
var appBrowser = this.browserbot.getCurrentWindow();
var datepicker = appBrowser.yourDatePickerId; //note: no quotes
var selectDate=new Date();
selectDate.setFullYear(yourYear,yourMonth,yourDay);
datepicker.SetDate(selectDate);
datepicker.DateInput.SetDate(selectDate);
and then use selenium GetEval in your test to call javascript code to set the date:
selenium.GetEval("javascript here");
You should definitely wrap it around some parametrised helper class that will generate the javascript code for you each time you want to set the date in the test by passing id of the control and date.
I finally have a solution that works. The key is to use javascript to call the client-side API for the telerik control. The same technique is required for all complex Telerik controls, e.g. RadInput.
I used the technique recommended on the WatiN website for writing your own control http://watinandmore.blogspot.com/2009/12/wrapping-complex-logic-in-control.html to come up with this:
public class TelerikDatePicker : Control<TextField>
{
public DateTime? Value
{
get
{
var jScript = string.Format(#"$find(""{0}"").get_selectedDate();", Element.Id);
var selectedDateStr = Eval(jScript);
return TranslateJavascriptDateStringIntoDateTime(selectedDateStr);
}
set
{
var jScript = string.Format(#"$find(""{0}"").set_selectedDate(new Date(""{1:MMMM dd,yyyy}""));", Element.Id, value);
Eval(jScript);
}
}
public void SetValue(DateTime? value)
{
if (value.HasValue)
Value = value.Value;
else
Clear();
}
public void Clear()
{
var jScript = string.Format(#"$find(""{0}"").clear();", Element.Id);
Eval(jScript);
}
private string Eval(string script)
{
return Element.DomContainer.Eval(script);
}
public bool IsEnabled()
{
var jScript = string.Format(#"$find(""{0}"").get_enabled();", Element.Id);
return Eval(jScript) == "true";
}
private DateTime? TranslateJavascriptDateStringIntoDateTime(string jsDateStr /*E.g. Mon Mar 12 00:00:00 UTC+0100 2012*/)
{
if (String.IsNullOrEmpty(jsDateStr) || jsDateStr == "null") return null;
var abbreviatedMonth = jsDateStr.Substring(4, 3);
var dayOfTheMonth = jsDateStr.Substring(8, 2).TrimEnd(' ');
var year = jsDateStr.Substring(jsDateStr.Length-4, 4);
const string format = "d MMM yyyy";
var dateStr = dayOfTheMonth + " " + abbreviatedMonth + " " + year;
return DateTime.ParseExact(dateStr, format, CultureInfo.InvariantCulture);
}
}
I had the same issue with a RadDatePicker that would post back empty after typing in values.
I managed to automate typing in the date into the input field with these steps:
Select the dateInput text box associated with the control.
Do a dateInput.MouseClick() on it
Type the date into the field Manager.Desktop.KeyBoard.TypeText("1/1/1990")
Do a .MouseClick() on any other element on the page, e.g. some div
I found that #4 was needed to fire the events to make the control blur therefore "saving" its value.
Then you can submit and the value should go along with it.
Solved that problem for SeleniumIDE - you have to use "fireEvent" method with value "blur" for "ControlID" after you've set value using "sendKeys" or "type" methods. Strange that this problem does not occur when automating with WebDriver.