Skip to content

Commit

Permalink
Merge pull request #993 from SubPointSolutions/dev
Browse files Browse the repository at this point in the history
SPMeta2 1.2.120-beta5, March 2017
  • Loading branch information
SubPointSupport authored Mar 30, 2017
2 parents 261eb1c + 1ffb9de commit 9233309
Show file tree
Hide file tree
Showing 16 changed files with 1,365 additions and 1,095 deletions.
56 changes: 28 additions & 28 deletions SPMeta2/Build/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2",
"Id": "SPMeta2.Core",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [ ],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
"ProjectUrl": "https://github.com/SubPointSolutions/spmeta2",
Expand Down Expand Up @@ -266,11 +266,11 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.Standard",
"Id": "SPMeta2.Core.Standard",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.Core",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
}
],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
Expand Down Expand Up @@ -311,11 +311,11 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.CSOM",
"Id": "SPMeta2.CSOM.Foundation",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.Core",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
}
],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
Expand Down Expand Up @@ -348,15 +348,15 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.CSOM.Standard",
"Id": "SPMeta2.CSOM.Standard",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.CSOM.Foundation",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
},
{
"Id": "SPMeta2.Core.Standard",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
}
],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
Expand Down Expand Up @@ -389,11 +389,11 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.SSOM",
"Id": "SPMeta2.SSOM.Foundation",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.Core",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
}
],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
Expand Down Expand Up @@ -426,15 +426,15 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.SSOM.Standard",
"Id": "SPMeta2.SSOM.Standard",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.SSOM.Foundation",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
},
{
"Id": "SPMeta2.Core.Standard",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
}
],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
Expand Down Expand Up @@ -468,11 +468,11 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.CSOM",
"Id": "SPMeta2.CSOM.Foundation-v14",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.Core",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
}
],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
Expand All @@ -498,15 +498,15 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.CSOM.Standard",
"Id": "SPMeta2.CSOM.Standard-v14",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.CSOM.Foundation-v14",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
},
{
"Id": "SPMeta2.Core.Standard",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
}
],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
Expand All @@ -532,11 +532,11 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.SSOM",
"Id": "SPMeta2.SSOM.Foundation-v14",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.Core",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
}
],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
Expand All @@ -562,15 +562,15 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.SSOM.Standard",
"Id": "SPMeta2.SSOM.Standard-v14",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.SSOM.Foundation-v14",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
},
{
"Id": "SPMeta2.Core.Standard",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
}
],
"LicenseUrl": "http://docs.subpointsolutions.com/spmeta2/license",
Expand All @@ -596,11 +596,11 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.CSOM",
"Id": "SPMeta2.CSOM.Foundation-v16",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.Core",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
},
{
"Id": "Microsoft.SharePointOnline.CSOM",
Expand Down Expand Up @@ -637,15 +637,15 @@
{
"CustomProjectFolder" : "SPMeta2/SPMeta2.CSOM.Standard",
"Id": "SPMeta2.CSOM.Standard-v16",
"Version": "1.2.120-beta4",
"Version": "1.2.120-beta5",
"Dependencies": [
{
"Id": "SPMeta2.CSOM.Foundation-v16",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
},
{
"Id": "SPMeta2.Core.Standard",
"Version": "1.2.120-beta4"
"Version": "1.2.120-beta5"
},
{
"Id": "Microsoft.SharePointOnline.CSOM",
Expand Down
203 changes: 105 additions & 98 deletions SPMeta2/SPMeta2.CSOM/ModelHandlers/Fields/CalculatedFieldModelHandler.cs
Original file line number Diff line number Diff line change
@@ -1,98 +1,105 @@
using System;
using System.Xml.Linq;
using Microsoft.SharePoint.Client;
using SPMeta2.Definitions;
using SPMeta2.Definitions.Fields;
using SPMeta2.Enumerations;
using SPMeta2.Services;
using SPMeta2.Utils;

namespace SPMeta2.CSOM.ModelHandlers.Fields
{
public class CalculatedFieldModelHandler : FieldModelHandler
{
#region properties

public override Type TargetType
{
get { return typeof(CalculatedFieldDefinition); }
}

protected override Type GetTargetFieldType(FieldDefinition model)
{
return typeof(FieldCalculated);
}

#endregion

#region methods

protected override void ProcessFieldProperties(Field field, FieldDefinition fieldModel)
{
// let base setting be setup
base.ProcessFieldProperties(field, fieldModel);

var typedFieldModel = fieldModel.WithAssertAndCast<CalculatedFieldDefinition>("model", value => value.RequireNotNull());
var typedField = field.Context.CastTo<FieldCalculated>(field);

if (!string.IsNullOrEmpty(typedFieldModel.Formula))
{
// can't really validate it automatically
// Improve CalculatedFieldDefinition with field ref check
// https://github.com/SubPointSolutions/spmeta2/issues/648
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Updating formula for a CalculatedField. Ensure FieldReferences are correct.");

typedField.Formula = typedFieldModel.Formula;
}

if (!string.IsNullOrEmpty(typedFieldModel.OutputType))
typedField.OutputType = (FieldType)Enum.Parse(typeof(FieldType), typedFieldModel.OutputType);
}

protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);

var typedFieldModel = fieldModel.WithAssertAndCast<CalculatedFieldDefinition>("model", value => value.RequireNotNull());

if (typedFieldModel.CurrencyLocaleId.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.LCID, typedFieldModel.CurrencyLocaleId);

// can't really validate it automatically
// Improve CalculatedFieldDefinition with field ref check
// https://github.com/SubPointSolutions/spmeta2/issues/648
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Crafting formula for a CalculatedField. Ensure FieldReferences are correct.");

// should be a new XML node
var formulaNode = new XElement(BuiltInFieldAttributes.Formula, typedFieldModel.Formula);
fieldTemplate.Add(formulaNode);

fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format, (int)Enum.Parse(typeof(DateTimeFieldFormatType), typedFieldModel.DateFormat));

if (typedFieldModel.ShowAsPercentage.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Percentage, typedFieldModel.ShowAsPercentage.Value.ToString().ToUpper());

if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Decimals, NumberFieldModelHandler.GetDecimalsValue(typedFieldModel.DisplayFormat));

fieldTemplate.SetAttribute(BuiltInFieldAttributes.ResultType, typedFieldModel.OutputType);

if (typedFieldModel.FieldReferences.Count > 0)
{
var fieldRefsNode = new XElement("FieldRefs");

foreach (var fieldRef in typedFieldModel.FieldReferences)
{
var fieldRefNode = new XElement("FieldRef");

fieldRefNode.SetAttribute("Name", fieldRef);
fieldRefsNode.Add(fieldRefNode);
}

fieldTemplate.Add(fieldRefsNode);
}
}

#endregion
}
}
using System;
using System.Xml.Linq;
using Microsoft.SharePoint.Client;
using SPMeta2.Definitions;
using SPMeta2.Definitions.Fields;
using SPMeta2.Enumerations;
using SPMeta2.Services;
using SPMeta2.Utils;

