Code Monkey home page Code Monkey logo

westwind.utilities's Introduction

Westwind.Utilities

Library Versions and Stats
Westwind.Utilities
Westwind.Utilities.Data
Documentation

A general purpose utility and helper library for .NET development

Supports the following Targets:

  • .NET Standard 2.0
  • .NET 4.62+

Installation

You can install the package from NuGet using the Visual Studio Package Manager or NuGet UI:

PM> install-package westwind.utilities

As of version 4.0 the Data related features are located in a separate NuGet Package:

PM> install-package westwind.utilities.data

Upgrading from v3 and using Data Access Features?

If you're switching from v3 or earlier and are using the Data Access features of the library, this is a breaking change that requires you to add the new westwind.utilities.data package.

What is it?

Every .NET application requires small, common and often repeated tasks. This library is a collection of those things that I commonly need on a regular basis and have compiled over the years.

It includes tools for:

and much, much more.

It's worthwhile to browse through the source code or the documentation to find out the myriad of useful functionality that is available, all in a small single assembly.

This assembly is the base for most other West Wind libraries.

License

This library is published under MIT license terms.

Copyright © 2012-2023 Rick Strahl, West Wind Technologies

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

westwind.utilities's People

Contributors

jamessquinn avatar rickstrahl avatar shps951023 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

westwind.utilities's Issues

in the time string utils - converting time entry to time

Hi, I am finding your lib helpful. Particularly when using it on time data input in a text box. For e.g. a time sheet where people sometimes enter 10.25 or 10,25 or 10:25 - it would be helpful if we could get this input normalized to time volumes

Could not load file or assembly 'System.Data.SqlClient

Hi Rick,
I am using Westwind.Utilities and am getting the following error on .net Core 3.1.
Search all over but can not find a solution... Do you have an idea how to fix this

'Could not load file or assembly 'System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'

Microsoft.Data.SqlClient for .NET Framework

I see that in #15 that a commit was made to support using the Microsoft.Data.SqlClient but only for .NET Core. The project I'm currently working on utilized Westwind in .NET Framework 4.8.1 but is migrating to using Azure SQL Servers via Azure Active Directory authentication. It is currently not able to pull translations from the database due to this. Is there a way to enable the Microsoft.Data.SqlClient for .NET Framework?

Use Microsoft.Data.SqlClient

According to Microsoft Microsoft.Data.SqlClient is the new client to use for SQL access. I ran into an issue with Westwind.Globalization when trying to use an Azure Active Directory Connection string which uses Authentication=Active Directory Password to configure access. I traced the problem to DbConnectionOptions not supporting that keyword, see exception below

System.ArgumentException
  HResult=0x80070057
  Message=Keyword not supported: 'authentication'.
  Source=System.Data.SqlClient
  StackTrace:
   at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)

Any thoughts on switching to the new SqlClient assembly?

Regards,
Shane Holder

SQL Provider Error

I am able to set up and use settings using the default provider. This works really well. I have a need to store some settings in a SQL Server database to act as a type of application-level settings. This is an enterprise-level software where I have multiple users logging into and using my software. I need to have the ability to save and access settings from a table for all users and be able to change these settings dynamically. I believe your utilities fit the bill perfectly.

I am having issues when using SqlServerConfigurationProvider. I am always getting an exception of the following:
WestWind error

I understand the error and have checked all the possibilities of open connections/pooling issues. This is not the case. I started a new project for just testing this function. The connection to the DB is not used any place in the project except setting the SqlServerConfigurationProvider.

I downloaded your repository and added it to my project so that I could step through your code and see where the issue is happening. See below:
Westwind SQL Error

The exception occurs at Line 110 when the DbCommand executes the ExecuteReader() method. The connection is never being opened and even if it was, this would fail because there is no customers table ("Select * from Customers").

Here is the code that I am using:

SqlServerApplicationConfig Class

Public Class SqlServerApplicationConfig : Inherits Westwind.Utilities.Configuration.AppConfiguration

    Public Property ApplicationTitle As String
    Public Property MaxPageItems As Integer

    Public Sub New()
        ApplicationTitle = "Configuration Tests"
        MaxPageItems = 15
    End Sub

    Protected Overrides Function OnCreateDefaultProvider(sectionName As String, configData As Object) As IConfigurationProvider
        Dim ConfigKey = 1
        If configData IsNot Nothing Then ConfigKey = CInt(configData)

        Dim MyConnectionString = "Data Source=(LocalDB)\MSSQLLOCALDB;AttachDbFilename=C:\Users\colena\SettingsTest.mdf;Integrated Security=True"

        Dim provider = New SqlServerConfigurationProvider(Of SqlServerApplicationConfig)
        provider.ConnectionString = MyConnectionString
        provider.Tablename = "ConfigurationSettings"
        provider.Key = ConfigKey

        Return provider

    End Function

End Class

AppSql Class

Public Class AppSql
    Shared Property Configuration As SqlServerApplicationConfig
    Shared Sub New()

        Configuration = New SqlServerApplicationConfig
        Configuration.Initialize()

    End Sub
End Class

Form1 Button1.Click handler

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim customMaxItems = AppSql.Configuration.MaxPageItems

    AppSql.Configuration.MaxPageItems = 567
    AppSql.Configuration.Write()


    Me.Text = $"{AppSql.Configuration.ApplicationTitle} - {AppSql.Configuration.MaxPageItems}"

