Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing hardcoded database name for item #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
namespace Transitus.Rainbow.Sync
{
using System.IO;
using System.Xml;
using System.IO;
using System.Xml;

using global::Rainbow.Filtering;
using global::Rainbow.Formatting;
using global::Rainbow.Storage.Yaml;
using global::Rainbow.Filtering;
using global::Rainbow.Formatting;
using global::Rainbow.Storage.Yaml;

using Sitecore.IO;
using Sitecore.IO;

public class RainbowItemDeserializer : IFileDeserializer
{
protected readonly ISerializationFormatter SerializationFormatter;
public class RainbowItemDeserializer : IFileDeserializer
{
protected readonly ISerializationFormatter SerializationFormatter;

public RainbowItemDeserializer()
{
// TODO: See if we can move this to a config file, rather than hard coding it here.
const string xmlNodeString = @"
public RainbowItemDeserializer()
{
// TODO: See if we can move this to a config file, rather than hard coding it here.
const string xmlNodeString = @"
<serializationFormatter type=""Rainbow.Storage.Yaml.YamlSerializationFormatter, Rainbow.Storage.Yaml"" singleInstance=""true"">
<fieldFormatter type=""Rainbow.Formatting.FieldFormatters.MultilistFormatter, Rainbow"" />
<fieldFormatter type=""Rainbow.Formatting.FieldFormatters.XmlFieldFormatter, Rainbow"" />
</serializationFormatter >
";
var doc = new XmlDocument();
doc.LoadXml(xmlNodeString);
var doc = new XmlDocument();
doc.LoadXml(xmlNodeString);

// TODO: See if we can move this to a config file, rather than hard coding it here.
const string fieldFilterXmlString = @"
// TODO: See if we can move this to a config file, rather than hard coding it here.
const string fieldFilterXmlString = @"
<fieldFilter type=""Rainbow.Filtering.ConfigurationFieldFilter, Rainbow"" singleInstance=""true"">
<exclude fieldID=""{B1E16562-F3F9-4DDD-84CA-6E099950ECC0}"" note=""'Last run' field on Schedule template (used to register tasks)"" />
<exclude fieldID=""{52807595-0F8F-4B20-8D2A-CB71D28C6103}"" note=""'__Owner' field on Standard Template"" />
Expand All @@ -37,34 +37,33 @@ public RainbowItemDeserializer()
<exclude fieldID=""{001DD393-96C5-490B-924A-B0F25CD9EFD8}"" note=""'__Lock' field on Standard Template"" />
</fieldFilter>
";
var fieldFilterXml = new XmlDocument();
fieldFilterXml.LoadXml(fieldFilterXmlString);
var fieldFilterXml = new XmlDocument();
fieldFilterXml.LoadXml(fieldFilterXmlString);

this.SerializationFormatter = new YamlSerializationFormatter(doc, new ConfigurationFieldFilter(fieldFilterXml));
}
this.SerializationFormatter = new YamlSerializationFormatter(doc, new ConfigurationFieldFilter(fieldFilterXml));
}

public IItem Deserialize(string filePath)
{
var syncItem = this.ReadItem(filePath);
public IItem Deserialize(string filePath)
{
var syncItem = this.ReadItem(filePath);

return syncItem;
}
return syncItem;
}

public string ItemFileExtension => ".yml";
public string ItemFileExtension => ".yml";

public IItem ReadItem(string filePath)
{
var file = new FileInfo(filePath);

lock (FileUtil.GetFileLock(file.FullName))
{
using (var reader = file.OpenRead())
{
var readItem = this.SerializationFormatter.ReadSerializedItem(reader, filePath);
readItem.DatabaseName = "master";
return new RainbowItem(readItem);
}
}
var file = new FileInfo(filePath);

lock (FileUtil.GetFileLock(file.FullName))
{
using (var reader = file.OpenRead())
{
var readItem = this.SerializationFormatter.ReadSerializedItem(reader, filePath);
return new RainbowItem(readItem);
}
}
}
}
}
}