namespace SPMeta2.CSOM.ModelHandlers.Fields
{
public class CalculatedFieldModelHandler : FieldModelHandler
{
#region properties

public override Type TargetType
{
get { return typeof(CalculatedFieldDefinition); }
}

protected override Type GetTargetFieldType(FieldDefinition model)
{
return typeof(FieldCalculated);
}

#endregion

#region methods

protected override void ProcessFieldProperties(Field field, FieldDefinition fieldModel)
{
// let base setting be setup
base.ProcessFieldProperties(field, fieldModel);

var typedFieldModel = fieldModel.WithAssertAndCast<CalculatedFieldDefinition>("model", value => value.RequireNotNull());
var typedField = field.Context.CastTo<FieldCalculated>(field);

if (!string.IsNullOrEmpty(typedFieldModel.Formula))
{
// can't really validate it automatically
// Improve CalculatedFieldDefinition with field ref check
// https://github.com/SubPointSolutions/spmeta2/issues/648
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Updating formula for a CalculatedField. Ensure FieldReferences are correct.");

typedField.Formula = typedFieldModel.Formula;

typedField.DateFormat = (DateTimeFieldFormatType)
Enum.Parse(typeof(DateTimeFieldFormatType), typedFieldModel.DateFormat);
}

if (!string.IsNullOrEmpty(typedFieldModel.OutputType))
typedField.OutputType = (FieldType)Enum.Parse(typeof(FieldType), typedFieldModel.OutputType);
}

protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
{
base.ProcessSPFieldXElement(fieldTemplate, fieldModel);

var typedFieldModel = fieldModel.WithAssertAndCast<CalculatedFieldDefinition>("model", value => value.RequireNotNull());

if (typedFieldModel.CurrencyLocaleId.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.LCID, typedFieldModel.CurrencyLocaleId);

// can't really validate it automatically
// Improve CalculatedFieldDefinition with field ref check
// https://github.com/SubPointSolutions/spmeta2/issues/648
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Crafting formula for a CalculatedField. Ensure FieldReferences are correct.");

// should be a new XML node
var formulaNode = new XElement(BuiltInFieldAttributes.Formula, typedFieldModel.Formula);
fieldTemplate.Add(formulaNode);

// must be enum name, actually

// Format="0" when provisioning CalculatedField #969
// https://github.com/SubPointSolutions/spmeta2/issues/969
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format, typedFieldModel.DateFormat);

if (typedFieldModel.ShowAsPercentage.HasValue)
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Percentage, typedFieldModel.ShowAsPercentage.Value.ToString().ToUpper());

if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
fieldTemplate.SetAttribute(BuiltInFieldAttributes.Decimals, NumberFieldModelHandler.GetDecimalsValue(typedFieldModel.DisplayFormat));

fieldTemplate.SetAttribute(BuiltInFieldAttributes.ResultType, typedFieldModel.OutputType);

if (typedFieldModel.FieldReferences.Count > 0)
{
var fieldRefsNode = new XElement("FieldRefs");

foreach (var fieldRef in typedFieldModel.FieldReferences)
{
var fieldRefNode = new XElement("FieldRef");

fieldRefNode.SetAttribute("Name", fieldRef);
fieldRefsNode.Add(fieldRefNode);
}

fieldTemplate.Add(fieldRefsNode);
}
}

#endregion
}
}
Loading

0 comments on commit 9233309

Please sign in to comment.