Giter Site home page Giter Site logo

unosquare / swan Goto Github PK

View Code? Open in Web Editor NEW
259.0 259.0 27.0 20.61 MB

Swan stands for Stuff We All Need. Unosquare's collection of C# extension methods and classes.

Home Page: https://unosquare.github.io/swan

License: MIT License

C# 100.00%
best-practices csharp csv-format deserialize dns json-serialization netcore netframework netstandard network ntp objectmapper

swan's People

Contributors

alexey-unosquare avatar amoraleso avatar brianx03 avatar bufferunderrun avatar chubbsnes65 avatar dependabot-preview[bot] avatar dependabot[bot] avatar geoperez avatar greciaveronica avatar israelramosm avatar jcorrea13 avatar jpalcala avatar k3z0 avatar kuyoska avatar marcolpr avatar marinasundstrom avatar mariodivece avatar nesb09 avatar oliverkenny avatar p- avatar pgrawehr avatar rdeago avatar serk352 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  avatar  avatar  avatar  avatar  avatar

swan's Issues

Model validator

Add a Model Validator component, allowing to include validation by expression or attributes.

ProcessRunner.GetProcessOutputAsync is not working

This is the code being used (From RaspberryIO Playground):

` public bool SetupWirelessNetwork(string adapterName, string networkSsid, string password = null)
{
var payload = "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\nupdate_config=1\n";

        payload += string.IsNullOrEmpty(password) ?
            $"network={{\n\tssid=\"{networkSsid}\"\n\t}}\n" :
            $"network={{\n\tssid=\"{networkSsid}\"\n\tpsk=\"{password}\"\n\t}}\n";

        try
        {
            File.WriteAllText("/etc/wpa_supplicant/wpa_supplicant.conf", payload);
            ProcessRunner.GetProcessOutputAsync("ifconfig >> /home/pi/ifconfig.txt");
            //ProcessRunner.GetProcessOutputAsync("sudo pkill -f wpa_supplicant >> /home/pi/Documents/kill_wpa.txt");
            //ProcessRunner.GetProcessOutputAsync("sudo wpa_supplicant", $"-B -D wext -i {adapterName} -c /etc/wpa_supplicant/wpa_supplicant.conf >> /home/pi/Documents/run_wpa.txt");
        }
        catch
        {
            return false;
        }

        return true;
    }`

After a while testing on raspberry, realized the "ProcessRunner.GetProcessOutputAsync" does nothing at all. Used the line "ProcessRunner.GetProcessOutputAsync("ifconfig >> /home/pi/ifconfig.txt");" to be sure and it did not created any file, but command worked on command line.

Am I using this the wrong way?

Migrate FFME primitives

Migrate the following classes to the solution:

SWAN Lite

  • AtomicBoolean.cs (root)
  • AtomicDouble.cs (root)
  • AtomicLong.cs (root)
  • Benchmark.cs (Components)
  • IWaitEvent.cs (Abstractions)
  • ISyncLocker.cs (Abstractions)
  • SyncLockerFactory.cs (Components)
  • WaitEventFactory.cs (Components)

SWAN Standard

  • DelayProvider.cs (Components)
  • RealtimeClock.cs (Components)

Terminal is not printing messages when ReadKey is waiting

If the logic has a task writing to the Terminal but the main thread is waiting for ReadKey, the messages are not shown:

Task.Factory.StartNew(async () =>
            {
                while (true)
                {
                    await Task.Delay(TimeSpan.FromSeconds(1));
                    "OK".Info();
                }
            });

            "Press any key".Info();
            Terminal.ReadKey(true);
``

Document MessageHub

Include a MessageHub section at README file. Check the Wiki for more information.

[Enhancement] Possibility to set data encoding in GetProcessResultAsync

Now the data is decoded using the default coding (for me ANSI). Please add the option to choose another type of encoding. Specifically, it would be great utf-8. (I encountered this when processing the output from ffprobe, which is in utf-8.)

So far, it can be handled by RunProcessAsync. The data can be read as follows:
Encoding.GetEncoding("utf-8").GetString(data).WriteLine();

High CPU usage on RaspberryPi using Terminal

ManualResetEventSlim causes spinwaits (high CPU usage)
Terminal.cs - Lines 21 and 22 need to be changed to:

        private static readonly ManualResetEvent OutputDone = new ManualResetEvent(false);
        private static readonly ManualResetEvent InputDone = new ManualResetEvent(true);

