Windows Mobile Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg
Showing posts with label WinRT. Show all posts
Showing posts with label WinRT. Show all posts

Friday, 6 April 2012

Dependency Injection framework for WinRT - Widows 8 application

Posted on 05:45 by Unknown
Am inceput sa lucrez la o aplicatie metro style pentru Windows 8. Toate bune si frumoase pana am ajuns in momentul in care am dorit sa folosesc un framework de DI. Cum inca vorbim de VS2011 BETA si un API redus pentru aplicatile metro style, m-am trezit ca nici un framework consacrat precum Unity, Ninject, Windsor nu a fost portat inca pentru acest tip de aplicatii.
Cauza pentru care inca nu a fost inca portat este destul de clara. Pentru aplicatiile metro style pentru Windows 8, nu folosim .NET Core si un .NET Framework, care are un API mult mai sarac. Multe functionalitati, mai ales din zona reflection lipsesc.
Am gasit pe codeplex un framework pentru WinRT, care se numea MetroIoc. http://metroioc.codeplex.com/
Parea destul de usor de folosit, asa ca am zis sa ii dau o sansa, sa vad daca functioneaza si daca este ce caut. API este foarte asemanator cu cel de la Unity, asa ca din punct de vedere a setup-ului la container l-am putut face foarte repede.
Am pregatit si o metoda de teste si surpriza. Testul nici macar nu a putut sa ruleze. A crapat procesul care rula testele. M-am mai jucat putin cu acesta, sperand ca poate sunt eu de vina, dar nu am reusit sa il fac sa functioneze.
Aplicatia la care lucrez fiind o aplicatie destul de simpla am zis ca cel mai bine este sa nu ma complic si sa risc sa am probleme in viitor. Revin la clasica proprietate "Instance" din fiecare clasa care vreau sa fie unica per proces.
O alta solutie ar fi sa imi definesc un ObjectFactory care sa imi tina in spate o lista statica de instante. M-am gandit ceva simplu, asemanator cu codul de mai jos:
public class ObjectFactory
{
public static ObjectFactory Instance { get; private set; }

static ObjectFactory()
{
Instance = new ObjectFactory();
}

private readonly Dictionary<Type, object> _objMapping;


public ObjectFactory()
{
_objMapping=new Dictionary<Type, object>();
}

public void AddObject<TType>(TType instance)
{
Type itemType = typeof (TType);
RemoveObject(itemType);

_objMapping.Add(itemType,instance);
}

private void RemoveObject(Type itemType)
{
if (_objMapping.ContainsKey(itemType))
{
_objMapping.Remove(itemType);
}
}

public TType GetInstance<TType>()
{
return (TType)_objMapping[typeof(TType)];
}
}

Mai mult de atata nu vreau sa fac in momentul de fata, deoarece ma astept ca in viitor o sa apara un mecanism de DI si pentru WinRT, si nu are rost sa incerc sa reinvetenz roata.
Read More
Posted in dependency injection, windows 8, WinRT | No comments

Wednesday, 28 March 2012

How to use C# library from JavaScript in Windows 8

