Data Scopes
Control in code what publication and/or language scope data comes from
Experience Management has different data scopes for published/unpublished data and data from different languages.
When you use Experience Manager Data in code, you can control what scope data comes from in one of the overloaded DataConnection's constructors.
Adding or saving data
When you add/save data, you should write data to the "unpublished" scope.
using (DataConnection connection = new DataConnection(PublicationScope.Unpublished))
{
Demo.Country country = DataConnection.New<Demo.Country>();
country.Id = Guid.NewGuid();
country.Name = name; // 'name' is a variable initialized outside this code
country = connection.Add<Demo.Country>(country);
}
Publishing data
If data has the publication workflow, you should set the PublicationStatus field to "published" if you want to publish the data immediately.
using (DataConnection connection = new DataConnection(PublicationScope.Unpublished))
{
Demo.Country country =
(from d in connection.Get<Demo.Country>()
where d.Name == name // 'name' is a variable initialized outside this code
select d).First();
country.PublicationStatus = "published";
connection.Update<Demo.Country>(country);
}
Overriding the language
If the language used needs to be overridden (for example, the data to be saved in the French rather than the default English locale), you should use the corresponding DataConnection's constructor.
using (DataConnection connection = new DataConnection(PublicationScope.Unpublished,
new CultureInfo("fr-CA")))
{
Demo.Country country =
(from d in connection.Get<Demo.Country>()
where d.Name == name // 'name' is a variable initialized outside this code
select d).First();
connection.Update<Demo.Country>(country);
}
More on data Stores in Experience Manager
datatypes in Experience Management can be publishable and non-publishable. datatypes can also support localization and exist in two or more language contexts.
When you create datatypes in Experience Management or programmatically. The datatypes are not published by default.
You can however make them publishable. In the CMS Console, you should check the "Has publishing" option on the datatype's settings. In code, you should inherit your datatype interface from the IPublishControlled interface. For more information, see Super interfaces .
public interface ICountry : IData, IPublishControlled
{
// ...
}
Hence, data in Experience Management can exist in two scopes: as "saved data" (also known as "unpublished data") and "published data". They are 100% identical type and identity-wise; however, published data can be only read from the "published" scope while an Experience Management administrator can also see "saved data" in the CMS Console.
When you publish saved data, it gets cloned from the "saved" to "published" scope. (The physical XML file or an SQL table that stands for a datatype will have "_Unpublished" and "_Published" suffixes to its name respectively.
For example : "Demo.Countries_Unpublished.xml" and "Demo.Countries_Published.xml")
When you manipulate data in code, you use a DataConnection object. When creating the DataConnection object , you can explicitly select what scope to use by setting the PublicationScope parameter in its constructor either to "PublicationScope.Published" or "PublicationScope.Unpublished".
using (DataConnection connection = new DataConnection(PublicationScope.Unpublished))
{
// ...
}
To make a datatype localizable, in the CMS Console, you should check the "Is localizable data" option. In code, you should inherit your datatype interface from the ILocalizedControlled interface.
public interface ICountry : IData, ILocalizedControlled
{
// ...
}
When you make a localizable datatype, it creates two XML files or SQL tables that stands for this "localized" datatype with the language code suffixes, for example"Demo.Countries_Published_en-US.xml" and "Demo.Countries_Published_fr-CA.xml" (and "Demo.Countries_Unpublished_en-US.xml" and "Demo.Countries_Unpublished_fr-CA.xml" for publishable datatypes).
The data will be originally kept in the default language. When you translate data item by item, the "translated" data will be added to the corresponding language-based datatype.
Again, when you manipulate data in code, you can explicitly choose the language context via the ad-hoc DataConnection object's constructor.
using (DataConnection connection = new DataConnection(new CultureInfo("fr-CA")))
{
// ...
}
For explicitly setting both the publication and language context, you should use the corresponding DataConnection's constructor:
using (DataConnection connection = new DataConnection(PublicationScope.Unpublished,
new CultureInfo("fr-CA")))
{
// ...
}