I am trying to list all the events from a native calendar using the code below.
I am getting an object, and I want the exact event string.
I have set a meeting in my calendar and I want to read the same.
private void getEvents() {
try {
EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_ONLY);
Enumeration events = eventList.items()
while (events.hasMoreElements()) {
Event event = (Event)events.nextElement();
Dialog.alert(event.toString());
}
} catch (PIMException e) {
Dialog.alert(e.getMessage());
}
}
I have added a meeting as a event in calendar and i want to read this.
I'm not sure exactly what you want but for example if you wanted to read the subject line you could do something like this:
if(eventList.isSupportedField(BlackBerryEvent.SUMMARY) && event.countValues(BlackBerryEvent.SUMMARY) > 0) {
subject = event.getString(BlackBerryEvent.SUMMARY, 0);
}
Related
I'm writing a plugin for a TFS process.
I need to get the Project Name from the TeamFoundationRequestContext whenever a work item is in the process of saving.
Normally I can get the work item ID because the record has already been saved. However, when the work Item is being saved the first time, I do not have a way to get the work item ID.
My question is how can I get the Project Name from the TeamFoundationRequestContext when the work item saves for the first time.
Here is a class that captures the work item changed event and checks to see if it is a newly created work item.
From within the event if it is a newly created work item you can then do what you need with the Project name that is associated with that work item.
using Microsoft.TeamFoundation.Framework.Server;
using System;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.WorkItemTracking.Server;
namespace TfsProcess.CaptureProjectNameOnNewWorkItem
{
public class CaptureProjectNameOnNewWorkItem : ISubscriber
{
public string Name
{
get
{
return "CaptureProjectNameOnNewWorkItem";
}
}
public SubscriberPriority Priority
{
get
{
return SubscriberPriority.Normal;
}
}
public EventNotificationStatus ProcessEvent(
TeamFoundationRequestContext requestContext,
NotificationType notificationType,
object notificationEventArgs,
out int statusCode,
out string statusMessage,
out ExceptionPropertyCollection properties)
{
statusCode = 0;
properties = null;
statusMessage = String.Empty;
try
{
ProcessNotification(notificationType, notificationEventArgs, requestContext);
}
catch (Exception exception)
{
TeamFoundationApplicationCore.LogException("Error processing event", exception);
}
return EventNotificationStatus.ActionPermitted;
}
private static void ProcessNotification(NotificationType notificationType, object notificationEventArgs, TeamFoundationRequestContext requestContext)
{
if (notificationType == NotificationType.Notification && notificationEventArgs is Microsoft.TeamFoundation.WorkItemTracking.Server.WorkItemChangedEvent)
{
var ev = notificationEventArgs as WorkItemChangedEvent;
if (ev.ChangeType == ChangeTypes.New)
{
//Do somethin with the project name of the newly created work item
// projectName = ev.PortfolioProject;
}
}
}
public Type[] SubscribedTypes()
{
return new Type[1] { typeof(WorkItemChangedEvent) };
}
}
}
Update:
You could create a plugin implementing the ITeamFoundationRequestFilter interface, which gets executed BEFORE or AFTER Team Foundation Server receives and processes requests. This allows you to validate work items and cancel the creation of the work item if it is not valid based on some logic for instance.
Here is a link to blog with a implementation of this that will cancel the creation of the work item if it is being created by a certain user.
Getting information from a TFS Request
How to implement ITeamFoundationRequestFilter
In order to get the Work Item ID you will intercept the xml soap response and parse it for the work item value.
Using the filter plugin you can filter for any of the methods responsible for updating, creating and querying work items.
The blog goes into more explanation and implementation.
The WorkItemChangedEvent event has a PortfolioProject property, so you should be able to get it like this:
var ev = (WorkItemChangedEvent)notificationEventArgs;
var projectName = ev.PortfolioProject
I'm using Vaadin Calendar component with EventProvider. It loads items corrently when displayed inititaly, but when I edit the calendar item it doest reflect changes on the screen. (caption name change or date changes) I even tried to set provider once again after entry update cal.setEventProvider(p); but it doesnt force calendar to fetch fresh data from provider. Any hint how to work with EventProvider and do entries updates on calendar?
I had a very similar problem a while back (Vaadin 7.1), and found out that the default implementation of ContainerEventProvider doesn't work properly. I do not remember all the details but my investigation showed a problem with the getEvents method. To solve it, I subclassed ContainerEventProvider with my own class and implemented an override of getEvents:
#Override
public List<CalendarEvent> getEvents(Date startDate, Date endDate) {
eventCache.clear();
// int[] rangeIndexes = getFirstAndLastEventIndex(startDate, endDate);
for (int i = 0; i < container.size(); i++) {
eventCache.add(getEvent(i));
}
return Collections.unmodifiableList(eventCache);
}
And this is the function that assigns a container to the calendar:
public void setCalendarContainerDataSource(Indexed ds) {
// this.vaadinCal.setContainerDataSource(ds); // this did't work
MyCalendarContainerEventProvider provider = new MyCalendarContainerEventProvider(ds);
provider.addEventSetChangeListener(new CalendarEventProvider.EventSetChangeListener() {
public void eventSetChange(EventSetChangeEvent changeEvent) {
vaadinCal.markAsDirty();
}
});
provider.addEventChangeListener(new EventChangeListener() {
public void eventChange(EventChangeEvent changeEvent) {
// Repaint if event changes
vaadinCal.markAsDirty();
}
});
vaadinCal.setEventProvider(provider);
}
I am using a DevExpress MVC Pivot Grid and trying to work out some problems with the loading and saving of layouts. So far I have the following:
I have set my CustomActionRouteValues in the PivotGridSettings as follows:
CustomActionRouteValues = new { Controller = "Home", Action = "PivotGridCustomCallback" },
Which points to the following:
public ActionResult PivotGridCustomCallback(string action, string reportName)
{
if (string.IsNullOrEmpty(reportName))
{
reportName = "Report 1";
}
var settings = PivotGridLayoutHelper.DefaultPivotGridSettings;
if (action == "Save")
{
// TODO: Find a better solution than this. At the moment, if Save is called once, it is then called again every time the user changes the layout.. which is why we have the 'saved' variable here.
bool saved = false;
settings.AfterPerformCallback = (sender, e) =>
{
if (saved)
{
return;
}
SaveLayout(((MVCxPivotGrid)sender).SaveLayoutToString(), reportName);
saved = true;
};
}
else if (action == "Load")
{
// TODO: Find a better solution than this. At the moment, if Load is called once, it is then called again every time the user changes the layout.. which is why we have the 'loaded' variable here.
bool loaded = false;
string layoutString = LoadLayout(reportName);
if (!string.IsNullOrEmpty(layoutString))
{
settings.BeforeGetCallbackResult = (sender, e) =>
{
if (loaded)
{
return;
}
((MVCxPivotGrid)sender).LoadLayoutFromString(layoutString, PivotGridWebOptionsLayout.DefaultLayout);
loaded = true;
};
}
}
ViewBag.PivotSettings = settings;
return PartialView("PivotPartial");
}
The problem, as you can see in the code comments, is that after performing an action just one time, it then gets called EVERY time I make any sort of change. So, for example... say I load a report.. that's fine.. but then when I try expand something or add a field.. or do ANYTHING, nothing seems to happen on the UI.. and I figured out that's because immediately, this code gets called again:
settings.BeforeGetCallbackResult = (sender, e) =>
{
((MVCxPivotGrid)sender).LoadLayoutFromString(layoutString, PivotGridWebOptionsLayout.DefaultLayout);
};
That just keeps resetting the values to the saved layout, which means the UI looks like it's unresponsive when trying to change anything.
This is why I now have the boolean variable called loaded to check if it's already loaded. That works.. but it's an ugly hack.. because it's making unnecessary trips to the server each and every time the user does anything on the pivot grid.
Surely there must be a way to prevent these actions from firing all the time?
I tried to do a basic form validation to require some fields on the form must filled in.
I tried to do the Validation check on the ViewModel, I have a ValidateForm function and will return a ValidationMessage, however, when the SaveCommand get call and it won't call back the current View again, so the error message Alert View won't popup. How can I recall the current View Model again after SaveCommand finished?
private string _ValidationMessage;
public string ValidationMessage
{
get { return _ValidationMessage; }
set
{
_ValidationMessage = value;
RaisePropertyChanged(() => ValidationMessage);
}
}
private string ValideForm()
{
if (string.IsNullOrEmpty(FirstName) || string.IsNullOrEmpty(LastName) || string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(ZipCode))
return "Fields with * are required.";
return null;
}
private MvxCommand _saveCommand;
public ICommand SaveCommand
{
get
{
_saveCommand = _saveCommand ?? new MvxCommand(SaveCommandHandler);
return _saveCommand;
}
}
private void SaveCommandHandler()
{
var validationMessage = ValideForm();
if (!string.IsNullOrEmpty(validationMessage))
{
ValidationMessage = validationMessage;
return;
}
ShowViewModel<NextScreenViewModel>();
}
I think this is the same question as MvvmCross Dialog. The poster there suggests several ways to do this, and my answer covers one more 'architectural' way to do it too.
If you'd prefer a simpler way, then you can also just use a string property - eg ErrorMessage. The view can listen for changes in that string. When they happen,
then the view can display an error dialog. This is a bit like the approach taken for Progress Dialogs in this video and code - N=34 - http://slodge.blogspot.co.uk/2013/07/n34-showing-progress-isbusy-display-n1.html
I have few meeting request in my native calendar scheduled for different date and time,i am trying to read the entire events scheduled for a specific date using the folloing code.
private void getEvents() {
try {
EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_ONLY);
Enumeration events = eventList.items();
while (events.hasMoreElements()) {
Event event = (Event)events.nextElement();
if(eventList.isSupportedField(Event.SUMMARY) && event.countValues(Event.SUMMARY) > 0) {
String subject = event.getString(Event.SUMMARY, 0);
Dialog.alert(subject);
}
}
}
catch (PIMException e) {
Dialog.alert(e.getMessage());
}
}
I am able to get the subject from native calendar ,but i want the code to read the meetings along with date and time,I am not able to do this.
The Date/Times of events are stored in the fields Event.START and Event.END as long values containing the number of milliseconds since the Unix epoch. See my answer to this question, and the API documents for the Event interface.