Giter Site home page Giter Site logo

easy.common's People

Contributors

abatishchev avatar dave-q avatar dums35 avatar maxtsarenko avatar nimaara avatar ppasieka 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

easy.common's Issues

CountLines does not reliably support encodings other than UTF-8 / ASCII

Here is an example using UTF-16:

[Test]
public void CountLinesTest()
{
    byte[] bytes = Encoding.BigEndianUnicode.GetBytes(" ਊ ");
    var stream = new MemoryStream(bytes);
    Assert.AreEqual(1, Easy.Common.Extensions.StreamExtensions.CountLines(stream));
}

Results in:

Expected: 1
But was:  3

The character I used is U+0a0a which is interpreted as two line feeds by CountLines. Basically any character in the form U+xx0A or U+xx0D or U+0Axx or U+0Dxx can be misinterpreted as an extra line.

I would suggest renaming the method to CountLinesUtf8 or similar.

Or pass in an Encoding / TextReader but then it won't be as fast.

[Clock] Unable to load DLL 'Kernel32.dll' on Linux

Hi thanks for this library, stumbled upon it recently and it's got some great stuff in there 👍

Just an issue I encountered with a .NET Core 2 app on a Raspberry Pi running Raspbian Linux (could be an issue on other linux distro's too?)

Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'Kernel32.dll': The specified module or one of its dependencies could not be found.

 (Exception from HRESULT: 0x8007007E)
   at Easy.Common.NativeMethods.GetSystemTimePreciseAsFileTime(Int64& filetime)
   at Easy.Common.Clock..ctor()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCreateInstance(CreateInstanceCallSite createInstanceCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitSingleton(SingletonCallSite singletonCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass22_0.<RealizeService>b__0(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at MyApp.Program.<Main>d__1.MoveNext() in D:\Workspace\my-app-raspberry-pi\src\MyApp\Program.cs:line 33
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MyApp.Program.<Main>(String[] args)

Basically when I build my Service Provider, the above error occurs, so it can't fall back to non precise time. I've worked around it by copying the Clock.cs source code in my project and using that without GetSystemTimePreciseAsFileTime(out preciseTime);. Am I missing a nuget package or is there some additional work required to not throw that error on startup?

Cheers

RestClient vs gzip

Hi @NimaAra , as title, does RestClient support gzip

var defaultHeaders = new Dictionary<string, string>
{
   {"Accept", "application/json"},
   {"User-Agent", "foo-bar"},
   {"Accept-Encoding", "gzip" },  // <===================
};

using (IRestClient client = new RestClient(defaultHeaders, timeout: 15.Seconds()))
{
   // ....
}

if it support gzip, how to unzip
thank you

compare property when rightvalue is null

reference code:

//Variance.cs:
private bool VariesImpl()
        {
            var isSequence = Property.PropertyType.IsSequence(out SequenceType _);

            if (LeftValue is null) { return RightValue != null; }
            if (RightValue is null) { return false; }

            if (!isSequence) { return !Equals(LeftValue, RightValue); }

            var left = ((IEnumerable)LeftValue).Cast<object>();
            var right = ((IEnumerable)RightValue).Cast<object>();
            return !left.SequenceEqual(right);
        }

qusetion:

if (RightValue is null) { return false; } shouldbe if (RightValue is null) { return true; }

becase, LeftValue is not null and RightValue is null

DiagnosticReport Throws System.NullReferenceException in PowerShell Core Beta 9

This is a great little library!

My interest in this is related to PowerShell Core development (PowerShell Core is the .Net 2.0 App that can run on almost any OS, as opposed to Windows PowerShell, which is the .Net Framework App that comes installed on Windows by default). Right now, there are a lot of basic cmdlets missing from PowerShell Core (like Get-NetIPAddress for network info), and this report can help fill-in the gaps until the PowerShell community gets around to creating some of the missing cmdlets.

Since PowerShell Core is a .Net 2.0 App, it should be able to load and use the netstandard2.0 assembly. I can load the assembly without issue, but running Generate() throws the below error:

PowerShell v6.0.0-beta.9
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\testadmin> Add-Type -Path "C:\Users\testadmin\.nuget\packages\Easy.Common.2.6.1\lib\netstandard2.0\Easy.Common.dll"
PS C:\Users\testadmin> [Easy.Common.DiagnosticReport]::Generate()
Unable to generate the Diagnostic Report. Error:
        System.NullReferenceException: Object reference not set to an instance of an object.
   at Easy.Common.DiagnosticReport.<AddProcess>g__Format17_1(String key, Object value, <>c__DisplayClass17_0& )
   at Easy.Common.DiagnosticReport.AddProcess(StringBuilder builder)
   at Easy.Common.DiagnosticReport.GenerateImpl(DiagnosticReportType type)
   at Easy.Common.DiagnosticReport.Generate(DiagnosticReportType type)

(As an FYI, the net45 assembly works fine in Windows PowerShell 5.1 - i.e. the .Net Framework App).

(Also, if you haven't worked with PowerShell Core before, you can grab an installer from here: https://github.com/PowerShell/PowerShell/releases)

Thanks again for making this!

Extend IRestClient to enable per request timeouts.

IRestClient currently relies on HttpClient default timeout which is 100 seconds. One can currently issue a different timeout per request by executing the following:

var cts = new CancellationTokenSource(TimeSpan.FromSeconds(15));
await client.GetAsync("http://localhost", cts.Token);

This should be made easier by exposing an overload accepting a Timespan as timeout for each of the following:

GetAsync
GetStringAsync
GetStreamAsync
GetByteArrayAsync
DeleteAsync
PostAsync
PutAsync

It is also important to note in order for this per request timeout to be effective, the default timeout must be set to infinite. So RestClient by default will set the timeout of its internal HttpClient to: System.Threading.Timeout.InfiniteTimeSpan unless a different value is provided via the constructor.

Extending Rest Client to expose more method on HttpClient so interfaces are more similar

Hello!

I commented on your blog post about this and you suggested I should contribute, so here I am, hello :)

Extending the class is simple enough, however I just wanted to get your thoughts on the IRestClient Interface. There is only one implementation in this library but could people have created their own implementations? Extending the interface could break their code which is not good.

My plan b is implement the 'missing' methods as extension methods of IRestClient - this would then not break any existing implementations of IRestClient.

What are you're thoughts?

.NET Core returns "<INVALID>" Processor Name

Thanks for the great tool! It's been a great help for getting system info for cross-platform .NET programs we're writing.

I've noticed what I think is a bug in getting the processor name in Windows in .NET Core applications.

private static string GetProcessorNameWindows()

This code block checks for .NET framework or .NET standard targets and returns if the application is not targeted to one of those two. Unfortunately this means that .NET Core applications return "< INVALID >", even though lines 772-773 would work perfectly fine. Can you either remove the targeting requirement, or include .NET Core in the conditional? Or wrap in a try/catch block?

Another request - can you make methods like GetProcessorName() and GetInstalledMemoryInGigaBytes() public? It would be nice to be able to display these outside of your diagnostic report.

I'd be happy to make a pull request - let me know if I should.

Uniqueness of IDGenerator

Hey, I saw your ID generator on your article and thought it was cool. Is it good for generating unique user IDs, though? Would I be better off using .NET's built in GUIDs?

Is it a better way?

Hi

Thanks for the effort.

I don't want to fiddle with ConnectionLeaseTimeout . So is it a better way to create a cache of httpclients based on base uri's. Each unique base uri will have it's own HttpClient. If we have 5 unique uri's we will have 5 items in the cache. URI is our key.

Do you think this is a better approach?

Thanks again!!!

DiagnosticReport report in json format

I love the idea behind the DiagnosticReport but would it be possible to return in a JSON string rather than a "prettified" report? I love all the information but my logging system wouldn't take in that very well as a preformatted string.

Thanks.

RestClient's AddConnectionLeaseTimeout method - redux

Finding a service endpoint and then setting its ConnectionLeaseTimeout value within the SPM for each and every full URI that RestClient talks to is potentially wasteful, since - as you say - "the method only cares about the host, schema and port everything else is ignored".

So say the caller of RestClient talks to a single API whose base URI is https://myapi.com/v1/ . Say you hit this API a 1000 times. RestClient will set ConnectionLeaseTimeout a 1000 times, but it only needs to do so once.

ReadLineCounter

I reviewed the readline code, and you should probably just fix your code to do that because there is nothing to be gained here.

Memory leak in RestClient

Hello,

The RestClient implementation seems to be leaking memory, fairly slowly in our case to be honest. Unfortunately, we have now switched to core 2.1 and httpClientFactory, which fixed the leak, so didn't look into the issue thoroughly enough. I suspect it is related to keeping the endpoints in memory. Hope this helps, let me know if I can provide any more useful info.

Question: How to support headers and cookies with IoC container set to per request?

Hello,

Sorry for not coming up with a more succinct title.

I have wrapped the RestClient in a service that will perform 4 HTTP requests serially and need to preserve some of the headers and cookies during these calls. My service will be injected into the web API controller via constructor injection and invoked from an API route. My container is Autofac and I have set my service and RestClient to be InstancePerRequest. So now that I have that out of the way, I was wondering about how to persist headers and cookies across the 4 calls? Also wondering if you have any feedback on the life-time of the RestClient given my requirements?

Thanks in advance Nima!

-Stephen

Did not consider the ServicePoint be removed from the servicepointmanager and it's resource get released after a timeout period

https://github.com/NimaAra/Easy.Common/blob/master/Easy.Common/RestClient.cs

You used Hashset in AddConnectionLeaseTimeout to check whether the service pointhas been set to the ConnectionLeaseTimeout to 1 min.

But as this https://stackoverflow.com/questions/53653640/net-servicepoint-object-lifecycle says, servicePoint object will be removed from the servicepointmanager and it's resource will get released after a timeout period, so seems your implementation did not consider this.

Actually, I am wondering have you ever met the issue with the link above said, since from the code I think you will just meet same issue.

RestClient's AddConnectionLeaseTimeout method

AddConnectionLeaseTimeout is confused.

First of all, it doesn't only "add connection lease timeout". It also adds to the collection of "all of the endpoints which this instance has sent a request to", which is returned by the public Endpoints property.

Secondly, since you note correctly regarding ServicePointManager.FindServicePoint(endpoint) that "the method only cares about the host, schema and port everything else is ignored", then it is redundant to perform:-

ServicePointManager.FindServicePoint(endpoint).ConnectionLeaseTimeout = <value>;

for each full URI. It is only necessary to do this once for any URI's host+schema+port. For some use cases of the RestClient class, this could result in a significant saving.

Of course, you'd need a second, purely-internal HashSet<Uri> in which to record the shortened URIs on which you've set ConnectionLeaseTimeout.

How do you test this RestClient ConnectionLeaseTimeout behavior?

Hi,

Sorry to use this Issues channel as I didn't see any other ways to communicate. I am not using this library directly but I need to set this ServicePointManager.ConnectionLeaseTimeout property. However in my test environment it doesn't work as expected. Do you have any experience on this one? like how to verify behavior?

Thanks
Chunyuan

Possible UnauthorizedAccessException in Easy.Common.DiagnosticReport.GetDriveDetails

There is a possible exception in Easy.Common.DiagnosticReport.GetDriveDetails when enumerating the details about the connected drives if there is a mapped drive the application or current user does not have access to.
It looks like accessing either VolumeLabel and DriveFormat could throw.

Specifically here: https://github.com/NimaAra/Easy.Common/blob/master/Easy.Common/DiagnosticReport/DiagnosticReport.cs#L298

Easy workaround:
Exclude drives from the report.
DiagnosticReport report = DiagnosticReport.Generate(DiagnosticReportType.Full & ~DiagnosticReportType.Drives);

Proper fix:
Maybe the best way would be to catch the exception and substitute with '-'.

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.