End Sub

I don't understand your code and would greatly appreciate any help you could provide.

Thanks,
Nathan

DbProviderFactory

Your blog post about DbProviderFactory brought me here as I am trying to get a lib to .NET Standard.
After some (unsuccesful) testing:
Is it possible, that there is some kind of variable "mismatch" in DataUtils.GetDbProviderFactory
regarding providername and providerName?

The exception I get is:
System.NotSupportedException: 'Unsupported Provider Factory specified: System.Data.SqlClient'

I replaced providername/providerName with _lower to make it clearer what I mean:

public static DbProviderFactory GetDbProviderFactory(string providerName)
{
#if NETFULL
    return DbProviderFactories.GetFactory(providerName);
#else
    var _lower = providerName.ToLower();

    if (_lower == "system.data.sqlclient")
        return GetDbProviderFactory(DataAccessProviderTypes.SqlServer);
    if (_lower == "system.data.sqlite" || _lower == "microsoft.data.sqlite")
        return GetDbProviderFactory(DataAccessProviderTypes.SqLite);
    if (_lower == "mysql.data.mysqlclient" || _lower == "mysql.data")
        return GetDbProviderFactory(DataAccessProviderTypes.MySql);
    if (_lower == "npgsql")
        return GetDbProviderFactory(DataAccessProviderTypes.PostgreSql);

    throw new NotSupportedException(string.Format(Resources.UnsupportedProviderFactory,providerName));
#endif
}

For now I ripped off this bit into "my" lib for a first workaround (and to see that it could be that mismatch):

    DbProviderFactory GetFactory(string providerName)
    {
        var _lower = providerName.ToLower();

        if (_lower == "system.data.sqlclient")
            return SqlClientFactory.Instance;

        return null;
    }

I hope it is some help and that I don't misunderstand something completly.
Thanks anyway (and for the blog post ;) )

DefineConstants values in Westwind.Utilities.csproj

In

https://github.com/RickStrahl/Westwind.Utilities/blob/master/Westwind.Utilities/Westwind.Utilities.csproj

<TargetFrameworks>netstandard2.0;net46;net40</TargetFrameworks>

So we have net46 in the list.

And later on we have the below.

  <PropertyGroup Condition=" '$(TargetFramework)' == 'net46'">
    <DefineConstants>NET45;NETFULL</DefineConstants>
  </PropertyGroup>

The "constant" NET45.

Is that a typo (copy/paste error)? Or on purpose?

Should it be (the below)?

<DefineConstants>NET46;NETFULL</DefineConstants>

I'm probably over thinking it (and its a mild typo and should be NET46)...

But I've having Net20, Net30, and Net35 "flashbacks" when 3.0 and 3.5 built on top of 2.0.

Thanks for all your blogs! I learn something new and stay updated with many of your articles.

After Update from 3.0.4 to 3.0.13 | ExecuteReader requires an open and available Connection. The connection's current state is Connecting

Hello,

after updating to the latest version of westwind utilities i get an InvalidOperationException while initiating a AppConfiguration with an SqlServerConfigurationProvider.

This is my Default-Provider

protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName,
                                                                object configData)
{
    string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    string tableName = "ApplicationConfiguration";

    var providerSql = new SqlServerConfigurationProvider<ApplicationConfiguration>()
    {
        ConnectionString = connectionString,
        Tablename = tableName,
        Key = 1,
    };

    return providerSql;
}

With the old version everything works as expected

i initiate the the ApplicationConfiguration within the contructor of a static class. And i am calling it in the Application_Start() of my MVC-Application.

XPathException: Expression must evaluate to a node-set

When setting the ConfigurationFile property of a ConfigurationFileConfigurationProvider object, leaving out the ConfigurationSection property, I get the following error at runtime, as soon as I try to access a property of my custom AppConfiguration class: "XPathException: Expression must evaluate to a node-set." When I set the ConfigurationSection property it works.
I just want to save the config file in a different directory, I don't expect to have to provide a ConfigurationSection value.

Update HtmlUtils.cs to fix XSS Attack , it's different between Westwind.Utilities.HtmlEncode and System.Web.HttpUtility.HtmlEncode on `'`.

Update HtmlUtils.cs to fix XSS Attack , it's different between Westwind.Utilities.HtmlEncode and System.Web.HttpUtility.HtmlEncode on '. by shps951023 · Pull Request #7 · RickStrahl/Westwind.Utilities

it's different between Westwind.Utilities.HtmlEncode and System.Web.HttpUtility.HtmlEncode on '.

	var HttpUtilityEncodeResult = System.Web.HttpUtility.HtmlEncode("alert('XSS Attack')"); //"alert(&#39;XSS Attack&#39;)"
	var WestwindEncodeResult = Westwind.Utilities.HtmlUtils.HtmlEncode("alert('XSS Attack')"); //"alert('XSS Attack')"

how to override settings with Secrets?

Can a WestWind Utilities application settings mapping be overridden by a Secrets.json?

The App Secret Docs show how to use a naming convention when mapping to a POCO.

"Application:ApplicationName": "secretTestAppName"

Is there a naming convention to set a secret so that it will override the setting in the appsettings.json?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.