├── .gitignore ├── README.md ├── docs ├── NI.Data.Storage.shfbproj ├── NI.Data.shfbproj ├── NI.Ioc.shfbproj └── NI.Vfs.shfbproj ├── examples ├── NI.Data.Examples.WebForms │ ├── App_Code │ │ └── DataHelper.cs │ ├── NI.Data.Examples.WebForms.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Web.config │ ├── book.aspx │ └── default.aspx ├── NI.Examples.sln └── NI.Ioc.Examples.ConsoleApp │ ├── App.config │ ├── NI.Ioc.Examples.ConsoleApp.csproj │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── TestClass.cs └── src ├── NI.Data.MySql ├── MySqlDalcFactory.cs ├── NI.Data.MySql.csproj ├── NI.Data.MySql.nuspec ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── NI.Data.SQLite ├── NI.Data.SQLite.csproj ├── NI.Data.SQLite.nuspec ├── Properties │ └── AssemblyInfo.cs ├── SQLiteDalcFactory.cs └── packages.config ├── NI.Data.Storage.Tests ├── DataSetStorageContext.cs ├── DataSetStorageDalcTests.cs ├── Model │ ├── DataSchemaTests.cs │ └── RelationshipTests.cs ├── NI.Data.Storage.Tests.csproj ├── ObjectContainerDalcStorageTest.cs ├── ObjectContainerSqlDalcStorageTests.cs ├── OwlEmbeddedSchemaStorageTests.cs ├── Properties │ └── AssemblyInfo.cs ├── RestServiceTest.cs ├── SQLiteStorageContext.cs ├── SQLiteStorageDalcTests.cs └── packages.config ├── NI.Data.Storage ├── DalcStorageQueryTranslator.cs ├── FieldMapping.cs ├── Interfaces │ ├── IDataSchemaStorage.cs │ ├── IObjectContainerStorage.cs │ └── ISqlObjectContainerStorage.cs ├── MetadataTableSchemaStorage.cs ├── Model │ ├── Class.cs │ ├── ClassPropertyLocation.cs │ ├── DataSchema.cs │ ├── ObjectContainer.cs │ ├── ObjectRelation.cs │ ├── Property.cs │ ├── PropertyDataType.cs │ └── Relationship.cs ├── NI.Data.Storage.csproj ├── NI.Data.Storage.nuspec ├── ObjectContainerDalcStorage.cs ├── ObjectContainerSqlDalcStorage.cs ├── OwlEmbeddedSchemaStorage.cs ├── Properties │ └── AssemblyInfo.cs ├── SchemaDataSetFactory.cs ├── Service │ ├── Actions │ │ ├── ChangeRow.cs │ │ ├── GetDataSchema.cs │ │ └── LoadRelex.cs │ ├── ApiException.cs │ ├── BasicAuthorizationManager.cs │ ├── ErrorHandler.cs │ ├── IStorageService.cs │ ├── Schema │ │ ├── DataRowItem.cs │ │ ├── DictionaryItem.cs │ │ ├── GetDataSchemaResult.cs │ │ ├── LoadRowsResult.cs │ │ └── LoadValuesResult.cs │ └── StorageService.cs └── StorageDalc.cs ├── NI.Data.Vfs ├── DalcFileContent.cs ├── DalcFileObject.cs ├── DalcFileStream.cs ├── DalcFileSystem.cs ├── DalcFileSystemHelper.cs ├── DataRowDictionary.cs ├── FileSystemDalc.cs ├── NI.Data.Vfs.csproj └── Properties │ └── AssemblyInfo.cs ├── NI.Data ├── AssemblyInfo.cs ├── DalcExt.cs ├── DataEventBroker.cs ├── DataHelper.cs ├── DataRowDalcMapper.cs ├── DataRowTrigger.cs ├── DataSetFactory.cs ├── DatasetDalc.cs ├── DbCommandEventArgs.cs ├── DbCommandGenerator.cs ├── DbDALC.cs ├── DbDalcView.cs ├── DbSqlBuilder.cs ├── DbTypeResolver.cs ├── DbValueComparer.cs ├── EvalQueryCondition.cs ├── GenericDbProviderFactory.cs ├── Interfaces │ ├── IDalc.cs │ ├── IDataSetFactory.cs │ ├── IDbCommandGenerator.cs │ ├── IDbDalcView.cs │ ├── IDbProviderFactory.cs │ ├── IDbSqlBuilder.cs │ ├── IObjectDataRowMapper.cs │ ├── IQueryValue.cs │ ├── ISqlBuilder.cs │ └── ISqlDalc.cs ├── Linq │ ├── DalcData.cs │ ├── DalcLinqExtensions.cs │ ├── DalcRecord.cs │ └── QueryProvider.cs ├── Logger.cs ├── NI.Data.csproj ├── NI.Data.nuspec ├── ObjectDalcMapper.cs ├── Permissions │ ├── DbPermissionCommandGenerator.cs │ ├── IQueryRule.cs │ ├── PermissionContext.cs │ └── QueryRule.cs ├── PropertyDataRowMapper.cs ├── Query │ ├── QConst.cs │ ├── QField.cs │ ├── QRawSql.cs │ ├── QSort.cs │ ├── QTable.cs │ ├── QVar.cs │ ├── Query.cs │ ├── QueryConditionNode.cs │ ├── QueryGroupNode.cs │ ├── QueryNegationNode.cs │ ├── QueryNode.cs │ └── QueryRawSqlNode.cs ├── RelationalExpressions │ ├── RelExParser.cs │ └── RelexBuilder.cs ├── SimpleStringTemplate.cs ├── SqlBuilder.cs ├── SqlClient │ ├── SqlClientDalcFactory.cs │ └── SqlClientDbSqlBuilder.cs ├── SqlCommandTraceTrigger.cs ├── Triggers │ ├── DataRowActionType.cs │ ├── DataRowTrigger.cs │ ├── InvalidateDataDependencyTrigger.cs │ └── SqlCommandTraceTrigger.cs └── Web │ ├── DalcDataSource.cs │ ├── DalcDataSourceChangeEventArgs.cs │ ├── DalcDataSourceSelectEventArgs.cs │ ├── DalcDataSourceView.cs │ └── DataCacheDependency.cs ├── NI.Ioc ├── ApplicationContainer.cs ├── ArrayFactory.cs ├── AssemblyInfo.cs ├── BaseMethodInvokingFactory.cs ├── ComponentConfiguration.xsd ├── ComponentFactory.cs ├── ComponentFactoryContext.cs ├── ComponentFactoryExt.cs ├── ComponentFactoryInvokingFactory.cs ├── ConstDictionary.cs ├── DelegateFactory.cs ├── DependencyAttribute.cs ├── EventBinder.cs ├── Exceptions │ └── XmlConfigurationException.cs ├── IndexerInvokingFactory.cs ├── IndexerProxy.cs ├── Interfaces │ ├── IComponentFactory.cs │ ├── IComponentFactoryAware.cs │ ├── IComponentFactoryConfiguration.cs │ ├── IComponentInitInfo.cs │ ├── IFactoryComponent.cs │ ├── IMapEntryInfo.cs │ ├── IPropertyInitInfo.cs │ ├── IServiceProviderAware.cs │ ├── IValueFactory.cs │ └── IValueInitInfo.cs ├── MethodInvokingFactory.cs ├── NI.Ioc.csproj ├── NI.Ioc.nuspec ├── PropertyInvokingFactory.cs ├── ReplacingFactory.cs ├── Schema │ ├── ComponentConfiguration.cs │ ├── ComponentInitInfo.cs │ ├── ListValueInitInfo.cs │ ├── MapEntryInfo.cs │ ├── MapValueInitInfo.cs │ ├── PropertyInitInfo.cs │ ├── RefValueInitInfo.cs │ ├── TypeValueInitInfo.cs │ └── ValueInitInfo.cs ├── ServiceProviderContext.cs ├── StaticFieldInvokingFactory.cs ├── StaticMethodInvokingFactory.cs ├── StaticPropertyInvokingFactory.cs ├── Summary.xml ├── TypeResolver.cs ├── XmlComponentConfiguration.cs ├── XmlComponentConfigurationSectionHandler.cs ├── XmlServiceProvider.cs └── XmlServiceProvider.resx ├── NI.Tests ├── Data │ ├── DataEventBrokerTest.cs │ ├── DataSetDalcTest.cs │ ├── DbCommandGeneratorTest.cs │ ├── LinqTests.cs │ ├── PermissionTest.cs │ ├── QueryTest.cs │ ├── SQLiteDalcTest.cs │ └── SimpleStringTemplateTest.cs ├── Ioc │ ├── ArrayFactoryTest.cs │ ├── ComponentFactoryTest.cs │ ├── EventBinderTest.cs │ ├── FuncInterfaceTest.cs │ ├── MethodInvokingFactoryTest.cs │ ├── StaticMethodInvokingFactoryTest.cs │ ├── StaticPropertyInvokingFactoryTest.cs │ └── XmlComponentConfigurationTest.cs ├── NI.Tests.csproj ├── Properties │ └── AssemblyInfo.cs ├── RelationalExpressions │ └── RelExQueryParserTest.cs ├── Text │ └── EvalTest.cs ├── Vfs │ └── VfsTest.cs └── packages.config ├── NI.Text ├── AssemblyInfo.cs ├── DataBind.cs ├── EvalHelper.cs ├── IndexerProxy.cs ├── NI.Text.csproj ├── NI.Text.nuspec ├── StringTemplate.cs └── Summary.xml ├── NI.Vfs ├── AllFileSelector.cs ├── AssemblyInfo.cs ├── Exceptions │ └── FileSystemException.cs ├── ExtensionFileSelector.cs ├── FileObjectComparer.cs ├── FileObjectEventArgs.cs ├── FileObjectExt.cs ├── Interfaces │ ├── IFileContent.cs │ ├── IFileObject.cs │ ├── IFileSelector.cs │ └── IFileSystem.cs ├── ListFileSelector.cs ├── LocalFile.cs ├── LocalFileContent.cs ├── LocalFilesystem.cs ├── MaskFileSelector.cs ├── MemoryFile.cs ├── MemoryFileContent.cs ├── MemoryFileSystem.cs ├── NI.Vfs.csproj ├── NI.Vfs.nuspec ├── RegexFileSelector.cs └── VfsXmlResolver.cs └── NICNET.sln /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | .idea/ 3 | /examples/*/bin 4 | /examples/*/obj 5 | /examples/*.suo 6 | /examples/*/*.user 7 | bin 8 | obj 9 | /src/*/NI.*.xml 10 | /src/*/*.user 11 | /src/*.suo 12 | /src/packages 13 | /src/NI.Tests/x64 14 | /src/NI.Tests/x86 15 | /src/NI.Data.Storage.Tests/x64 16 | /src/NI.Data.Storage.Tests/x86 17 | /src/NI.Data.SQLite/x64 18 | /src/NI.Data.SQLite/x86 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NIC.NET 2 | NIC.NET is a set of open source reusable components originally developed by NewtonIdeas.com company in 2005-2008. 3 | Right now these components are maintained by NReco team as part of NReco Framework infrastructure. 4 | 5 | Core components: 6 | 12 | These components are also available as nuget packages. 13 | 14 | ## Copyright & License 15 | NIC.NET Version 1.0 © 2005-2008 NewtonIdeas.com (published under LGPL) 16 | Changes and version 2.0 © 2008-2015 Vitalii Fedorchenko + other contributors (LGPL) 17 | -------------------------------------------------------------------------------- /examples/NI.Data.Examples.WebForms/App_Code/DataHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Data; 5 | using System.Web; 6 | 7 | namespace NI.Data.Examples.WebForms.App_Code { 8 | 9 | public static class DataHelper { 10 | 11 | public static IDalc GetDalc() { 12 | DataSet ds = HttpContext.Current.Session["dataset"] as DataSet; 13 | if (ds == null) { 14 | ds = CreateBookDS(); 15 | var r = ds.Tables["books"].NewRow(); 16 | r["title"] = "Twenty Thousand Leagues Under the Sea"; 17 | r["description"] = "Twenty Thousand Leagues Under the Sea is a classic science fiction novel by French writer Jules Verne published in 1870. It tells the story of Captain Nemo and his submarine Nautilus, as seen from the perspective of Professor Pierre Aronnax."; 18 | r["rating"] = 5; 19 | r["author_id"] = 1; 20 | ds.Tables["books"].Rows.Add(r); 21 | 22 | var author1Row = ds.Tables["authors"].NewRow(); 23 | author1Row["name"] = "Jules Verne"; 24 | ds.Tables["authors"].Rows.Add(author1Row); 25 | 26 | ds.AcceptChanges(); 27 | HttpContext.Current.Session["dataset"] = ds; 28 | } 29 | return new DataSetDalc(ds); 30 | } 31 | 32 | public static DataSet CreateBookDS() { 33 | var ds = new DataSet(); 34 | var bookTbl = ds.Tables.Add("books"); 35 | var idCol = bookTbl.Columns.Add("id", typeof(int)); 36 | idCol.AutoIncrement = true; 37 | idCol.AutoIncrementSeed = 1; 38 | bookTbl.PrimaryKey = new[] { idCol }; 39 | 40 | bookTbl.Columns.Add("title", typeof(string)); 41 | bookTbl.Columns.Add("description", typeof(string)); 42 | bookTbl.Columns.Add("author_id", typeof(int)); 43 | bookTbl.Columns.Add("rating", typeof(int)); 44 | 45 | var authorTbl = ds.Tables.Add("authors"); 46 | var authorIdCol = authorTbl.Columns.Add("id", typeof(int)); 47 | authorIdCol.AutoIncrement = true; 48 | authorIdCol.AutoIncrementSeed = 1; 49 | authorTbl.PrimaryKey = new[] { authorIdCol }; 50 | authorTbl.Columns.Add("name", typeof(string)); 51 | 52 | return ds; 53 | } 54 | 55 | } 56 | } -------------------------------------------------------------------------------- /examples/NI.Data.Examples.WebForms/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NI.Data.Examples.WebForms")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Vitalii Fedorchenko")] 12 | [assembly: AssemblyProduct("NI.Data.Examples.WebForms")] 13 | [assembly: AssemblyCopyright("Copyright © Vitalii Fedorchenko 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("8336a2cb-fbe5-4d1c-a49a-4d981dc8f647")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /examples/NI.Data.Examples.WebForms/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/NI.Examples.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Express 2013 for Web 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NI.Ioc.Examples.ConsoleApp", "NI.Ioc.Examples.ConsoleApp\NI.Ioc.Examples.ConsoleApp.csproj", "{61A57744-B9A6-41C2-8215-A2452BE90403}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NI.Data.Examples.WebForms", "NI.Data.Examples.WebForms\NI.Data.Examples.WebForms.csproj", "{075ECF83-8A22-44CE-ACB5-A0AB3FB3FF41}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NI.Data", "..\src\NI.Data\NI.Data.csproj", "{AC4B7A7E-55CA-4EAE-9FFA-DD6582390E81}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NI.Ioc", "..\src\NI.Ioc\NI.Ioc.csproj", "{25702474-5D4D-4EEA-A68A-3662A0966ED6}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {61A57744-B9A6-41C2-8215-A2452BE90403}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {61A57744-B9A6-41C2-8215-A2452BE90403}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {61A57744-B9A6-41C2-8215-A2452BE90403}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {61A57744-B9A6-41C2-8215-A2452BE90403}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {075ECF83-8A22-44CE-ACB5-A0AB3FB3FF41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {075ECF83-8A22-44CE-ACB5-A0AB3FB3FF41}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {075ECF83-8A22-44CE-ACB5-A0AB3FB3FF41}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {075ECF83-8A22-44CE-ACB5-A0AB3FB3FF41}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {AC4B7A7E-55CA-4EAE-9FFA-DD6582390E81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {AC4B7A7E-55CA-4EAE-9FFA-DD6582390E81}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {AC4B7A7E-55CA-4EAE-9FFA-DD6582390E81}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {AC4B7A7E-55CA-4EAE-9FFA-DD6582390E81}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {25702474-5D4D-4EEA-A68A-3662A0966ED6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {25702474-5D4D-4EEA-A68A-3662A0966ED6}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {25702474-5D4D-4EEA-A68A-3662A0966ED6}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {25702474-5D4D-4EEA-A68A-3662A0966ED6}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /examples/NI.Ioc.Examples.ConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Configuration; 6 | 7 | using NI.Ioc; 8 | 9 | namespace NI.Ioc.Examples.ConsoleApp 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | Console.WriteLine("Loading IoC-container configuration..."); 16 | 17 | var config = ConfigurationManager.GetSection("appContainer") as IComponentFactoryConfiguration; 18 | // or variant that is marked as not deprecated 19 | 20 | Console.WriteLine("Creating IoC-container..."); 21 | var factory = new ComponentFactory(config, true); 22 | 23 | Console.WriteLine("Created {0} non-lazy instances", factory.Counters.CreateInstance); 24 | 25 | var componentNames = new[] {"datetimenow", "datetimenow-3days", "nonLazyNonSingletonTestComponent", "appName"}; 26 | 27 | foreach (var componentName in componentNames) { 28 | Console.WriteLine("'{0}'.ToString(): {1}", componentName, factory.GetComponent(componentName)); 29 | } 30 | 31 | Console.ReadLine(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/NI.Ioc.Examples.ConsoleApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NI.Ioc.Examples.ConsoleApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("NI")] 12 | [assembly: AssemblyProduct("NI.Ioc.Examples.ConsoleApp")] 13 | [assembly: AssemblyCopyright("Copyright © NI 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("18f9b9b8-450a-40b6-8899-8b17ca7c80b0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/NI.Data.MySql/MySqlDalcFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Data; 17 | using System.Data.Common; 18 | using MySql.Data.MySqlClient; 19 | using MySql.Data; 20 | using System.ComponentModel; 21 | 22 | namespace NI.Data.MySql 23 | { 24 | 25 | /// 26 | /// MySQL Dalc Factory implementation 27 | /// 28 | public class MySqlDalcFactory : GenericDbProviderFactory 29 | { 30 | 31 | public MySqlDalcFactory() 32 | : base(MySqlClientFactory.Instance) { 33 | } 34 | 35 | public override object GetInsertId(IDbConnection connection) { 36 | if (connection.State != ConnectionState.Open) 37 | throw new InvalidOperationException("GetInsertId requires opened connection"); 38 | using (var cmd = CreateCommand()) { 39 | cmd.CommandText = "SELECT LAST_INSERT_ID()"; 40 | cmd.Connection = connection; 41 | return cmd.ExecuteScalar(); 42 | } 43 | } 44 | 45 | 46 | 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/NI.Data.MySql/NI.Data.MySql.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | 10 | http://www.nrecosite.com 11 | 12 | false 13 | $description$ 14 | Copyright 2004-2014 Newtonideas 15 | NI.Data MySql 16 | 17 | -------------------------------------------------------------------------------- /src/NI.Data.MySql/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NI.Data.MySql")] 9 | [assembly: AssemblyDescription("MySql Data Provider factory for DALC")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("NewtonIdeas")] 12 | [assembly: AssemblyProduct("Open NIC.NET")] 13 | [assembly: AssemblyCopyright("Copyright © NewtonIdeas 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ba099873-41cb-4a34-9643-255c3982c41b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("2.0.1")] 36 | [assembly: AssemblyFileVersion("2.0.1")] 37 | -------------------------------------------------------------------------------- /src/NI.Data.MySql/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/NI.Data.SQLite/NI.Data.SQLite.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | 10 | http://www.nrecosite.com/dalc_net.aspx 11 | 12 | false 13 | $description$ 14 | Copyright 2004-2014 Newtonideas 15 | NI.Data SQLite 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/NI.Data.SQLite/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NI.Data.SQLite")] 9 | [assembly: AssemblyDescription("SQLite Data Provider factory for NI.Data DALC")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("NewtonIdeas")] 12 | [assembly: AssemblyProduct("Open NIC.NET")] 13 | [assembly: AssemblyCopyright("Copyright © 2013 NewtonIdeas")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ea45aedd-e010-421f-bc03-52e7c2075cd6")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("2.0.0")] 36 | [assembly: AssemblyFileVersion("2.0.0")] 37 | -------------------------------------------------------------------------------- /src/NI.Data.SQLite/SQLiteDalcFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2013 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Data; 17 | using System.Data.Common; 18 | using System.Data.SQLite; 19 | using System.ComponentModel; 20 | 21 | namespace NI.Data.SQLite 22 | { 23 | 24 | /// 25 | /// SQLite Dalc Factory implementation 26 | /// 27 | public class SQLiteDalcFactory : GenericDbProviderFactory 28 | { 29 | public SQLiteDalcFactory() 30 | : base(SQLiteFactory.Instance) { 31 | ParamPlaceholderFormat = "?"; 32 | 33 | } 34 | 35 | public override object GetInsertId(IDbConnection connection) { 36 | if (connection.State != ConnectionState.Open) 37 | throw new InvalidOperationException("GetInsertId requires opened connection"); 38 | return ((SQLiteConnection)connection).LastInsertRowId; 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/NI.Data.SQLite/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /src/NI.Data.Storage.Tests/Model/DataSchemaTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using NUnit.Framework; 8 | 9 | using NI.Data.Storage.Model; 10 | 11 | namespace NI.Data.Storage.Tests.Model { 12 | 13 | [TestFixture] 14 | public class DataSchemaTests { 15 | 16 | [Test] 17 | public void InferRelationshipByID() { 18 | var schema = DataSetStorageContext.CreateTestSchema(); 19 | 20 | var r1 = schema.InferRelationshipByID("contacts_contactCompany_companies.companies_companyCountry_countries", schema.FindClassByID("contacts") ); 21 | Assert.NotNull(r1); 22 | Assert.True(r1.Inferred); 23 | Assert.AreEqual(2, r1.InferredByRelationships.Count() ); 24 | Assert.AreEqual("countries", r1.Object.ID ); 25 | 26 | var r2 = schema.InferRelationshipByID("companies_companyCountry_countries.contacts_contactCompany_companies", schema.FindClassByID("countries")); 27 | Assert.NotNull(r2); 28 | Assert.True(r2.Inferred); 29 | Assert.AreEqual("contacts", r2.Object.ID); 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/NI.Data.Storage.Tests/Model/RelationshipTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using NUnit.Framework; 8 | 9 | using NI.Data.Storage.Model; 10 | 11 | namespace NI.Data.Storage.Tests.Model { 12 | 13 | [TestFixture] 14 | public class RelationshipTests { 15 | 16 | [Test] 17 | public void EqualsAndHashCode() { 18 | var class1 = new Class("class1"); 19 | var class2 = new Class("class2"); 20 | var pred1 = new Class("pred1") { IsPredicate = true }; 21 | var pred2 = new Class("pred2") { IsPredicate = true }; 22 | 23 | var rel1 = new Relationship(class1, pred1, class2, false,false, null); 24 | var rel1same = new Relationship(class1, pred1, class2, false,false, null); 25 | Assert.AreEqual( 26 | rel1same, rel1); 27 | Assert.AreEqual( 28 | rel1same.GetHashCode(), rel1.GetHashCode() ); 29 | Assert.AreNotEqual( 30 | new Relationship(class2, pred1, class1, false, false, null), rel1); 31 | Assert.AreNotEqual( 32 | new Relationship(class1, pred2, class2, false, false, null), rel1); 33 | 34 | var rel2 = new Relationship(class2, pred2, class1, false, false, null); 35 | var infRel1 = new Relationship(class1, new[] { rel1, rel2 }, class1); 36 | var infRel1same = new Relationship(class1, new[] { rel1, rel2 }, class1); 37 | Assert.True(infRel1.Inferred); 38 | Assert.AreEqual( infRel1same, infRel1 ); 39 | Assert.AreEqual(infRel1same.GetHashCode(), infRel1.GetHashCode() ); 40 | 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/NI.Data.Storage.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NI.Data.Storage.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("NI.Data.Storage.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("19c2ee8a-3e50-425d-ab48-49e156d5694b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/NI.Data.Storage.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/FieldMapping.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace NI.Data.Storage { 7 | public class FieldMapping { 8 | QField[] Fields; 9 | QField[] CompactFields; 10 | IDictionary DirectMapping; 11 | IDictionary RevMapping; 12 | public FieldMapping(QField[] fields) { 13 | Fields = fields; 14 | DirectMapping = new Dictionary(); 15 | RevMapping = new Dictionary(); 16 | if (fields != null && fields.Length > 0) { 17 | CompactFields = new QField[Fields.Length]; 18 | for (int i = 0; i < CompactFields.Length; i++) { 19 | var f = Fields[i]; 20 | if (f.Prefix != null && f.Expression == null) { 21 | var originalFieldName = f.ToString().Replace('.', '_'); 22 | var compactName = "f_" + i.ToString() + "_" + f.Name; 23 | RevMapping[compactName] = originalFieldName; 24 | DirectMapping[originalFieldName] = compactName; 25 | CompactFields[i] = new QField(compactName, f.ToString()); 26 | } else { 27 | CompactFields[i] = f; 28 | } 29 | } 30 | } else { 31 | CompactFields = Fields; 32 | } 33 | } 34 | 35 | public QField[] GetCompactFields() { 36 | return CompactFields; 37 | } 38 | 39 | public string GetOriginalFieldName(string compactName) { 40 | return RevMapping.ContainsKey(compactName) ? RevMapping[compactName] : compactName; 41 | } 42 | 43 | public string GetCompactFieldName(string originalName) { 44 | return DirectMapping.ContainsKey(originalName) ? DirectMapping[originalName] : originalName; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Interfaces/IDataSchemaStorage.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Threading.Tasks; 21 | 22 | using NI.Data.Storage.Model; 23 | 24 | namespace NI.Data.Storage { 25 | 26 | /// 27 | /// Represents data schema persistence storage 28 | /// 29 | public interface IDataSchemaStorage { 30 | 31 | /// 32 | /// Returns actual from metadata storage 33 | /// 34 | DataSchema GetSchema(); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Interfaces/ISqlObjectContainerStorage.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Threading.Tasks; 21 | using System.Data; 22 | 23 | using NI.Data; 24 | using NI.Data.Storage.Model; 25 | 26 | namespace NI.Data.Storage { 27 | 28 | /// 29 | /// Represents abstract SQL-specific storage for 30 | /// 31 | public interface ISqlObjectContainerStorage : IObjectContainerStorage { 32 | 33 | /// 34 | /// Execute object query and pass result as for specified handler 35 | /// 36 | /// object query to execute 37 | /// delegate that accepts with query result 38 | void LoadObjectReader(Query q, Action handler); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Model/ObjectRelation.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Threading.Tasks; 21 | 22 | namespace NI.Data.Storage.Model { 23 | 24 | /// 25 | /// Represents relation between two objects 26 | /// 27 | public class ObjectRelation { 28 | 29 | public long SubjectID { get; private set; } 30 | public Relationship Relation { get; private set; } 31 | public long ObjectID { get; private set; } 32 | 33 | public ObjectRelation(long subjId, Relationship r, long objId) { 34 | SubjectID = subjId; 35 | Relation = r; 36 | ObjectID = objId; 37 | } 38 | 39 | public override string ToString() { 40 | return String.Format("[SubjectID={0}; {1}; ObjectID={2}]", SubjectID, Relation.ToString(), ObjectID); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/NI.Data.Storage.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | Vitalii Fedorchenko 8 | $author$ 9 | 10 | http://www.nrecosite.com/semantic_storage_net.aspx 11 | 12 | false 13 | $description$ 14 | Copyright 2013-2015 Vitalii Fedorchenko 15 | NI.Data ADO.NET DAL EAV Engine Entity-Attribute-Value Triplestore 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NI.Data.Storage")] 9 | [assembly: AssemblyDescription("NI.Data.Storage provides ADO.NET-like access to data represented with entity-attribute-value model. Entities may be queried, created, updated and deleted like usual database tables.")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Vitalii Fedorchenko")] 12 | [assembly: AssemblyProduct("NI.Data.Storage")] 13 | [assembly: AssemblyCopyright("Copyright © Vitalii Fedorchenko 2013-2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("fd64292d-46ac-4c2c-81d0-932893b2f02f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("2.1.0.0")] 36 | [assembly: AssemblyFileVersion("2.1.0.0")] 37 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/SchemaDataSetFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2014 Vitalii Fedorchenko 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Collections.Generic; 17 | using System.Linq; 18 | using System.Text; 19 | using System.Data; 20 | 21 | using NI.Data; 22 | using NI.Data.Storage.Model; 23 | 24 | namespace NI.Data.Storage { 25 | 26 | /// 27 | /// implementation based on . 28 | /// 29 | public class SchemaDataSetFactory : IDataSetFactory { 30 | 31 | protected Func GetSchema { get; set; } 32 | 33 | /// 34 | /// Initializes new instance of SchemaDataSetFactory with specified DataSchema provider. 35 | /// 36 | /// delegate that returns DataSchema structure 37 | public SchemaDataSetFactory(Func getSchema) { 38 | GetSchema = getSchema; 39 | } 40 | 41 | /// 42 | /// Construct DataSet object with DataTable schema for specifed table name. 43 | /// 44 | /// table name 45 | /// DataSet with DataTable for specified table name 46 | public DataSet GetDataSet(string tableName) { 47 | if (String.IsNullOrEmpty(tableName)) 48 | throw new ArgumentNullException("tableName is empty"); 49 | var schema = GetSchema(); 50 | var ds = new DataSet(); 51 | var dataClass = schema.FindClassByID(tableName); 52 | if (dataClass==null) 53 | return null; 54 | 55 | var tbl = dataClass.CreateDataTable(); 56 | ds.Tables.Add(tbl); 57 | return ds; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Service/Actions/GetDataSchema.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Runtime.Serialization; 21 | using System.ServiceModel; 22 | 23 | using NI.Data.Storage.Model; 24 | using NI.Data.Storage.Service.Schema; 25 | 26 | namespace NI.Data.Storage.Service.Actions { 27 | 28 | public class GetDataSchema { 29 | 30 | DataSchema Schema; 31 | 32 | public GetDataSchema(DataSchema schema) { 33 | Schema = schema; 34 | } 35 | 36 | public GetDataSchemaResult Execute() { 37 | var res = new GetDataSchemaResult(); 38 | 39 | foreach (var c in Schema.Classes.Where(c=>!c.IsPredicate) ) { 40 | var cInfo = new DataSchemaClassInfo() { 41 | ID = c.ID, 42 | Name = c.Name, 43 | }; 44 | foreach (var cProp in c.Properties) { 45 | var propLoc = cProp.GetLocation(c); 46 | cInfo.Properties.Add( new DataSchemaPropertyInfo() { 47 | ID = cProp.ID, 48 | Name = cProp.Name, 49 | DataTypeID = cProp.DataType.ID, 50 | DerivedFromPropertyID = propLoc.Location==PropertyValueLocationType.Derived ? propLoc.DerivedFrom.Property.ID : null 51 | } ); 52 | } 53 | res.Classes.Add(cInfo); 54 | } 55 | foreach (var r in Schema.Relationships.Where(r=>r.ID!=null && !r.Reversed) ) { 56 | var relInfo = new DataSchemaRelationshipInfo() { 57 | ID = r.ID, 58 | SubjectClassID = r.Subject.ID, 59 | ObjectClassID = r.Object.ID, 60 | PredicateName = r.Predicate.Name, 61 | ObjectMultiplicity = r.Multiplicity, 62 | SubjectMultiplicity = r.ReversedRelationship.Multiplicity 63 | }; 64 | res.Relationships.Add(relInfo); 65 | } 66 | 67 | return res; 68 | } 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Service/ApiException.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Web; 21 | using System.Net; 22 | using System.ServiceModel; 23 | using System.ServiceModel.Web; 24 | using System.Runtime.Serialization; 25 | 26 | namespace NI.Data.Storage.Service { 27 | 28 | public class ApiException : ApplicationException { 29 | 30 | public HttpStatusCode StatusCode { get; private set; } 31 | 32 | public string ErrorId { get; private set; } 33 | 34 | public ApiException(string msg, HttpStatusCode code) : this( msg, code, null) { } 35 | 36 | public ApiException(string msg, HttpStatusCode code, string errorCode) : this( msg, code, errorCode, null ) { 37 | } 38 | 39 | public ApiException(string msg, HttpStatusCode code, string errorCode, Exception inner) : base( msg, inner ) { 40 | StatusCode = code; 41 | ErrorId = errorCode; 42 | } 43 | } 44 | 45 | [DataContract(Name = "error")] 46 | public class ApiFault { 47 | 48 | [DataMember] 49 | public string Message { get; set; } 50 | 51 | public ApiFault(string msg) { 52 | Message = msg; 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Service/IStorageService.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.ServiceModel; 21 | using System.ServiceModel.Web; 22 | using System.Xml.Serialization; 23 | using System.ComponentModel; 24 | 25 | using NI.Data.Storage.Service; 26 | using NI.Data.Storage.Service.Actions; 27 | using NI.Data.Storage.Service.Schema; 28 | 29 | namespace NI.Data.Storage.Service { 30 | 31 | [ServiceContract] 32 | public interface IStorageService { 33 | 34 | [OperationContract] 35 | [WebInvoke(UriTemplate = "/schema", Method = "GET")] 36 | [FaultContract(typeof(ApiFault))] 37 | [Description("Get data schema (classes, properties)")] 38 | GetDataSchemaResult GetDataSchema(); 39 | 40 | [OperationContract] 41 | [WebInvoke(UriTemplate = "/load/rows?q={relex}&totalcount={totalcount}", Method = "GET")] 42 | [FaultContract(typeof(ApiFault))] 43 | [Description("Load storage data as rows collection by query (relex expression)")] 44 | LoadRowsResult LoadRows(string relex, bool totalcount); 45 | 46 | [OperationContract] 47 | [WebInvoke(UriTemplate = "/load/values?q={relex}&totalcount={totalcount}", Method = "GET")] 48 | [FaultContract(typeof(ApiFault))] 49 | [Description("Load storage data as values collection by query (relex expression)")] 50 | LoadValuesResult LoadValues(string relex, bool totalcount); 51 | 52 | [OperationContract] 53 | [WebInvoke(UriTemplate = "/data/{tableName}", Method = "POST")] 54 | long? InsertRow(string tableName, DictionaryItem data); 55 | 56 | [OperationContract] 57 | [WebInvoke(UriTemplate = "/data/{tableName}/{id}", Method = "PUT")] 58 | void UpdateRow(string tableName, string id, DictionaryItem data); 59 | 60 | [OperationContract] 61 | [WebInvoke(UriTemplate = "/data/{tableName}/{id}", Method = "DELETE")] 62 | void DeleteRow(string tableName, string id); 63 | 64 | [OperationContract] 65 | [WebInvoke(UriTemplate = "/data/{tableName}/{id}", Method = "GET")] 66 | DictionaryItem LoadRow(string tableName, string id); 67 | 68 | [OperationContract] 69 | [WebInvoke(UriTemplate = "/delete?q={relex}", Method = "GET")] 70 | int DeleteRows(string relex); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Service/Schema/DataRowItem.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Runtime.Serialization; 21 | using System.Xml.Serialization; 22 | using System.Data; 23 | using System.Threading.Tasks; 24 | using System.Globalization; 25 | 26 | namespace NI.Data.Storage.Service.Schema { 27 | 28 | [Serializable] 29 | public class DataRowItem : ISerializable { 30 | DataRow DataRow; 31 | 32 | public DataRowItem(DataRow r) { 33 | DataRow = r; 34 | } 35 | 36 | public void GetObjectData(SerializationInfo info, StreamingContext context) { 37 | foreach (DataColumn c in DataRow.Table.Columns) { 38 | if (DataRow.IsNull(c)) { 39 | info.AddValue(c.ColumnName, null, c.DataType); 40 | } else { 41 | var val = DataRow[c]; 42 | info.AddValue(c.ColumnName, val, c.DataType); 43 | } 44 | } 45 | } 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Service/Schema/DictionaryItem.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Runtime.Serialization; 21 | using System.Xml.Serialization; 22 | using System.Data; 23 | using System.Threading.Tasks; 24 | using System.Globalization; 25 | using System.Security.Permissions; 26 | 27 | namespace NI.Data.Storage.Service.Schema { 28 | 29 | [Serializable] 30 | public class DictionaryItem : ISerializable { 31 | public IDictionary Data; 32 | 33 | public DictionaryItem() { 34 | Data = new Dictionary(); 35 | } 36 | 37 | public DictionaryItem(IDictionary data) { 38 | Data = data; 39 | } 40 | 41 | //[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)] 42 | protected DictionaryItem(SerializationInfo info, StreamingContext context) { 43 | var e = info.GetEnumerator(); 44 | Data = new Dictionary(); 45 | while (e.MoveNext()) { 46 | Data[e.Name] = e.Value; 47 | } 48 | } 49 | 50 | public void GetObjectData(SerializationInfo info, StreamingContext context) { 51 | foreach (var entry in Data) { 52 | if (entry.Value == null || DBNull.Value.Equals(entry.Value)) 53 | continue; 54 | 55 | info.AddValue(entry.Key, entry.Value, entry.Value.GetType()); 56 | } 57 | } 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Service/Schema/LoadRowsResult.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Xml.Serialization; 21 | using System.Runtime.Serialization; 22 | using System.Data; 23 | using System.ComponentModel; 24 | using System.Threading.Tasks; 25 | 26 | namespace NI.Data.Storage.Service.Schema { 27 | 28 | [DataContract(Name = "rowsResult")] 29 | public class LoadRowsResult { 30 | 31 | [DataMember(Name = "data")] 32 | public RowList Data { get; set; } 33 | 34 | [DataMember(Name = "totalcount", EmitDefaultValue=true)] 35 | [DefaultValue(null)] 36 | public int? TotalCount { get; set; } 37 | 38 | public LoadRowsResult() { 39 | } 40 | 41 | } 42 | 43 | [CollectionDataContract(ItemName = "row")] 44 | public class RowList : List { } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/NI.Data.Storage/Service/Schema/LoadValuesResult.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2013-2014 Vitalii Fedorchenko 5 | * Copyright 2014 NewtonIdeas 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Xml.Serialization; 21 | using System.Runtime.Serialization; 22 | using System.Data; 23 | using System.ComponentModel; 24 | using System.Threading.Tasks; 25 | 26 | namespace NI.Data.Storage.Service.Schema { 27 | 28 | [DataContract(Name = "valuesResult")] 29 | public class LoadValuesResult { 30 | 31 | [DataMember(Name="columns")] 32 | public string[] Columns { get; set; } 33 | 34 | [DataMember(Name = "data")] 35 | public IList Data { get; set; } 36 | 37 | [DataMember(Name = "totalcount", EmitDefaultValue=true)] 38 | [DefaultValue(null)] 39 | public int? TotalCount { get; set; } 40 | 41 | public LoadValuesResult() { 42 | } 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/NI.Data.Vfs/DalcFileContent.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * NIC.NET library 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Collections.Generic; 17 | using System.Text; 18 | using System.IO; 19 | 20 | using NI.Vfs; 21 | 22 | namespace NI.Data.Vfs { 23 | /// 24 | /// Dalc base file content implementation 25 | /// 26 | public class DalcFileContent: IFileContent { 27 | 28 | protected DalcFileObject _File; 29 | protected DalcFileStream fileStream = null; 30 | protected DateTime _LastModifiedTime = DateTime.Now; 31 | 32 | public DalcFileContent(DalcFileObject file) { 33 | _File = file; 34 | } 35 | 36 | /// 37 | /// Instance of file object 38 | /// 39 | public IFileObject File { 40 | get { return _File; } 41 | } 42 | 43 | /// 44 | /// Name (key) of content 45 | /// 46 | public string Name { 47 | get { return File.Name; } 48 | } 49 | 50 | public Stream GetStream(FileAccess access) { 51 | if (File.Type!=FileType.File) 52 | throw new FileSystemException(); // TODO: more structured exception 53 | ReopenStream(); 54 | return fileStream; 55 | } 56 | 57 | public long Size { 58 | get { return fileStream.Length; } 59 | } 60 | 61 | public DateTime LastModifiedTime { 62 | get { return _LastModifiedTime; } 63 | set { _LastModifiedTime = value; } 64 | } 65 | 66 | protected void ReopenStream() { 67 | DalcFileStream newFileStream = new DalcFileStream(this); 68 | if (fileStream!=null) { 69 | fileStream.CloseMemoryStream(); 70 | byte[] data = fileStream.ToArray(); 71 | newFileStream.Write(data,0,data.Length); 72 | newFileStream.Seek(0, SeekOrigin.Begin); 73 | } 74 | fileStream = newFileStream; 75 | } 76 | 77 | public void Close() { 78 | if (fileStream!=null) { 79 | _File.SaveContent(); //Save content in storage 80 | fileStream.CloseMemoryStream(); //Close memory(underlying) stream 81 | } 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/NI.Data.Vfs/DalcFileStream.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * NIC.NET library 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.IO; 17 | 18 | namespace NI.Data.Vfs { 19 | /// 20 | /// Specific implementation of stream for DalcFileContent instances 21 | /// 22 | public class DalcFileStream : MemoryStream { 23 | 24 | private DalcFileContent Content; 25 | 26 | public override void Close() { 27 | Content.Close(); 28 | base.Close(); 29 | } 30 | 31 | public DalcFileStream(DalcFileContent content) { 32 | Content = content; 33 | } 34 | 35 | public void CloseMemoryStream() { 36 | base.Close(); 37 | } 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/NI.Data.Vfs/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NI.Data.Vfs")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("NI.Data.Vfs")] 13 | [assembly: AssemblyCopyright("NewtonIdeas")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("5276a757-ee5b-4bf2-b417-72e703dc5446")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /src/NI.Data/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("NI.Data")] 10 | [assembly: AssemblyDescription("Fast and flexible DB-independent data layer for .NET. Supports abstract queries (RelEx), SQL-dataviews, triggers and query hooks.")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("NewtonIdeas")] 13 | [assembly: AssemblyProduct("Open NIC.NET")] 14 | [assembly: AssemblyCopyright("NewtonIdeas")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("2.0.10")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /src/NI.Data/DataHelper.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | using System.Data; 21 | using System.IO; 22 | 23 | namespace NI.Data { 24 | 25 | public static class DataHelper { 26 | public static DataSet GetDataSetFromXml(string xml) { 27 | var ds = new DataSet(); 28 | ds.ReadXml(new StringReader(xml)); 29 | return ds; 30 | } 31 | 32 | public static void EnsureConnectionOpen(IDbConnection connection, Action a) { 33 | bool closeConn = false; 34 | if (connection.State != ConnectionState.Open) { 35 | connection.Open(); 36 | closeConn = true; 37 | } 38 | try { 39 | a(); 40 | } finally { 41 | if (closeConn) 42 | connection.Close(); 43 | } 44 | } 45 | 46 | public static QueryNode MapQValue(QueryNode qNode, Func mapFunc) { 47 | if (qNode is QueryGroupNode) { 48 | var group = new QueryGroupNode((QueryGroupNode)qNode); 49 | for (int i = 0; i < group.Nodes.Count; i++) 50 | group.Nodes[i] = MapQValue(group.Nodes[i], mapFunc); 51 | return group; 52 | } 53 | if (qNode is QueryConditionNode) { 54 | var origCndNode = (QueryConditionNode)qNode; 55 | var cndNode = new QueryConditionNode(origCndNode.Name, 56 | mapFunc(origCndNode.LValue), 57 | origCndNode.Condition, 58 | mapFunc(origCndNode.RValue)); 59 | return cndNode; 60 | } 61 | if (qNode is QueryNegationNode) { 62 | var negNode = new QueryNegationNode((QueryNegationNode)qNode); 63 | for (int i = 0; i < negNode.Nodes.Count; i++) 64 | negNode.Nodes[i] = MapQValue(negNode.Nodes[i], mapFunc); 65 | return negNode; 66 | } 67 | return qNode; 68 | } 69 | 70 | public static void SetQueryVariables(QueryNode node, Action setVar) { 71 | if (node is QueryConditionNode) { 72 | var cndNode = (QueryConditionNode)node; 73 | if (cndNode.LValue is QVar) 74 | setVar( (QVar) cndNode.LValue); 75 | if (cndNode.RValue is QVar) 76 | setVar( (QVar) cndNode.RValue); 77 | } 78 | if (node != null) 79 | foreach (var cNode in node.Nodes) 80 | SetQueryVariables(cNode, setVar); 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/NI.Data/DbCommandEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Data; 18 | 19 | namespace NI.Data 20 | { 21 | /// 22 | /// Database command event arguments. 23 | /// 24 | public class DbCommandEventArgs : EventArgs 25 | { 26 | 27 | /// 28 | /// Get or set affected source name. 29 | /// 30 | public string TableName { get; private set; } 31 | 32 | /// 33 | /// Get or set DB command type. 34 | /// 35 | public StatementType CommandType { get; private set; } 36 | 37 | /// 38 | /// Get or set event argument 39 | /// 40 | public IDbCommand Command { get; private set; } 41 | 42 | 43 | public DbCommandEventArgs(string tableName, StatementType commandType, IDbCommand command) 44 | { 45 | TableName = tableName; 46 | CommandType = commandType; 47 | Command = command; 48 | } 49 | } 50 | 51 | /// 52 | /// Represents database command executing event data 53 | /// 54 | public class DbCommandExecutingEventArgs : DbCommandEventArgs { 55 | 56 | public DbCommandExecutingEventArgs(string tableName, StatementType commandType, IDbCommand command) : 57 | base(tableName, commandType, command) { } 58 | } 59 | 60 | /// 61 | /// Represents database command executed event data 62 | /// 63 | public class DbCommandExecutedEventArgs : DbCommandEventArgs { 64 | 65 | public DbCommandExecutedEventArgs(string tableName, StatementType commandType, IDbCommand command) : 66 | base(tableName, commandType, command) { } 67 | } 68 | 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/NI.Data/DbTypeResolver.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Data; 18 | using System.Data.Common; 19 | 20 | namespace NI.Data 21 | { 22 | /// 23 | /// DbType enumeration member resolver. 24 | /// 25 | public class DbTypeResolver 26 | { 27 | bool _UseAnsiString = false; 28 | 29 | public bool UseAnsiString { 30 | get { return _UseAnsiString; } 31 | set { _UseAnsiString = value; } 32 | } 33 | 34 | public DbTypeResolver() 35 | { 36 | } 37 | 38 | /// 39 | /// Resolve DbType by System.Type 40 | /// 41 | /// .net type 42 | /// DB type 43 | public virtual DbType Resolve(Type type) { 44 | if (type==typeof(byte) ) return DbType.Byte; 45 | if (type==typeof(bool) ) return DbType.Boolean; 46 | if (type==typeof(long) ) return DbType.Int64; 47 | if (type==typeof(int) ) return DbType.Int32; 48 | if (type==typeof(double) ) return DbType.Double; 49 | if (type==typeof(float) ) return DbType.Single; 50 | if (type==typeof(string) ) return UseAnsiString ? DbType.AnsiString : DbType.String; 51 | if (type==typeof(byte[]) ) return DbType.Binary; 52 | if (type==typeof(DateTime) ) return DbType.DateTime; 53 | if (type==typeof(Guid) ) return DbType.Guid; 54 | if (type==typeof(Decimal) ) return DbType.Decimal; 55 | if (type==typeof(TimeSpan)) return DbType.Time; 56 | if (type == typeof(DateTimeOffset)) return DbType.DateTimeOffset; 57 | return DbType.Object; 58 | } 59 | 60 | public virtual DbType Resolve(object value) { 61 | if (value!=null) 62 | return Resolve(value.GetType()); 63 | return DbType.Object; 64 | } 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/NI.Data/DbValueComparer.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2014 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Collections; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | 21 | namespace NI.Data { 22 | 23 | public class DbValueComparer : IComparer { 24 | 25 | static IComparer _Instance = new DbValueComparer(); 26 | 27 | public static IComparer Instance { 28 | get { 29 | return _Instance; 30 | } 31 | } 32 | 33 | public int Compare(object a, object b) { 34 | if (a == null && b == null) 35 | return 0; 36 | if (a == null && b != null) 37 | return -1; 38 | if (a != null && b == null) 39 | return 1; 40 | 41 | if ((a is IList) && (b is IList)) { 42 | IList aList = (IList)a; 43 | IList bList = (IList)b; 44 | if (aList.Count < bList.Count) 45 | return -1; 46 | if (aList.Count > bList.Count) 47 | return +1; 48 | for (int i = 0; i < aList.Count; i++) { 49 | int r = Compare(aList[i], bList[i]); 50 | if (r != 0) 51 | return r; 52 | } 53 | // lists are equal 54 | return 0; 55 | } 56 | if (a is IComparable) { 57 | 58 | // try to convert b to a type (because standard impl of IComparable for simple types are stupid enough) 59 | try { 60 | object bConverted = Convert.ChangeType(b, a.GetType()); 61 | return ((IComparable)a).CompareTo(bConverted); 62 | } catch { 63 | } 64 | 65 | // try to compare without any conversions 66 | try { 67 | return ((IComparable)a).CompareTo(b); 68 | } catch { } 69 | 70 | 71 | } 72 | if (b is IComparable) { 73 | // try to compare without any conversions 74 | try { 75 | return -((IComparable)b).CompareTo(a); 76 | } catch { } 77 | 78 | // try to convert a to b type 79 | try { 80 | object aConverted = Convert.ChangeType(a, b.GetType()); 81 | return -((IComparable)b).CompareTo(aConverted); 82 | } catch { 83 | } 84 | } 85 | 86 | throw new Exception("Cannot compare"); 87 | } 88 | 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/IDalc.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Data; 18 | using System.Collections; 19 | using System.Collections.Generic; 20 | 21 | namespace NI.Data 22 | { 23 | 24 | /// 25 | /// Data access layer component interface 26 | /// 27 | /// Represents set of methods for accessing and updating tabular data source. 28 | public interface IDalc 29 | { 30 | 31 | /// 32 | /// Execute given query and passes data reader to handler 33 | /// 34 | /// query to execute 35 | /// execution result callback 36 | void ExecuteReader(Query q, Action handler); 37 | 38 | /// 39 | /// Load data into dataset by query 40 | /// 41 | /// query to load 42 | /// DataSet for results data 43 | /// DataTable loaded with query data 44 | DataTable Load(Query q, DataSet ds); 45 | 46 | /// 47 | /// Update data in datasource according to changes of specified DataTable 48 | /// 49 | /// DataTable with changed rows 50 | void Update(DataTable t); 51 | 52 | /// 53 | /// Update records in data source matched by query with specified changeset 54 | /// 55 | /// query 56 | /// Container with record changes 57 | /// number of updated records 58 | int Update(Query query, IDictionary data); 59 | 60 | /// 61 | /// Insert data from dictionary container to datasource 62 | /// 63 | /// Source name for data 64 | /// Container with record data 65 | void Insert(string tableName, IDictionary data); 66 | 67 | /// 68 | /// Delete data from dataset by query 69 | /// 70 | /// query that specifies data to delete 71 | /// number of deleted records 72 | int Delete(Query query); 73 | 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/IDataSetFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Data; 18 | 19 | namespace NI.Data 20 | { 21 | 22 | public interface IDataSetFactory { 23 | 24 | /// 25 | /// Get empty DataSet instance with schema for specified table name 26 | /// 27 | /// name of table 28 | /// DataSet with schema 29 | DataSet GetDataSet(string tableName); 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/IDbCommandGenerator.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Data; 18 | using System.ComponentModel; 19 | using System.Collections; 20 | using System.Collections.Generic; 21 | 22 | namespace NI.Data 23 | { 24 | 25 | /// 26 | /// Represents set of methods for constructing IDbCommand with appropriate SQL command 27 | /// 28 | public interface IDbCommandGenerator 29 | { 30 | /// 31 | /// Compose IDbCommand instance with SELECT by query 32 | /// 33 | IDbCommand ComposeSelect(Query query); 34 | 35 | /// 36 | /// Compose DB adapter update commands (insert,update,delete) for specified DataTable 37 | /// 38 | void ComposeAdapterUpdateCommands(IDbDataAdapter adapter, DataTable table); 39 | 40 | /// 41 | /// Compose IDbCommand with SQL insert for specified table name and column name -> value map 42 | /// 43 | IDbCommand ComposeInsert(string tableName, IDictionary data); 44 | 45 | /// 46 | /// Compose IDbCommand with SQL delete by query 47 | /// 48 | IDbCommand ComposeDelete(Query query); 49 | 50 | /// 51 | /// Compose IDbCommand with SQL update by query and specified column name -> value map 52 | /// 53 | IDbCommand ComposeUpdate(Query query, IDictionary data); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/IDbDalcView.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections; 18 | 19 | namespace NI.Data 20 | { 21 | /// 22 | /// Represents DALC data view methods and properties 23 | /// 24 | public interface IDbDalcView 25 | { 26 | 27 | /// 28 | /// Determines whether this dataview matches given table 29 | /// 30 | bool IsMatchTable(QTable table); 31 | 32 | /// 33 | /// Compose dataview SQL select text by specified query 34 | /// 35 | /// query to this dataview 36 | /// SQL builder 37 | /// dataview SQL select text 38 | string ComposeSelect(Query q, IDbSqlBuilder sqlBuilder); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/IDbProviderFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Data; 18 | using System.Data.Common; 19 | 20 | namespace NI.Data 21 | { 22 | 23 | /// 24 | /// Factory for creating database-specific ADO.NET implementations required by DALC components 25 | /// 26 | public interface IDbProviderFactory { 27 | 28 | /// 29 | /// Create data adapter and bind row updating/updated event handlers 30 | /// 31 | IDbDataAdapter CreateDataAdapter( 32 | EventHandler onRowUpdating, 33 | EventHandler onRowUpdated); 34 | 35 | /// 36 | /// Create command 37 | /// 38 | IDbCommand CreateCommand(); 39 | 40 | /// 41 | /// Create connection 42 | /// 43 | IDbConnection CreateConnection(); 44 | 45 | /// 46 | /// Add new constant parameter 47 | /// 48 | string AddCommandParameter(IDbCommand cmd, object value); 49 | 50 | /// 51 | /// Add new data column parameter 52 | /// 53 | string AddCommandParameter(IDbCommand cmd, DataColumn column, DataRowVersion sourceVersion); 54 | 55 | /// 56 | /// Creare SQL builder 57 | /// 58 | IDbSqlBuilder CreateSqlBuilder(IDbCommand dbCommand); 59 | 60 | /// 61 | /// Get ID of last inserted record 62 | /// 63 | object GetInsertId(IDbConnection connection); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/IDbSqlBuilder.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Data; 18 | using System.Data.Common; 19 | 20 | namespace NI.Data 21 | { 22 | /// 23 | /// Represents database-specific SQL builder interface. 24 | /// 25 | /// NI.Data.ISqlBuilder 26 | public interface IDbSqlBuilder : ISqlBuilder 27 | { 28 | /// 29 | /// Build SQL select command text by query 30 | /// 31 | string BuildSelect(Query query); 32 | 33 | /// 34 | /// Build ORDER BY part of SQL command by query 35 | /// 36 | string BuildSort(Query query); 37 | 38 | /// 39 | /// Build SQL list of fields to select by 40 | /// 41 | string BuildFields(Query query); 42 | 43 | /// 44 | /// Build command parameter by value and return SQL placeholder text 45 | /// 46 | string BuildCommandParameter(object value); 47 | 48 | /// 49 | /// Build command parameter by DataColumn and return SQL placeholder text 50 | /// 51 | string BuildCommandParameter(DataColumn col, DataRowVersion sourceVersion); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/IObjectDataRowMapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | using System.Data; 6 | 7 | namespace NI.Data { 8 | 9 | /// 10 | /// Represents set of methods for two-directional mapping between DataRow and object 11 | /// 12 | public interface IObjectDataRowMapper { 13 | 14 | /// 15 | /// Map DataRow values to specified object 16 | /// 17 | /// source DataRow 18 | /// target object 19 | void MapTo(DataRow r, object o); 20 | 21 | /// 22 | /// Map object data to DataRow 23 | /// 24 | /// source object 25 | /// target DataRow 26 | /// skip mapping for PK values 27 | void MapFrom(object o, DataRow r, bool skipPk); 28 | 29 | /// 30 | /// Get object's value by specified DataColumn 31 | /// 32 | /// object 33 | /// DataColumn 34 | /// value which corresponds to specified DataColumn 35 | object GetFieldValue(object o, DataColumn c); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/IQueryValue.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | 18 | namespace NI.Data 19 | { 20 | /// 21 | /// Marker interface for query value object 22 | /// 23 | public interface IQueryValue 24 | { 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/ISqlBuilder.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | 18 | namespace NI.Data 19 | { 20 | /// 21 | /// Represents abstract SQL builder interface. 22 | /// 23 | public interface ISqlBuilder 24 | { 25 | /// 26 | /// Build string representation of specified IQueryValue 27 | /// 28 | string BuildValue(IQueryValue v); 29 | 30 | /// 31 | /// Build string representation of specified sort field 32 | /// 33 | string BuildSort(QSort sortFld); 34 | 35 | /// 36 | /// Build string representation of specified QueryNode (condition) 37 | /// 38 | string BuildExpression(QueryNode node); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/NI.Data/Interfaces/ISqlDalc.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Data; 18 | using System.Collections; 19 | 20 | namespace NI.Data 21 | { 22 | 23 | /// 24 | /// Represents SQL-specified DALC component 25 | /// 26 | public interface ISqlDalc : IDalc { 27 | 28 | /// 29 | /// Execute SQL command 30 | /// 31 | /// SQL command text 32 | /// number of affected records 33 | int ExecuteNonQuery(string sqlText); 34 | 35 | /// 36 | /// Execute given raw SQL and return data reader 37 | /// 38 | void ExecuteReader(string sqlText, Action handler); 39 | 40 | /// 41 | /// Execute custom SQL command and store result in specified dataset 42 | /// 43 | void Load(string sqlText, DataSet ds); 44 | 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/NI.Data/Linq/DalcData.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections; 18 | using System.Collections.Generic; 19 | using System.Linq; 20 | using System.Linq.Expressions; 21 | using System.Text; 22 | 23 | namespace NI.Data.Linq 24 | { 25 | public class DalcData : IOrderedQueryable { 26 | QueryProvider QueryPrv; 27 | Expression Expr; 28 | 29 | internal DalcData(QueryProvider provider) 30 | { 31 | QueryPrv = provider; 32 | Expr = Expression.Constant(this); 33 | } 34 | 35 | internal DalcData(QueryProvider provider, Expression expression) { 36 | QueryPrv = provider; 37 | Expr = expression; 38 | } 39 | 40 | public IEnumerator GetEnumerator() { 41 | return (QueryPrv.Execute>(Expression)).GetEnumerator(); 42 | } 43 | 44 | IEnumerator IEnumerable.GetEnumerator() 45 | { 46 | return (QueryPrv.Execute(Expression)).GetEnumerator(); 47 | } 48 | 49 | public Type ElementType 50 | { 51 | get { return typeof(TData); } 52 | } 53 | 54 | public Expression Expression 55 | { 56 | get { return Expr; } 57 | } 58 | 59 | public System.Linq.IQueryProvider Provider 60 | { 61 | get { return QueryPrv; } 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/NI.Data/Linq/DalcLinqExtensions.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | using System.Text; 20 | 21 | namespace NI.Data.Linq 22 | { 23 | public static class DalcLinqExtensions 24 | { 25 | public static IQueryable Linq(this IDalc dalc, string tableName) 26 | { 27 | return new DalcData(new QueryProvider(tableName, dalc)); 28 | } 29 | 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/NI.Data/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace NI.Data { 8 | 9 | /// 10 | /// Internal NI.Data assembly logger 11 | /// 12 | /// Default handlers use Trace and Debug classes 13 | public class Logger { 14 | 15 | static Action error; 16 | static Action debug; 17 | static Action info; 18 | 19 | static Logger() { 20 | error = TraceError; 21 | info = TraceInfo; 22 | debug = DebugPrint; 23 | } 24 | 25 | Type t; 26 | 27 | public Logger(Type t) { 28 | this.t = t; 29 | } 30 | 31 | public static void SetError(Action errorHandler) { 32 | error = errorHandler; 33 | } 34 | public static void SetDebug(Action debugHandler) { 35 | debug = debugHandler; 36 | } 37 | public static void SetInfo(Action infoHandler) { 38 | info = infoHandler; 39 | } 40 | 41 | static void TraceError(Type t, string m) { 42 | Trace.TraceError("[{0}] {1}", t, m); 43 | } 44 | 45 | static void TraceInfo(Type t, string m) { 46 | Trace.TraceInformation("[{0}] {1}", t, m); 47 | } 48 | 49 | static void DebugPrint(Type t, string m) { 50 | System.Diagnostics.Debug.Print( "[{0}] {1}", t, m ); 51 | } 52 | 53 | public void Error(string s) { 54 | if (error!=null) 55 | error(t,s); 56 | } 57 | 58 | public void Error(string s, params object[] args) { 59 | Error( String.Format(s,args) ); 60 | } 61 | 62 | public void Info(string s) { 63 | if (info != null) 64 | info(t,s); 65 | } 66 | 67 | public void Info(string s, params object[] args) { 68 | Info(String.Format(s, args)); 69 | } 70 | 71 | public void Debug(string s) { 72 | if (debug != null) 73 | debug(t,s); 74 | } 75 | 76 | public void Debug(string s, params object[] args) { 77 | Debug(String.Format(s, args)); 78 | } 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/NI.Data/NI.Data.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | Vitalii Fedorchenko 8 | $author$ 9 | 10 | http://www.nrecosite.com/dalc_net.aspx 11 | 12 | false 13 | $description$ 14 | 15 | Copyright 2004-2012 NewtonIdeas, v2 2013-2014 Vitalii Fedorchenko 16 | DAL DataBase ADO.NET Data 17 | 18 | -------------------------------------------------------------------------------- /src/NI.Data/Permissions/IQueryRule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace NI.Data.Permissions { 7 | 8 | /// 9 | /// Represents query rule used by 10 | /// 11 | public interface IQueryRule { 12 | QueryNode ComposeCondition(PermissionContext context); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/NI.Data/Permissions/PermissionContext.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Security; 18 | using System.Security.Principal; 19 | using System.Threading; 20 | using System.Collections.Generic; 21 | using System.Globalization; 22 | 23 | namespace NI.Data.Permissions 24 | { 25 | /// 26 | /// Represents query permission context 27 | /// 28 | public class PermissionContext 29 | { 30 | public string TableName { get; private set; } 31 | 32 | public DalcOperation Operation { get; private set; } 33 | 34 | public IPrincipal Principal { get; private set; } 35 | 36 | public PermissionContext(string tableName, DalcOperation operation) { 37 | TableName = tableName; 38 | Principal = Thread.CurrentPrincipal; 39 | Operation = operation; 40 | } 41 | 42 | public string IdentityName { 43 | get { 44 | return Principal != null && Principal.Identity != null ? Principal.Identity.Name : null; 45 | } 46 | } 47 | 48 | public bool IsInRole(string role) { 49 | return Principal!=null ? Principal.IsInRole(role) : false; 50 | } 51 | 52 | public virtual object GetValue(string varName) { 53 | var memberName = varName.Trim(); 54 | var t = this.GetType(); 55 | var p = t.GetProperty(memberName); 56 | if (p!=null) { 57 | return p.GetValue(this, null); 58 | } 59 | if (memberName.IndexOf('(')>0 && memberName[memberName.Length-1] == ')') { 60 | var methodParts = varName.Split(new[]{'(',')'}, StringSplitOptions.RemoveEmptyEntries ); 61 | var m = t.GetMethod(methodParts[0]); 62 | if (m!=null && m.GetParameters().Length==1) { 63 | var param = m.GetParameters()[0]; 64 | return m.Invoke(this, new[] { Convert.ChangeType(methodParts[1], param.ParameterType, CultureInfo.InvariantCulture) }); 65 | } 66 | } 67 | return null; 68 | } 69 | } 70 | 71 | [Flags] 72 | public enum DalcOperation { 73 | Select = 1, 74 | Update = 2, 75 | Delete = 4, 76 | Change = 2+4, 77 | Any = 1+2+4 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/NI.Data/PropertyDataRowMapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Globalization; 5 | 6 | using System.Data; 7 | 8 | namespace NI.Data { 9 | 10 | /// 11 | /// Maps object properties to DataRow column values 12 | /// 13 | public class PropertyDataRowMapper : IObjectDataRowMapper { 14 | 15 | public IDictionary FieldToProperty { get; private set; } 16 | 17 | public PropertyDataRowMapper(IDictionary fieldToProperty) { 18 | FieldToProperty = fieldToProperty; 19 | } 20 | 21 | public virtual object GetFieldValue(object o, DataColumn c) { 22 | var pInfo = o.GetType().GetProperty(GetPropertyName(c.ColumnName)); 23 | if (pInfo == null) 24 | return null; 25 | return pInfo.GetValue(o, null); 26 | } 27 | 28 | public virtual void MapTo(DataRow r, object o) { 29 | foreach (DataColumn c in r.Table.Columns) { 30 | var pInfo =o.GetType().GetProperty(GetPropertyName(c.ColumnName)); 31 | if (pInfo != null) { 32 | var rVal = r[c]; 33 | if (rVal == null || DBNull.Value.Equals(rVal)) { 34 | rVal = null; 35 | if (Nullable.GetUnderlyingType(pInfo.PropertyType) == null && pInfo.PropertyType.IsValueType) 36 | rVal = Activator.CreateInstance(pInfo.PropertyType); 37 | } else { 38 | var propType = pInfo.PropertyType; 39 | if (Nullable.GetUnderlyingType(propType) != null) 40 | propType = Nullable.GetUnderlyingType(propType); 41 | 42 | if (propType.IsEnum) { 43 | rVal = Enum.Parse(propType, rVal.ToString(), true); 44 | } else { 45 | rVal = Convert.ChangeType(rVal, propType, CultureInfo.InvariantCulture); 46 | } 47 | } 48 | pInfo.SetValue(o, rVal, null); 49 | } 50 | } 51 | 52 | } 53 | 54 | public virtual void MapFrom(object o, DataRow r, bool skipPk) { 55 | foreach (DataColumn c in r.Table.Columns) { 56 | var pInfo = o.GetType().GetProperty(GetPropertyName(c.ColumnName)); 57 | if (pInfo == null) 58 | continue; 59 | if (skipPk && Array.IndexOf(r.Table.PrimaryKey, c) >= 0) 60 | continue; 61 | var pVal = pInfo.GetValue(o, null); 62 | if (pVal == null) { 63 | if (c.AutoIncrement) 64 | continue; 65 | pVal = DBNull.Value; 66 | } else { 67 | pVal = Convert.ChangeType(pVal, c.DataType, CultureInfo.InvariantCulture); 68 | } 69 | r[c] = pVal; 70 | } 71 | 72 | } 73 | 74 | protected string GetPropertyName(string fldName) { 75 | return FieldToProperty != null && FieldToProperty.ContainsKey(fldName) ? FieldToProperty[fldName] : fldName; 76 | } 77 | 78 | 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/NI.Data/Query/QRawSql.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Diagnostics; 18 | 19 | namespace NI.Data 20 | { 21 | /// 22 | /// Represents raw SQL query value 23 | /// 24 | [DebuggerDisplay("{SqlText}")] 25 | [Serializable] 26 | public class QRawSql : IQueryValue { 27 | 28 | /// 29 | /// Get SQL text 30 | /// 31 | public string SqlText { 32 | get; private set; 33 | } 34 | 35 | /// 36 | /// Initializes a new instance of the QRawSql with specfield SQL text 37 | /// 38 | /// 39 | public QRawSql(string sqlText) { 40 | SqlText = sqlText; 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/NI.Data/Query/QTable.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.ComponentModel; 18 | using System.Diagnostics; 19 | using System.Text.RegularExpressions; 20 | 21 | namespace NI.Data 22 | { 23 | /// 24 | /// Represents query table information 25 | /// 26 | [DebuggerDisplay("{Name}")] 27 | [Serializable] 28 | public class QTable 29 | { 30 | 31 | /// 32 | /// Get source name (string identifier) 33 | /// 34 | public string Name { get; private set; } 35 | 36 | /// 37 | /// Get source name alias used in query nodes 38 | /// 39 | public string Alias { get; private set; } 40 | 41 | /// 42 | /// Initializes a new instance of the QSource with the specified source name 43 | /// 44 | /// source name string 45 | public QTable(string tableName) { 46 | int dotIdx = tableName.LastIndexOf('.'); // allow dot in table name (alias for this case is required), like dbo.users.u 47 | if (dotIdx >= 0) { 48 | Name = tableName.Substring(0, dotIdx); 49 | Alias = tableName.Substring(dotIdx+1); 50 | } 51 | else { 52 | Name = tableName; 53 | Alias = null; 54 | } 55 | 56 | } 57 | 58 | /// 59 | /// Initializes a new instance of the QSource with the specified source name and alias 60 | /// 61 | /// source name string 62 | /// alias string 63 | public QTable(string tableName, string alias) { 64 | Name = tableName; 65 | Alias = alias; 66 | } 67 | 68 | /// 69 | /// Returns a string representation of this QSource 70 | /// 71 | /// string that represents QSource in [name].[alias] format 72 | public override string ToString() { 73 | return String.IsNullOrEmpty(Alias) ? Name : Name+"."+Alias; 74 | } 75 | 76 | public static implicit operator QTable(string value) { 77 | return new QTable(value); 78 | } 79 | public static implicit operator string(QTable value) { 80 | return value.ToString(); 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/NI.Data/Query/QueryConditionNode.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Diagnostics; 19 | 20 | 21 | namespace NI.Data { 22 | 23 | [DebuggerDisplay("{LValue} {Condition} {RValue}")] 24 | [Serializable] 25 | public class QueryConditionNode : QueryNode { 26 | 27 | private IQueryValue _LValue; 28 | private Conditions _Condition; 29 | private IQueryValue _RValue; 30 | 31 | public IQueryValue LValue { 32 | get { return _LValue; } 33 | } 34 | 35 | public Conditions Condition { 36 | get { return _Condition; } 37 | } 38 | 39 | public IQueryValue RValue { 40 | get { return _RValue; } 41 | } 42 | 43 | public override IList Nodes { 44 | get { 45 | var l = new List(); 46 | if (LValue is QueryNode) 47 | l.Add( (QueryNode)LValue ); 48 | if (RValue is QueryNode) 49 | l.Add( (QueryNode)RValue ); 50 | return l; 51 | } 52 | } 53 | 54 | 55 | public QueryConditionNode(IQueryValue lvalue, Conditions conditions, IQueryValue rvalue) { 56 | _RValue = rvalue; 57 | _Condition = conditions; 58 | _LValue = lvalue; 59 | } 60 | 61 | public QueryConditionNode(string name, IQueryValue lvalue, Conditions conditions, IQueryValue rvalue) : 62 | this(lvalue, conditions, rvalue) { 63 | Name = name; 64 | } 65 | 66 | public QueryConditionNode(QueryConditionNode node) { 67 | Name = node.Name; 68 | _LValue = node.LValue; 69 | _Condition = node.Condition; 70 | _RValue = node.RValue; 71 | } 72 | 73 | } 74 | 75 | [Flags] 76 | public enum Conditions { 77 | Equal = 1, 78 | LessThan = 2, 79 | GreaterThan = 4, 80 | Like = 8, 81 | In = 16, 82 | Null = 32, 83 | Not = 64 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/NI.Data/Query/QueryNegationNode.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Diagnostics; 19 | using System.Runtime.Serialization; 20 | 21 | namespace NI.Data { 22 | 23 | /// 24 | /// Represents logical negation operator 25 | /// 26 | [DebuggerDisplay("{Nodes}")] 27 | [Serializable] 28 | public class QueryNegationNode : QueryNode { 29 | 30 | private QueryNode[] SingleNodeList; 31 | 32 | [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] 33 | public override IList Nodes { 34 | get { return SingleNodeList; } 35 | } 36 | 37 | /// 38 | /// Initializes a new instance of the QueryNegationNode that wraps specified node 39 | /// 40 | /// condition node to negate 41 | public QueryNegationNode(QueryNode node) { 42 | SingleNodeList = new QueryNode[] { node }; 43 | } 44 | 45 | public QueryNegationNode(QueryNegationNode copyNode) { 46 | SingleNodeList = new QueryNode[] { copyNode.Nodes[0] }; 47 | Name = copyNode.Name; 48 | } 49 | 50 | 51 | } 52 | 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/NI.Data/Query/QueryNode.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | 19 | namespace NI.Data 20 | { 21 | /// 22 | /// Represents abstract query node that contains child nodes. 23 | /// 24 | [Serializable] 25 | public abstract class QueryNode 26 | { 27 | public abstract IList Nodes { get; } 28 | 29 | public string Name { get; set; } 30 | 31 | internal QueryNode() { 32 | } 33 | 34 | /// 35 | /// OR operator 36 | /// 37 | public static QueryGroupNode operator | (QueryNode node1, QueryNode node2) { 38 | QueryGroupNode res = new QueryGroupNode(QueryGroupNodeType.Or); 39 | res.Nodes.Add(node1); 40 | res.Nodes.Add(node2); 41 | return res; 42 | } 43 | 44 | /// 45 | /// AND operator 46 | /// 47 | public static QueryGroupNode operator & (QueryNode node1, QueryNode node2) { 48 | QueryGroupNode res = new QueryGroupNode(QueryGroupNodeType.And); 49 | res.Nodes.Add(node1); 50 | res.Nodes.Add(node2); 51 | return res; 52 | } 53 | 54 | 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/NI.Data/Query/QueryRawSqlNode.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Diagnostics; 19 | using System.Runtime.Serialization; 20 | 21 | namespace NI.Data { 22 | 23 | [DebuggerDisplay("{SqlText}")] 24 | [Serializable] 25 | public class QueryRawSqlNode : QueryNode { 26 | 27 | /// 28 | /// Nodes collection 29 | /// 30 | public override IList Nodes { get { return new QueryNode[0]; } } 31 | 32 | public string SqlText { 33 | get; private set; 34 | } 35 | 36 | public QueryRawSqlNode(string sqlText) { 37 | SqlText = sqlText; 38 | } 39 | 40 | 41 | 42 | 43 | } 44 | 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/NI.Data/SqlClient/SqlClientDalcFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Copyright 2008-2013 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Data; 18 | using System.Data.Common; 19 | using System.Data.SqlClient; 20 | using System.ComponentModel; 21 | 22 | namespace NI.Data.SqlClient 23 | { 24 | 25 | public class SqlClientDalcFactory : GenericDbProviderFactory 26 | { 27 | 28 | public bool TopOptimization { get; set; } 29 | 30 | public bool ConstOptimization { get; set; } 31 | 32 | public bool NameBrackets { get; set; } 33 | 34 | public SqlClientDalcFactory() : base(SqlClientFactory.Instance) { 35 | TopOptimization = false; 36 | ConstOptimization = false; 37 | NameBrackets = false; 38 | } 39 | 40 | public override IDbSqlBuilder CreateSqlBuilder(IDbCommand dbCommand) { 41 | return new SqlClientDbSqlBuilder(dbCommand, this); 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/NI.Data/Triggers/DataRowActionType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace NI.Data.Triggers { 7 | 8 | [Flags] 9 | public enum DataRowActionType { 10 | None = 0, 11 | 12 | /// 13 | /// Occurs before row insert. 14 | /// 15 | Inserting = 1, 16 | 17 | /// 18 | /// Occurs after row insert. 19 | /// 20 | Inserted = 2, 21 | 22 | /// 23 | /// Occurs before row update. 24 | /// 25 | Updating = 4, 26 | 27 | /// 28 | /// Occurs after row update 29 | /// 30 | Updated = 8, 31 | 32 | /// 33 | /// Occurs before row delete 34 | /// 35 | Deleting = 16, 36 | 37 | /// 38 | /// Occurs after row delete 39 | /// 40 | Deleted = 32, 41 | 42 | /// 43 | /// Inserting or Updating 44 | /// 45 | Saving = 1 + 4, 46 | 47 | /// 48 | /// Inserted or Updated 49 | /// 50 | Saved = 2 + 8, 51 | 52 | /// 53 | /// Any data row action 54 | /// 55 | Any = 1+2+4+8+16+32 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/NI.Data/Triggers/InvalidateDataDependencyTrigger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Specialized; 4 | using System.Collections.Generic; 5 | using System.Data.Common; 6 | using System.Text; 7 | 8 | using System.Data; 9 | using NI.Data; 10 | 11 | using NI.Data.Triggers; 12 | 13 | namespace NI.Data.Web { 14 | 15 | /// 16 | /// Triggers DataCacheDependency invalidation by data modification events 17 | /// 18 | public class InvalidateDataDependencyTrigger { 19 | 20 | static Logger log = new Logger(typeof(DataRowTrigger)); 21 | 22 | public string DataSourceID { get; set; } 23 | 24 | public InvalidateDataDependencyTrigger(string dataSourceId, DataEventBroker broker) { 25 | broker.Subscribe( IsMatch, new EventHandler(RowUpdatedHandler) ); 26 | } 27 | 28 | public virtual void RowUpdatedHandler(object sender, RowUpdatedEventArgs e) { 29 | if (!IsMatch(e)) 30 | return; 31 | 32 | var tblName = e.Row.Table.TableName; 33 | try { 34 | log.Debug("NotifyChanged (DataSource={0}, TableName={1}) deps count = {2}", DataSourceID, tblName, DataCacheDependency.DependencyPool.Count); 35 | DataCacheDependency.NotifyChanged(DataSourceID, tblName); 36 | } catch (Exception ex) { 37 | log.Error("Cache invalidation failed during NotifyChanged (DataSource={1}, TableName={2}): {0}", 38 | ex, DataSourceID, tblName); 39 | } 40 | 41 | } 42 | 43 | protected virtual bool IsMatch(EventArgs e) { 44 | if (!(e is RowUpdatedEventArgs)) return false; 45 | var statementType = ((RowUpdatedEventArgs)e).StatementType; 46 | return 47 | statementType==StatementType.Insert || 48 | statementType==StatementType.Update || 49 | statementType==StatementType.Delete; 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/NI.Data/Web/DalcDataSourceChangeEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2014 NewtonIdeas 5 | * Copyright 2008-2014 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Collections; 19 | using System.ComponentModel; 20 | using System.Linq; 21 | using System.Text; 22 | 23 | namespace NI.Data.Web { 24 | 25 | public class DalcDataSourceChangeEventArgs : CancelEventArgs { 26 | string _TableName; 27 | IDictionary _OldValues; 28 | IDictionary _Values; 29 | IDictionary _Keys; 30 | int _AffectedCount; 31 | 32 | public string TableName { 33 | get { return _TableName; } 34 | set { _TableName = value; } 35 | } 36 | 37 | public IDictionary OldValues { 38 | get { return _OldValues; } 39 | set { _OldValues = value; } 40 | } 41 | 42 | public IDictionary Values { 43 | get { return _Values; } 44 | set { _Values = value; } 45 | } 46 | 47 | public IDictionary Keys { 48 | get { return _Keys; } 49 | set { _Keys = value; } 50 | } 51 | public int AffectedCount { 52 | get { return _AffectedCount; } 53 | internal set { _AffectedCount = value; } 54 | } 55 | 56 | public DalcDataSourceChangeEventArgs(string tableName, IDictionary keys, IDictionary oldValues, IDictionary newValues) { 57 | TableName = tableName; 58 | Keys = keys; 59 | OldValues = oldValues; 60 | Values = newValues; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/NI.Data/Web/DalcDataSourceSelectEventArgs.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2014 NewtonIdeas 5 | * Copyright 2008-2014 Vitalii Fedorchenko (changes and v.2) 6 | * Distributed under the LGPL licence 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | #endregion 15 | 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Collections; 19 | using System.ComponentModel; 20 | using System.Linq; 21 | using System.Text; 22 | using System.Data; 23 | using System.Web.UI; 24 | 25 | namespace NI.Data.Web { 26 | 27 | public class DalcDataSourceSelectEventArgs : CancelEventArgs { 28 | Query _SelectQuery; 29 | DataSet _Data; 30 | DataSourceSelectArguments _SelectArgs; 31 | 32 | public Query SelectQuery { 33 | get { return _SelectQuery; } 34 | set { _SelectQuery = value; } 35 | } 36 | 37 | public DataSet Data { 38 | get { return _Data; } 39 | set { _Data = value; } 40 | } 41 | 42 | public DataSourceSelectArguments SelectArgs { 43 | get { return _SelectArgs; } 44 | set { _SelectArgs = value; } 45 | } 46 | 47 | public int FetchedRowCount { 48 | get { return Data.Tables[SelectQuery.Table].Rows.Count; } 49 | } 50 | 51 | public DalcDataSourceSelectEventArgs(Query q, DataSourceSelectArguments args, DataSet ds) { 52 | SelectQuery = q; 53 | SelectArgs = args; 54 | Data = ds; 55 | } 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/NI.Data/Web/DataCacheDependency.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Web.Caching; 6 | 7 | namespace NI.Data.Web { 8 | 9 | /// 10 | /// Establishes a relationship between an item stored in an ASP.NET application's Cache object and the results of data query 11 | /// 12 | public class DataCacheDependency : CacheDependency { 13 | 14 | internal static List DependencyPool = new List(); 15 | 16 | public string DataSource { get; private set; } 17 | public string[] TableNames { get; private set; } 18 | 19 | /// 20 | /// Initializes a new instance of the DataCacheDependency and creates dependency from specified data table 21 | /// 22 | /// unique data source identifier 23 | /// data table name 24 | public DataCacheDependency(string dataSourceId, string tableName) : this(dataSourceId,new[]{tableName}) { 25 | } 26 | 27 | /// 28 | /// Initializes a new instance of the DataCacheDependency and creates dependency from specified data tables 29 | /// 30 | /// unique data source identifier 31 | /// list of data table names 32 | public DataCacheDependency(string dataSourceId, string[] tableNames) { 33 | DataSource = dataSourceId; 34 | TableNames = tableNames; 35 | lock (DependencyPool) { 36 | DependencyPool.Add(this); 37 | } 38 | } 39 | 40 | public virtual bool IsMatch(string dataSource, string tableName) { 41 | return DataSource==dataSource && Array.IndexOf(TableNames,tableName)>=0; 42 | } 43 | 44 | public static void NotifyChanged(string dataSourceId, string tableName) { 45 | for (int i = 0; i < DependencyPool.Count; i++) { 46 | var dep = DependencyPool[i]; 47 | if (!dep.Disposed && dep.IsMatch(dataSourceId, tableName)) 48 | dep.NotifyDependencyChanged(dep, EventArgs.Empty); 49 | } 50 | } 51 | 52 | bool Disposed = false; 53 | protected override void DependencyDispose() { 54 | if (!Disposed) { 55 | Disposed = true; 56 | lock (DependencyPool) { 57 | DependencyPool.Remove(this); 58 | } 59 | } 60 | base.DependencyDispose(); 61 | } 62 | 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/NI.Ioc/ArrayFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Collections; 17 | 18 | 19 | 20 | namespace NI.Ioc 21 | { 22 | /// 23 | /// ArrayFactory used for defining typed arrays inside Winter configuration. 24 | /// 25 | /// 26 | /// <component name="intArray" type="NI.Ioc.ArrayFactory,NI.Ioc" singleton="true"> 27 | /// <property name="ElementType"><type>System.Int32,mscorlib</type></property> 28 | /// <property name="Elements"><list><entry>1</entry></list></property> 29 | /// </component> 30 | /// 31 | /// 32 | public class ArrayFactory : IFactoryComponent 33 | { 34 | Type _ElementType; 35 | IEnumerable _Elements; 36 | 37 | /// 38 | /// Get or set array element type 39 | /// 40 | public Type ElementType { 41 | get { return _ElementType; } 42 | set { _ElementType = value; } 43 | } 44 | 45 | /// 46 | /// Get or set enumerations of array 47 | /// 48 | public IEnumerable Elements { 49 | get { return _Elements; } 50 | set { _Elements = value; } 51 | } 52 | 53 | /// 54 | /// Default Constructor 55 | /// 56 | public ArrayFactory() 57 | { 58 | } 59 | 60 | public object GetObject() { 61 | ArrayList list = new ArrayList(); 62 | foreach (object o in Elements) 63 | if (!(o is IConvertible)) 64 | list.Add( o ); 65 | else 66 | list.Add( Convert.ChangeType(o, ElementType) ); 67 | return list.ToArray(ElementType); 68 | } 69 | 70 | public Type GetObjectType() { 71 | return Array.CreateInstance(ElementType, 0).GetType(); 72 | } 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/NI.Ioc/BaseMethodInvokingFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | 20 | public abstract class BaseMethodInvokingFactory 21 | { 22 | /// 23 | /// Get or set target method args values 24 | /// 25 | public object[] TargetMethodArgs { get; set; } 26 | 27 | /// 28 | /// Get or set target method args types 29 | /// 30 | public Type[] TargetMethodArgTypes { get; set; } 31 | 32 | public BaseMethodInvokingFactory() 33 | { 34 | } 35 | 36 | protected Type[] ResolveMethodArgTypes() { 37 | if (TargetMethodArgTypes != null) 38 | return TargetMethodArgTypes; 39 | int argsCount = TargetMethodArgs != null ? TargetMethodArgs.Length : 0; 40 | Type[] argTypes = new Type[argsCount]; 41 | for (int i = 0; i < argTypes.Length; i++) 42 | argTypes[i] = TargetMethodArgs[i] != null ? TargetMethodArgs[i].GetType() : typeof(object); 43 | return argTypes; 44 | } 45 | 46 | protected object[] PrepareMethodArgs(object[] args, Type[] argTypes) { 47 | object[] argValues = args!=null ? new object[args.Length] : new object[0]; 48 | for (int i=0; i 21 | /// ServiceProviderContext used for referencing to IoC container inside its configuration. 22 | /// 23 | public class ComponentFactoryContext : IComponentFactoryAware, IFactoryComponent 24 | { 25 | 26 | /// 27 | /// Get or set context service provider 28 | /// 29 | public IComponentFactory ComponentFactory { 30 | get; set; 31 | } 32 | 33 | public object GetObject() { 34 | return ComponentFactory; 35 | } 36 | 37 | public Type GetObjectType() { 38 | return typeof(IComponentFactory); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/NI.Ioc/ComponentFactoryExt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace NI.Ioc { 7 | 8 | /// 9 | /// Common IComponentFactory interface extensions 10 | /// 11 | public static class ComponentFactoryExt { 12 | 13 | /// 14 | /// Return an instance of the specified component that match specified type. 15 | /// 16 | /// type the component must match 17 | /// 18 | /// component instance of desired type 19 | public static T GetComponent(this IComponentFactory factory, string name) { 20 | return (T)factory.GetComponent(name, typeof(T)); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/NI.Ioc/ComponentFactoryInvokingFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// Factory that returns specific component from owning component factory. 21 | /// 22 | public class ComponentFactoryInvokingFactory : IComponentFactoryAware, IFactoryComponent 23 | { 24 | 25 | /// 26 | /// Get or set component factory instance 27 | /// 28 | public IComponentFactory ComponentFactory { get; set; } 29 | 30 | /// 31 | /// Get or set component name to retrieve from component factory 32 | /// 33 | public string ServiceName { get; set; } 34 | 35 | public ComponentFactoryInvokingFactory() 36 | { 37 | } 38 | 39 | public object GetObject() { 40 | return ComponentFactory.GetComponent(ServiceName); 41 | } 42 | 43 | public Type GetObjectType() { 44 | return typeof(object); 45 | } 46 | 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/NI.Ioc/DependencyAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.ComponentModel; 17 | using System.Reflection; 18 | 19 | namespace NI.Ioc { 20 | 21 | /// 22 | /// This attribute is used to mark properties as targets for injection. 23 | /// 24 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 25 | public class DependencyAttribute : Attribute 26 | { 27 | 28 | /// 29 | /// Get or set flag that indicates whether target property is required dependency 30 | /// 31 | public string Name { get; private set; } 32 | 33 | /// 34 | /// Create an instance of DependencyAttribute with no name (injection by type). 35 | /// 36 | public DependencyAttribute() { 37 | } 38 | 39 | /// 40 | /// Create an instance of DependencyAttribute with the given name. 41 | /// 42 | public DependencyAttribute(string name) { 43 | Name = name; 44 | } 45 | 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/NI.Ioc/Exceptions/XmlConfigurationException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace NI.Ioc.Exceptions { 7 | 8 | [Serializable] 9 | public class XmlConfigurationException : Exception { 10 | 11 | public XmlConfigurationException(string msg) 12 | : base(msg) { 13 | 14 | } 15 | 16 | public XmlConfigurationException(string msg, Exception inner) 17 | : base(msg, inner) { 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/NI.Ioc/IndexerInvokingFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Reflection; 17 | 18 | namespace NI.Ioc { 19 | 20 | /// 21 | /// Factory component which returns a value represented by specified object's indexer property. 22 | /// 23 | public class IndexerInvokingFactory : IFactoryComponent { 24 | /// 25 | /// Get or set target object 26 | /// 27 | public object TargetObject { get; set; } 28 | 29 | /// 30 | /// Get or set indexer arguments 31 | /// 32 | public object[] IndexerArgs { get; set; } 33 | 34 | public IndexerInvokingFactory() { 35 | } 36 | 37 | public object GetObject() { 38 | IndexerProxy indexer = new IndexerProxy(TargetObject); 39 | return indexer[IndexerArgs]; 40 | } 41 | 42 | public Type GetObjectType() { 43 | IndexerProxy indexer = new IndexerProxy(TargetObject); 44 | return indexer[IndexerArgs]!=null ? indexer[IndexerArgs].GetType() : typeof(object); 45 | } 46 | 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/NI.Ioc/IndexerProxy.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Collections; 17 | using System.Linq; 18 | using System.Reflection; 19 | 20 | namespace NI.Ioc 21 | { 22 | 23 | // Proxy-class that can be used for accessing indexer of an object 24 | internal class IndexerProxy { 25 | object IndexedObj; 26 | 27 | public IndexerProxy(object indexed_obj) { 28 | IndexedObj = indexed_obj; 29 | } 30 | 31 | public object this[params object[] i] { 32 | get { 33 | //special handling of arrays 34 | if (IndexedObj is Array) { 35 | return ((Array)IndexedObj).GetValue(i.Select(ii => Convert.ToInt32(ii)).ToArray()); 36 | } 37 | 38 | Type[] arg_types = new Type[i.Length]; 39 | for (int k = 0; k < i.Length; k++) 40 | arg_types[k] = i[k].GetType(); 41 | 42 | MethodInfo methodInfo = IndexedObj.GetType().GetMethod("get_Item", arg_types); 43 | if (methodInfo != null) 44 | return methodInfo.Invoke(IndexedObj, i); 45 | 46 | throw new NotImplementedException("Cannot find get indexer for such arguments"); 47 | } 48 | set { 49 | //special handling of arrays 50 | if (IndexedObj is Array) { 51 | ((Array)IndexedObj).SetValue(value, i.Select(ii => Convert.ToInt32(ii)).ToArray()); 52 | return; 53 | } 54 | 55 | Type[] arg_types = new Type[i.Length + 1]; 56 | object[] args = new object[i.Length + 1]; 57 | for (int k = 0; k < i.Length; k++) { 58 | arg_types[k] = i[k].GetType(); 59 | args[k] = i[k]; 60 | } 61 | arg_types[i.Length] = value != null ? value.GetType() : typeof(object); 62 | args[i.Length] = value; 63 | 64 | MethodInfo methodInfo = IndexedObj.GetType().GetMethod("set_Item", arg_types); 65 | if (methodInfo != null) 66 | methodInfo.Invoke(IndexedObj, args); 67 | else 68 | throw new NotImplementedException("Cannot find set indexer for such arguments"); 69 | } 70 | } 71 | 72 | } 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IComponentFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// The root interface for accessing a IoC components container. 21 | /// 22 | /// 23 | /// This is the basic client view of a components container. 24 | /// 25 | public interface IComponentFactory : IServiceProvider 26 | { 27 | /// 28 | /// Return an instance, which may be shared or independent, of specified component 29 | /// 30 | object GetComponent(string name); 31 | 32 | /// 33 | /// Return an instance, which may be shared or independent, of the specified component. 34 | /// 35 | /// component name 36 | /// type the component must match. Can be an interface or base of the actual class, or null for any match. 37 | /// component instance 38 | object GetComponent(string name, Type requiredType); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IComponentFactoryAware.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | 18 | 19 | namespace NI.Ioc 20 | { 21 | 22 | /// 23 | /// Interface to be implemented by components that wish to be aware of their owning IComponentFactory. 24 | /// 25 | public interface IComponentFactoryAware 26 | { 27 | /// 28 | /// Set owning service factory to component instance 29 | /// 30 | IComponentFactory ComponentFactory { set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IComponentFactoryConfiguration.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Collections; 17 | 18 | namespace NI.Ioc 19 | { 20 | /// 21 | /// Represents components graph configuration 22 | /// 23 | public interface IComponentFactoryConfiguration : IEnumerable 24 | { 25 | 26 | /// 27 | /// Get number of components definitions 28 | /// 29 | int Count { get; } 30 | 31 | /// 32 | /// Get component definition by name (alias) 33 | /// 34 | /// ICompanyInitInfo object or null 35 | IComponentInitInfo this[string name] { get; } 36 | 37 | /// 38 | /// Get component definition by System.Type 39 | /// 40 | /// ICompanyInitInfo object or null 41 | IComponentInitInfo this[Type type] { get; } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IComponentInitInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Collections; 17 | 18 | namespace NI.Ioc 19 | { 20 | /// 21 | /// Represents initialization information about component 22 | /// 23 | public interface IComponentInitInfo 24 | { 25 | 26 | /// 27 | /// Is this component a "singleton" (one shared instance). 28 | /// 29 | bool Singleton { get; } 30 | 31 | /// 32 | /// Is this object to be lazily initialized 33 | /// 34 | bool LazyInit { get; } 35 | 36 | /// 37 | /// Component name (string identifier). 38 | /// 39 | string Name { get; } 40 | 41 | /// 42 | /// Component System.Type 43 | /// 44 | Type ComponentType { get; } 45 | 46 | /// 47 | /// Component description text. Null by default. 48 | /// 49 | string Description { get; } 50 | 51 | /// 52 | /// Constructor arguments 53 | /// 54 | IValueInitInfo[] ConstructorArgs { get; } 55 | 56 | /// 57 | /// Properies to set 58 | /// 59 | IPropertyInitInfo[] Properties { get; } 60 | 61 | /// 62 | /// Initialization method name. Null by default. 63 | /// 64 | string InitMethod { get; } 65 | 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IFactoryComponent.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// Represents container factory component (component that implements custom object initialization logic) 21 | /// 22 | /// The root interface for accessing a inversion-of-control container. 23 | public interface IFactoryComponent 24 | { 25 | /// 26 | /// Returns an instance of the object this factory creates. 27 | /// 28 | /// constructed object instance 29 | object GetObject(); 30 | 31 | /// 32 | /// Returns the object type returned by the GetObject() method 33 | /// 34 | /// Type 35 | Type GetObjectType(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IMapEntryInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NI.Factory.Xml { 4 | /// 5 | /// IPropertyInfo 6 | /// 7 | public interface IMapEntryInfo { 8 | /// 9 | /// Entry key 10 | /// 11 | string Key { get; } 12 | 13 | /// 14 | /// Entry value 15 | /// 16 | IValueInfo Value { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IPropertyInitInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// Represents property initalization definition 21 | /// 22 | public interface IPropertyInitInfo 23 | { 24 | /// 25 | /// Property name 26 | /// 27 | string Name { get; } 28 | 29 | /// 30 | /// Property value 31 | /// 32 | IValueInitInfo Value { get; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IServiceProviderAware.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.ComponentModel; 17 | 18 | namespace NI.Ioc 19 | { 20 | /// 21 | /// Interface to be implemented by components that wish to be aware of their owning IServiceProvider. 22 | /// 23 | public interface IServiceProviderAware 24 | { 25 | IServiceProvider ServiceProvider { set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IValueFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// Factory used to initialize a new instance by IValueInitInfo 21 | /// 22 | public interface IValueFactory 23 | { 24 | object GetInstance(object value, Type requiredType); 25 | object GetInstance(IComponentInitInfo componentInfo, Type requiredType); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/NI.Ioc/Interfaces/IValueInitInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// Represents value initialization information 21 | /// 22 | public interface IValueInitInfo 23 | { 24 | object GetValue(IValueFactory factory, Type conversionType); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/NI.Ioc/NI.Ioc.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | Vitalii Fedorchenko 8 | $author$ 9 | 10 | http://www.nrecosite.com/ioc_container_net.aspx 11 | 12 | false 13 | $description$ 14 | 15 | Copyright 2004-2012 NewtonIdeas, v2 2013-2014 Vitalii Fedorchenko 16 | Ioc DependencyInjection DI XML 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/NI.Ioc/PropertyInvokingFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Reflection; 17 | 18 | namespace NI.Ioc { 19 | 20 | /// 21 | /// Factory component which returns a value represented by specified object's property. 22 | /// 23 | public class PropertyInvokingFactory : IFactoryComponent { 24 | object _TargetObject; 25 | string _TargetProperty; 26 | 27 | /// 28 | /// Get or set target object 29 | /// 30 | public object TargetObject { get; set; } 31 | 32 | /// 33 | /// Get or set static target property name 34 | /// 35 | public string TargetProperty { get; set; } 36 | 37 | public PropertyInvokingFactory() { 38 | } 39 | 40 | public object GetObject() { 41 | Type targetType = TargetObject.GetType(); 42 | 43 | System.Reflection.PropertyInfo pInfo = targetType.GetProperty( TargetProperty, BindingFlags.Instance|BindingFlags.Public); 44 | if (pInfo==null) 45 | throw new MissingMemberException( targetType.ToString(), TargetProperty); 46 | return pInfo.GetValue( TargetObject, null ); 47 | } 48 | 49 | public Type GetObjectType() { 50 | Type targetType = TargetObject.GetType(); 51 | 52 | System.Reflection.PropertyInfo pInfo = targetType.GetProperty( TargetProperty, BindingFlags.Instance|BindingFlags.Public); 53 | if (pInfo==null) 54 | throw new MissingMemberException( targetType.ToString(), TargetProperty); 55 | return pInfo.PropertyType; 56 | } 57 | 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/NI.Ioc/ReplacingFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.ComponentModel; 17 | using System.Reflection; 18 | 19 | namespace NI.Ioc 20 | { 21 | /// 22 | /// Factory component which returns a specified object. 23 | /// 24 | /// 25 | /// <component name="testEnabled" type="NI.Ioc.ReplacingFactory,NI.Ioc" singleton="true"> 26 | /// <property name="TargetObject"><value><ref name="testEnabledVariable"/></property> 27 | /// </component> 28 | /// 29 | public class ReplacingFactory : IFactoryComponent 30 | { 31 | /// 32 | /// Get or set object to return 33 | /// 34 | public object TargetObject { get; set; } 35 | 36 | public ReplacingFactory() { 37 | } 38 | 39 | public ReplacingFactory(object target) { 40 | TargetObject = target; 41 | } 42 | 43 | public object GetObject() { 44 | return TargetObject; 45 | } 46 | 47 | public Type GetObjectType() { 48 | return TargetObject.GetType(); 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/NI.Ioc/Schema/ComponentInitInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Xml; 17 | using System.Collections; 18 | using System.Collections.Generic; 19 | using System.Reflection; 20 | 21 | 22 | namespace NI.Ioc 23 | { 24 | /// 25 | /// Represents component initialization information 26 | /// 27 | public class ComponentInitInfo : IComponentInitInfo 28 | { 29 | 30 | bool ValuesInitialized = false; 31 | 32 | /// 33 | /// Singleton flag. True by default. 34 | /// 35 | public bool Singleton { get; set; } 36 | 37 | /// 38 | /// Lazy init flag. False by default. 39 | /// 40 | public bool LazyInit { get; set; } 41 | 42 | /// 43 | /// Component name 44 | /// 45 | public string Name { get; set; } 46 | 47 | /// 48 | /// Component parent name 49 | /// 50 | public string Parent { get; set; } 51 | 52 | /// 53 | /// Initialization method name. Null by default. 54 | /// 55 | public string InitMethod { get; set; } 56 | 57 | /// 58 | /// Component System.Type 59 | /// 60 | public Type ComponentType { get; set; } 61 | 62 | /// 63 | /// Component description. Null by default. 64 | /// 65 | public string Description { get; set; } 66 | 67 | /// 68 | /// Constructor arguments. 69 | /// 70 | public IValueInitInfo[] ConstructorArgs { get; set; } 71 | 72 | /// 73 | /// Properies to set 74 | /// 75 | public IPropertyInitInfo[] Properties { get; set; } 76 | 77 | 78 | public ComponentInitInfo() { } 79 | 80 | public ComponentInitInfo(string name, Type t, bool singleton, bool lazyInit) { 81 | Name = name; 82 | ComponentType = t; 83 | Singleton = singleton; 84 | LazyInit = lazyInit; 85 | } 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/NI.Ioc/Schema/ListValueInitInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Collections; 17 | using System.Collections.Generic; 18 | 19 | namespace NI.Ioc 20 | { 21 | /// 22 | /// List value initialization info 23 | /// 24 | public class ListValueInitInfo : IValueInitInfo 25 | { 26 | public IValueInitInfo[] Values; 27 | bool isOnlyConstValues = false; 28 | IDictionary cachedTypedArrays = null; 29 | private object cachedTypedArraysSyncObject = new object(); 30 | 31 | public ListValueInitInfo(IValueInitInfo[] values) 32 | { 33 | Values = values; 34 | isOnlyConstValues = true; 35 | for (int i=0;i(); 63 | cachedTypedArrays[elemType] = (Array)listArray.Clone(); 64 | } 65 | if (conversionType.IsArray) 66 | return listArray; // nothing to convert 67 | return factory.GetInstance(listArray, conversionType); 68 | } 69 | } 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/NI.Ioc/Schema/MapEntryInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NI.Factory.Xml 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/NI.Ioc/Schema/PropertyInitInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// Property initialization information 21 | /// 22 | public class PropertyInfo : IPropertyInitInfo 23 | { 24 | string _Name; 25 | IValueInitInfo _Value; 26 | 27 | public string Name { get { return _Name; } } 28 | 29 | public IValueInitInfo Value { get { return _Value; } } 30 | 31 | public PropertyInfo(string name, IValueInitInfo value) 32 | { 33 | _Name = name; 34 | _Value = value; 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/NI.Ioc/Schema/RefValueInitInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// Value initialization info represented by reference to another component definition 21 | /// 22 | public class RefValueInfo : IValueInitInfo 23 | { 24 | public IComponentInitInfo ComponentRef { get; private set; } 25 | 26 | public string ComponentMethod { get; private set; } 27 | 28 | public RefValueInfo(IComponentInitInfo componentRef) : this(componentRef, null) { 29 | } 30 | 31 | public RefValueInfo(IComponentInitInfo componentRef, string method) { 32 | ComponentRef = componentRef; 33 | ComponentMethod = method; 34 | } 35 | 36 | public object GetValue(IValueFactory factory, Type conversionType) 37 | { 38 | if (ComponentMethod!=null) { 39 | var targetInstance = factory.GetInstance(ComponentRef, typeof(object) ); 40 | var delegFactory = new DelegateFactory(targetInstance, ComponentMethod); 41 | if (typeof(Delegate).IsAssignableFrom(conversionType)) { 42 | delegFactory.DelegateType = conversionType; 43 | } 44 | return factory.GetInstance( 45 | delegFactory.GetObject(), 46 | conversionType 47 | ); 48 | } else { 49 | return factory.GetInstance(ComponentRef, conversionType); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/NI.Ioc/Schema/TypeValueInitInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// Value initialization info that represents some Type 21 | /// 22 | public class TypeValueInitInfo : IValueInitInfo 23 | { 24 | public Type Value; 25 | 26 | public TypeValueInitInfo(Type value) 27 | { 28 | Value = value; 29 | } 30 | 31 | public object GetValue(IValueFactory factory, Type conversionType) { 32 | return Value; 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/NI.Ioc/Schema/ValueInitInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Ioc 18 | { 19 | /// 20 | /// Value initialization info represented by specified object 21 | /// 22 | public class ValueInitInfo : IValueInitInfo 23 | { 24 | public object Value; 25 | 26 | public ValueInitInfo(object value) 27 | { 28 | Value = value; 29 | } 30 | 31 | public object GetValue(IValueFactory factory, Type conversionType) { 32 | return factory.GetInstance(Value, conversionType); 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/NI.Ioc/ServiceProviderContext.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.ComponentModel; 17 | 18 | namespace NI.Ioc 19 | { 20 | /// 21 | /// ServiceProviderContext used for referencing to IoC container inside its configuration. 22 | /// 23 | public class ServiceProviderContext : IServiceProviderAware, IFactoryComponent 24 | { 25 | IServiceProvider _ServiceProvider; 26 | 27 | /// 28 | /// Get or set context service provider 29 | /// 30 | public IServiceProvider ServiceProvider { 31 | get { return _ServiceProvider; } 32 | set { _ServiceProvider = value; } 33 | } 34 | 35 | public object GetObject() { 36 | return ServiceProvider; 37 | } 38 | 39 | public Type GetObjectType() { 40 | return typeof(IServiceProvider); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/NI.Ioc/StaticFieldInvokingFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Reflection; 17 | 18 | 19 | 20 | namespace NI.Ioc { 21 | 22 | /// 23 | /// StaticFieldInvokingFactory used for defining instance as static field of some class. 24 | /// 25 | /// 26 | /// <component name="datetimenow" type="NI.Ioc.StaticFieldInvokingFactory,NI.Ioc" singleton="false" lazy-init="true"> 27 | /// <property name="TargetType"><type>System.DBNull,Mscorlib</type></property> 28 | /// <property name="TargetField"><value>Value</value></property> 29 | /// </component> 30 | /// 31 | public class StaticFieldInvokingFactory : IFactoryComponent { 32 | Type _TargetType; 33 | string _TargetField; 34 | 35 | /// 36 | /// Get or set target type 37 | /// 38 | public Type TargetType { 39 | get { return _TargetType; } 40 | set { _TargetType = value; } 41 | } 42 | 43 | /// 44 | /// Get or set static target property name 45 | /// 46 | public string TargetField { 47 | get { return _TargetField; } 48 | set { _TargetField = value; } 49 | } 50 | 51 | public StaticFieldInvokingFactory() { 52 | } 53 | 54 | public object GetObject() { 55 | System.Reflection.FieldInfo fInfo = TargetType.GetField(TargetField, BindingFlags.Static | BindingFlags.Public); 56 | if (fInfo == null) 57 | throw new MissingFieldException(TargetType.ToString(), TargetField); 58 | return fInfo.GetValue(null); 59 | } 60 | 61 | public Type GetObjectType() { 62 | System.Reflection.FieldInfo fInfo = TargetType.GetField(TargetField, BindingFlags.Static | BindingFlags.Public); 63 | if (fInfo == null) 64 | throw new MissingFieldException(TargetType.ToString(), TargetField); 65 | return fInfo.FieldType; 66 | } 67 | 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/NI.Ioc/StaticPropertyInvokingFactory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Reflection; 17 | 18 | 19 | 20 | namespace NI.Ioc { 21 | 22 | /// 23 | /// Factory component which returns a value represented by specified static property. 24 | /// 25 | /// 26 | /// <component name="datetimenow" type="NI.Ioc.StaticPropertyInvokingFactory,NI.Ioc" singleton="false" lazy-init="true"> 27 | /// <property name="TargetType"><type>System.DateTime,Mscorlib</type></property> 28 | /// <property name="TargetProperty"><value>Now</value></property> 29 | /// </component> 30 | /// 31 | public class StaticPropertyInvokingFactory : IFactoryComponent { 32 | Type _TargetType; 33 | string _TargetProperty; 34 | 35 | /// 36 | /// Get or set target type 37 | /// 38 | public Type TargetType { 39 | get { return _TargetType; } 40 | set { _TargetType = value; } 41 | } 42 | 43 | /// 44 | /// Get or set static target property name 45 | /// 46 | public string TargetProperty { 47 | get { return _TargetProperty; } 48 | set { _TargetProperty = value; } 49 | } 50 | 51 | public StaticPropertyInvokingFactory() { 52 | } 53 | 54 | public object GetObject() { 55 | 56 | System.Reflection.PropertyInfo pInfo = TargetType.GetProperty( TargetProperty, BindingFlags.Static|BindingFlags.Public); 57 | if (pInfo==null) 58 | throw new MissingMemberException( TargetType.ToString(), TargetProperty); 59 | return pInfo.GetValue( null, null ); 60 | } 61 | 62 | public Type GetObjectType() { 63 | System.Reflection.PropertyInfo pInfo = TargetType.GetProperty( TargetProperty, BindingFlags.Static|BindingFlags.Public); 64 | if (pInfo==null) 65 | throw new MissingMemberException( TargetType.ToString(), TargetProperty); 66 | return pInfo.PropertyType; 67 | } 68 | 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/NI.Ioc/Summary.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Winter IoC Container components namespace. 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/NI.Ioc/XmlComponentConfigurationSectionHandler.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas, Vitalii Fedorchenko (v.2 changes) 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Xml; 17 | using System.IO; 18 | using System.Xml.Schema; 19 | using System.Xml.XPath; 20 | using System.Configuration; 21 | using System.Reflection; 22 | using System.ComponentModel; 23 | using System.Text; 24 | 25 | 26 | namespace NI.Ioc 27 | { 28 | 29 | /// 30 | /// Configuration section handler for XmlComponentConfiguration 31 | /// (so you may place configuration in the app.config or web.config) 32 | /// 33 | /// 34 | /// <configSections> 35 | /// <section name="ioc" type="NI.Ioc.XmlComponentConfigurationSectionHandler, NI.Ioc" /> 36 | /// </configSections> 37 | /// <ioc> 38 | /// <!-- components definitions --> 39 | /// </ioc> 40 | /// 41 | public class XmlComponentConfigurationSectionHandler : IConfigurationSectionHandler { 42 | 43 | public XmlComponentConfigurationSectionHandler() { 44 | } 45 | 46 | public virtual object Create(object parent, object input, XmlNode section) { 47 | try { 48 | var config = new XmlComponentConfiguration(section.InnerXml); 49 | return config; 50 | } catch (Exception ex) { 51 | throw new ConfigurationException( ex.Message, ex); 52 | } 53 | 54 | } 55 | 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/NI.Ioc/XmlServiceProvider.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | text/microsoft-resx 32 | 33 | 34 | 1.0.0.0 35 | 36 | 37 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 38 | 39 | 40 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/NI.Tests/Data/DataEventBrokerTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using NUnit.Framework; 7 | using NI.Data; 8 | 9 | namespace NI.Tests.Data { 10 | 11 | public class DataEventBrokerTest { 12 | 13 | [Test] 14 | public void PublishAndSubscribe() { 15 | var broker = new DataEventBroker(); 16 | 17 | int publishingCallCount = 0; 18 | int publishedCallCount = 0; 19 | int allEventsSubscriberCallCount = 0; 20 | int customEventsSubscriberCallCount = 0; 21 | EventHandler publishingHandler = (sender, args) => { 22 | publishingCallCount++; 23 | }; 24 | EventHandler publishedHandler = (sender, args) => { 25 | publishedCallCount++; 26 | Assert.AreEqual( publishingCallCount, publishedCallCount ); 27 | }; 28 | EventHandler allEventsSubscribedHandler = (sender, args) => { 29 | allEventsSubscriberCallCount++; 30 | Assert.AreEqual(allEventsSubscriberCallCount, publishingCallCount ); 31 | Assert.AreEqual(allEventsSubscriberCallCount-1, publishedCallCount); 32 | }; 33 | EventHandler customEventsSubscribedHandler = (sender, args) => { 34 | customEventsSubscriberCallCount++; 35 | }; 36 | 37 | broker.Publishing += publishingHandler; 38 | broker.Published += publishedHandler; 39 | 40 | broker.Subscribe(allEventsSubscribedHandler); 41 | broker.Subscribe(customEventsSubscribedHandler); 42 | 43 | broker.Publish( this, EventArgs.Empty ); 44 | Assert.AreEqual( 1, allEventsSubscriberCallCount ); 45 | Assert.AreEqual(0, customEventsSubscriberCallCount); 46 | 47 | broker.Publish(this, new CustomEventArgs() ); 48 | Assert.AreEqual(2, allEventsSubscriberCallCount); 49 | Assert.AreEqual(1, customEventsSubscriberCallCount); 50 | } 51 | 52 | public class CustomEventArgs : EventArgs { 53 | } 54 | 55 | [Test] 56 | public void Unsubscribe() { 57 | var broker = new DataEventBroker(); 58 | 59 | var counterHandler = new CounterHanlder(); 60 | broker.Subscribe( new EventHandler(counterHandler.Handler) ); 61 | broker.Subscribe(new EventHandler(counterHandler.Handler)); 62 | 63 | var anotherHandlerCounter = 0; 64 | broker.Subscribe( (sender,args) => { 65 | anotherHandlerCounter++; 66 | }); 67 | 68 | Assert.True( broker.Unsubscribe( new EventHandler(counterHandler.Handler) ) ); 69 | Assert.False(broker.Unsubscribe(new EventHandler(counterHandler.Handler))); 70 | 71 | broker.Publish(this, new CustomEventArgs() ); 72 | Assert.AreEqual(0, counterHandler.Counter); 73 | Assert.AreEqual(1, anotherHandlerCounter); 74 | } 75 | 76 | public class CounterHanlder { 77 | public int Counter = 0; 78 | public void Handler(object sender, EventArgs e) { 79 | Counter++; 80 | } 81 | } 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/NI.Tests/Data/LinqTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using NI.Data; 7 | using NI.Data.Linq; 8 | using NUnit.Framework; 9 | 10 | namespace NI.Tests.Data { 11 | public class LinqTests { 12 | 13 | [Test] 14 | public void LinqDalcRecord() { 15 | var dsDalc = DataSetDalcTest.createDsDalc(); 16 | 17 | var q1 = from r in dsDalc.Linq("users") 18 | where r["name"] == "Joe" 19 | select r; 20 | Assert.AreEqual("Joe", q1.FirstOrDefault()["name"].Value.ToString()); 21 | 22 | var q2 = dsDalc.Linq("users").OrderByDescending(r => r["id"]); 23 | var q2arr = q2.ToArray(); 24 | 25 | Assert.AreEqual(3, q2arr.Length); 26 | Assert.AreEqual(3, Convert.ToInt32(q2arr[0]["id"].Value)); 27 | 28 | // single value 29 | var q3 = dsDalc.Linq("users").OrderBy(r => r["id"]).Select(r => r["id"]); 30 | var q3val = q3.Single(); 31 | Assert.AreEqual(1, Convert.ToInt32(q3val.Value)); 32 | 33 | } 34 | 35 | [Test] 36 | public void LinqDto() { 37 | var dsDalc = DataSetDalcTest.createDsDalc(); 38 | 39 | var q1 = from u in dsDalc.Linq("users") 40 | where u.id == 2 41 | select u; 42 | var q1res = q1.First(); 43 | Assert.AreEqual("Joe", q1res.name); 44 | } 45 | 46 | public class User { 47 | public int id { get; set; } 48 | public string name { get; set; } 49 | public string role { get; set; } 50 | } 51 | 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/NI.Tests/Data/QueryTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | using NI.Data; 5 | 6 | using NUnit.Framework; 7 | 8 | namespace NI.Tests.Data 9 | { 10 | /// 11 | /// 12 | [TestFixture] 13 | [NUnit.Framework.Category("NI.Data")] 14 | public class QueryTest 15 | { 16 | [Test] 17 | public void test_QSortField() { 18 | QSort fld = (QSort)"name"; 19 | Assert.AreEqual( fld.Field.Name, "name", "QSortField parse error"); 20 | Assert.AreEqual( fld.SortDirection, ListSortDirection.Ascending, "QSortField parse error"); 21 | 22 | fld = (QSort)"email desc "; 23 | Assert.AreEqual( fld.Field.Name, "email", "QSortField parse error"); 24 | Assert.AreEqual( fld.SortDirection, ListSortDirection.Descending, "QSortField parse error"); 25 | 26 | fld = (QSort)"email desc "; 27 | Assert.AreEqual( fld.Field.Name, "email", "QSortField parse error"); 28 | Assert.AreEqual( fld.SortDirection, ListSortDirection.Descending, "QSortField parse error"); 29 | 30 | fld = (QSort)" email desc "; 31 | Assert.AreEqual( fld.Field.Name, "email", "QSortField parse error"); 32 | Assert.AreEqual( fld.SortDirection, ListSortDirection.Descending, "QSortField parse error"); 33 | 34 | fld = (QSort)"position asc"; 35 | Assert.AreEqual( fld.Field.Name, "position", "QSortField parse error"); 36 | Assert.AreEqual( fld.SortDirection, ListSortDirection.Ascending, "QSortField parse error"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/NI.Tests/Data/SimpleStringTemplateTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Collections.Generic; 4 | 5 | using NI.Data; 6 | 7 | using NUnit.Framework; 8 | 9 | namespace NI.Tests.Data 10 | { 11 | /// 12 | /// 13 | [TestFixture] 14 | [NUnit.Framework.Category("NI.Data")] 15 | public class SimpleStringTemplateTest 16 | { 17 | [Test] 18 | public void FormatTemplate() { 19 | var testStr = "TEST @SqlOrderBy[order by {0};order by u.id desc] TEST"; 20 | var strTpl = new SimpleStringTemplate(testStr); 21 | strTpl.ReplaceMissedTokens = false; 22 | Assert.AreEqual(testStr, strTpl.FormatTemplate(new Dictionary())); 23 | strTpl.ReplaceMissedTokens = true; 24 | Assert.AreEqual("TEST order by u.id desc TEST", strTpl.FormatTemplate(new Dictionary())); 25 | 26 | Assert.AreEqual("TEST order by name TEST", strTpl.FormatTemplate( 27 | new Dictionary() { 28 | {"SqlOrderBy", "name"} 29 | } )); 30 | 31 | 32 | Assert.AreEqual("1+2", 33 | new SimpleStringTemplate("@A[{0}+@B]",2).FormatTemplate(new Dictionary() { 34 | {"A", 1}, {"B", 2} 35 | }) 36 | ); 37 | 38 | Assert.AreEqual("No replace: @Test", 39 | new SimpleStringTemplate("No replace: @@Test").FormatTemplate(new Dictionary() { 40 | {"Test", "bla"} 41 | }) 42 | ); 43 | 44 | Assert.AreEqual( 45 | "and 1=2", 46 | new SimpleStringTemplate( 47 | "@class_id[and id in metadata_property_to_class(class_id=\"class_id\":var)[property_id]];and 1=2]").FormatTemplate( 48 | new Dictionary() { 49 | {"class_id", ""} 50 | } 51 | ) 52 | ); 53 | 54 | Assert.AreEqual( 55 | "zzz@WAW;[]", 56 | new SimpleStringTemplate( 57 | "zzz@A[@WAW;;[]]]").FormatTemplate( 58 | new Dictionary() { 59 | {"A", "1"} 60 | } 61 | ) 62 | ); 63 | Assert.AreEqual( 64 | "zzz [] ", 65 | new SimpleStringTemplate( 66 | "zzz@A[\\;; [\\] ]").FormatTemplate( 67 | new Dictionary() { 68 | {"A", ""} 69 | } 70 | ) 71 | ); 72 | 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/NI.Tests/Ioc/ArrayFactoryTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NI.Ioc; 4 | 5 | using NUnit.Framework; 6 | 7 | namespace NI.Tests.Ioc 8 | { 9 | /// 10 | /// ArrayFactoryTest. 11 | /// 12 | [TestFixture] 13 | [Category("NI.Ioc")] 14 | public class ArrayFactoryTest 15 | { 16 | public ArrayFactoryTest() 17 | { 18 | } 19 | 20 | [Test] 21 | public void test_GetObject() { 22 | ArrayFactory arrayFactory = new ArrayFactory(); 23 | arrayFactory.ElementType = typeof(string); 24 | arrayFactory.Elements = new string[] {"a", "b"}; 25 | 26 | Assert.AreEqual( arrayFactory.GetObjectType(), typeof(string[]), "GetObjectType failed"); 27 | string[] obj = arrayFactory.GetObject() as string[]; 28 | Assert.AreEqual( obj.Length, 2, "Invalid result object"); 29 | Assert.AreEqual( obj[0], "a", "Invalid first element of result object"); 30 | Assert.AreEqual( obj[1], "b", "Invalid second element of result object"); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/NI.Tests/Ioc/EventBinderTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NI.Ioc; 4 | 5 | using NUnit.Framework; 6 | 7 | namespace NI.Tests.Ioc 8 | { 9 | /// 10 | /// Test for EventBinder. 11 | /// 12 | [TestFixture] 13 | [Category("NI.Ioc")] 14 | public class EventBinderTest 15 | { 16 | public EventBinderTest() { 17 | } 18 | 19 | //event TestEvent; 20 | 21 | [Test] 22 | public void test_Init() { 23 | EventBinder EventBinder = new EventBinder(); 24 | EventBinder.SenderObject = this; 25 | EventBinder.ReceiverObject = this; 26 | EventBinder.SenderEvent = "TestEventToBind"; 27 | EventBinder.ReceiverMethod = "TestMethodToBind"; 28 | 29 | EventBinder.Init(); 30 | TestEventArgs arg1 = new TestEventArgs(); 31 | this.TestEventToBind(this,arg1); 32 | Assert.AreEqual( true, arg1.Result ); 33 | 34 | 35 | EventBinder.SenderObject = this; 36 | EventBinder.ReceiverObject = this; 37 | EventBinder.SenderEvent = "TestEventToBind"; 38 | EventBinder.ReceiverMethod = "SimpleTestMethodToBind"; 39 | 40 | EventBinder.Init(); 41 | TestEventArgs arg2 = new TestEventArgs(); 42 | this.TestEventToBind.Invoke(this, arg2); 43 | Assert.AreEqual( true, arg2.Result ); 44 | } 45 | 46 | public class TestEventArgs : EventArgs { 47 | public bool Result = false; 48 | 49 | public TestEventArgs() { } 50 | } 51 | 52 | public void TestMethodToBind(object sender, EventArgs e) { 53 | ((TestEventArgs)e).Result = true; 54 | } 55 | 56 | public void SimpleTestMethodToBind(object sender, EventArgs e) { 57 | ((TestEventArgs)e).Result = true; 58 | } 59 | 60 | public event EventHandler TestEventToBind; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/NI.Tests/Ioc/FuncInterfaceTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NI.Ioc; 4 | 5 | using NUnit.Framework; 6 | 7 | namespace NI.Tests.Ioc 8 | { 9 | /// 10 | /// ArrayFactoryTest. 11 | /// 12 | [TestFixture] 13 | [Category("NI.Ioc")] 14 | public class FuncInterfaceTest 15 | { 16 | public FuncInterfaceTest() 17 | { 18 | } 19 | 20 | [Test] 21 | public void test_GetObject() { 22 | Func f = (i) => { return i.ToString(); }; 23 | 24 | 25 | 26 | 27 | } 28 | 29 | public interface ITest { 30 | string ToStr(int i); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/NI.Tests/Ioc/MethodInvokingFactoryTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NI.Ioc; 4 | 5 | using NUnit.Framework; 6 | 7 | namespace NI.Tests.Ioc 8 | { 9 | /// 10 | /// Test for MethodInvokingFactory. 11 | /// 12 | [TestFixture] 13 | [Category("NI.Ioc")] 14 | public class MethodInvokingFactoryTest 15 | { 16 | public MethodInvokingFactoryTest() 17 | { 18 | } 19 | 20 | [Test] 21 | public void test_GetObject() { 22 | MethodInvokingFactory methodInvokingFactory = new MethodInvokingFactory(); 23 | methodInvokingFactory.TargetObject = this; 24 | methodInvokingFactory.TargetMethod = "TestMethodToInvoke"; 25 | methodInvokingFactory.TargetMethodArgTypes = new Type[] { typeof(string), typeof(int) }; 26 | methodInvokingFactory.TargetMethodArgs = new object[] { "ZZZ", 2 }; 27 | 28 | Assert.AreEqual( methodInvokingFactory.GetObject(), "ZZZ,2", "GetObject fails"); 29 | Assert.AreEqual( methodInvokingFactory.GetObjectType(), typeof(string), "GetObjectType fails"); 30 | 31 | methodInvokingFactory.TargetMethod = "SimpleTestMethodToInvoke"; 32 | methodInvokingFactory.TargetMethodArgTypes = null; 33 | methodInvokingFactory.TargetMethodArgs = null; 34 | 35 | Assert.AreEqual( methodInvokingFactory.GetObject(), (int)0, "GetObject fails"); 36 | } 37 | 38 | public string TestMethodToInvoke(string a, int b) { 39 | return String.Format("{0},{1}", a,b); 40 | } 41 | 42 | public int SimpleTestMethodToInvoke() { 43 | return 0; 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/NI.Tests/Ioc/StaticMethodInvokingFactoryTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NI.Ioc; 4 | 5 | using NUnit.Framework; 6 | 7 | namespace NI.Tests.Ioc 8 | { 9 | /// 10 | /// Test for StaticMethodInvokingFactoryTest. 11 | /// 12 | [TestFixture] 13 | [Category("NI.Ioc")] 14 | public class StaticMethodInvokingFactoryTest 15 | { 16 | public StaticMethodInvokingFactoryTest() 17 | { 18 | } 19 | 20 | [Test] 21 | public void test_GetObject() { 22 | StaticMethodInvokingFactory staticMethodInvokingFactory = new StaticMethodInvokingFactory(); 23 | staticMethodInvokingFactory.TargetType = typeof(System.Text.Encoding); 24 | staticMethodInvokingFactory.TargetMethod = "GetEncoding"; 25 | staticMethodInvokingFactory.TargetMethodArgTypes = new Type[] { typeof(int) }; 26 | staticMethodInvokingFactory.TargetMethodArgs = new object[] { (int)1252 }; 27 | 28 | 29 | Assert.AreEqual( staticMethodInvokingFactory.GetObjectType(), typeof(System.Text.Encoding), "GetObjectType fails"); 30 | System.Text.Encoding enc = (System.Text.Encoding)staticMethodInvokingFactory.GetObject(); 31 | Assert.AreEqual( enc.CodePage, (int)1252, "GetObject fails"); 32 | 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/NI.Tests/Ioc/StaticPropertyInvokingFactoryTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NI.Ioc; 4 | 5 | using NUnit.Framework; 6 | 7 | namespace NI.Tests.Ioc 8 | { 9 | /// 10 | /// 11 | [TestFixture] 12 | [Category("NI.Ioc")] 13 | public class StaticPropertyInvokingFactoryTest 14 | { 15 | public StaticPropertyInvokingFactoryTest() 16 | { 17 | 18 | } 19 | [Test] 20 | public void test_GetObject() { 21 | StaticPropertyInvokingFactory statPropFactory = new StaticPropertyInvokingFactory(); 22 | statPropFactory.TargetType = typeof(customClass); 23 | statPropFactory.TargetProperty = "staticProperty"; 24 | 25 | object res = statPropFactory.GetObject(); 26 | Assert.AreEqual( res, "staticvalue", "GetObject fails"); 27 | } 28 | 29 | public class customClass { 30 | 31 | public string objectProperty { 32 | get { 33 | return "objectvalue"; 34 | } 35 | set { 36 | } 37 | } 38 | 39 | public static string staticProperty { 40 | get { 41 | return "staticvalue"; 42 | } 43 | } 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/NI.Tests/Ioc/XmlComponentConfigurationTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using NI.Ioc; 4 | using NI.Ioc.Exceptions; 5 | using NUnit.Framework; 6 | 7 | namespace NI.Tests.Ioc 8 | { 9 | /// 10 | /// ArrayFactoryTest. 11 | /// 12 | [TestFixture] 13 | [Category("NI.Ioc")] 14 | public class XmlComponentConfigurationTest 15 | { 16 | public XmlComponentConfigurationTest() 17 | { 18 | } 19 | 20 | [Test] 21 | public void FromXmlString() { 22 | var xmlConfig = new XmlComponentConfiguration(@" 23 | 24 | test 25 | 26 | 27 | 28 | 29 | "); 30 | Assert.AreEqual("test", xmlConfig.Description); 31 | Assert.AreEqual(2, xmlConfig.Count); 32 | } 33 | 34 | [Test] 35 | [ExpectedException(typeof(XmlConfigurationException))] 36 | public void WrongNamespace() { 37 | var xmlConfig = new XmlComponentConfiguration(@" 38 | 39 | test 40 | "); 41 | } 42 | 43 | [Test] 44 | [ExpectedException(typeof(XmlConfigurationException))] 45 | public void WrongConfigSchema() { 46 | var xmlConfig = new XmlComponentConfiguration(@" 47 | 48 | 49 | 50 | "); 51 | } 52 | 53 | [Test] 54 | [ExpectedException(typeof(XmlConfigurationException))] 55 | public void WrongRef() { 56 | var xmlConfig = new XmlComponentConfiguration(@" 57 | 58 | 59 | 60 | 61 | "); 62 | } 63 | 64 | [Test] 65 | [ExpectedException(typeof(XmlConfigurationException))] 66 | public void WrongType() { 67 | var xmlConfig = new XmlComponentConfiguration(@" 68 | 69 | 70 | 71 | "); 72 | } 73 | 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/NI.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NI.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("NI.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("8c67b41d-50e4-4b52-b723-c2a9d77ec7de")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/NI.Tests/Text/EvalTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Data; 6 | using NUnit.Framework; 7 | 8 | using NI.Text; 9 | 10 | namespace NI.Tests.Expressions 11 | { 12 | /// 13 | /// 14 | [TestFixture] 15 | [Category("NI.Expressions")] 16 | public class EvalTest 17 | { 18 | public EvalTest() 19 | { 20 | } 21 | 22 | [Test] 23 | public void test_DataBind() { 24 | var dataBinder = new DataBind(); 25 | 26 | var someArr = new[] { "a", "b", "c" }; 27 | Assert.AreEqual(3, (int)dataBinder.Eval(someArr, ".Length")); 28 | Assert.AreEqual("b", (string)dataBinder.Eval(someArr, "[1]")); 29 | 30 | var dict = new Hashtable() { 31 | {"name", "AAA"}, 32 | {"k", new KeyValuePair("a", new TimeSpan(0,1,2) ) } 33 | }; 34 | Assert.AreEqual("AAA", (string)dataBinder.Eval(dict, "[name]")); 35 | Assert.IsNull( dataBinder.Eval(dict, "[name1]")); 36 | Assert.AreEqual("a", (string)dataBinder.Eval(dict, "[k].Key")); 37 | Assert.AreEqual(2, (int) dataBinder.Eval(dict, "[k].Value.Seconds")); 38 | } 39 | 40 | [Test] 41 | public void test_StringTemplate() { 42 | var st = new StringTemplate(); 43 | 44 | var vars = new Hashtable() { 45 | {"name", "John"}, 46 | {"company", "Johnson&Johnson"}, 47 | {"age", 65}, 48 | {"birthday", new DateTime(1985, 1, 5)} 49 | }; 50 | var noMarkerStr = "Just a text without markers."; 51 | Assert.AreEqual(noMarkerStr, st.Eval(vars,noMarkerStr) ); 52 | 53 | var simpleMarkersStr = "Hello, {var:name}, you are {var:age} years old! You born in {databind:[birthday].Month}/{var:birthday,dd}."; 54 | var simpleMarkersStrRes = "Hello, John, you are 65 years old! You born in 1/05."; 55 | 56 | Assert.AreEqual(simpleMarkersStrRes, st.Eval(vars, simpleMarkersStr)); 57 | 58 | Assert.AreEqual("Johnson&Johnson", st.Eval(vars, "{xml:{var:company}}")); 59 | 60 | } 61 | 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/NI.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/NI.Text/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("NI.Text")] 10 | [assembly: AssemblyDescription("StringTemplate and DataBind evaluators")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("NewtonIdeas")] 13 | [assembly: AssemblyProduct("Open NIC.NET")] 14 | [assembly: AssemblyCopyright("Newtonideas")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("2.0.0")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /src/NI.Text/EvalHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Xml; 8 | using System.IO; 9 | 10 | namespace NI.Text { 11 | 12 | /// 13 | /// Helper class that includes typical evaluation functions used in StringTemplate 14 | /// 15 | public static class EvalHelper { 16 | 17 | public static string IsInRole(IDictionary context, string role) { 18 | return Thread.CurrentPrincipal.IsInRole(role).ToString(); 19 | } 20 | 21 | public static string Variable(IDictionary context, string contextKey) { 22 | int commaIdx = contextKey.IndexOfAny(new[]{',',':'}); 23 | object value; 24 | if (commaIdx != -1) { 25 | value = context[contextKey.Substring(0, commaIdx)]; 26 | IFormattable formattable = value as IFormattable; 27 | if (formattable != null) 28 | value = formattable.ToString(contextKey.Substring(commaIdx + 1), null); 29 | } else 30 | value = context[contextKey]; 31 | 32 | return Convert.ToString(value); 33 | } 34 | 35 | public static string XmlEncode(IDictionary context, string s) { 36 | StringWriter strWr = new StringWriter(); 37 | XmlTextWriter xmlWr = new XmlTextWriter(strWr); 38 | xmlWr.WriteString(s); 39 | return strWr.ToString(); 40 | } 41 | 42 | public static string XmlAttributeEncode(IDictionary context, string s) { 43 | StringWriter strWr = new StringWriter(); 44 | XmlTextWriter xmlWr = new XmlTextWriter(strWr); 45 | xmlWr.WriteAttributeString("a", s); 46 | string result = strWr.ToString(); 47 | return result.Substring(3, result.Length - 4); 48 | } 49 | 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/NI.Text/NI.Text.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | Vitalii Fedorchenko 8 | $author$ 9 | 10 | http://www.nrecosite.com 11 | 12 | false 13 | $description$ 14 | Copyright 2004-2012 NewtonIdeas, v2 2013-2014 Vitalii Fedorchenko 15 | StringTemplate DataBind 16 | 17 | -------------------------------------------------------------------------------- /src/NI.Text/Summary.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | The NI.Expressions namespace contains classes that can evaluate expressions. 5 | Expression is a string that can be evaluated at run time in some context. 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/NI.Vfs/AllFileSelector.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.IO; 17 | 18 | namespace NI.Vfs 19 | { 20 | /// 21 | /// A IFileSelector that selects all files 22 | /// 23 | public class AllFileSelector : IFileSelector 24 | { 25 | FileType FilterType = FileType.Imaginary; 26 | 27 | public AllFileSelector() 28 | { 29 | } 30 | 31 | public AllFileSelector(FileType filterType) { 32 | FilterType = filterType; 33 | } 34 | 35 | public bool IncludeFile(IFileObject file) { 36 | return FilterType == FileType.Imaginary ? true : file.Type == FilterType; 37 | } 38 | 39 | public bool TraverseDescendents(IFileObject file) { 40 | return true; 41 | } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/NI.Vfs/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | // 9 | [assembly: AssemblyTitle("NI.Vfs")] 10 | [assembly: AssemblyDescription("Virtual file system (VFS) provides a single API for accessing various different file systems.")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("NewtonIdeas")] 13 | [assembly: AssemblyProduct("Open NIC.NET")] 14 | [assembly: AssemblyCopyright("NewtonIdeas 2004-2014")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Revision and Build Numbers 27 | // by using the '*' as shown below: 28 | 29 | [assembly: AssemblyVersion("2.0.1")] 30 | 31 | // 32 | // In order to sign your assembly you must specify a key to use. Refer to the 33 | // Microsoft .NET Framework documentation for more information on assembly signing. 34 | // 35 | // Use the attributes below to control which key is used for signing. 36 | // 37 | // Notes: 38 | // (*) If no key is specified, the assembly is not signed. 39 | // (*) KeyName refers to a key that has been installed in the Crypto Service 40 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 41 | // a key. 42 | // (*) If the KeyFile and the KeyName values are both specified, the 43 | // following processing occurs: 44 | // (1) If the KeyName can be found in the CSP, that key is used. 45 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 46 | // in the KeyFile is installed into the CSP and used. 47 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 48 | // When specifying the KeyFile, the location of the KeyFile should be 49 | // relative to the project output directory which is 50 | // %Project Directory%\obj\. For example, if your KeyFile is 51 | // located in the project directory, you would specify the AssemblyKeyFile 52 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 53 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 54 | // documentation for more information on this. 55 | // 56 | [assembly: AssemblyDelaySign(false)] 57 | [assembly: AssemblyKeyFile("")] 58 | [assembly: AssemblyKeyName("")] 59 | -------------------------------------------------------------------------------- /src/NI.Vfs/Exceptions/FileSystemException.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Vfs { 18 | 19 | /// 20 | /// File system exception 21 | /// 22 | public class FileSystemException : ApplicationException { 23 | 24 | IFileObject _File = null; 25 | 26 | public IFileObject File { 27 | get { return _File; } 28 | } 29 | 30 | public FileSystemException() : base("File system error") { 31 | } 32 | 33 | public FileSystemException(string message) : base (message) { } 34 | 35 | public FileSystemException(string message, IFileObject file) : base(message) { 36 | _File = file; 37 | } 38 | 39 | public FileSystemException(string message, Exception innerException) : base (message, innerException) { } 40 | 41 | public FileSystemException(string message, IFileObject file, Exception innerException) : base(message, innerException) { 42 | _File = file; 43 | } 44 | 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/NI.Vfs/ExtensionFileSelector.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.IO; 17 | 18 | namespace NI.Vfs 19 | { 20 | /// 21 | /// A IFileSelector that selects files by explicit list of extensions 22 | /// 23 | public class ExtensionFileSelector : IFileSelector 24 | { 25 | protected string[] Extensions; 26 | const string ExtensionSeparator = "."; 27 | StringComparison Comparision = StringComparison.CurrentCultureIgnoreCase; 28 | 29 | public ExtensionFileSelector(params string[] extensions) { 30 | Extensions = new string[extensions.Length]; 31 | // normalize extensions 32 | for (int i = 0; i < Extensions.Length; i++) 33 | Extensions[i] = extensions[i].StartsWith(ExtensionSeparator) ? extensions[i] : "." + extensions[i]; 34 | } 35 | 36 | public bool IncludeFile(IFileObject file) { 37 | string ext = Path.GetExtension( file.Name ); 38 | for (int i = 0; i < Extensions.Length; i++) 39 | if (Extensions[i].Equals(ext, Comparision)) 40 | return true; 41 | return false; 42 | } 43 | 44 | public bool TraverseDescendents(IFileObject file) { 45 | return true; 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/NI.Vfs/FileObjectComparer.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Collections; 17 | using System.ComponentModel; 18 | using System.IO; 19 | 20 | namespace NI.Vfs 21 | { 22 | 23 | public class FileObjectComparer : IComparer { 24 | ListSortDirection _SortDirection = ListSortDirection.Ascending; 25 | FileObjectField _Field; 26 | 27 | public ListSortDirection SortDirection { 28 | get { return _SortDirection; } 29 | set { _SortDirection = value; } 30 | } 31 | 32 | public enum FileObjectField { 33 | Name, LastModifiedTime, Size, Extension 34 | } 35 | 36 | public FileObjectField Field { 37 | get { return _Field; } 38 | set { _Field = value; } 39 | } 40 | 41 | public FileObjectComparer(FileObjectField fld) { 42 | Field = fld; 43 | } 44 | 45 | public FileObjectComparer(FileObjectField fld, ListSortDirection sortDirection) { 46 | SortDirection = sortDirection; 47 | Field = fld; 48 | } 49 | 50 | public int Compare(object x, object y) { 51 | if (x is IFileObject && y is IFileObject) { 52 | IFileObject xFile = (IFileObject)x; 53 | IFileObject yFile = (IFileObject)y; 54 | 55 | if (Field==FileObjectField.Name) { 56 | return SortDirection==ListSortDirection.Ascending ? 57 | xFile.Name.CompareTo(yFile.Name) : yFile.Name.CompareTo(xFile.Name); 58 | } 59 | 60 | if (Field==FileObjectField.LastModifiedTime) { 61 | return SortDirection==ListSortDirection.Ascending ? 62 | xFile.Content.LastModifiedTime.CompareTo(yFile.Content.LastModifiedTime) : 63 | yFile.Content.LastModifiedTime.CompareTo(xFile.Content.LastModifiedTime); 64 | } 65 | 66 | if (Field==FileObjectField.Size) { 67 | return SortDirection==ListSortDirection.Ascending ? 68 | xFile.Content.Size.CompareTo(yFile.Content.Size) : 69 | yFile.Content.Size.CompareTo(xFile.Content.Size); 70 | } 71 | 72 | if (Field==FileObjectField.Extension) { 73 | return SortDirection==ListSortDirection.Ascending ? 74 | Path.GetExtension(xFile.Name).CompareTo( Path.GetExtension(yFile.Name) ) : 75 | Path.GetExtension(yFile.Name).CompareTo( Path.GetExtension(xFile.Name) ); 76 | } 77 | 78 | } 79 | return 0; 80 | } 81 | 82 | 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/NI.Vfs/Interfaces/IFileContent.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.IO; 17 | 18 | namespace NI.Vfs 19 | { 20 | /// 21 | /// Represents the data content of a file. 22 | /// 23 | public interface IFileContent 24 | { 25 | /// 26 | /// Returns the file which this is the content of. 27 | /// 28 | IFileObject File { get; } 29 | 30 | /// 31 | /// Returns a stream for reading or writing the file's content. 32 | /// 33 | /// file access type (read or write). 34 | /// Note that access type option may not be supported by some implementations. 35 | /// An stream to read or write the file's content. 36 | Stream GetStream(FileAccess access); 37 | 38 | /// 39 | /// Determines the size of the file, in bytes. 40 | /// 41 | long Size { get; } 42 | 43 | /// 44 | /// Get or set the last-modified timestamp of the file. 45 | /// 46 | DateTime LastModifiedTime { get; set; } 47 | 48 | /// 49 | /// Closes all resources used by the content, including any open stream. 50 | /// 51 | void Close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/NI.Vfs/Interfaces/IFileSelector.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Vfs 18 | { 19 | /// 20 | /// This interface is used to select files when traversing a file hierarchy. 21 | /// 22 | public interface IFileSelector 23 | { 24 | /// 25 | /// Determines if a file or folder should be selected. 26 | /// This method is called in depthwise order (that is, it is called for the children of a folder before it is called for the folder itself). 27 | /// 28 | /// the file or folder to select 29 | /// true if the file should be selected. 30 | bool IncludeFile(IFileObject file); 31 | 32 | /// 33 | /// Determines whether a folder should be traversed. If this method returns true 34 | /// is called for each of the children of the folder, and each of the child folders is recursively traversed. 35 | /// 36 | /// the file or folder to select. 37 | /// true if the folder should be traversed. 38 | bool TraverseDescendents(IFileObject file); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/NI.Vfs/Interfaces/IFileSystem.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | 17 | namespace NI.Vfs 18 | { 19 | /// 20 | /// 21 | public interface IFileSystem 22 | { 23 | /// 24 | /// Returns the root file of this file system. 25 | /// 26 | IFileObject Root { get; } 27 | 28 | /// 29 | /// Finds a file in this file system. 30 | /// 31 | IFileObject ResolveFile(string name); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/NI.Vfs/ListFileSelector.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.IO; 17 | 18 | namespace NI.Vfs 19 | { 20 | /// 21 | /// A IFileSelector that selects files by explicit list of names 22 | /// 23 | public class ListFileSelector : IFileSelector 24 | { 25 | protected string[] Names; 26 | StringComparison Comparision = StringComparison.CurrentCultureIgnoreCase; 27 | 28 | public ListFileSelector(params string[] names) 29 | { 30 | Names = new string[names.Length]; 31 | // normalize file names 32 | for (int i=0; i= 0; 41 | if (isFullPath && Names[i].Equals(normFileName, Comparision)) 42 | return true; 43 | if (!isFullPath && Names[i].Equals(onlyFileName, Comparision)) 44 | return true; 45 | } 46 | return false; 47 | } 48 | 49 | public bool TraverseDescendents(IFileObject file) { 50 | // TODO: more intellectual behaviour should be implemented here 51 | return true; 52 | } 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/NI.Vfs/MemoryFileContent.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.IO; 17 | 18 | namespace NI.Vfs 19 | { 20 | /// 21 | /// The content of a in-memory file. 22 | /// 23 | public class MemoryFileContent : IFileContent 24 | { 25 | protected MemoryFile MemoryFile; 26 | protected MemoryStream LastStream = null; 27 | protected DateTime _LastModifiedTime = DateTime.Now; 28 | 29 | protected byte[] ContentBytes = null; 30 | 31 | public MemoryFileContent(MemoryFile file) 32 | { 33 | MemoryFile = file; 34 | } 35 | 36 | public IFileObject File { 37 | get { return MemoryFile; } 38 | } 39 | 40 | public Stream GetStream(FileAccess access) { 41 | if (File.Type!=FileType.File) 42 | throw new FileSystemException("Not a file"); // TODO: more structured exception 43 | 44 | if (ContentBytes!=null && access==FileAccess.Read) 45 | return new MemoryStream(ContentBytes, false); 46 | 47 | LastStream = new MemoryFileStream(this); 48 | if (ContentBytes != null) { 49 | LastStream.Write(ContentBytes,0,ContentBytes.Length); 50 | LastStream.Seek(0, SeekOrigin.Begin); 51 | } 52 | return LastStream; 53 | } 54 | 55 | public long Size { 56 | get { 57 | return ContentBytes!=null ? ContentBytes.Length : 0; 58 | } 59 | } 60 | 61 | public DateTime LastModifiedTime { 62 | get { return _LastModifiedTime; } 63 | set { _LastModifiedTime = value; } 64 | } 65 | 66 | public void Close() { 67 | if (LastStream!=null) { 68 | LastStream.Close(); 69 | } 70 | } 71 | 72 | internal class MemoryFileStream : MemoryStream { 73 | MemoryFileContent FileContent; 74 | 75 | public MemoryFileStream(MemoryFileContent fileContent) { 76 | FileContent = fileContent; 77 | } 78 | 79 | public override void Close() { 80 | base.Close(); 81 | FileContent.ContentBytes = ToArray(); 82 | } 83 | 84 | } 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/NI.Vfs/MemoryFileSystem.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.IO; 17 | using System.Collections; 18 | using System.Collections.Generic; 19 | 20 | namespace NI.Vfs 21 | { 22 | /// 23 | /// In-memory filesystem provider implementation. 24 | /// 25 | public class MemoryFileSystem : IFileSystem 26 | { 27 | protected IDictionary MemoryFilesMap; 28 | 29 | public IEnumerable MemoryFiles { 30 | get { return MemoryFilesMap.Values; } 31 | } 32 | 33 | public MemoryFileSystem() 34 | { 35 | MemoryFilesMap = new Dictionary(); 36 | } 37 | 38 | 39 | public IFileObject Root { 40 | get { return ResolveFile(""); } 41 | } 42 | 43 | public IFileObject ResolveFile(string name) { 44 | if (name.Length>0) { 45 | if (name.Contains("..")) { 46 | var fakeRootPath = "f:\\"; 47 | var fakeAbsolutePath = Path.GetFullPath( Path.Combine(fakeRootPath, name) ); 48 | name = fakeAbsolutePath.Substring(Path.GetPathRoot(fakeAbsolutePath).Length); 49 | } 50 | 51 | // use only one symbol as directory separator 52 | name = name.Replace( Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar ); 53 | // normalize file name 54 | name = Path.Combine( Path.GetDirectoryName(name), Path.GetFileName(name) ); 55 | } 56 | 57 | if (!MemoryFilesMap.ContainsKey(name)) { 58 | var newFile = new MemoryFile( name, name.Length>0 ? FileType.Imaginary : FileType.Folder, this); 59 | } 60 | return MemoryFilesMap[name]; 61 | } 62 | 63 | internal void AddFile(MemoryFile f) { 64 | MemoryFilesMap[f.Name] = f; 65 | } 66 | 67 | public void Clear() { 68 | MemoryFilesMap.Clear(); 69 | } 70 | 71 | 72 | 73 | 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/NI.Vfs/NI.Vfs.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | 10 | http://www.nrecosite.com/vfs_net.aspx 11 | 12 | false 13 | $description$ 14 | Copyright 2004-2012 NewtonIdeas, v2 2013-2014 Vitalii Fedorchenko 15 | Vfs Filesystem 16 | 17 | -------------------------------------------------------------------------------- /src/NI.Vfs/RegexFileSelector.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | /* 3 | * Open NIC.NET library (http://nicnet.googlecode.com/) 4 | * Copyright 2004-2012 NewtonIdeas 5 | * Distributed under the LGPL licence 6 | * 7 | * Unless required by applicable law or agreed to in writing, software 8 | * distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | #endregion 14 | 15 | using System; 16 | using System.Text.RegularExpressions; 17 | using System.IO; 18 | 19 | namespace NI.Vfs 20 | { 21 | /// 22 | /// A IFileSelector that selects files by regular expression 23 | /// 24 | public class RegexFileSelector : IFileSelector 25 | { 26 | protected string FilenameRegexPattern; 27 | protected Regex FilenameRegex; 28 | 29 | public RegexFileSelector(string fileNameRegex) { 30 | FilenameRegexPattern = fileNameRegex; 31 | FilenameRegex = new Regex(FilenameRegexPattern, RegexOptions.Compiled|RegexOptions.Singleline); 32 | } 33 | 34 | public bool IncludeFile(IFileObject file) { 35 | return FilenameRegex.IsMatch(file.Name); 36 | } 37 | 38 | public bool TraverseDescendents(IFileObject file) { 39 | // TODO: more intellectual behaviour should be implemented here 40 | return true; 41 | } 42 | } 43 | } 44 | --------------------------------------------------------------------------------