How to handle concurrence when call Exchange web service - concurrency

We have an application which can book appointment in Exchange by EWS(Exchange web service), we use following code to book
CheckAppointmentsIsBookedInSameTime();
var appointment = new Microsoft.Exchange.WebServices.Data.Appointment(ExchangeService);
...
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
The CheckAppointmentsIsBookedInSameTime will get all booked appointments and check if an appointment was booked in same time. It will throw exception if a appointment was booked.
Currently it have concurrence problem. Two user can book same appointment in same time range if they do operation in same time. The book result is one is accept, one is declined.
My question is, during an appointment is in booking(in progress, but not done), how do we check the appointment in booking if another guy want to booking same appointment in same time?

Related

Default shipping method

I am trying to write a shipping method base on both by country and also weight-base in Django-oscar. It seems the default shipping methods must also have these
from oscar.apps.shipping.methods import Free, FixedPrice, NoShippingRequired
I do not required any of the above and would only provide discount for shipping through discounts.
How do I write by repository.py so I do not apply any of these oscar.apps.shipping.methods import Free, FixedPrice, NoShippingRequired
So I can just write my class Repository (CoreRepository):
Without writing
methods += [NoShippingRequired()]
methods += [FixedPrice()]
methods += [Free()]
The method I have written is not code based but implemented through the shipping menu in the dashboard. I followed the following to set my shipping.
https://groups.google.com/forum/#!topic/django-oscar/H4tf20ujm8k
When testing, on the page 'Shipping Menu', both the 'HandDelivery', and my weight-based by country shipping method button is displayed to customer. Which means customer can click the HandDelivery button too even when customer is based internationally. I wished to disable that 'HandDelivery' button at the Shipping method page, so it is not an option for customers to select at all.
Another option is to attached a message to this button to make it clear to customers that clicking that button means arranging to collect item from warehouse within 1 week of reservation.
How do I display that the message to the customer? Customer is not taking onto the payment page. And an email is sent so items can be collected within 7 days? Like similar to argos, reserve, item, go to shop, pay, and collect. So I could change the discription of 'HandDelivery' to reserve. Then customer does not pay but pay upon collection. But how?
EDIT: Apparently Oscar has several ways to define shipping; updating answer to cover methods defined in the dashboard!
Once you have forked Oscar's shipping app, you can override the repository class and only return the shipping you want.
If you've defined your weight-based shipping through the dashboard, you can get it with the WeightBased model, and only return that:
forked_apps/shipping/repository.py:
from oscar.apps.shipping import repository
from oscar.core.loading import get_model
from . import methods
WeightBased = get_model('shipping', 'WeightBased')
class Repository(repository.Repository):
def get_available_shipping_methods(self, basket, user=None,
shipping_addr=None, request=None, **kwargs):
if shipping_addr:
weightbased_set = WeightBased.objects.all()
if weightbased_set:
return ( list(weightbased_set), )
# If no address was specified, or weight-based options are
# not available, return the "Reserve" shipping option
return ( methods.Reserve(), )
forked_apps/shipping/methods.py:
from oscar.apps.shipping import methods
class Reserve(methods.NoShippingRequired):
code = 'RESERVE'
name = 'Reserve'
description = 'Items will be reserved at the warehouse for 7 days'
Delaying payment would involve forking the payment app, and would be worth its own question.
The Oscar documentation also has some good information on further customization of shipping options in the "How to configure shipping" section.

Errors when saving hasMany with parent using Ember Data

I have some nested Ember Data models week->hasMany('workout')->hasMany('exercises')
In my app I need to create an entire new week. I accomplish this by
var newWeek = WT.PlanWeek.store.createRecord('planWeek', attributes );
// create a couple new workouts
newWorkout = WT.PlanWorkout.store.createRecord('planWorkout', attributes);
newWeek.get('workouts').pushObject(newWorkout);
// repeat...
// create exercises on the workouts the same way and push them on the the workout
newExercise = WT.PlanWeek.store.createRecord('planExercise', attributes);
newWorkout.get('exercises').pushObject(newExercise);
newWorkout.save();
I have a couple problems with this save.
I save the both the workout and the child exercises in the workout API call - when the call returns this appends a second set of exercises to the workout instead of replacing the existing exercises (even though I set workout.exercises to the newly persisted exercises in the serializer extractSingle).
When the server returns it doesn't update the workouts in the week with the new ids. I end up with the new persisted workouts that correctly belongTo the week, but week.get('workouts') still points to the unpersisted workouts with no id.
Any ideas or suggestions?

