diff --git a/.gitignore b/.gitignore index 62ea6e3d..05bb8535 100644 --- a/.gitignore +++ b/.gitignore @@ -97,7 +97,6 @@ AppPackages/ [Bb]in [Oo]bj # sql -TestResults [Tt]est[Rr]esult* *.Cache ClientBin @@ -113,5 +112,6 @@ Backup*/ UpgradeLog*.XML # Log files -*.log *.log.[123456789] +*.db-shm +*.db-wal diff --git a/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/App.config b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/App.config new file mode 100644 index 00000000..bff7bf9a --- /dev/null +++ b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/App.config @@ -0,0 +1,30 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/EntityFrameworkTest.db b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/EntityFrameworkTest.db new file mode 100644 index 00000000..16c6f2b6 Binary files /dev/null and b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/EntityFrameworkTest.db differ diff --git a/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/FrameworkSettingsTest.cs b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/FrameworkSettingsTest.cs new file mode 100644 index 00000000..71b6cd66 --- /dev/null +++ b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/FrameworkSettingsTest.cs @@ -0,0 +1,65 @@ +/* + * Copyright 2020 Systemic Pty Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Sif.Framework.Settings; +using Sif.Framework.Model.Infrastructure; +using Sif.Framework.Model.Requests; +using Sif.Framework.Model.Settings; +using Tardigrade.Framework.Configurations; +using Tardigrade.Framework.EntityFramework.Configurations; +using Xunit; + +namespace Sif.Framework.EntityFramework.Tests +{ + public class FrameworkSettingsTest + { + private readonly IFrameworkSettings settings; + + public FrameworkSettingsTest() + { + settings = new ConsumerSettings( + new ApplicationConfiguration(new AppSettingsConfigurationSource("name=SettingsDb"))); + } + + [Fact] + public void GetSettings_ValidSettings_Success() + { + Assert.Equal(Accept.XML, settings.Accept); + Assert.Equal("Sif3DemoConsumer", settings.ApplicationKey); + Assert.Equal("SIF_HMACSHA256", settings.AuthenticationMethod); + Assert.False(settings.CompressPayload); + Assert.Equal("DemoConsumer", settings.ConsumerName); + Assert.Equal(ContentType.XML, settings.ContentType); + Assert.Equal("http://www.sifassociation.org/datamodel/au/3.4", settings.DataModelNamespace); + Assert.False(settings.DeleteOnUnregister); + Assert.Equal(EnvironmentType.DIRECT, settings.EnvironmentType); + Assert.Equal("http://localhost:62921/api/environments/environment", settings.EnvironmentUrl); + Assert.Equal(10, settings.EventProcessingWaitTime); + Assert.Equal("http://www.sifassociation.org/infrastructure/3.2.1", settings.InfrastructureNamespace); + Assert.Null(settings.InstanceId); + Assert.True(settings.JobBinding); + Assert.Equal("any", settings.JobClasses); + Assert.True(settings.JobTimeoutEnabled); + Assert.Equal(60, settings.JobTimeoutFrequency); + Assert.Equal(5, settings.NavigationPageSize); + Assert.Equal("SecretDem0", settings.SharedSecret); + Assert.Equal("Sif3Framework", settings.SolutionId); + Assert.Equal(10, settings.StartupDelay); + Assert.Equal("3.2.1", settings.SupportedInfrastructureVersion); + Assert.Null(settings.UserToken); + } + } +} \ No newline at end of file diff --git a/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/Properties/AssemblyInfo.cs b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..82abc040 --- /dev/null +++ b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Sif.Framework.EntityFramework.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Sif.Framework.EntityFramework.Tests")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f4546d54-e46e-4d8d-9a8f-ffdc67c54e1d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/Sif.Framework.EntityFramework.Tests.csproj b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/Sif.Framework.EntityFramework.Tests.csproj new file mode 100644 index 00000000..56d43b4a --- /dev/null +++ b/Code/Sif.Framework.Tests/Sif.Framework.EntityFramework.Tests/Sif.Framework.EntityFramework.Tests.csproj @@ -0,0 +1,79 @@ + + + + + Debug + AnyCPU + {F4546D54-E46E-4D8D-9A8F-FFDC67C54E1D} + Library + Properties + Sif.Framework.EntityFramework.Tests + Sif.Framework.EntityFramework.Tests + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + 5.0.0 + + + 1.0.113.7 + + + 11.1.0 + + + 2.4.1 + + + 2.4.3 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + PreserveNewest + + + + + {2b13d050-aa2c-45a6-ba26-8b2706b7e227} + Sif.Framework + + + + \ No newline at end of file diff --git a/Code/Sif.Framework.Tests/Sif.Framework.Tests.sln b/Code/Sif.Framework.Tests/Sif.Framework.Tests.sln new file mode 100644 index 00000000..1c64ac8e --- /dev/null +++ b/Code/Sif.Framework.Tests/Sif.Framework.Tests.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30717.126 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sif.Framework.EntityFramework.Tests", "Sif.Framework.EntityFramework.Tests\Sif.Framework.EntityFramework.Tests.csproj", "{F4546D54-E46E-4D8D-9A8F-FFDC67C54E1D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sif.Framework.Tests", "Sif.Framework.Tests\Sif.Framework.Tests.csproj", "{2BCC7798-CA9C-42B5-971B-4374DB30D4F6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sif.Framework", "..\Sif3Framework\Sif.Framework\Sif.Framework.csproj", "{2B13D050-AA2C-45A6-BA26-8B2706B7E227}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F4546D54-E46E-4D8D-9A8F-FFDC67C54E1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F4546D54-E46E-4D8D-9A8F-FFDC67C54E1D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F4546D54-E46E-4D8D-9A8F-FFDC67C54E1D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F4546D54-E46E-4D8D-9A8F-FFDC67C54E1D}.Release|Any CPU.Build.0 = Release|Any CPU + {2BCC7798-CA9C-42B5-971B-4374DB30D4F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2BCC7798-CA9C-42B5-971B-4374DB30D4F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2BCC7798-CA9C-42B5-971B-4374DB30D4F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2BCC7798-CA9C-42B5-971B-4374DB30D4F6}.Release|Any CPU.Build.0 = Release|Any CPU + {2B13D050-AA2C-45A6-BA26-8B2706B7E227}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B13D050-AA2C-45A6-BA26-8B2706B7E227}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B13D050-AA2C-45A6-BA26-8B2706B7E227}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B13D050-AA2C-45A6-BA26-8B2706B7E227}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1F1A78DA-B94C-422F-A1A0-88D153DD81FE} + EndGlobalSection +EndGlobal diff --git a/Code/Sif.Framework.Tests/Sif.Framework.Tests/Class1.cs b/Code/Sif.Framework.Tests/Sif.Framework.Tests/Class1.cs new file mode 100644 index 00000000..bae8ec3f --- /dev/null +++ b/Code/Sif.Framework.Tests/Sif.Framework.Tests/Class1.cs @@ -0,0 +1,8 @@ +using System; + +namespace Sif.Framework.Tests +{ + public class Class1 + { + } +} diff --git a/Code/Sif.Framework.Tests/Sif.Framework.Tests/Sif.Framework.Tests.csproj b/Code/Sif.Framework.Tests/Sif.Framework.Tests/Sif.Framework.Tests.csproj new file mode 100644 index 00000000..9f5c4f4a --- /dev/null +++ b/Code/Sif.Framework.Tests/Sif.Framework.Tests/Sif.Framework.Tests.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/Code/Sif3Framework/Sif.Framework.EnvironmentProvider/Sif.Framework.EnvironmentProvider.csproj b/Code/Sif3Framework/Sif.Framework.EnvironmentProvider/Sif.Framework.EnvironmentProvider.csproj index dc740cad..fc81d088 100644 --- a/Code/Sif3Framework/Sif.Framework.EnvironmentProvider/Sif.Framework.EnvironmentProvider.csproj +++ b/Code/Sif3Framework/Sif.Framework.EnvironmentProvider/Sif.Framework.EnvironmentProvider.csproj @@ -47,22 +47,21 @@ ..\packages\Antlr3.Runtime.3.5.1\lib\net40-client\Antlr3.Runtime.dll - - ..\packages\AutoMapper.7.0.1\lib\net45\AutoMapper.dll + + ..\packages\AutoMapper.10.1.1\lib\net461\AutoMapper.dll ..\packages\Iesi.Collections.4.0.4\lib\net461\Iesi.Collections.dll - - ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll - True + + ..\packages\log4net.2.0.12\lib\net45\log4net.dll - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll - - ..\packages\NHibernate.5.1.3\lib\net461\NHibernate.dll + + ..\packages\NHibernate.5.3.5\lib\net461\NHibernate.dll ..\packages\Remotion.Linq.2.2.0\lib\net45\Remotion.Linq.dll @@ -73,21 +72,19 @@ ..\packages\Sif.Specification.Infrastructure.3.2.1\lib\netstandard2.0\Sif.Specification.Infrastructure.dll - - ..\packages\slf4net.0.1.32.1\lib\net35\slf4net.dll - True + + ..\packages\slf4net.1.1.0\lib\net40\slf4net.dll - - ..\packages\slf4net.log4net.0.1.32.1\lib\net35\slf4net.log4net.dll - True + + ..\packages\slf4net.log4net.1.1.0\lib\net40\slf4net.log4net.dll - - ..\packages\System.Data.SQLite.Core.1.0.109.2\lib\net46\System.Data.SQLite.dll + + ..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\lib\net46\System.Data.SQLite.dll - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll @@ -104,11 +101,11 @@ - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.6\lib\net45\System.Web.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll - - ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.6\lib\net45\System.Web.Http.WebHost.dll + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll @@ -183,12 +180,12 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + +
+ + + + + + + + + + + + + + + + + + + diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/ConsumerApp.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/ConsumerApp.cs index cc335b57..209225e7 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/ConsumerApp.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/ConsumerApp.cs @@ -1,5 +1,5 @@ /* - * Copyright 2018 Systemic Pty Ltd + * Copyright 2020 Systemic Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,25 +19,30 @@ using Sif.Framework.Demo.Au.Consumer.Utils; using Sif.Framework.Model.Query; using Sif.Framework.Model.Responses; +using Sif.Framework.Model.Settings; +using Sif.Framework.Settings; using Sif.Framework.Utils; using Sif.Specification.DataModel.Au; using System; using System.Collections.Generic; using System.Linq; +using Tardigrade.Framework.Configurations; +using Tardigrade.Framework.EntityFramework.Configurations; namespace Sif.Framework.Demo.Au.Consumer { internal class ConsumerApp { - private static readonly slf4net.ILogger log = slf4net.LoggerFactory.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private static readonly slf4net.ILogger Log = slf4net.LoggerFactory.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private static readonly Random Random = new Random(); - private static Random random = new Random(); + private enum SettingsSource { Database, File } private static StudentPersonal CreateStudent() { NameOfRecordType name = new NameOfRecordType { Type = NameOfRecordTypeType.LGL, FamilyName = RandomNameGenerator.FamilyName, GivenName = RandomNameGenerator.GivenName }; PersonInfoType personInfo = new PersonInfoType { Name = name }; - StudentPersonal studentPersonal = new StudentPersonal { LocalId = random.Next(10000, 99999).ToString(), PersonInfo = personInfo }; + StudentPersonal studentPersonal = new StudentPersonal { LocalId = Random.Next(10000, 99999).ToString(), PersonInfo = personInfo }; return studentPersonal; } @@ -54,15 +59,37 @@ private static List CreateStudents(int count) return studentPersonalsCache; } - private void RunStudentPersonalConsumer() + private static IFrameworkSettings GetSettings(SettingsSource source) { - StudentPersonalConsumer studentPersonalConsumer = new StudentPersonalConsumer( - SettingsManager.ConsumerSettings.ApplicationKey, - SettingsManager.ConsumerSettings.InstanceId, - SettingsManager.ConsumerSettings.UserToken, - SettingsManager.ConsumerSettings.SolutionId); + IFrameworkSettings settings; + + switch (source) + { + case SettingsSource.Database: + settings = new ConsumerSettings(new ApplicationConfiguration(new AppSettingsConfigurationSource("name=SettingsDb"))); + break; + + case SettingsSource.File: + settings = SettingsManager.ConsumerSettings; + break; + + default: + settings = SettingsManager.ConsumerSettings; + break; + } + return settings; + } + + private static void RunStudentPersonalConsumer(IFrameworkSettings settings) + { + var studentPersonalConsumer = new StudentPersonalConsumer( + settings.ApplicationKey, + settings.InstanceId, + settings.UserToken, + settings.SolutionId, + settings); studentPersonalConsumer.Register(); - if (log.IsInfoEnabled) log.Info("Registered the Consumer."); + if (Log.IsInfoEnabled) Log.Info("Registered the Consumer."); try { @@ -70,11 +97,11 @@ private void RunStudentPersonalConsumer() foreach (StudentPersonal student in queriedStudents) { - if (log.IsInfoEnabled) log.Info("Queried student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); + if (Log.IsInfoEnabled) Log.Info("Queried student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); } // Retrieve Bart Simpson using QBE. - if (log.IsInfoEnabled) log.Info("*** Retrieve Bart Simpson using QBE."); + if (Log.IsInfoEnabled) Log.Info("*** Retrieve Bart Simpson using QBE."); NameOfRecordType name = new NameOfRecordType { FamilyName = "Simpson", GivenName = "Bart" }; PersonInfoType personInfo = new PersonInfoType { Name = name }; StudentPersonal studentPersonal = new StudentPersonal { PersonInfo = personInfo }; @@ -82,11 +109,11 @@ private void RunStudentPersonalConsumer() foreach (StudentPersonal student in filteredStudents) { - if (log.IsInfoEnabled) log.Info("Filtered student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); + if (Log.IsInfoEnabled) Log.Info("Filtered student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); } // Create a new student. - if (log.IsInfoEnabled) log.Info("*** Create a new student."); + if (Log.IsInfoEnabled) Log.Info("*** Create a new student."); string[] text = new string[] { @" @@ -108,15 +135,15 @@ private void RunStudentPersonalConsumer() try { StudentPersonal retrievedNewStudent = studentPersonalConsumer.Create(newStudent, true); - if (log.IsInfoEnabled) log.Info($"Created new student {newStudent.PersonInfo.Name.GivenName} {newStudent.PersonInfo.Name.FamilyName} with ID of {studentID}."); + if (Log.IsInfoEnabled) Log.Info($"Created new student {newStudent.PersonInfo.Name.GivenName} {newStudent.PersonInfo.Name.FamilyName} with ID of {studentID}."); } catch (UnauthorizedAccessException) { - if (log.IsInfoEnabled) log.Info($"Access to create a new student is rejected."); + if (Log.IsInfoEnabled) Log.Info($"Access to create a new student is rejected."); } // Create multiple new students. - if (log.IsInfoEnabled) log.Info("*** Create multiple new students."); + if (Log.IsInfoEnabled) Log.Info("*** Create multiple new students."); List newStudents = CreateStudents(5); try @@ -126,12 +153,12 @@ private void RunStudentPersonalConsumer() foreach (CreateStatus status in multipleCreateResponse.StatusRecords) { - if (log.IsInfoEnabled) log.Info("Create status code is " + status.StatusCode); + if (Log.IsInfoEnabled) Log.Info("Create status code is " + status.StatusCode); newStudents[count++].RefId = status.Id; } // Update multiple students. - if (log.IsInfoEnabled) log.Info("*** Update multiple students."); + if (Log.IsInfoEnabled) Log.Info("*** Update multiple students."); foreach (StudentPersonal student in newStudents) { student.PersonInfo.Name.GivenName += "o"; @@ -143,16 +170,16 @@ private void RunStudentPersonalConsumer() foreach (UpdateStatus status in multipleUpdateResponse.StatusRecords) { - if (log.IsInfoEnabled) log.Info("Update status code is " + status.StatusCode); + if (Log.IsInfoEnabled) Log.Info("Update status code is " + status.StatusCode); } } catch (UnauthorizedAccessException) { - if (log.IsInfoEnabled) log.Info($"Access to update multiple students is rejected."); + if (Log.IsInfoEnabled) Log.Info($"Access to update multiple students is rejected."); } // Delete multiple students. - if (log.IsInfoEnabled) log.Info("*** Delete multiple students."); + if (Log.IsInfoEnabled) Log.Info("*** Delete multiple students."); ICollection refIds = new List(); foreach (CreateStatus status in multipleCreateResponse.StatusRecords) @@ -166,38 +193,38 @@ private void RunStudentPersonalConsumer() foreach (DeleteStatus status in multipleDeleteResponse.StatusRecords) { - if (log.IsInfoEnabled) log.Info("Delete status code is " + status.StatusCode); + if (Log.IsInfoEnabled) Log.Info("Delete status code is " + status.StatusCode); } } catch (UnauthorizedAccessException) { - if (log.IsInfoEnabled) log.Info($"Access to delete multiple students is rejected."); + if (Log.IsInfoEnabled) Log.Info($"Access to delete multiple students is rejected."); } } catch (UnauthorizedAccessException) { - if (log.IsInfoEnabled) log.Info($"Access to create multiple new students is rejected."); + if (Log.IsInfoEnabled) Log.Info($"Access to create multiple new students is rejected."); } // Retrieve all students from zone "Gov" and context "Curr". - if (log.IsInfoEnabled) log.Info("*** Retrieve all students from zone \"Gov\" and context \"Curr\"."); + if (Log.IsInfoEnabled) Log.Info("*** Retrieve all students from zone \"Gov\" and context \"Curr\"."); IEnumerable students = studentPersonalConsumer.Query(zoneId: "Gov", contextId: "Curr"); foreach (StudentPersonal student in students) { - if (log.IsInfoEnabled) log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); + if (Log.IsInfoEnabled) Log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); } if (students.Count() > 1) { // Retrieve a single student. - if (log.IsInfoEnabled) log.Info("*** Retrieve a single student."); + if (Log.IsInfoEnabled) Log.Info("*** Retrieve a single student."); string studentId = students.ElementAt(1).RefId; StudentPersonal secondStudent = studentPersonalConsumer.Query(studentId); - if (log.IsInfoEnabled) log.Info("Name of second student is " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName); + if (Log.IsInfoEnabled) Log.Info("Name of second student is " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName); // Update that student and confirm. - if (log.IsInfoEnabled) log.Info("*** Update that student and confirm."); + if (Log.IsInfoEnabled) Log.Info("*** Update that student and confirm."); secondStudent.PersonInfo.Name.GivenName = "Homer"; secondStudent.PersonInfo.Name.FamilyName = "Simpson"; @@ -205,15 +232,15 @@ private void RunStudentPersonalConsumer() { studentPersonalConsumer.Update(secondStudent); secondStudent = studentPersonalConsumer.Query(studentId); - if (log.IsInfoEnabled) log.Info("Name of second student has been changed to " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName); + if (Log.IsInfoEnabled) Log.Info("Name of second student has been changed to " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName); } catch (UnauthorizedAccessException) { - if (log.IsInfoEnabled) log.Info($"Access to update a student is rejected."); + if (Log.IsInfoEnabled) Log.Info($"Access to update a student is rejected."); } // Delete that student and confirm. - if (log.IsInfoEnabled) log.Info("*** Delete that student and confirm."); + if (Log.IsInfoEnabled) Log.Info("*** Delete that student and confirm."); try { @@ -223,21 +250,21 @@ private void RunStudentPersonalConsumer() if (studentDeleted) { - if (log.IsInfoEnabled) log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was successfully deleted."); + if (Log.IsInfoEnabled) Log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was successfully deleted."); } else { - if (log.IsInfoEnabled) log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was NOT deleted."); + if (Log.IsInfoEnabled) Log.Info("Student " + secondStudent.PersonInfo.Name.GivenName + " " + secondStudent.PersonInfo.Name.FamilyName + " was NOT deleted."); } } catch (UnauthorizedAccessException) { - if (log.IsInfoEnabled) log.Info($"Access to delete a student is rejected."); + if (Log.IsInfoEnabled) Log.Info($"Access to delete a student is rejected."); } } // Retrieve students based on Teaching Group using Service Paths. - if (log.IsInfoEnabled) log.Info("*** Retrieve students based on Teaching Group using Service Paths."); + if (Log.IsInfoEnabled) Log.Info("*** Retrieve students based on Teaching Group using Service Paths."); EqualCondition condition = new EqualCondition() { Left = "TeachingGroups", Right = "597ad3fe-47e7-4b2c-b919-a93c564d19d0" }; IList conditions = new List { @@ -250,7 +277,7 @@ private void RunStudentPersonalConsumer() foreach (StudentPersonal student in teachingGroupStudents) { - if (log.IsInfoEnabled) log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); + if (Log.IsInfoEnabled) Log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); if (student.SIF_ExtendedElements != null && student.SIF_ExtendedElements.Length > 0) { @@ -258,7 +285,7 @@ private void RunStudentPersonalConsumer() { foreach (string content in element.Text) { - if (log.IsInfoEnabled) log.Info("Extended element text is ...\n" + content); + if (Log.IsInfoEnabled) Log.Info("Extended element text is ...\n" + content); } } } @@ -266,87 +293,103 @@ private void RunStudentPersonalConsumer() } catch (UnauthorizedAccessException) { - if (log.IsInfoEnabled) log.Info("Access to query students by Service Path TeachingGroups/{}/StudentPersonals is rejected."); + if (Log.IsInfoEnabled) Log.Info("Access to query students by Service Path TeachingGroups/{}/StudentPersonals is rejected."); } // Retrieve student changes since a particular point as defined by the Changes Since marker. - if (log.IsInfoEnabled) log.Info("*** Retrieve student changes since a particular point as defined by the Changes Since marker."); + if (Log.IsInfoEnabled) Log.Info("*** Retrieve student changes since a particular point as defined by the Changes Since marker."); string changesSinceMarker = studentPersonalConsumer.GetChangesSinceMarker(); IEnumerable changedStudents = studentPersonalConsumer.QueryChangesSince(changesSinceMarker, out string nextChangesSinceMarker); - if (log.IsInfoEnabled) log.Info("Iteration 1 - Student changes based on Changes Since marker - " + changesSinceMarker); + if (Log.IsInfoEnabled) Log.Info("Iteration 1 - Student changes based on Changes Since marker - " + changesSinceMarker); if (changedStudents == null || changedStudents.Count() == 0) { - if (log.IsInfoEnabled) log.Info("No student changes"); + if (Log.IsInfoEnabled) Log.Info("No student changes"); } else { foreach (StudentPersonal student in changedStudents) { - if (log.IsInfoEnabled) log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); + if (Log.IsInfoEnabled) Log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); } } changesSinceMarker = nextChangesSinceMarker; nextChangesSinceMarker = null; changedStudents = studentPersonalConsumer.QueryChangesSince(changesSinceMarker, out nextChangesSinceMarker); - if (log.IsInfoEnabled) log.Info("Iteration 2 - Student changes based on Changes Since marker - " + changesSinceMarker); + if (Log.IsInfoEnabled) Log.Info("Iteration 2 - Student changes based on Changes Since marker - " + changesSinceMarker); if (changedStudents == null || changedStudents.Count() == 0) { - if (log.IsInfoEnabled) log.Info("No student changes"); + if (Log.IsInfoEnabled) Log.Info("No student changes"); } else { foreach (StudentPersonal student in changedStudents) { - if (log.IsInfoEnabled) log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); + if (Log.IsInfoEnabled) Log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); } } changesSinceMarker = nextChangesSinceMarker; nextChangesSinceMarker = null; changedStudents = studentPersonalConsumer.QueryChangesSince(changesSinceMarker, out nextChangesSinceMarker); - if (log.IsInfoEnabled) log.Info("Iteration 3 - Student changes based on Changes Since marker - " + changesSinceMarker); + if (Log.IsInfoEnabled) Log.Info("Iteration 3 - Student changes based on Changes Since marker - " + changesSinceMarker); if (changedStudents == null || changedStudents.Count() == 0) { - if (log.IsInfoEnabled) log.Info("No student changes"); + if (Log.IsInfoEnabled) Log.Info("No student changes"); } else { foreach (StudentPersonal student in changedStudents) { - if (log.IsInfoEnabled) log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); + if (Log.IsInfoEnabled) Log.Info("Student name is " + student.PersonInfo.Name.GivenName + " " + student.PersonInfo.Name.FamilyName); } } } catch (UnauthorizedAccessException) { - if (log.IsInfoEnabled) log.Info($"Access to query students is rejected."); + if (Log.IsInfoEnabled) Log.Info($"Access to query students is rejected."); } catch (Exception e) { - if (log.IsErrorEnabled) log.Error("Error running the StudentPersonal Consumer.\n" + ExceptionUtils.InferErrorResponseMessage(e), e); + if (Log.IsErrorEnabled) Log.Error("Error running the StudentPersonal Consumer.\n" + ExceptionUtils.InferErrorResponseMessage(e), e); } finally { studentPersonalConsumer.Unregister(); - if (log.IsInfoEnabled) log.Info("Unregistered the Consumer."); + if (Log.IsInfoEnabled) Log.Info("Unregistered the Consumer."); } } - private static void Main(string[] args) + private static SettingsSource SelectSettingsSource() { - ConsumerApp app = new ConsumerApp(); + Console.WriteLine(); + Console.Write("Would you like to read the application settings from the SifFramework.config (F)ile or from the SifFrameworkConfig.db (D)atabase? Pressing enter defaults to (F)ile. - "); + ConsoleKeyInfo info; + do + { + info = Console.ReadKey(); + } + while (info.Key != ConsoleKey.D && info.Key != ConsoleKey.F && info.Key != ConsoleKey.Enter); + + Console.WriteLine(); + Console.WriteLine(); + + return info.Key == ConsoleKey.D ? SettingsSource.Database : SettingsSource.File; + } + + private static void Main() + { try { - app.RunStudentPersonalConsumer(); + RunStudentPersonalConsumer(GetSettings(SelectSettingsSource())); } catch (Exception e) { - if (log.IsErrorEnabled) log.Error("Error running the Student Personal CRUD Consumer.\n" + ExceptionUtils.InferErrorResponseMessage(e), e); + if (Log.IsErrorEnabled) Log.Error("Error running the Student Personal CRUD Consumer.\n" + ExceptionUtils.InferErrorResponseMessage(e), e); } Console.WriteLine("Press any key to continue ..."); diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentPersonalConsumer.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentPersonalConsumer.cs index 26e20072..854e41d6 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentPersonalConsumer.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentPersonalConsumer.cs @@ -1,12 +1,12 @@ /* - * Copyright 2017 Systemic Pty Ltd - * + * Copyright 2020 Systemic Pty Ltd + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,23 +16,27 @@ using Sif.Framework.Consumers; using Sif.Framework.Demo.Au.Consumer.Models; +using Sif.Framework.Model.Settings; namespace Sif.Framework.Demo.Au.Consumer.Consumers { - - class StudentPersonalConsumer : BasicConsumer + internal class StudentPersonalConsumer : BasicConsumer { - - public StudentPersonalConsumer(string applicationKey, string instanceId = null, string userToken = null, string solutionId = null) - : base(applicationKey, instanceId, userToken, solutionId) + public StudentPersonalConsumer( + Model.Infrastructure.Environment environment, + IFrameworkSettings settings = null) + : base(environment, settings) { } - public StudentPersonalConsumer(Model.Infrastructure.Environment environment) - : base(environment) + public StudentPersonalConsumer( + string applicationKey, + string instanceId = null, + string userToken = null, + string solutionId = null, + IFrameworkSettings settings = null) + : base(applicationKey, instanceId, userToken, solutionId, settings) { } - } - -} +} \ No newline at end of file diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentPersonalEventConsumer.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentPersonalEventConsumer.cs index 191cf87f..456a8a25 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentPersonalEventConsumer.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentPersonalEventConsumer.cs @@ -1,12 +1,12 @@ /* - * Copyright 2017 Systemic Pty Ltd - * + * Copyright 2020 Systemic Pty Ltd + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,76 +17,84 @@ using Sif.Framework.Consumers; using Sif.Framework.Demo.Au.Consumer.Models; using Sif.Framework.Model.Responses; +using Sif.Framework.Model.Settings; using System.Collections.Generic; namespace Sif.Framework.Demo.Au.Consumer.Consumers { - - class StudentPersonalEventConsumer : BasicEventConsumer + internal class StudentPersonalEventConsumer : BasicEventConsumer { - private static readonly slf4net.ILogger log = slf4net.LoggerFactory.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private readonly slf4net.ILogger log = + slf4net.LoggerFactory.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public StudentPersonalEventConsumer(Model.Infrastructure.Environment environment) - : base(environment) + public StudentPersonalEventConsumer( + Model.Infrastructure.Environment environment, + IFrameworkSettings settings = null) + : base(environment, settings) { } - public StudentPersonalEventConsumer(string applicationKey, string instanceId = null, string userToken = null, string solutionId = null) - : base(applicationKey, instanceId, userToken, solutionId) + public StudentPersonalEventConsumer( + string applicationKey, + string instanceId = null, + string userToken = null, + string solutionId = null, + IFrameworkSettings settings = null) + : base(applicationKey, instanceId, userToken, solutionId, settings) { } public override void OnCreateEvent(List objs, string zoneId = null, string contextId = null) { - if (log.IsDebugEnabled) log.Debug($"*** OnCreateEvent handler called ..."); + if (log.IsDebugEnabled) log.Debug("*** OnCreateEvent handler called ..."); if (log.IsDebugEnabled) log.Debug($"*** >>> Zone ID is {zoneId}."); if (log.IsDebugEnabled) log.Debug($"*** >>> Context ID is {contextId}."); foreach (StudentPersonal student in objs) { - if (log.IsDebugEnabled) log.Debug($"*** >>> Student created is {student.PersonInfo.Name.GivenName} {student.PersonInfo.Name.FamilyName}."); + if (log.IsDebugEnabled) + log.Debug( + $"*** >>> Student created is {student.PersonInfo.Name.GivenName} {student.PersonInfo.Name.FamilyName}."); } - } public override void OnDeleteEvent(List objs, string zoneId = null, string contextId = null) { - if (log.IsDebugEnabled) log.Debug($"*** OnDeleteEvent handler called ..."); + if (log.IsDebugEnabled) log.Debug("*** OnDeleteEvent handler called ..."); if (log.IsDebugEnabled) log.Debug($"*** >>> Zone ID is {zoneId}."); if (log.IsDebugEnabled) log.Debug($"*** >>> Context ID is {contextId}."); foreach (StudentPersonal student in objs) { - if (log.IsDebugEnabled) log.Debug($"*** >>> Student deleted is {student.PersonInfo.Name.GivenName} {student.PersonInfo.Name.FamilyName}."); + if (log.IsDebugEnabled) + log.Debug( + $"*** >>> Student deleted is {student.PersonInfo.Name.GivenName} {student.PersonInfo.Name.FamilyName}."); } - } public override void OnErrorEvent(ResponseError error, string zoneId = null, string contextId = null) { - if (log.IsDebugEnabled) log.Debug($"*** OnErrorEvent handler called ..."); + if (log.IsDebugEnabled) log.Debug("*** OnErrorEvent handler called ..."); if (log.IsDebugEnabled) log.Debug($"*** >>> Zone ID is {zoneId}."); if (log.IsDebugEnabled) log.Debug($"*** >>> Context ID is {contextId}."); - if (log.IsDebugEnabled) log.Debug($"*** >>> Error: {error.Message}."); - } - public override void OnUpdateEvent(List objs, bool partialUpdate, string zoneId = null, string contextId = null) + public override void OnUpdateEvent(List objs, bool partialUpdate, string zoneId = null, + string contextId = null) { - if (log.IsDebugEnabled) log.Debug($"*** OnUpdateEvent handler called ..."); + if (log.IsDebugEnabled) log.Debug("*** OnUpdateEvent handler called ..."); if (log.IsDebugEnabled) log.Debug($"*** >>> Partial update is {partialUpdate}."); if (log.IsDebugEnabled) log.Debug($"*** >>> Zone ID is {zoneId}."); if (log.IsDebugEnabled) log.Debug($"*** >>> Context ID is {contextId}."); foreach (StudentPersonal student in objs) { - if (log.IsDebugEnabled) log.Debug($"*** >>> Student updated is {student.PersonInfo.Name.GivenName} {student.PersonInfo.Name.FamilyName}."); + if (log.IsDebugEnabled) + log.Debug( + $"*** >>> Student updated is {student.PersonInfo.Name.GivenName} {student.PersonInfo.Name.FamilyName}."); } - } - } - -} +} \ No newline at end of file diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentSchoolEnrollmentConsumer.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentSchoolEnrollmentConsumer.cs index 259805ba..0d428852 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentSchoolEnrollmentConsumer.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Consumers/StudentSchoolEnrollmentConsumer.cs @@ -1,5 +1,5 @@ /* - * Copyright 2018 Systemic Pty Ltd + * Copyright 2020 Systemic Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,18 +16,26 @@ using Sif.Framework.Consumers; using Sif.Framework.Demo.Au.Consumer.Models; +using Sif.Framework.Model.Settings; namespace Sif.Framework.Demo.Au.Consumer.Consumers { internal class StudentSchoolEnrollmentConsumer : BasicConsumer { - public StudentSchoolEnrollmentConsumer(string applicationKey, string instanceId = null, string userToken = null, string solutionId = null) - : base(applicationKey, instanceId, userToken, solutionId) + public StudentSchoolEnrollmentConsumer( + Model.Infrastructure.Environment environment, + IFrameworkSettings settings = null) + : base(environment, settings) { } - public StudentSchoolEnrollmentConsumer(Model.Infrastructure.Environment environment) - : base(environment) + public StudentSchoolEnrollmentConsumer( + string applicationKey, + string instanceId = null, + string userToken = null, + string solutionId = null, + IFrameworkSettings settings = null) + : base(applicationKey, instanceId, userToken, solutionId, settings) { } } diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/EnrollmentConsumerApp.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/EnrollmentConsumerApp.cs index cbf98047..8bc1ca92 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/EnrollmentConsumerApp.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/EnrollmentConsumerApp.cs @@ -1,5 +1,5 @@ /* - * Copyright 2018 Systemic Pty Ltd + * Copyright 2020 Systemic Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,8 @@ private void RunConsumer() SettingsManager.ConsumerSettings.ApplicationKey, SettingsManager.ConsumerSettings.InstanceId, SettingsManager.ConsumerSettings.UserToken, - SettingsManager.ConsumerSettings.SolutionId); + SettingsManager.ConsumerSettings.SolutionId, + SettingsManager.ConsumerSettings); consumer.Register(); if (log.IsInfoEnabled) log.Info("Registered the Consumer."); diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/EventConsumerApp.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/EventConsumerApp.cs index c33bd493..e481566a 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/EventConsumerApp.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/EventConsumerApp.cs @@ -65,7 +65,8 @@ private static void Main(string[] args) SettingsManager.ConsumerSettings.ApplicationKey, SettingsManager.ConsumerSettings.InstanceId, SettingsManager.ConsumerSettings.UserToken, - SettingsManager.ConsumerSettings.SolutionId); + SettingsManager.ConsumerSettings.SolutionId, + SettingsManager.ConsumerSettings); studentPersonalConsumer.Start("Sif3DemoZone1", "DEFAULT"); if (log.IsInfoEnabled) log.Info("Started the Event Consumer."); diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Sif.Framework.Demo.Au.Consumer.csproj b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Sif.Framework.Demo.Au.Consumer.csproj index 4a259f7c..bbc5195d 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Sif.Framework.Demo.Au.Consumer.csproj +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/Sif.Framework.Demo.Au.Consumer.csproj @@ -59,6 +59,9 @@ + + PreserveNewest + Always @@ -68,16 +71,22 @@ - 2.0.8 + 2.0.12 - 3.2.1.14 + 4.0.0 3.4.7 - 0.1.32.1 + 1.1.0 + + + 1.0.113.7 + + + 11.1.0 diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/SifFrameworkConfig.db b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/SifFrameworkConfig.db new file mode 100644 index 00000000..16c6f2b6 Binary files /dev/null and b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Consumer/SifFrameworkConfig.db differ diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/App_Data/SifFrameworkConfig.db b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/App_Data/SifFrameworkConfig.db new file mode 100644 index 00000000..97702773 Binary files /dev/null and b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/App_Data/SifFrameworkConfig.db differ diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/SchoolInfosProvider.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/SchoolInfosProvider.cs index c8ff5454..0840042f 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/SchoolInfosProvider.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/SchoolInfosProvider.cs @@ -1,12 +1,12 @@ /* - * Copyright 2017 Systemic Pty Ltd - * + * Copyright 2020 Systemic Pty Ltd + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,16 +17,18 @@ using Sif.Framework.Demo.Au.Provider.Models; using Sif.Framework.Demo.Au.Provider.Services; using Sif.Framework.Providers; +using Sif.Framework.Settings; using System.Web.Http; +using Tardigrade.Framework.Configurations; +using Tardigrade.Framework.EntityFramework.Configurations; namespace Sif.Framework.Demo.Au.Provider.Controllers { - public class SchoolInfosProvider : BasicProvider { - - public SchoolInfosProvider() - : base(new SchoolInfoService()) + public SchoolInfosProvider() : base( + new SchoolInfoService(), + new ProviderSettings(new ApplicationConfiguration(new AppSettingsConfigurationSource("name=SettingsDb")))) { } @@ -35,7 +37,5 @@ public override IHttpActionResult BroadcastEvents(string zoneId = null, string c { return base.BroadcastEvents(zoneId, contextId); } - } - } \ No newline at end of file diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/StudentPersonalsProvider.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/StudentPersonalsProvider.cs index 467d79fb..fd41f090 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/StudentPersonalsProvider.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/StudentPersonalsProvider.cs @@ -1,12 +1,12 @@ /* - * Copyright 2017 Systemic Pty Ltd - * + * Copyright 2020 Systemic Pty Ltd + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,22 +17,25 @@ using Sif.Framework.Demo.Au.Provider.Models; using Sif.Framework.Demo.Au.Provider.Services; using Sif.Framework.Providers; +using Sif.Framework.Settings; using Sif.Framework.WebApi.ModelBinders; using System.Web.Http; +using Tardigrade.Framework.Configurations; +using Tardigrade.Framework.EntityFramework.Configurations; namespace Sif.Framework.Demo.Au.Provider.Controllers { - public class StudentPersonalsProvider : BasicProvider { - - public StudentPersonalsProvider() - : base(new StudentPersonalService()) + public StudentPersonalsProvider() : base( + new StudentPersonalService(), + new ProviderSettings(new ApplicationConfiguration(new AppSettingsConfigurationSource("name=SettingsDb")))) { } [Route("~/api/StudentPersonals/StudentPersonal")] - public override IHttpActionResult Post(StudentPersonal obj, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Post(StudentPersonal obj, [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { return base.Post(obj, zoneId, contextId); } @@ -42,7 +45,5 @@ public override IHttpActionResult BroadcastEvents(string zoneId = null, string c { return base.BroadcastEvents(zoneId, contextId); } - } - } \ No newline at end of file diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/StudentSchoolEnrollmentsProvider.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/StudentSchoolEnrollmentsProvider.cs index 6ac33280..e82e6f73 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/StudentSchoolEnrollmentsProvider.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Controllers/StudentSchoolEnrollmentsProvider.cs @@ -1,5 +1,5 @@ /* - * Copyright 2018 Systemic Pty Ltd + * Copyright 2020 Systemic Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,13 +17,18 @@ using Sif.Framework.Demo.Au.Provider.Models; using Sif.Framework.Demo.Au.Provider.Services; using Sif.Framework.Providers; +using Sif.Framework.Settings; using System.Web.Http; +using Tardigrade.Framework.Configurations; +using Tardigrade.Framework.EntityFramework.Configurations; namespace Sif.Framework.Demo.Au.Provider.Controllers { public class StudentSchoolEnrollmentsProvider : BasicProvider { - public StudentSchoolEnrollmentsProvider() : base(new StudentSchoolEnrollmentService()) + public StudentSchoolEnrollmentsProvider() : base( + new StudentSchoolEnrollmentService(), + new ProviderSettings(new ApplicationConfiguration(new AppSettingsConfigurationSource("name=SettingsDb")))) { } diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Global.asax.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Global.asax.cs index 90f54f47..66512983 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Global.asax.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Global.asax.cs @@ -1,15 +1,20 @@ using Sif.Framework.Demo.Au.Provider.Models; +using Sif.Framework.Model.Settings; using Sif.Framework.Service.Registration; using Sif.Framework.Service.Serialisation; +using Sif.Framework.Settings; using Sif.Framework.Utils; using Sif.Framework.WebApi; using Sif.Framework.WebApi.MediaTypeFormatters; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Net.Http.Formatting; using System.Web.Http; using System.Web.Http.ExceptionHandling; using System.Xml.Serialization; +using Tardigrade.Framework.Configurations; +using Tardigrade.Framework.EntityFramework.Configurations; namespace Sif.Framework.Demo.Au.Provider { @@ -21,10 +26,13 @@ protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); + IFrameworkSettings settings = GetSettings(); + // URL Postfix Extension: Update the configuration to recognise postfix extensions and map known // extensions to MIME Types. Additional changes to WebApiConfig.cs are required to fully enable this // feature. - GlobalConfiguration.Configuration.Formatters.JsonFormatter.AddUriPathExtensionMapping("json", "application/json"); + GlobalConfiguration.Configuration.Formatters.JsonFormatter + .AddUriPathExtensionMapping("json", "application/json"); GlobalConfiguration.Configuration.Formatters.XmlFormatter.AddUriPathExtensionMapping("xml", "text/xml"); // XML Serialisation: Define the specific XML serialiser to use to ensure that SIF Data Model Objects (as @@ -34,64 +42,99 @@ protected void Application_Start() // XML Serialisation: For each SIF Data Model Object used by each SIF Provider, the following entries are // required to define the root element for each collection object. - XmlRootAttribute schoolInfosXmlRootAttribute = new XmlRootAttribute("SchoolInfos") { Namespace = SettingsManager.ProviderSettings.DataModelNamespace, IsNullable = false }; - ISerialiser> schoolInfosSerialiser = SerialiserFactory.GetXmlSerialiser>(schoolInfosXmlRootAttribute); + var schoolInfosXmlRootAttribute = new XmlRootAttribute("SchoolInfos") + { Namespace = settings.DataModelNamespace, IsNullable = false }; + ISerialiser> schoolInfosSerialiser = + SerialiserFactory.GetXmlSerialiser>(schoolInfosXmlRootAttribute); xmlFormatter.SetSerializer>((XmlSerializer)schoolInfosSerialiser); - XmlRootAttribute studentPersonalsXmlRootAttribute = new XmlRootAttribute("StudentPersonals") { Namespace = SettingsManager.ProviderSettings.DataModelNamespace, IsNullable = false }; - ISerialiser> studentPersonalsSerialiser = SerialiserFactory.GetXmlSerialiser>(studentPersonalsXmlRootAttribute); + var studentPersonalsXmlRootAttribute = new XmlRootAttribute("StudentPersonals") + { Namespace = settings.DataModelNamespace, IsNullable = false }; + ISerialiser> studentPersonalsSerialiser = + SerialiserFactory.GetXmlSerialiser>(studentPersonalsXmlRootAttribute); xmlFormatter.SetSerializer>((XmlSerializer)studentPersonalsSerialiser); - XmlRootAttribute studentSchoolEnrollmentsXmlRootAttribute = new XmlRootAttribute("StudentSchoolEnrollments") { Namespace = SettingsManager.ProviderSettings.DataModelNamespace, IsNullable = false }; - ISerialiser> studentSchoolEnrollmentsSerialiser = SerialiserFactory.GetXmlSerialiser>(studentSchoolEnrollmentsXmlRootAttribute); - xmlFormatter.SetSerializer>((XmlSerializer)studentSchoolEnrollmentsSerialiser); + var studentSchoolEnrollmentsXmlRootAttribute = new XmlRootAttribute("StudentSchoolEnrollments") + { Namespace = settings.DataModelNamespace, IsNullable = false }; + ISerialiser> studentSchoolEnrollmentsSerialiser = + SerialiserFactory.GetXmlSerialiser>( + studentSchoolEnrollmentsXmlRootAttribute); + xmlFormatter.SetSerializer>( + (XmlSerializer)studentSchoolEnrollmentsSerialiser); // Replacement custom JSON formatter (compliant with Goessner notation). - XmlToJsonFormatter xmlToJsonFormatter = new XmlToJsonFormatter - { - UseXmlSerializer = true - }; + var xmlToJsonFormatter = new XmlToJsonFormatter { UseXmlSerializer = true }; xmlToJsonFormatter.AddUriPathExtensionMapping("json", "application/json"); xmlToJsonFormatter.SetSerializer>((XmlSerializer)schoolInfosSerialiser); xmlToJsonFormatter.SetSerializer>((XmlSerializer)studentPersonalsSerialiser); - xmlToJsonFormatter.SetSerializer>((XmlSerializer)studentSchoolEnrollmentsSerialiser); + xmlToJsonFormatter.SetSerializer>( + (XmlSerializer)studentSchoolEnrollmentsSerialiser); GlobalConfiguration.Configuration.Formatters.Add(xmlToJsonFormatter); - GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.JsonFormatter); + GlobalConfiguration.Configuration.Formatters.Remove( + GlobalConfiguration.Configuration.Formatters.JsonFormatter); // Alternative 1. - //XmlRootAttribute xmlRootAttribute = new XmlRootAttribute("StudentPersonals") { Namespace = SettingsManager.ProviderSettings.DataModelNamespace, IsNullable = false }; - //xmlFormatter.SetSerializer>(new XmlSerializer(typeof(List), xmlRootAttribute)); + //var xmlRootAttribute = new XmlRootAttribute("StudentPersonals") + //{ Namespace = settings.DataModelNamespace, IsNullable = false }; + //xmlFormatter.SetSerializer>( + // new XmlSerializer(typeof(List), xmlRootAttribute)); // Alternative 2. - //XmlAttributes attributes = new XmlAttributes(); - //attributes.XmlRoot = new XmlRootAttribute("StudentPersonals") { Namespace = SettingsManager.ProviderSettings.DataModelNamespace, IsNullable = false }; - //XmlAttributeOverrides overrides = new XmlAttributeOverrides(); + //var attributes = new XmlAttributes(); + //attributes.XmlRoot = new XmlRootAttribute("StudentPersonals") + //{ Namespace = settings.DataModelNamespace, IsNullable = false }; + //var overrides = new XmlAttributeOverrides(); //overrides.Add(typeof(List), attributes); - //xmlFormatter.SetSerializer>(new XmlSerializer(typeof(List), overrides)); + //xmlFormatter + // .SetSerializer>(new XmlSerializer(typeof(List), overrides)); // Configure global exception loggers for unexpected errors. GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger()); // Configure a global exception handler for unexpected errors. - GlobalConfiguration.Configuration.Services.Replace(typeof(IExceptionHandler), new GlobalUnexpectedExceptionHandler()); + GlobalConfiguration.Configuration.Services + .Replace(typeof(IExceptionHandler), new GlobalUnexpectedExceptionHandler()); Trace.TraceInformation("********** Application_Start **********"); - Register(); + Register(settings); } - protected void Application_End(object sender, System.EventArgs e) + protected void Application_End(object sender, EventArgs e) { Trace.TraceInformation("********** Application_End **********"); Unregister(); } + private IFrameworkSettings GetSettings() + { + IFrameworkSettings settings; + string settingsSource = System.Configuration.ConfigurationManager.AppSettings["demo.settingsSource"]; + + if ("Database".Equals(settingsSource, StringComparison.InvariantCultureIgnoreCase)) + { + settings = new ProviderSettings(new ApplicationConfiguration(new AppSettingsConfigurationSource("name=SettingsDb"))); + } + else if ("File".Equals(settingsSource, StringComparison.InvariantCultureIgnoreCase)) + { + settings = SettingsManager.ProviderSettings; + } + else + { + settings = SettingsManager.ProviderSettings; + } + + return settings; + } + /// /// Register this SIF Provider with the EnvironmentProvider based upon settings defined in the SIF 3.0 /// Framework configuration, e.g. SifFramework.config. /// - private void Register() + private void Register(IFrameworkSettings settings) { - registrationService = RegistrationManager.ProviderRegistrationService; + registrationService = RegistrationManager.GetProviderRegistrationService( + settings, + SessionsManager.ProviderSessionService); registrationService.Register(); } diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Sif.Framework.Demo.Au.Provider.csproj b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Sif.Framework.Demo.Au.Provider.csproj index fbab1fb0..99bf0509 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Sif.Framework.Demo.Au.Provider.csproj +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/Sif.Framework.Demo.Au.Provider.csproj @@ -1,5 +1,6 @@  + Debug @@ -50,22 +51,63 @@ ..\packages\Antlr3.Runtime.3.5.1\lib\net40-client\Antlr3.Runtime.dll - - ..\packages\AutoMapper.7.0.1\lib\net45\AutoMapper.dll + + ..\packages\AutoMapper.10.1.1\lib\net461\AutoMapper.dll + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll ..\packages\Iesi.Collections.4.0.4\lib\net461\Iesi.Collections.dll - - ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll - True + + ..\packages\log4net.2.0.12\lib\net45\log4net.dll + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Microsoft.Extensions.Configuration.5.0.0\lib\net461\Microsoft.Extensions.Configuration.dll + + + ..\packages\Microsoft.Extensions.Configuration.Abstractions.5.0.0\lib\net461\Microsoft.Extensions.Configuration.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Configuration.EnvironmentVariables.5.0.0\lib\net461\Microsoft.Extensions.Configuration.EnvironmentVariables.dll + + + ..\packages\Microsoft.Extensions.Configuration.FileExtensions.5.0.0\lib\net461\Microsoft.Extensions.Configuration.FileExtensions.dll + + + ..\packages\Microsoft.Extensions.Configuration.Json.5.0.0\lib\net461\Microsoft.Extensions.Configuration.Json.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.5.0.1\lib\net461\Microsoft.Extensions.DependencyInjection.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.5.0.0\lib\net461\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + ..\packages\Microsoft.Extensions.FileProviders.Abstractions.5.0.0\lib\net461\Microsoft.Extensions.FileProviders.Abstractions.dll - - ..\packages\NHibernate.5.1.3\lib\net461\NHibernate.dll + + ..\packages\Microsoft.Extensions.FileProviders.Physical.5.0.0\lib\net461\Microsoft.Extensions.FileProviders.Physical.dll + + + ..\packages\Microsoft.Extensions.FileSystemGlobbing.5.0.0\lib\net461\Microsoft.Extensions.FileSystemGlobbing.dll + + + ..\packages\Microsoft.Extensions.Primitives.5.0.0\lib\net461\Microsoft.Extensions.Primitives.dll + + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\NHibernate.5.3.5\lib\net461\NHibernate.dll ..\packages\Remotion.Linq.2.2.0\lib\net45\Remotion.Linq.dll @@ -73,8 +115,8 @@ ..\packages\Remotion.Linq.EagerFetching.2.2.0\lib\net45\Remotion.Linq.EagerFetching.dll - - ..\packages\Sif.Framework.3.2.1.14\lib\net461\Sif.Framework.dll + + ..\packages\Sif.Framework.4.0.0\lib\net461\Sif.Framework.dll ..\packages\Sif.Specification.DataModel.Au.3.4.7\lib\netstandard2.0\Sif.Specification.DataModel.Au.dll @@ -82,24 +124,82 @@ ..\packages\Sif.Specification.Infrastructure.3.2.1\lib\netstandard2.0\Sif.Specification.Infrastructure.dll - - ..\packages\slf4net.0.1.32.1\lib\net35\slf4net.dll - True + + ..\packages\slf4net.1.1.0\lib\net40\slf4net.dll - - ..\packages\slf4net.log4net.0.1.32.1\lib\net35\slf4net.log4net.dll - True + + ..\packages\slf4net.log4net.1.1.0\lib\net40\slf4net.log4net.dll + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll + + + ..\packages\System.Configuration.ConfigurationManager.5.0.0\lib\net461\System.Configuration.ConfigurationManager.dll - - ..\packages\System.Data.SQLite.Core.1.0.109.2\lib\net46\System.Data.SQLite.dll + + + ..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\lib\net46\System.Data.SQLite.dll + + + ..\packages\System.Data.SQLite.EF6.1.0.113.0\lib\net46\System.Data.SQLite.EF6.dll + + + ..\packages\System.Data.SQLite.Linq.1.0.113.0\lib\net46\System.Data.SQLite.Linq.dll + + ..\packages\System.Linq.Dynamic.Core.1.2.7\lib\net46\System.Linq.Dynamic.Core.dll + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Security.AccessControl.5.0.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net461\System.Security.Cryptography.Algorithms.dll + True + True + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + True + + + ..\packages\System.Security.Permissions.5.0.0\lib\net461\System.Security.Permissions.dll + + + ..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + + + ..\packages\System.Text.Encodings.Web.5.0.0\lib\net461\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.5.0.0\lib\net461\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + ..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll @@ -113,17 +213,24 @@ - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.6\lib\net45\System.Web.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll - - ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.6\lib\net45\System.Web.Http.WebHost.dll + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll + + ..\packages\Tardigrade.Framework.11.1.0\lib\net461\Tardigrade.Framework.dll + + + ..\packages\Tardigrade.Framework.EntityFramework.11.1.0\lib\net461\Tardigrade.Framework.EntityFramework.dll + + @@ -158,6 +265,9 @@ Always + + PreserveNewest + Designer PreserveNewest @@ -169,9 +279,7 @@ Web.config - - - + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) @@ -197,13 +305,16 @@ - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + @@ -243,27 +267,27 @@ - + - + - + - + - + - + @@ -273,6 +297,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/packages.config b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/packages.config index c598f659..708cf718 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/packages.config +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Au.Provider/packages.config @@ -1,22 +1,56 @@  - + + - - - - - - - + + + + + + + + + + + + + + + + + + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/EventsProvider.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/EventsProvider.cs index a2f426f8..ba9e7aa2 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/EventsProvider.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/EventsProvider.cs @@ -1,5 +1,5 @@ /* - * Copyright 2018 Systemic Pty Ltd + * Copyright 2020 Systemic Pty Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,39 +31,43 @@ namespace Sif.Framework.Demo.Broker.Controllers { public class EventsProvider : BasicProvider { - private static readonly slf4net.ILogger log = slf4net.LoggerFactory.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + private readonly slf4net.ILogger log = + slf4net.LoggerFactory.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public EventsProvider() : base(new StudentPersonalService()) + public EventsProvider() : base(new StudentPersonalService(), SettingsManager.ProviderSettings) { } [Route("~/api/Events/Event")] - public override IHttpActionResult Post(StudentPersonal obj, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Post( + StudentPersonal obj, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { return base.Post(obj, zoneId, contextId); } - public override IHttpActionResult Post(List objs, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Post( + List objs, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { foreach (KeyValuePair> nameValues in Request.Headers) { - if (log.IsDebugEnabled) log.Debug($"*** Header field is [{nameValues.Key}:{string.Join(",", nameValues.Value)}]"); + if (log.IsDebugEnabled) + log.Debug($"*** Header field is [{nameValues.Key}:{string.Join(",", nameValues.Value)}]"); } - //return base.Post(objs, zoneId, contextId); - string sessionToken; - - if (!authenticationService.VerifyAuthenticationHeader(Request.Headers, out sessionToken)) + if (!AuthenticationService.VerifyAuthenticationHeader(Request.Headers, out string _)) { return Unauthorized(); } if ((zoneId != null && zoneId.Length != 1) || (contextId != null && contextId.Length != 1)) { - return BadRequest("Request failed for object " + typeof(StudentPersonal).Name + " as Zone and/or Context are invalid."); + return BadRequest($"Request failed for object {TypeName} as Zone and/or Context are invalid."); } - IHttpActionResult result; ICollection createStatuses = new List(); try @@ -73,53 +77,73 @@ public override IHttpActionResult Post(List objs, [MatrixParame foreach (StudentPersonal obj in objs) { bool hasAdvisoryId = !string.IsNullOrWhiteSpace(obj.RefId); - createType status = new createType(); - status.advisoryId = (hasAdvisoryId ? obj.RefId : null); + var status = new createType { advisoryId = (hasAdvisoryId ? obj.RefId : null) }; try { - if (mustUseAdvisory.HasValue && mustUseAdvisory.Value == true) + if (mustUseAdvisory.HasValue) { - if (hasAdvisoryId) + if (mustUseAdvisory.Value && !hasAdvisoryId) { - status.id = service.Create(obj, mustUseAdvisory, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])).RefId; - status.statusCode = ((int)HttpStatusCode.Created).ToString(); + status.error = ProviderUtils.CreateError( + HttpStatusCode.BadRequest, + TypeName, + "Create request failed as object ID is not provided, but mustUseAdvisory is true."); + status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } else { - status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(StudentPersonal).Name, "Create request failed as object ID is not provided, but mustUseAdvisory is true."); - status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); + status.id = Service.Create(obj, mustUseAdvisory, zoneId?[0], contextId?[0]).RefId; + status.statusCode = ((int)HttpStatusCode.Created).ToString(); } } else { - status.id = service.Create(obj, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])).RefId; + status.id = Service.Create(obj, null, zoneId?[0], contextId?[0]).RefId; status.statusCode = ((int)HttpStatusCode.Created).ToString(); } } catch (AlreadyExistsException e) { - status.error = ProviderUtils.CreateError(HttpStatusCode.Conflict, typeof(StudentPersonal).Name, "Object " + typeof(StudentPersonal).Name + " with ID of " + obj.RefId + " already exists.\n" + e.Message); + status.error = ProviderUtils.CreateError( + HttpStatusCode.Conflict, + TypeName, + $"Object {TypeName} with ID of {obj.RefId} already exists.\n{e.Message}"); status.statusCode = ((int)HttpStatusCode.Conflict).ToString(); } catch (ArgumentException e) { - status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(StudentPersonal).Name, "Object to create of type " + typeof(StudentPersonal).Name + (hasAdvisoryId ? " with ID of " + obj.RefId : "") + " is invalid.\n " + e.Message); + status.error = ProviderUtils.CreateError( + HttpStatusCode.BadRequest, + TypeName, + $"Object to create of type {TypeName}" + + (hasAdvisoryId ? $" with ID of {obj.RefId}" : "") + $" is invalid.\n{e.Message}"); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } catch (CreateException e) { - status.error = ProviderUtils.CreateError(HttpStatusCode.BadRequest, typeof(StudentPersonal).Name, "Request failed for object " + typeof(StudentPersonal).Name + (hasAdvisoryId ? " with ID of " + obj.RefId : "") + ".\n " + e.Message); + status.error = ProviderUtils.CreateError( + HttpStatusCode.BadRequest, + TypeName, + $"Request failed for object {TypeName}" + + (hasAdvisoryId ? $" with ID of {obj.RefId}" : "") + $".\n{e.Message}"); status.statusCode = ((int)HttpStatusCode.BadRequest).ToString(); } catch (RejectedException e) { - status.error = ProviderUtils.CreateError(HttpStatusCode.NotFound, typeof(StudentPersonal).Name, "Create request rejected for object " + typeof(StudentPersonal).Name + " with ID of " + obj.RefId + ".\n" + e.Message); + status.error = ProviderUtils.CreateError( + HttpStatusCode.NotFound, + TypeName, + $"Create request rejected for object {TypeName} with ID of {obj.RefId}.\n{e.Message}"); status.statusCode = ((int)HttpStatusCode.Conflict).ToString(); } catch (Exception e) { - status.error = ProviderUtils.CreateError(HttpStatusCode.InternalServerError, typeof(StudentPersonal).Name, "Request failed for object " + typeof(StudentPersonal).Name + (hasAdvisoryId ? " with ID of " + obj.RefId : "") + ".\n " + e.Message); + status.error = ProviderUtils.CreateError( + HttpStatusCode.InternalServerError, + TypeName, + $"Request failed for object {TypeName}" + + (hasAdvisoryId ? $" with ID of {obj.RefId}" : "") + $".\n{e.Message}"); status.statusCode = ((int)HttpStatusCode.InternalServerError).ToString(); } @@ -131,10 +155,9 @@ public override IHttpActionResult Post(List objs, [MatrixParame // Need to ignore exceptions otherwise it would not be possible to return status records of processed objects. } - createResponseType createResponse = new createResponseType { creates = createStatuses.ToArray() }; - result = Ok(createResponse); + var createResponse = new createResponseType { creates = createStatuses.ToArray() }; - return result; + return Ok(createResponse); } } } \ No newline at end of file diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/QueuesProvider.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/QueuesProvider.cs index c149b0a4..a38f47a6 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/QueuesProvider.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/QueuesProvider.cs @@ -1,12 +1,12 @@ /* - * Copyright 2018 Systemic Pty Ltd - * + * Copyright 2020 Systemic Pty Ltd + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,7 +19,6 @@ using Sif.Framework.Demo.Broker.Utils; using Sif.Framework.Model.Exceptions; using Sif.Framework.Providers; -using Sif.Framework.Service.Providers; using Sif.Framework.Utils; using Sif.Framework.WebApi.ActionResults; using Sif.Framework.WebApi.ModelBinders; @@ -32,19 +31,15 @@ namespace Sif.Framework.Demo.Broker.Controllers { - public class QueuesProvider : BasicProvider { - private static int availableMessageBatches = 5; - private static string[] eventActionType = { "CREATE", "DELETE", "UPDATE" }; - private static Random random = new Random(); - private static string[] replacementType = { "FULL", "PARTIAL" }; + private static readonly string[] EventActionType = { "CREATE", "DELETE", "UPDATE" }; + private static readonly Random Random = new Random(); + private static readonly string[] ReplacementType = { "FULL", "PARTIAL" }; - public QueuesProvider() : this(new QueueService()) - { - } + private static int availableMessageBatches = 5; - protected QueuesProvider(IBasicProviderService service) : base(service) + public QueuesProvider() : base(new QueueService(), SettingsManager.ProviderSettings) { } @@ -57,31 +52,33 @@ public override IHttpActionResult BroadcastEvents(string zoneId = null, string c /// /// Add a custom header to an action result and return it. /// - /// Action result. + /// Action result. /// Name of the header. /// Value associated with the header. /// Action result with a custom header. - private IHttpActionResult CreateCustomActionResult(IHttpActionResult result, string headerName, string headerValue) + private static IHttpActionResult CreateCustomActionResult( + IHttpActionResult result, + string headerName, + string headerValue) { return new CustomHeaderResult(result, headerName, new[] { headerValue }); } private static StudentPersonal CreateStudent() { - - NameOfRecordType name = new NameOfRecordType + var name = new NameOfRecordType { Type = NameOfRecordTypeType.LGL, FamilyName = RandomNameGenerator.FamilyName, GivenName = RandomNameGenerator.GivenName }; - PersonInfoType personInfo = new PersonInfoType { Name = name }; + var personInfo = new PersonInfoType { Name = name }; - StudentPersonal studentPersonal = new StudentPersonal + var studentPersonal = new StudentPersonal { RefId = Guid.NewGuid().ToString(), - LocalId = random.Next(10000, 99999).ToString(), + LocalId = Random.Next(10000, 99999).ToString(), PersonInfo = personInfo }; @@ -90,9 +87,9 @@ private static StudentPersonal CreateStudent() private static List CreateStudents(int count) { - List students = new List(); + var students = new List(); - for (int i = 0; i < count; i++) + for (var i = 0; i < count; i++) { StudentPersonal studentPersonal = CreateStudent(); students.Add(studentPersonal); @@ -101,12 +98,23 @@ private static List CreateStudents(int count) return students; } - public override IHttpActionResult Delete(deleteRequestType deleteRequest, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Delete( + deleteRequestType deleteRequest, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { return StatusCode(HttpStatusCode.MethodNotAllowed); } - public override IHttpActionResult Get(string object1, [FromUri(Name = "id1")] string refId1, string object2 = null, [FromUri(Name = "id2")] string refId2 = null, string object3 = null, [FromUri(Name = "id3")] string refId3 = null, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Get( + string object1, + [FromUri(Name = "id1")] string refId1, + string object2 = null, + [FromUri(Name = "id2")] string refId2 = null, + string object3 = null, + [FromUri(Name = "id3")] string refId3 = null, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { return StatusCode(HttpStatusCode.MethodNotAllowed); } @@ -114,23 +122,22 @@ public override IHttpActionResult Get(string object1, [FromUri(Name = "id1")] st [Route("~/api/Queues/{queueId}/messages")] public IHttpActionResult Get(string queueId) { - if (availableMessageBatches == 0) { return StatusCode(HttpStatusCode.NoContent); } availableMessageBatches--; - List students = CreateStudents(random.Next(1, 5)); + List students = CreateStudents(Random.Next(1, 5)); IHttpActionResult result = Ok(students); - string eventActionValue = eventActionType[random.Next(eventActionType.Length)]; + string eventActionValue = EventActionType[Random.Next(EventActionType.Length)]; result = CreateCustomActionResult(result, "eventAction", eventActionValue); result = CreateCustomActionResult(result, "messageId", Guid.NewGuid().ToString()); result = CreateCustomActionResult(result, "minWaitTime", "10"); if ("UPDATE".Equals(eventActionValue)) { - string replacementValue = replacementType[random.Next(replacementType.Length)]; + string replacementValue = ReplacementType[Random.Next(ReplacementType.Length)]; result = CreateCustomActionResult(result, "Replacement", replacementValue); } @@ -140,34 +147,34 @@ public IHttpActionResult Get(string queueId) [Route("~/api/Queues/{queueId}/messages;deleteMessageId={deleteMessageId}")] public IHttpActionResult Get(string queueId, string deleteMessageId) { - if (availableMessageBatches == 0) { return StatusCode(HttpStatusCode.NoContent); } availableMessageBatches--; - List students = CreateStudents(random.Next(1, 5)); + List students = CreateStudents(Random.Next(1, 5)); IHttpActionResult result = Ok(students); - string eventActionValue = eventActionType[random.Next(eventActionType.Length)]; + string eventActionValue = EventActionType[Random.Next(EventActionType.Length)]; result = CreateCustomActionResult(result, "eventAction", eventActionValue); result = CreateCustomActionResult(result, "messageId", Guid.NewGuid().ToString()); result = CreateCustomActionResult(result, "minWaitTime", "10"); if ("UPDATE".Equals(eventActionValue)) { - string replacementValue = replacementType[random.Next(replacementType.Length)]; + string replacementValue = ReplacementType[Random.Next(ReplacementType.Length)]; result = CreateCustomActionResult(result, "Replacement", replacementValue); } return result; } - public override IHttpActionResult Get([FromUri(Name = "id")] string refId, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Get( + [FromUri(Name = "id")] string refId, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { - string sessionToken; - - if (!authenticationService.VerifyAuthenticationHeader(Request.Headers, out sessionToken)) + if (!AuthenticationService.VerifyAuthenticationHeader(Request.Headers, out string _)) { return Unauthorized(); } @@ -179,14 +186,14 @@ public override IHttpActionResult Get([FromUri(Name = "id")] string refId, [Matr if ((zoneId != null && zoneId.Length != 1) || (contextId != null && contextId.Length != 1)) { - return BadRequest("Request failed for object " + typeof(Queue).Name + " as Zone and/or Context are invalid."); + return BadRequest($"Request failed for object {TypeName} as Zone and/or Context are invalid."); } IHttpActionResult result; try { - Queue obj = service.Retrieve(refId, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])); + Queue obj = Service.Retrieve(refId, zoneId?[0], contextId?[0]); if (obj == null) { @@ -196,15 +203,14 @@ public override IHttpActionResult Get([FromUri(Name = "id")] string refId, [Matr { result = Ok(obj); } - } catch (ArgumentException e) { - result = BadRequest("Invalid argument: id=" + refId + ".\n" + e.Message); + result = BadRequest($"Invalid argument: id={refId}.\n{e.Message}"); } catch (QueryException e) { - result = BadRequest("Request failed for object " + typeof(Queue).Name + " with ID of " + refId + ".\n " + e.Message); + result = BadRequest($"Request failed for object {TypeName} with ID of {refId}.\n{e.Message}"); } catch (Exception e) { @@ -214,29 +220,35 @@ public override IHttpActionResult Get([FromUri(Name = "id")] string refId, [Matr return result; } - public override IHttpActionResult Head([MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Head( + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { return StatusCode(HttpStatusCode.MethodNotAllowed); } [NonAction] - public override IHttpActionResult Post(List objs, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Post( + List objs, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { return StatusCode(HttpStatusCode.MethodNotAllowed); } - public override IHttpActionResult Post(Queue obj, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Post( + Queue obj, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { - string sessionToken; - - if (!authenticationService.VerifyAuthenticationHeader(Request.Headers, out sessionToken)) + if (!AuthenticationService.VerifyAuthenticationHeader(Request.Headers, out string _)) { return Unauthorized(); } if ((zoneId != null && zoneId.Length != 1) || (contextId != null && contextId.Length != 1)) { - return BadRequest("Request failed for object " + typeof(Queue).Name + " as Zone and/or Context are invalid."); + return BadRequest($"Request failed for object {TypeName} as Zone and/or Context are invalid."); } IHttpActionResult result; @@ -246,28 +258,27 @@ public override IHttpActionResult Post(Queue obj, [MatrixParameter] string[] zon bool hasAdvisoryId = !string.IsNullOrWhiteSpace(obj.RefId); bool? mustUseAdvisory = HttpUtils.GetMustUseAdvisory(Request.Headers); - if (mustUseAdvisory.HasValue && mustUseAdvisory.Value == true) + if (mustUseAdvisory.HasValue) { - - if (hasAdvisoryId) + if (mustUseAdvisory.Value && !hasAdvisoryId) { - Queue createdObject = service.Create(obj, mustUseAdvisory, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])); - string uri = Url.Link("DefaultApi", new { controller = TypeName, id = createdObject.RefId }); - result = Created(uri, createdObject); + result = BadRequest( + $"Request failed for object {TypeName} as object ID is not provided, but mustUseAdvisory is true."); } else { - result = BadRequest($"Request failed for object {TypeName} as object ID is not provided, but mustUseAdvisory is true."); + Queue createdObject = Service.Create(obj, mustUseAdvisory, zoneId?[0], contextId?[0]); + string uri = Url.Link("DefaultApi", new { controller = TypeName, id = createdObject.RefId }); + result = Created(uri, createdObject); } - } else { - Queue createdObject = service.Create(obj, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])); - string uri = Url.Link("DefaultApi", new { controller = typeof(Queue).Name, id = createdObject.RefId }); + Queue createdObject = Service.Create(obj, null, zoneId?[0], contextId?[0]); + string uri = + Url.Link("DefaultApi", new { controller = TypeName, id = createdObject.RefId }); result = Created(uri, createdObject); } - } catch (AlreadyExistsException) { @@ -275,11 +286,11 @@ public override IHttpActionResult Post(Queue obj, [MatrixParameter] string[] zon } catch (ArgumentException e) { - result = BadRequest("Object to create of type " + typeof(Queue).Name + " is invalid.\n " + e.Message); + result = BadRequest($"Object to create of type {TypeName} is invalid.\n{e.Message}"); } catch (CreateException e) { - result = BadRequest("Request failed for object " + typeof(Queue).Name + ".\n " + e.Message); + result = BadRequest($"Request failed for object {TypeName}.\n{e.Message}"); } catch (RejectedException) { @@ -287,7 +298,7 @@ public override IHttpActionResult Post(Queue obj, [MatrixParameter] string[] zon } catch (QueryException e) { - result = BadRequest("Request failed for object " + typeof(Queue).Name + ".\n " + e.Message); + result = BadRequest($"Request failed for object {TypeName}.\n{e.Message}"); } catch (Exception e) { @@ -297,16 +308,21 @@ public override IHttpActionResult Post(Queue obj, [MatrixParameter] string[] zon return result; } - public override IHttpActionResult Put(List objs, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Put( + List objs, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { return StatusCode(HttpStatusCode.MethodNotAllowed); } - public override IHttpActionResult Put([FromUri(Name = "id")] string refId, Queue obj, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Put( + [FromUri(Name = "id")] string refId, + Queue obj, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { return StatusCode(HttpStatusCode.MethodNotAllowed); } - } - } \ No newline at end of file diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/SubscriptionsProvider.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/SubscriptionsProvider.cs index a45e90de..1ebe05c6 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/SubscriptionsProvider.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Controllers/SubscriptionsProvider.cs @@ -1,12 +1,12 @@ /* - * Copyright 2018 Systemic Pty Ltd - * + * Copyright 2020 Systemic Pty Ltd + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,7 +18,6 @@ using Sif.Framework.Demo.Broker.Services; using Sif.Framework.Model.Exceptions; using Sif.Framework.Providers; -using Sif.Framework.Service.Providers; using Sif.Framework.Utils; using Sif.Framework.WebApi.ModelBinders; using System; @@ -28,15 +27,9 @@ namespace Sif.Framework.Demo.Broker.Controllers { - public class SubscriptionsProvider : BasicProvider { - - protected SubscriptionsProvider() : base(new SubscriptionService()) - { - } - - protected SubscriptionsProvider(IBasicProviderService service) : base(service) + public SubscriptionsProvider() : base(new SubscriptionService(), SettingsManager.ProviderSettings) { } @@ -46,11 +39,12 @@ public override IHttpActionResult BroadcastEvents(string zoneId = null, string c return base.BroadcastEvents(zoneId, contextId); } - public override IHttpActionResult Get([FromUri(Name = "id")] string refId, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Get( + [FromUri(Name = "id")] string refId, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { - string sessionToken; - - if (!authenticationService.VerifyAuthenticationHeader(Request.Headers, out sessionToken)) + if (!AuthenticationService.VerifyAuthenticationHeader(Request.Headers, out string _)) { return Unauthorized(); } @@ -62,14 +56,14 @@ public override IHttpActionResult Get([FromUri(Name = "id")] string refId, [Matr if ((zoneId != null && zoneId.Length != 1) || (contextId != null && contextId.Length != 1)) { - return BadRequest("Request failed for object " + typeof(Subscription).Name + " as Zone and/or Context are invalid."); + return BadRequest($"Request failed for object {TypeName} as Zone and/or Context are invalid."); } IHttpActionResult result; try { - Subscription obj = service.Retrieve(refId, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])); + Subscription obj = Service.Retrieve(refId, zoneId?[0], contextId?[0]); if (obj == null) { @@ -79,15 +73,14 @@ public override IHttpActionResult Get([FromUri(Name = "id")] string refId, [Matr { result = Ok(obj); } - } catch (ArgumentException e) { - result = BadRequest("Invalid argument: id=" + refId + ".\n" + e.Message); + result = BadRequest($"Invalid argument: id={refId}.\n{e.Message}"); } catch (QueryException e) { - result = BadRequest("Request failed for object " + typeof(Subscription).Name + " with ID of " + refId + ".\n " + e.Message); + result = BadRequest($"Request failed for object {TypeName} with ID of {refId}.\n{e.Message}"); } catch (Exception e) { @@ -98,23 +91,27 @@ public override IHttpActionResult Get([FromUri(Name = "id")] string refId, [Matr } [NonAction] - public override IHttpActionResult Post(List objs, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Post( + List objs, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { return base.Post(objs, zoneId, contextId); } - public override IHttpActionResult Post(Subscription obj, [MatrixParameter] string[] zoneId = null, [MatrixParameter] string[] contextId = null) + public override IHttpActionResult Post( + Subscription obj, + [MatrixParameter] string[] zoneId = null, + [MatrixParameter] string[] contextId = null) { - string sessionToken; - - if (!authenticationService.VerifyAuthenticationHeader(Request.Headers, out sessionToken)) + if (!AuthenticationService.VerifyAuthenticationHeader(Request.Headers, out string _)) { return Unauthorized(); } if ((zoneId != null && zoneId.Length != 1) || (contextId != null && contextId.Length != 1)) { - return BadRequest("Request failed for object " + typeof(Subscription).Name + " as Zone and/or Context are invalid."); + return BadRequest($"Request failed for object {TypeName} as Zone and/or Context are invalid."); } IHttpActionResult result; @@ -124,28 +121,26 @@ public override IHttpActionResult Post(Subscription obj, [MatrixParameter] strin bool hasAdvisoryId = !string.IsNullOrWhiteSpace(obj.RefId); bool? mustUseAdvisory = HttpUtils.GetMustUseAdvisory(Request.Headers); - if (mustUseAdvisory.HasValue && mustUseAdvisory.Value == true) + if (mustUseAdvisory.HasValue) { - - if (hasAdvisoryId) + if (mustUseAdvisory.Value && !hasAdvisoryId) { - Subscription createdObject = service.Create(obj, mustUseAdvisory, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])); - string uri = Url.Link("DefaultApi", new { controller = TypeName, id = createdObject.RefId }); - result = Created(uri, createdObject); + result = BadRequest( + $"Request failed for object {TypeName} as object ID is not provided, but mustUseAdvisory is true."); } else { - result = BadRequest($"Request failed for object {TypeName} as object ID is not provided, but mustUseAdvisory is true."); + Subscription createdObject = Service.Create(obj, mustUseAdvisory, zoneId?[0], contextId?[0]); + string uri = Url.Link("DefaultApi", new { controller = TypeName, id = createdObject.RefId }); + result = Created(uri, createdObject); } - } else { - Subscription createdObject = service.Create(obj, zoneId: (zoneId == null ? null : zoneId[0]), contextId: (contextId == null ? null : contextId[0])); - string uri = Url.Link("DefaultApi", new { controller = typeof(Subscription).Name, id = createdObject.RefId }); + Subscription createdObject = Service.Create(obj, null, zoneId?[0], contextId?[0]); + string uri = Url.Link("DefaultApi", new { controller = TypeName, id = createdObject.RefId }); result = Created(uri, createdObject); } - } catch (AlreadyExistsException) { @@ -153,11 +148,11 @@ public override IHttpActionResult Post(Subscription obj, [MatrixParameter] strin } catch (ArgumentException e) { - result = BadRequest("Object to create of type " + typeof(Subscription).Name + " is invalid.\n " + e.Message); + result = BadRequest($"Object to create of type {TypeName} is invalid.\n{e.Message}"); } catch (CreateException e) { - result = BadRequest("Request failed for object " + typeof(Subscription).Name + ".\n " + e.Message); + result = BadRequest($"Request failed for object {TypeName}.\n{e.Message}"); } catch (RejectedException) { @@ -165,7 +160,7 @@ public override IHttpActionResult Post(Subscription obj, [MatrixParameter] strin } catch (QueryException e) { - result = BadRequest("Request failed for object " + typeof(Subscription).Name + ".\n " + e.Message); + result = BadRequest($"Request failed for object {TypeName}.\n{e.Message}"); } catch (Exception e) { @@ -174,7 +169,5 @@ public override IHttpActionResult Post(Subscription obj, [MatrixParameter] strin return result; } - } - } \ No newline at end of file diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Global.asax.cs b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Global.asax.cs index af3b0b52..70e46d0a 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Global.asax.cs +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Global.asax.cs @@ -24,7 +24,8 @@ protected void Application_Start() // URL Postfix Extension: Update the configuration to recognise postfix extensions and map known // extensions to MIME Types. Additional changes to WebApiConfig.cs are required to fully enable this // feature. - GlobalConfiguration.Configuration.Formatters.JsonFormatter.AddUriPathExtensionMapping("json", "application/json"); + GlobalConfiguration.Configuration.Formatters.JsonFormatter + .AddUriPathExtensionMapping("json", "application/json"); GlobalConfiguration.Configuration.Formatters.XmlFormatter.AddUriPathExtensionMapping("xml", "text/xml"); // XML Serialisation: Define the specific XML serialiser to use to ensure that SIF Data Model Objects (as @@ -34,35 +35,40 @@ protected void Application_Start() // XML Serialisation: For each SIF Data Model Object used by each SIF Provider, the following entries are // required to define the root element for each collection object. - XmlRootAttribute queuesXmlRootAttribute = new XmlRootAttribute("Queues") { Namespace = SettingsManager.ProviderSettings.InfrastructureNamespace, IsNullable = false }; - ISerialiser> queuesSerialiser = SerialiserFactory.GetXmlSerialiser>(queuesXmlRootAttribute); + var queuesXmlRootAttribute = new XmlRootAttribute("Queues") + { Namespace = SettingsManager.ProviderSettings.InfrastructureNamespace, IsNullable = false }; + ISerialiser> queuesSerialiser = + SerialiserFactory.GetXmlSerialiser>(queuesXmlRootAttribute); formatter.SetSerializer>((XmlSerializer)queuesSerialiser); - XmlRootAttribute subscriptionsXmlRootAttribute = new XmlRootAttribute("Subscriptions") { Namespace = SettingsManager.ProviderSettings.InfrastructureNamespace, IsNullable = false }; - ISerialiser> subscriptionsSerialiser = SerialiserFactory.GetXmlSerialiser>(subscriptionsXmlRootAttribute); + var subscriptionsXmlRootAttribute = new XmlRootAttribute("Subscriptions") + { Namespace = SettingsManager.ProviderSettings.InfrastructureNamespace, IsNullable = false }; + ISerialiser> subscriptionsSerialiser = + SerialiserFactory.GetXmlSerialiser>(subscriptionsXmlRootAttribute); formatter.SetSerializer>((XmlSerializer)subscriptionsSerialiser); - XmlRootAttribute studentPersonalsXmlRootAttribute = new XmlRootAttribute("StudentPersonals") { Namespace = SettingsManager.ProviderSettings.DataModelNamespace, IsNullable = false }; - ISerialiser> studentPersonalsSerialiser = SerialiserFactory.GetXmlSerialiser>(studentPersonalsXmlRootAttribute); + var studentPersonalsXmlRootAttribute = new XmlRootAttribute("StudentPersonals") + { Namespace = SettingsManager.ProviderSettings.DataModelNamespace, IsNullable = false }; + ISerialiser> studentPersonalsSerialiser = + SerialiserFactory.GetXmlSerialiser>(studentPersonalsXmlRootAttribute); formatter.SetSerializer>((XmlSerializer)studentPersonalsSerialiser); // Replacement custom JSON formatter (compliant with Goessner notation). - XmlToJsonFormatter xmlToJsonFormatter = new XmlToJsonFormatter - { - UseXmlSerializer = true - }; + var xmlToJsonFormatter = new XmlToJsonFormatter { UseXmlSerializer = true }; xmlToJsonFormatter.AddUriPathExtensionMapping("json", "application/json"); xmlToJsonFormatter.SetSerializer>((XmlSerializer)queuesSerialiser); xmlToJsonFormatter.SetSerializer>((XmlSerializer)subscriptionsSerialiser); xmlToJsonFormatter.SetSerializer>((XmlSerializer)studentPersonalsSerialiser); GlobalConfiguration.Configuration.Formatters.Add(xmlToJsonFormatter); - GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.JsonFormatter); + GlobalConfiguration.Configuration.Formatters + .Remove(GlobalConfiguration.Configuration.Formatters.JsonFormatter); // Configure global exception loggers for unexpected errors. GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new TraceExceptionLogger()); // Configure a global exception handler for unexpected errors. - GlobalConfiguration.Configuration.Services.Replace(typeof(IExceptionHandler), new GlobalUnexpectedExceptionHandler()); + GlobalConfiguration.Configuration.Services.Replace(typeof(IExceptionHandler), + new GlobalUnexpectedExceptionHandler()); Trace.TraceInformation("********** Application_Start **********"); Register(); @@ -80,7 +86,9 @@ protected void Application_End(object sender, System.EventArgs e) /// private void Register() { - registrationService = RegistrationManager.ProviderRegistrationService; + registrationService = RegistrationManager.GetProviderRegistrationService( + SettingsManager.ProviderSettings, + SessionsManager.ProviderSessionService); registrationService.Register(); } diff --git a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Sif.Framework.Demo.Broker.csproj b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Sif.Framework.Demo.Broker.csproj index 09870bd2..7b2cc21f 100644 --- a/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Sif.Framework.Demo.Broker.csproj +++ b/Code/Sif3FrameworkDemo/Sif.Framework.Demo.Broker/Sif.Framework.Demo.Broker.csproj @@ -1,7 +1,6 @@  - - + Debug @@ -48,25 +47,60 @@ ..\packages\Antlr3.Runtime.3.5.1\lib\net40-client\Antlr3.Runtime.dll - - ..\packages\AutoMapper.7.0.1\lib\net45\AutoMapper.dll + + ..\packages\AutoMapper.10.1.1\lib\net461\AutoMapper.dll ..\packages\Iesi.Collections.4.0.4\lib\net461\Iesi.Collections.dll - - ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll - True + + ..\packages\log4net.2.0.12\lib\net45\log4net.dll + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll - - ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.3.6.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Microsoft.Extensions.Configuration.5.0.0\lib\net461\Microsoft.Extensions.Configuration.dll + + + ..\packages\Microsoft.Extensions.Configuration.Abstractions.5.0.0\lib\net461\Microsoft.Extensions.Configuration.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Configuration.EnvironmentVariables.5.0.0\lib\net461\Microsoft.Extensions.Configuration.EnvironmentVariables.dll + + + ..\packages\Microsoft.Extensions.Configuration.FileExtensions.5.0.0\lib\net461\Microsoft.Extensions.Configuration.FileExtensions.dll + + + ..\packages\Microsoft.Extensions.Configuration.Json.5.0.0\lib\net461\Microsoft.Extensions.Configuration.Json.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.5.0.0\lib\net461\Microsoft.Extensions.DependencyInjection.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.5.0.0\lib\net461\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + ..\packages\Microsoft.Extensions.FileProviders.Abstractions.5.0.0\lib\net461\Microsoft.Extensions.FileProviders.Abstractions.dll - - ..\packages\NHibernate.5.1.3\lib\net461\NHibernate.dll + + ..\packages\Microsoft.Extensions.FileProviders.Physical.5.0.0\lib\net461\Microsoft.Extensions.FileProviders.Physical.dll + + + ..\packages\Microsoft.Extensions.FileSystemGlobbing.5.0.0\lib\net461\Microsoft.Extensions.FileSystemGlobbing.dll + + + ..\packages\Microsoft.Extensions.Primitives.5.0.0\lib\net461\Microsoft.Extensions.Primitives.dll + + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\NHibernate.5.3.5\lib\net461\NHibernate.dll ..\packages\Remotion.Linq.2.2.0\lib\net45\Remotion.Linq.dll @@ -74,8 +108,8 @@ ..\packages\Remotion.Linq.EagerFetching.2.2.0\lib\net45\Remotion.Linq.EagerFetching.dll - - ..\packages\Sif.Framework.3.2.1.14\lib\net461\Sif.Framework.dll + + ..\packages\Sif.Framework.4.0.0\lib\net461\Sif.Framework.dll ..\packages\Sif.Specification.DataModel.Au.3.4.7\lib\netstandard2.0\Sif.Specification.DataModel.Au.dll @@ -83,24 +117,76 @@ ..\packages\Sif.Specification.Infrastructure.3.2.1\lib\netstandard2.0\Sif.Specification.Infrastructure.dll - - ..\packages\slf4net.0.1.32.1\lib\net35\slf4net.dll - True + + ..\packages\slf4net.1.1.0\lib\net40\slf4net.dll - - ..\packages\slf4net.log4net.0.1.32.1\lib\net35\slf4net.log4net.dll - True + + ..\packages\slf4net.log4net.1.1.0\lib\net40\slf4net.log4net.dll + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll + + + ..\packages\System.Configuration.ConfigurationManager.5.0.0\lib\net461\System.Configuration.ConfigurationManager.dll - - ..\packages\System.Data.SQLite.Core.1.0.109.2\lib\net46\System.Data.SQLite.dll + + + ..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.113.3\lib\net46\System.Data.SQLite.dll + + ..\packages\System.Linq.Dynamic.Core.1.2.6\lib\net46\System.Linq.Dynamic.Core.dll + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + - - ..\packages\Microsoft.AspNet.WebApi.Client.5.2.6\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Security.AccessControl.5.0.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net461\System.Security.Cryptography.Algorithms.dll + True + True + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + True + True + + + ..\packages\System.Security.Permissions.5.0.0\lib\net461\System.Security.Permissions.dll + + + ..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + + + ..\packages\System.Text.Encodings.Web.5.0.0\lib\net461\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.5.0.0\lib\net461\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + ..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll @@ -114,17 +200,21 @@ - - ..\packages\Microsoft.AspNet.WebApi.Core.5.2.6\lib\net45\System.Web.Http.dll + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll - - ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.6\lib\net45\System.Web.Http.WebHost.dll + + ..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll + + ..\packages\Tardigrade.Framework.11.1.0\lib\net461\Tardigrade.Framework.dll + + @@ -196,15 +286,16 @@ + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + + - +