Data Scopes

Control in code what publication and/or language scope data comes from

C1 CMS has different data scopes for published/unpublished data and data from different languages.

When you use C1 CMS 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 (say, the data to be saved in the Danish rather than the default English locale), you should use the corresponding DataConnection's constructor.

using (DataConnection connection = new DataConnection(PublicationScope.Unpublished,
						      new CultureInfo("da-DK")))
{
	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 scopes in C1 CMS

Data types in Composite can be publishable and non-publishable. Data types can also support localization and exist in two or more language contexts. (Read more in "How is localizable and publishable data handled on pages?".)

When you create data types in the CMS Console or programmatically, the data types are non-publishable by default.

You can however make them publishable. In the CMS Console, you should check the "Has publishing" option on the data type's settings. In code, you should inherit your data type interface from the IPublishControlled interface.

public interface ICountry : IData, IPublishControlled
{
	// ...
}

Hence, data in C1 CMS can exist in two scopes: as "saved data" (a.k.a. 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 a C1 CMS 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 data type will have "_Unpublished" and "_Published" suffixes to its name respectively, e.g. "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 data type localizable, in the CMS Console, you should check the "Is localizable data" option. In code, you should inherit your data type interface from the ILocalizedControlled interface.

public interface ICountry : IData, ILocalizedControlled
{
	// ...
}

When you make a localizable data type, it creates two XML files or SQL tables that stands for this "localized" data type with the language code suffixes, e.g. "Demo.Countries_Published_en-US.xml" and "Demo.Countries_Published_da-DK.xml" (and "Demo.Countries_Unpublished_en-US.xml" and "Demo.Countries_Unpublished_da-DK.xml" for publishable data types).

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 data type.

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("da-DK")))
{
	// ...
}

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("da-DK")))
{
	// ...
}