How to get user Interests?

This is not a duplicate of How can I get the interests of my friend through facebook api?. user_interests permission (to access /me/interests) is useless (if not deprecated) Facebook feature that hardly ever returns any data.
Instead, I am referring to the data aggregated by Facebook at this page:
These are all user likes grouped into categories like "Music", "Books", "TV Shows", etc. Generally, user likes can be retrieved through /me/likes. However, the latter query returns a rather vivid array of categories.
Is there a way to get user likes categorised into the same generic categories like Facebook does?
https://developers.facebook.com/docs/reference/api/user/:
The User object has the following connections:
books: The books listed on the user's profile.
games: Games the user has added to the Arts and Entertainment section of their profile.
movies: The movies listed on the user's profile.
music: The music listed on the user's profile.
television: The television listed on the user's profile.
The fields favorite_athletes and favorite_teams are deprecated, though. Not sure, if there will be any replacement for these analog to the above connections – or if users are just supposed to normally “like” the fan pages of athletes/teams in the future.
My approach to this issue is to process the API data within my application as such:
'Books' => array('Fictional Character', 'Writer', 'Book', 'Author', 'Book Store', 'Library', 'Magazine'),
'Films' => array('Actor/Director', 'Movie', 'Producer', 'Studio', 'Movie Theater', 'TV/Movie Award', 'Fictional Character', 'Movies/Music'),
[..]
e.g., if user likes "Writer" or "Book", I assign the like to "Books" category.
However, this solution is not ideal as Facebook might change category names, add new names, etc.

Adding a view counter to objects using Django Celery

Not that it matters, but this is a follow-up to this question.
I want to keep a count of how many times each object in my database has been viewed. Let's say we have a Person model, with several instances. We want to keep a counter of how many times each instance has been viewed in the Person model, using Django Celery to avoid waiting for the database writes.
At the moment I'm doing this:
from celery.decorators import task
class Person(models.Model):
name = models.CharField(max_length=50)
class Stats(models.Model):
person = models.ForeignKey('Person', unique=True)
#task
def addView(self):
se = StatEvent()
se.save()
self.views.add(se)
class StatEvent(models.Model):
date = models.DateTimeField(auto_now_add=True)
Then, every time the view is called which lists a page of persons, I get all persons, update the statistics like this:
person.get_stats().addView.delay(person.get_stats())
where after I then return the list of persons to be displayed in the browser. I thought that the updating of the statistics would happen asynchronously, but there's a clear and long delay before the page is displayed, which is confirmed by having a print statement shown for each addition in the Celery command window. The page is only rendered once the last statistic has been updated.
How do I ensure that the user doesn't wait for the database update to finish?
Update
I thought it might have something to do with there not being enough worker processes to process each person separately, so I instead made a function that accepts a list of persons as parameter, and used this as the task to be executed. So, only one task in the queue:
#task(ignore_result=True)
def addViews(persons):
for person in persons:
stats = listing.get_stats()
se = StatEvent()
se.save()
stats.views.add(se)
However, when print to the console, like this:
print "adding"
print tasks.addClicks(persons)
print "done"
Then there's a clear delay between the "adding" and "done" step, and the returned value of the function is None.
Turns out my original suspicion about there not being enough workers was correct. My new function that put everything in one task solved the problem - I was just missing the .delay in that last tasks.addClicks(persons) call.

Exchange Appointment Types

I use the following code to save an appointment via Exchange Web Services Managed API:
Appointment appointment = new Appointment(m_exchangeService);
appointment.Subject = subject;
appointment.Body = body;
appointment.Start = start;
appointment.End = end;
appointment.Save();
When I do this the Appointment is created as a 'meeting' in Outlook. But I just want to have it as normal Appointment not a meeting.
How do i do this?
I found an answer. The following code creates a normal nonmeeting Appointment
appointment.Save(WellKnownFolderName.Calendar, SendInvitationsMode.SendToNone);