Change DequeueOutputTask to a background (NOT THREADPOOL PLEASE) Thread with BelowNormalPriority. Here are all the changes:

               // Change declaration
               private static readonly Thread DequeueOutputTask;

                // Here we start the output task, fire-and-forget
                DequeueOutputTask = new Thread(DequeueOutputAsync)
                {
                    IsBackground = true,
                    Name = nameof(DequeueOutputTask),
                    Priority = ThreadPriority.BelowNormal
                };

               // Change signature:
               private static void DequeueOutputAsync()

              // wrap the outer loop of DequeueOutputAsync with:
              using (var tickLock = new ManualResetEvent(false))
              {

              // Change await Task.Delay(1) to 
              tickLock.WaitOne(1);
...


I need this fixed to continue one of my projects.
And you need this fixed to continue the AccessCore project as well

New .csproj with SDK "Microsoft.NET.Sdk.Web" fail to load

Cannot deploy ASP.NET Core project with SSHDeploy which depends on SWAN.

Unhandled Exception: System.ArgumentException: Project file is not of the new .csproj type.
     at Unosquare.Swan.Components.CsProjFile`1..ctor(Stream stream, Boolean leaveOpen)
     at Unosquare.Labs.SshDeploy.Program.Main(String[] args)

It is because the CsProjFile class checks for Sdk="Microsoft.NET.Sdk", and assumes that it is what makes it the new .csproj-format, but there is also Microsoft.NET.Sdk.Web for web projects.

Is that really the only way to check if it is the new csproj-format?

SWAN Lite and SWAN Full

Allow the solution to build SWAN Lite (no networking) to reduce overhead of DLL when you don't require the network related classes.

API CopyMemory in kernel32.dll is not supported for this application type. Unosquare.Swan.dll calls this API.

Hi,

we use Embed IO in one of our apps, which uses SWAN. Wenn we try to publish the app to the Windows Store, we get the error "API CopyMemory in kernel32.dll is not supported for this application type. Unosquare.Swan.dll calls this API."

We checked the code for Embed IO and did not found any reference to CircularBuffer() which causes the problem in SWAN:

    [DllImport("kernel32")]
    public static extern void CopyMemory(IntPtr destination, IntPtr source, uint length);

As a workaround for us we code remove the CircularBuffer Class from SWAN and resubmit but this is not a long term solution.

Could you implement a managed alternative and not using the unmanaged Windows API anymore?

Thanks and regards

Guido

Bug in RunProcessAsync?

I'm trying to process the output data from ffprobe. I have a problem processing with RunProcessAsync. The output is duplicated and garbled. Can you look at it, please?

Here is my code:

        private async Task RunTest()
        {
            string output = "";
            string output2 = "";

            var result = await ProcessRunner.RunProcessAsync(
               @"C:\Users\Test\Documents\ff\ffprobe.exe",
               "-v quiet -print_format xml -show_format \"b.mp4\"",
               // A success callback with a reference to the output and the process itself
               (data, proc) =>
               {
                   output = Encoding.GetEncoding("utf-8").GetString(data);
                   output2 += output;
                   Console.WriteLine("Success callback. Length: " + output.Length);
               },
               // An error callback with a reference to the error and the process itself
               (data, proc) =>
               {

               }
              );

            Console.WriteLine("Complete length:" + output2.Length);
            Console.WriteLine(output2);
        }

The console output is:

Success callback. Length: 517
Success callback. Length: 2048
Complete length:2565
<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
    <format filename="b.mp4" nb_streams="4" nb_programs="0" format_name="mov,mp4,m4a,3gp,3g2,mj2" format_long_name="QuickTime / MOV" start_time="0.000000" duration="60.095000" size="5510872" bit_rate="733621" probe_score="100">
        <tag key="major_brand" value="mp42"/>
        <tag key="minor_version" value="1"/>
        <tag key="compatible_brands" value="mp42avc1"/>
        <tag key="creation_time" value="2010-02-09T01:55:39.000000Z"/>
    </format>
</ffprobe>
n="1.0" encoding="UTF-8"?>
<ffprobe>
    <format filename="b.mp4" nb_streams="4" nb_programs="0" format_name="mov,mp4,m4a,3gp,3g2,mj2" format_long_name="QuickTime / MOV" start_time="0.000000" duration="60.095000" size="5510872" bit_rate="733621" probe_score="100">
        <tag key="major_brand" value="mp42"/>
        <tag key="minor_version" value="1"/>
        <tag key="compatible_brands" value="mp42avc1"/>
        <tag key="creation_time" value="2010-02-09T01:55:39.000000Z"/>
    </format>
???????????????????????????????????????????????????????????????????????????????????????????????

Here is sample video: b.zip

Reduce dependencies

Verify that System.Console and System.Collections.Nongeneric are indeed needed

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.