Posted on 01:08 by Unknown
Nu stiu daca v-ati jucat pana acuma cu Windows 8 si Visual Studio 2011, dar o sa aveti o surpriza. Aplicatiile pe care le puteti scrie pentru desktop pot sa fie XAML (impreuna cu C#) sau HTML5 (HTML, CSS, JavaScript).
WinRT (Windows Runtime) ne permite sa avem interoperabilitate intre C++, C#, JavaScript. Este asemanator cu ce era COM+ pe vechiul Windows. Prin intermediul sau putem sa comunicam intre cele trei limbaje. Din punct de vedere tehnicec, WinRT este mult mai simplu decat P/Invoke, avand o sintaxa destul de simpla. Un fisier ".winmd", o sa contina tot API pe care noi il expunem intr-un format destul de asemanator cu cel de .NET.
Metadatele dintr-un ".winmd" descriu codul care a fost scris pentru WinRT. Prin intermediul acestor informatii, putem apela atat API sistemului de operare cat si librarii scrise in alte limbaje de programare. Tot API-ul sistemului de operare pe care noi il accesam din orice limbaj se face prin intermediul WinRT.
Mai jos o sa prezint cum putem sa scriem cod C# care sa fie folosit de JavaScript si ce probleme pot sa apara.
Odata ce am creeat proiectul .NET, putem sa ii schimbam output type-ul la "WinMD". In momentul cand facem acest lucru procesul de build o sa se schimbe putin. Pentru a crea assembly-ul o sa se folosesca un tool cu numele "Windows Metadata Explorer". Odata ce am facut acest pas o sa vedem o multime de warning-uri si erori din cauza ca clasele trebuie sa respecte cateva reguli.
O clasa pe care vrem sa o expunem pentru a putea sa fie consumata de JavaScript trebuie sa fie sealed. Clasele pe care nu dorim sa poata fi consumate de JavaScript trebuie sa aibe atributul [EnableComposition]. Destul de interesant mi se s-a parut ca in cazul in care avem o clasa goala, o sa avem parte de eroare, chiar daca e sealed.
In cazul in care lucrati cu liste (input paramas sau return value), sa nu uitati sa folositi interfete. De exemplu folositi IList si nu List. Partea buna este ca nu suntem obligati sa folosim un array. In cazul in care uitati de acest lucru o sa va treziti cu o eroare de genul:
Method Ex.Foo.GetAll()' has a parameter of type 'System.Collections.Generic.List' in its signature. Although this type is not a valid Windows Runtime type, it implements interfaces which are valid Windows Runtime types. Consider changing the method signature to instead use one of the following types: 'System.Collections.Generic.IList, System.Collections.Generic.IReadOnlyList, System.Collections.Generic.IEnumerable'.
Partea buna este ca mesajul ne da destule informatii despre care este problema si o solutie la aceasta problema. As vrea sa vad mai des erori care ne indica si solutii, nu doar sa urle ca nu e in regula.
Nu incercati sa va definiti interfete generice, clase generice sau metode generice. In acest moment acest lucru nu este suportat in acest moment. Poate din cauza ca notiunea de generic nu exista sau nu are acelasi sens in toata limbajele. Acelasi lucru se intampla si cu metodele declarate virtual. Nu putem sa avem metode virtual.

public sealed Foo
{
private IList<string> _items;
public IList<string> GetAll()
{
return _items;
}
public string DefaultItem { get; set; }
}
Apelurile pe care le putem face pot sa fie atat sincrone, dar si asincrone. In cazul in care vreti sa faceti apeluri asincrone puteti sa folositi Task<...>. Daca incercati sa faceti acest lucru o sa vedeti o eroare din cauza ca Task<...> nu este inclus in WinRT. O solutie la aceasta problema este ca in loc sa returnam Task<...> sa returnam un IAsyncOperation<...>.
Prin intermediul acestuia putem sa facem un apel asincron. Trebuie abut grija deoarece de la developer preview la consumer preview lucrurile s-au schimbat putin. Inainte era folosita metoda urmatoare pentru a crea un nou IAsyncOperation
AsyncFactory.Create(() => { ... } );
Daca incercam sa folosim AsyncFactory o sa ne trezim cu urmatorul mesaj de eroare:
The name 'AsyncFactory' does not exist in the current context
Dar o sa ne trezim ca nu mai putem sa gasim aceast factory. Pentru a putea returna un IAsyncFactory putem sa facem in felul urmator:
return Task.Run<string>( async () =>
{
return "someString";
}).AsAsyncOperation();
Mai jos puteti sa gasiti codul scris in C# si JavaScript pentru a putea apela cod C# din JavaScript. Nu uitati ca in proiectul care contine JavaScript sa adaugati o referinta la proiectul vostru.
C#
public sealed class Foo()
{
public IAsyncOperation<string> GetDefault()
{
return Task.Run<string>( async () =>
{
return "Default"
}).AsAsyncOperation();
}
}
JavaScript
var foo = new MyNamespace.Foo();
foo.GetDefault().then(
function(result)
{
// Do something with result
}
)
In mare am vazut cam ce se poate face. Mi se pare un feature destul de dragut, care in cazul aplicatiilor complexe o sa ne ajute extrem de mult.
Enjoy!
Read More
Posted in C#, javascript, windows 8, WinRT | No comments
Older Posts Home
Subscribe to: Posts (Atom)

Popular Posts

  • E-Learning Vendors Attempt to Morph Mobile
    The sign should read: " Don't touch! Wet Paint !" I had a good chuckle today after receiving my latest emailed copy of the eLe...
  • Content Types - Level 6: Rich Media
    Level 6: Rich Media NOTE: This is part 7 of 7 and the conclusion of this continuing series; please see earlier posts for more background inf...
  • CDN is not the only solution to improve the page speed - Reverse Caching Proxy
    I heard more and more often think like this: “If your website is to slow, you should use a CDN.” Great, CDN is THE solution for any kind of ...
  • Publishing our CellCast Widget for iPad
    The rush has been on this week as our development team worked to design a new version of our CellCast Widget specifically for Apple's up...
  • NetCamp 2012 - Windows 8 development experience
    During this week I participate to NetCamp 2012.  This was the 6th NetCamp event and is organizing by Evensys. NetCamp is a dedicated event f...
  • SQL - UNION and UNION ALL
    I think that all of us used until now UNION in a SQLstatement. Using this operator we can combine the result of 2 queries. For example we wa...
  • Password/Token/PIN definition
    Password, Token, PIN, Passcode… every day we use this items when we need to authenticate in different systems. I observed that there are tim...
  • Shared Access Signature and URL encoding on Windows Azure
    Playing a little with Shared Access Signature was quite nice. In this moment this new functionality has a great potential. Playing a little ...
  • Content Types - Level 4: Reference
    Level 4: Reference Materials & Static Content NOTE: This is part 5 of 7 in a continuing series; please see earlier posts for more backgr...
  • Content Types - Level 5: Courseware
    Level 5: Content and Courseware NOTE: This is part 6 of 7 in a continuing series; please see earlier posts for more background information. ...

Categories

  • .NET
  • .NET nice to have
  • #if DEBUG
  • 15 iunie 2011
  • 15 octombrie 2011
  • 2011
  • abstracta
  • action
  • adaugare
  • ajax
  • Amsterdam
  • Android
  • aplicatii
  • App Fabric
  • Apple iSlate
  • array
  • as
  • ASP.NET
  • AsReadOnly
  • Assembly comun
  • async
  • Asynchronous programming
  • asyncron
  • Autofac
  • AutoMapper
  • az
  • Azure
  • Azure AppFabric Cache
  • Azure backup solution
  • Azure Storage Explorer
  • azure. cloud
  • backup
  • BCP utility
  • bing maps v7
  • BitArray
  • BlackBerry
  • blob
  • BlobContainerPublicAccessType
  • breakpoint
  • bucuresti
  • C#
  • cache
  • CallerMemberName
  • CellCast
  • Certificate
  • CES
  • change
  • ChannelFactory
  • clasa
  • classinitialize
  • clean code
  • click event
  • close
  • Cloud
  • Cluj
  • cluj-napoca
  • Code contracts
  • code retrat
  • codecamp
  • CollectionAssert
  • Compact Edition
  • compara
  • Comparer T .Default
  • CompareTo
  • comparison
  • comunitate
  • concurs
  • Conditional attribute
  • configurare
  • connection string
  • container
  • content type
  • control
  • Convert
  • convertAll
  • convertor
  • cross platform
  • CRUD
  • css
  • custom properties
  • custom request
  • DACPAC
  • Daniel Andres
  • data sync service
  • database
  • date time
  • datetime
  • debug
  • default
  • delegate
  • dependency injection
  • deploy
  • DeploymentItem
  • design patterns
  • Dev de Amsterdam
  • development stoage
  • dictionary
  • diferente
  • digging
  • director
  • Directory.Exist
  • disable
  • dispatcher
  • dispose
  • dropdown
  • dynamic
  • EF
  • email
  • encoding
  • entity framework
  • enum
  • enumerable
  • Environment.NewLine
  • error
  • error 404
  • error handling
  • eveniment
  • event
  • ews
  • excel
  • exception
  • exchange
  • exita
  • explicit
  • export
  • extension
  • field
  • File.Exist
  • finalize
  • fire and forget
  • Fluent interface pattern
  • format
  • func
  • GC.SuppressFinalize
  • generic
  • getdirectoryname
  • globalization
  • gmail
  • hackathon
  • Hadoop
  • handle
  • HTML
  • html 5
  • Html.ActionLink
  • http://www.blogger.com/img/blank.gif
  • HttpModule
  • IComparable
  • IE
  • ienumerable
  • IIS
  • image
  • implicit
  • import
  • int
  • internationalization
  • Internet Explorer
  • interop
  • Ioc
  • IP Filter
  • iPhone
  • iQuest
  • IStructuralEquatable
  • ITCamp
  • itspark
  • java script
  • javascript
  • July 2012
  • KeyedByTypeCollection
  • KeyNotFoundException
  • Kinect SDK
  • lambda expression
  • LightSwitch Microsoft Silverlight
  • linq
  • list
  • lista
  • lista servicii
  • liste
  • Live Connect
  • Live ID
  • load
  • localization
  • lock
  • m-learning
  • MAC
  • Mango
  • map
  • mapare
  • mapare propietati
  • messagequeue
  • meta properties
  • method
  • MethodImpl
  • Metro App
  • Microsoft
  • Microsoft Sync Framework
  • mlearning
  • mlearning devices
  • Mobile Apps
  • mobile in the cloud
  • mobile learning
  • mobile services
  • Mobile Web
  • mongoDb
  • monitorizare
  • msmq
  • multitasking
  • MVC
  • MVC 3
  • MVVM
  • namespace
  • nextpartitionkey
  • nextrowkey
  • Ninject
  • nivel acces
  • no result
  • normalize
  • nosql
  • null expcetion
  • null object pattern
  • NullReferenceException
  • OAuth API
  • office
  • offline
  • Open ID
  • openhackeu2011
  • operations
  • operator
  • optimization
  • option
  • outputcache
  • OutputCacheProvider
  • override
  • paginare
  • pagination
  • path
  • persistare
  • Portable Library tool
  • Post event – CodeCamp Cluj-Napoca
  • predicate
  • predictions
  • prezentare
  • process
  • proiect
  • property
  • propietati
  • query
  • ReadOnlyCollection
  • ReadOnlyDictionary
  • referinta
  • reflection
  • remote
  • reply command
  • request
  • request response
  • resouce
  • REST
  • REST Client
  • RESTSharp
  • ronua
  • rss
  • rulare
  • salvare in fisier
  • sc
  • schimbare timp
  • select
  • select nodes
  • send
  • serializare
  • serialization
  • Server.Transfer. Resposen.Redirect
  • service bus
  • ServiceBase
  • servicecontroller
  • sesiune
  • session
  • Session_End
  • Session_Start
  • setup
  • Sibiu
  • signalR
  • Silverlight
  • sincronizare
  • Single Responsibility Principle
  • SkyDrive
  • skype
  • smartphones
  • smtp
  • Snapguide
  • sniffer
  • socket
  • solid
  • spec#
  • sql
  • Sql Azure
  • SQL CE
  • sql server 2008 RC
  • SRP
  • startuptype
  • stateful
  • stateless
  • static
  • stergere
  • store
  • store procedure
  • stream
  • string
  • string.join
  • struct
  • StructuralEqualityComparer
  • submit
  • switch
  • Symbian
  • Synchronized
  • system
  • tabele
  • table
  • techEd 2012
  • tempdata
  • test
  • testcleanup
  • testinitialize
  • testmethod
  • thread
  • timer
  • ToLower
  • tool
  • tostring
  • Total Cost Calculator
  • trace ASP.NET
  • transcoding
  • tuplu
  • tutorial
  • TWmLearning
  • type
  • unit test
  • unittest
  • UrlParameter.Optional
  • Validate
  • validation
  • verificare
  • video
  • view
  • ViewBag
  • virtual
  • visual studio
  • VM role
  • Vunvulea Radu
  • wallpaper
  • WCF
  • WebBrower
  • WebRequest
  • where clause
  • Windows
  • windows 8
  • Windows Azure
  • Windows Azure Service Management CmdLets
  • windows live messenger
  • Windows Mobile
  • Windows Phone
  • windows service
  • windows store application
  • Windows Task
  • WinRT
  • word
  • workaround
  • XBox
  • xml
  • xmlns
  • XNA
  • xpath
  • YMesseger
  • Yonder
  • Zip

Blog Archive

  • ▼  2013 (139)
    • ▼  November (17)
      • Service Bus - Optimize consumers using prefetch an...
      • Extract relative Uri using MakeRelativeUri method
      • Sync Group - Let's talk about Performance
      • [PostEvent] Slides from MSSummit 2013, Bucharest
      • How to get the instance index of a web role or wor...
      • Sync Group - A good solution to synchronize SQL Da...
      • Throttling and Availability over Windows Azure Ser...
      • How to monitor clients that access your blob storage?
      • Digging through SignalR - Dependency Resolver
      • [Event] Global Day of Coderetreat in Cluj-Napoca! ...
      • Windows Azure Service Bus - What ports are used
      • Debugging in production
      • Simple load balancer for SQL Server Database
      • [PostEvent] MSSummit 2013, Bucharest
      • How to read response time when you run a performan...
      • VM and load balancer, direct server return, availa...
      • Bugs that cover each other
    • ►  October (12)
    • ►  September (10)
    • ►  August (7)
    • ►  July (8)
    • ►  June (15)
    • ►  May (12)
    • ►  April (17)
    • ►  March (16)
    • ►  February (9)
    • ►  January (16)
  • ►  2012 (251)
    • ►  December (9)
    • ►  November (19)
    • ►  October (26)
    • ►  September (13)
    • ►  August (35)
    • ►  July (28)
    • ►  June (27)
    • ►  May (24)
    • ►  April (18)
    • ►  March (17)
    • ►  February (20)
    • ►  January (15)
  • ►  2011 (127)
    • ►  December (11)
    • ►  November (20)
    • ►  October (8)
    • ►  September (8)
    • ►  August (8)
    • ►  July (10)
    • ►  June (5)
    • ►  May (8)
    • ►  April (9)
    • ►  March (14)
    • ►  February (20)
    • ►  January (6)
  • ►  2010 (26)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
    • ►  June (2)
    • ►  May (1)
    • ►  April (4)
    • ►  March (1)
    • ►  February (1)
    • ►  January (14)
Powered by Blogger.

About Me

Unknown
View my complete profile