Your SlideShare is downloading. ×
Tomislav Capan - Muzika Hr Dodatak Primjeri (IT Showoff)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Tomislav Capan - Muzika Hr Dodatak Primjeri (IT Showoff)

439
views

Published on

Primjeri iz predavanja Tomislava Capana

Primjeri iz predavanja Tomislava Capana

Published in: News & Politics, Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
439
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. © Copyright Muzika.hr 2010.
    IT ShowOff – Dodatak- Primjeri -
    12. veljače 2010.
  • 2. NHibernate
    © Copyright Muzika.hr 2010.
    2
  • 3. © Copyright Muzika.hr 2010.
    3
    NHibernate- Primjer mapiranja objekta -
    namespace MuzikaHr.Core.Model
    {
    public class City
    {
    /// <summary>Protected constructor. Used internally by NHibernate.</summary>
    protected City() { }
    public City(int id) { Id = id; }
    protectedvirtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtualRegionAssociatedRegion { get; set; }
    public virtual IList<EventLocation> EventLocations { get; protected set; }
    // -- domain logic methods here...
    }
    }
  • 4. © Copyright Muzika.hr 2010.
    4
    NHibernate- Primjer mapiranja objekta -
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name=“MuzikaHr.Core.Model.City, MuzikaHr.Core" table="grad" lazy="true">
    <idname="Id" column="sifGrad">
    <generator class="native" />
    </id>
    <propertyname="Name" column="imeGrad"/>
    <many-to-onename="AssociatedRegion" column="sifRegija"
    class="MuzikaHr.Core.Model.Region, MuzikaHr.Core” />
    <bagname="EventLocations" table="eventLocation" inverse="true" cascade="none">
    <keycolumn="cityId"/>
    <one-to-many class="MuzikaHr.Core.Model.EventLocation, MuzikaHr.Core" />
    </bag>
    </class>
    </hibernate-mapping>
  • 5. © Copyright Muzika.hr 2010.
    5
    NHibernate- Primjer dohvata podataka -
    namespace MuzikaHr.Data.NHibernate
    {
    public class CityDao : AbstractNHibernateDao<City, int>, ICityDao
    {
    // -- constructor here
    public List<City> GetCitiesByRegion(int regionId)
    {
    ICriteria criteria = NHibernateSession.CreateCriteria(typeof(City))
    .Add(Expression.Eq("AssociatedRegion.Id", regionId))
    .AddOrder(Order.Asc("Name"));
    try { return criteria.List<City>() as List<City>; }
    catch (HibernateException exc) {...}
    }
    }
    }
  • 6. SparkViewEngine
    © Copyright Muzika.hr 2010.
    6
  • 7. © Copyright Muzika.hr 2010.
    7
    SparkViewEngineViewData Dictionary, lokalne varijable
    Template:
    <s:viewdataArticles="IList[[MuzikaHr.Models.Article]]"/>
    <s:varstyles="new[] {‘left',’right'}"/>
    <ps:each="var article in Articles"
    class="${styles[articleIndex%2]}“>${article.Title}
    </p>
    Rezultat:
    <p class="left">Vangelis</p>
    <p class="right">Simple Minds</p>
    <p class="left">The Stranglers</p>
    <p class="right">Michael Jackson (1958.–2009.)</p>
    <p class="left">A Perfect Circle</p>
    <p class="right">Suede (1989.–2003.)</p>
  • 8. © Copyright Muzika.hr 2010.
    8
    SparkViewEngineIterator (for-each), if-clause
    automatske iterator-varijable: Index, Count, IsFirst, IsLast
    Template:
    <s:foreach="var lineItem in CurrentInvoice.LineItems">
    <tr><td>Item ${lineItemIndex + 1} of ${lineItemCount}</td>
    <td>${lineItem.Etc}</td></tr>
    <trs:if="lineItemIsLast"><td>Grand total</td><td>${grandTotal}</td></tr>
    </s:for>
    Rezultat:
    <tr><td>Item 1 of 14</td><td>5</td></tr>
    <tr><td>Item 2 of 14</td><td>2</td></tr>
    <tr><td>Item 3 of 14</td><td>9</td></tr>
    ...
    <tr><td>Item 14 of 14</td><td>14</td></tr>
    <tr><td>Grand total</td><td>97</td></tr>
  • 9. © Copyright Muzika.hr 2010.
    9
    SparkViewEngineConditional attribute output
    Template:
    <s:viewdatafeaturedHeading=“MuzikaHr.Models.Heading"/>
    <s:viewdataHeadings=“IList[[MuzikaHr.Models.Heading]]"/>
    <ul>
    <lis:each="var heading in Headings">
    <a ... class="selected?{heading.Id==featuredHeading.Id}">${heading.Name}</a>
    <li>
    </ul>
    Rezultat:
    <ul>
    <li><a href="...">Sve</a></li>
    <li><a href="...">Interview</a></li>
    <li><a href="..."class="selected">Biografije</a></li>
    <li><a href="...">B Scena</a></li>
    <li><a href="...">Zanimljivosti</a></li>
    </ul>
  • 10. © Copyright Muzika.hr 2010.
    10
    SparkViewEngine: Macro
    Macro helper function:
    Metoda koja prima argumente i kao rezultat vraća string
    Macro definicija:
    <s:macro name="ShowError"caption="string" message="string">
    <div class="message error">
    <h3>${caption}</h3>
    <div>${message}</div>
    <% logger.Warn(caption); %>
    </div>
    </s:macro>
    Macro poziv iz templatea:
    <s:viewdataerrorMessage="string" />
    <h2>Place Order</h2>
    <s:test if="!string.IsNullOrEmpty(errorMessage)">
    ${ShowError("Failed to place order", errorMessage)}
    </s:test>
    ...