February 10, 2011 Silverlight 4 comments
February 10, 2011 Silverlight 4 comments
Here is binding (I did not change it):
<UserControls:NumericTextBox AllowDecimals=”True”
Minimum=”0″ UseMinimum=”True”
Maximum=”999.999″ UseMaximum=”True”
MaxLength=”6″
Value=”{Binding Mileage, Mode=TwoWay}”
private double? _mileage; public double? Mileage { get { return _mileage; } set { _mileage = value; EnteredMileage = value; RaisePropertyChanged("Mileage"); } }
_mileage = EnteredMileage.HasValue ? EnteredMileage : CalculatedMileage; RaisePropertyChanged("Mileage");
February 10, 2011 Book Reviews, Certification, Success No comments
Training Kit
Exam 70-561: TS: Microsoft .NET Framework 3.5, ADO.NET Application Development
You can see my transcript using this information:
https://mcp.microsoft.com/authenticate/validatemcp.aspx
Transcript ID: 904316
Access Code: andriybuday
Nearest certification plans
January 31, 2011 NHibernate No comments
Most of our current NHibernate saving methods look like below:
public void SaveCustomer(CustomerEntity customer) { var transaction = GetActiveTransaction(); transaction.Begin(); try { // some code Session.SaveOrUpdate(customer); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); throw e; } }
this works great if you need to save just Customer or just Vendor. But in recent time we got kindof challenge to save Customer and Vendor at once in scope of one transaction for piece of functionality, and at the same time method should work for another piece of functionality.
For this we change our methods as following:
public void SaveVendor(VendorEntity vendor) { using (var scope = new TransactionScope(TransactionScopeOption.Required)) // if there is no transaction scope, new will be created... { using (var transaction = Session.BeginTransaction()) { // some code Session.SaveOrUpdate(vendor); transaction.Commit(); } scope.Complete(); } }
Now we can utilize our methods higher in the call stack:
public void SaveBunchOfInformationAtOnce(CustomerEntity customer, VendorEntity vendor) { try { using(var scope = new TransactionScope(TransactionScopeOption.RequiresNew)) // always new transaction will be created { CustomersRepository.SaveCustomer(customer); VendorsRepository.SaveVendor(vendor); scope.Complete(); } } catch(Exception e) { // log errors... throw; } }
This all works just fine both for existing method calls and for new one. Hope it helps.
Next thing that I might need to put into place is to distribute transactions through WCF services. That should be fun.
January 26, 2011 English, Success 4 comments
I attended English courses in my company for about 9 months. For this time I learnt a lot of new stuff, and revisited whole bunch of grammar. Also I slightly increased my vocabulary.
I’ve mentioned many times that English courses are very important for outsourcing company and for me particularly. I even described one of the lessons and recommended some activities to do to learn English.
So this is very good result, but unfortunately my average score is about 80%, so I might not be eligible for next free of charge course. But honestly I do not hurry for being English course’s student for another 9 months. It makes me tired… because I have to allocate additionally 4-5 hours per week and as usual I rob it from my sleep hours. I think that the next most needed thing for me is to practice more and more. Actually I even planned to find someone who would like to talk with me in English all the time. Not my girl – she is more German expert and weak in English, and not my best friend – he is too shy or smth..
January 21, 2011 Certification, Success 8 comments
That happened! Passing this exam was the main stone on my road to MCPD Enterprise.
How did I prepare?
I already mentioned that I prepared as usual by reading training kit. But this time I did most of the Labs, because I have really little experience in Web Development.
Honestly for me ASP revealed to be very simple for understanding and easy to work with. I guess because it intersects with other technologies and also because I have more or less good dev experience in other areas.
Also I did not concentrate on learning ASP.NET extremely well. We all know that nothing with ViewState and other aspects of it are now history. ASP MVC should be technology number one for learning web, but I had to pass this exam. Also understanding what is under MVC and from what it all started is good.
Passing Exam
Exam has 45 questions for about 3 hours. I hated answering them. They were long to read and extremely boring. I HATE THIS EXAM QUESTIONS. 2 screens of question is too much, it kills.
I PASSED EXAM with score 907, woot!
You can see my transcript using this information:
https://mcp.microsoft.com/authenticate/validatemcp.aspx
Transcript ID: 904316
Access Code: andriybuday
January 20, 2011 Book Reviews No comments
Hello there. For me it is time to pass next exam on the way to MCPD Enterprise Dev. This time it is ASP.NET exam. For me it is the most difficult of the exams, since I have really little experience in web development.
For my training to exam as usually I read training kit. Finally it was not boring for me to read it. Probably because greater part of it was new to me. I also performed most of the ASP.NET Labs. The most interesting was the beginning of the book and its end. And I almost scrolled ado.net chapter, since there was nothing new to me. (Fine that training kit for ado.net exam, which is gonna be my next exam, is about 400 pages only, so I can be calm about reading it.)
I started preparing to exam about 2-3 months ago, but since I’m lazy it was going slowly and because I scheduled exam for 21th Jan… which is… today, I have had to prepare to exam my evenings in recent time, this made me little bit tired and out of schedule with learning more asp stuff. Actually at the moment when I started preparing I had been thinking that I could implement small web site and run thought msdn solidly. Ah.. I did not do this. I’m afraid to fail it as it was with my WinForms exam twice.
Tomorrow Today early morning I will be passing this exam. Wish me good luck.
January 11, 2011 Design Patterns No comments
For some reason I have thought about good example for Adapter design pattern for a long period of time. There might be straightforward example with two classes, one of which has OperationA and other has OpA and we need to adapt them, but there is no analogy in that example. In this case it would not worse reading this post. Also I thought about example in which we have complex objects with many properties and methods, where you would need to perform some real conversion. But by the way of thinking there was always electricity adapter in my head circling. In Lviv there is still many apartments where old thin sockets exist, to overcome this people buy small adapters, almost as on the picture on the right, except not that cruel.
So we have our notebook charger that easily fits wide European socket. In your apartment all sockets are new, so you get used to it. Your NewElectricitySystem has method MatchWideSocket. But in your friend’s apartment there is still old one and his OldElectricitySystem has only method MatchThinSocket. Unfortunately you cannot drill sockets in someone else’s flat, you have to buy Adapter, that allows you consume the same electricity, but with old system.
ADAPTER
Adapter – is design pattern that allows us use object, which we cannot change, by providing its functionality thought known interface.
// Adaptee class OldElectricitySystem { public string MatchThinSocket() { return "220V"; } } // known interface in our code interface INewElectricitySystem { string MatchWideSocket(); } class NewElectricitySystem : INewElectricitySystem { public string MatchWideSocket() { return "220V"; } } // Adapter class Adapter : INewElectricitySystem { private readonly OldElectricitySystem _adaptee; public Adapter(OldElectricitySystem adaptee) { _adaptee = adaptee; } // All the magic lives here // in our adapter we translate from // what we (code) cannot use straightway into what we can public string MatchWideSocket() { return _adaptee.MatchThinSocket(); } } class ElectricityConsumer { // Charging device can be used only with new system public static void ChargeNotebook(INewElectricitySystem electricitySystem) { Console.WriteLine(electricitySystem.MatchWideSocket()); } } public class AdapterDemo { public static void Run() { // We can easily operate with our new system var newElectricitySystem = new NewElectricitySystem(); ElectricityConsumer.ChargeNotebook(newElectricitySystem); // We have to adapt to old system using adapter var oldElectricitySystem = new OldElectricitySystem(); var adapter = new Adapter(oldElectricitySystem); ElectricityConsumer.ChargeNotebook(adapter); } }
Yet another name for this pattern is Wrapper. That is because it wraps functionality of some object, representing it in another interface.
Actually we can also implement it slightly differently than I have it here. In the example above we use composition, but our adapter can easily implement two interfaces of the old and new system and then once created by one of the constructors we would use our adapter in both directions.
January 8, 2011 Success, YearPlanReport 9 comments
So time for new year resolution has came.
I created similar list last year and wrote why I really think that having list of things you want to do during the year is very important. I listened to many of time management books, especially I like those recommendations that includes all aspects of the life.
Accordingly that their point of view life consists with following set of aspects: health, relations, finances, emotions, work. If at least one of this aspects lame you wouldn’t enjoy your life entirely since other aspects will suffer. I found that in recent time I neglected my health. Yeah, I’m young so I do not feel myself completely crappy, but anyway I don’t like situation in which I’m now. That is why I’m planning to have some activities in list that should help me with my health. In this country you have to work half of your life to get apartments to live in… wtf? yeah, that’s truth, so there have to be some better ways to earn more money, not only sweatshoping work. To enjoy my life it would be perfect to travel abroad with middle-low budget.
Here below is my resolution list for 2011
(list above is not ordered in any way…)
Do you have your plan for this year? If you don’t better think about it, because “if you fail to plan, you plan to fail”.
Ok list looks large but fair enough to achieve this in year term. Thank you for reading my resolutions and please share yours!
January 5, 2011 Revision of my activity, Success, YearPlanReport No comments
So the list I had in the beginning of 2010:
Next thing I will create blog post “Where do you want to be in a Year?” for the 2011.
Till next time.
January 4, 2011 Design Patterns No comments
Facade is design pattern that provides us with one entry point to subsystem, simplifying its usage and understanding.
In our example facade would be terminal-serving station (SkiResortFacade), subsystem would be whole bunch of renting buildings, paydesks, hotels. Of course we can go all around the resort, if we like this, but if we take a look from software development point of view if devs will walk all around and use as they wish, it will not lead to positive consequences. And skiers-newcomers will never know where they should go for the first time.
internal class SkiRent { public int RentBoots(int feetSize, int skierLevel) { return 20; } public int RentSki(int weight, int skierLevel) { return 40; } public int RentPole(int height) { return 5; } } internal class SkiResortTicketSystem { public int BuyOneDayTicket() { return 120; } public int BuyHalfDayTicket() { return 60; } } internal class HotelBookingSystem { public int BookRoom(int roomQuality) { switch (roomQuality) { case 3: return 250; case 4: return 500; case 5: return 900; default: throw new ArgumentException("roomQuality should be in range [3;5]","roomQuality"); } } } public class SkiResortFacade { private SkiRent _skiRent = new SkiRent(); private SkiResortTicketSystem _skiResortTicketSystem = new SkiResortTicketSystem(); private HotelBookingSystem _hotelBookingSystem = new HotelBookingSystem(); public int HaveGoodOneDayRest(int height, int weight, int feetSize, int skierLevel, int roomQuality) { int skiPrice = _skiRent.RentSki(weight, skierLevel); int skiBootsPrice = _skiRent.RentBoots(feetSize, skierLevel); int polePrice = _skiRent.RentPole(height); int oneDayTicketPrice = _skiResortTicketSystem.BuyOneDayTicket(); int hotelPrice = _hotelBookingSystem.BookRoom(roomQuality); return skiPrice + skiBootsPrice + polePrice + oneDayTicketPrice + hotelPrice; } public int HaveRestWithOwnSkis() { int oneDayTicketPrice = _skiResortTicketSystem.BuyOneDayTicket(); return oneDayTicketPrice; } } public class FacadeDemo { public static void Run() { var skiResortFacade = new SkiResortFacade(); int weekendRestPrice = skiResortFacade.HaveGoodOneDayRest(175, 60, 42, 2, 3); Console.WriteLine("Price: {0}", weekendRestPrice); } }
This design pattern in some way represents very important encapsulation principle but just on higher level. On this level we encapsulate whole subsystem instead of class. Big systems usually consist with many subsystems that communicate between each other by using facades. Space station connects to another station using one mechanism, not with gluing together hundreds of wires and tubes. Also an good way to develop software would be to have some kind of facade (it might be set of known interfaces) inside of each assembly, so it can be used easily from other parts of your application.
Thank you.
My design patterns table