Upgrade un Feature


Se fac(e) ce trebuie adaugat si se redenumeste elements.xml in elements_v2.xml s.a.m.d. ptr fiecare element nou adaugat.

Apoi in feature definition

 

   1: <Feature Id="86689158-7048-4421-AD21-E0DEF0D67C81" Version="2.0.0.0" >

   2: <ElementManifests>

   3: <ElementManifest Location="elements.xml" />

   4: <ElementManifest Location="elements_v2.xml" />

   5: </ElementManifests>

   6: <UpgradeActions>

   7: <VersionRange BeginVersion="1.0.0.0" EndVersion="2.0.0.0">

   8: <ApplyElementManifests>

   9: <ElementManifest Location="elements_v2.xml"/>

  10: </ApplyElementManifests>

  11: </VersionRange>

  12: </UpgradeActions>

  13: </Feature>

Pentru upgrade-uri succesive (de la v.2 la 3) se mai adauga intrari de tipul

<VersionRange BeginVersion="1.0.0.0" EndVersion="3.0.0.0">

<!—de la vesriunea 1 la 3 –>

</VersionRange>

sau

<VersionRange BeginVersion="2.0.0.0" EndVersion="3.0.0.0">

<!—de la versiunea 2 la 3 –>

</VersionRange>

fiecare cu elementele care definesc upgrade-ul.

Din cod cu FeatureUpgrading se defineste in feature.xml ca UpgradeActions

 

   1: <Feature Id="86689158-7048-4421-AD21-E0DEF0D67C81" Version="2.0.0.0" >

   2: <UpgradeActions

   3: ReceiverAssembly="nume_assembly, [four-part assembly name]"

   4: ReceiverClass="nume_clasa.FeatureReceiver" >

   5: <VersionRange BeginVersion="1.0.0.0" EndVersion="2.0.0.0">

   6: <CustomUpgradeAction Name="nume_actiune_ca_parametru">

   7: <Parameters>

   8: <Parameter Name="parametru">Descriere parametru</Parameter>

   9: </Parameters>

  10: </CustomUpgradeAction>

  11: </VersionRange>

  12: </UpgradeActions>

  13: </Feature>

 

apoi in FeatureReceiver

 

   1: public override void FeatureUpgrading(SPFeatureReceiverProperties props,

   2: string upgradeActionName,

   3: IDictionary<string, string> parameters) {

   4:  

   5: SPWeb site = props.Feature.Parent as SPWeb;

   6: if (site != null) {

   7: // ce actiune se executa 

   8: switch (upgradeActionName) {

   9: case "ceva":

  10:  

  11: string NewTitle = parameters["NewSiteTitle"];//param din feature.xml

  12: site.Title = NewTitle;

  13: site.Update();

  14: break;

  15: default:

  16: // unexpected feature upgrade action

  17: break;

  18: }

  19: }

  20: }

Anunțuri

Lasă un răspuns

Completează mai jos detaliile tale sau dă clic pe un icon pentru a te autentifica:

Logo WordPress.com

Comentezi folosind contul tău WordPress.com. Dezautentificare / Schimbă )

Poză Twitter

Comentezi folosind contul tău Twitter. Dezautentificare / Schimbă )

Fotografie Facebook

Comentezi folosind contul tău Facebook. Dezautentificare / Schimbă )

Fotografie Google+

Comentezi folosind contul tău Google+. Dezautentificare / Schimbă )

Conectare la %s