Snippets tagged c#

  • Count noise-lines in C# code

    This is the code I used to generate this pie chart: http://pic.twitter.com/PgPEFByg56 Enough said?

    9 people like this

    Posted: 11 years ago by Kit Eason

  • Make option type usable in C#

    Using FSharpOption is painful from C#, but it doesn't have to.

    3 people like this

    Posted: 9 years ago by Gauthier Segay

  • C# motion detection source code: How to achieve tripwire with a USB webcam

    Tripwire is a special part of motion detection that can be used to monitor and alert on specific changes. More specifically: tripwire means the detection of intrusion. This code snippet presents how to create a C# software by using prewritten computer vision components (http://www.camera-sdk.com/) allowing you to get notified when your USB webcam triggers an intrusion. For instance, by using this application, you can use your camera to alarm when a people enters into the shop/office, or even to count how many people entered, etc. After the necessary using lines and objects you need to implement the Main method and the necessary functions for connecting to a USB webcamera. The startBt_Click method is used to start the tripwire functionality. Thereafter you can see how to handle the enter and exit events. Nothing could be more simple! :)

    0 people like this

    Posted: 5 years ago by chewie-wookiee

  • How to send SMS using ASP.NET through HTTP (C#)

    Hello Guys, This short ASP.NET code snippet is intended to provide you a brief review on how to add SMS functionality to your website. You will see, this is a very simple but smart solution. This ASP.NET application is able to send messages by using HTTP requests towards the SMS gateway that sends the SMSs to the destination telephone via a GSM modem or an IP SMS connection. Let’s take a quick look at the software requirements that are essentially needed for this solution. In order to send SMS messages from your ASP.NET application, you need a development platform, e.g Visual Studio, of course, .NET Framework 4.0, Internet Information Services (IIS) and an SMS gateway (I used Ozeki NG – http://www.ozekisms.com). You also need a GSM modem attached to your PC or an IP SMS connection to be able to send messages. Okay and now let’s use the code snippet! Copy the content of smssend.aspx and smssend.aspx.cs into the main directory of the IIS server - C:\Inetpub\wwwroot\ directory (). Configure the fixed data in the smssend.aspx.cs file (the IP address and port number of the SMS gateway, username, password). Launch your SMS gateway Server. Start a web browser and enter this URL: http://127.0.0.1/smssend.aspx - where 127.0.0.1 means that the smssend.aspx and smssend.aspx.cs files can be found on the same computer on which the browser has been opened). Fill in the required fields, and then click the Send button. It’s as easy as that! Happy coding! :)

    2 people like this

    Posted: 4 years ago by Aarav Gupta

  • Awaiting arbitrary C# awaitables

    Uses SRTPs to define a general purpose adapter for awaiting arbitrary C# awaitables in F# async workflows.

    3 people like this

    Posted: 3 years ago by Eirik Tsarpalis

  • How to implement conference calling for a SIP softphone in C#?

    A conference call is a meeting, conducted over the phone using audio, between two or more people and usually for the purposes of discussing a particular topic. In my former snippets I dealt with text-to-speech and speech-to-text functionalities. So the implementation of conference calling can sound a little bit strange as compared with my previous tutorials. But I thought it provides a good opportunity for a new challange, so I thought I share my upshot expectedly that it will be useful for you. A softphone with built-in conference call feature can be greatly used in business communication as well as in companionship. The source code below is ready for use, so you only need to copy&paste it to your Visual Studio, then modify the necessary fields. (Do not forget to add the necessary DLL file providing the VoIP background to your references: http://www.voip-sip-sdk.com) This program will be a console application that functions as a softphone making conference calling possible. This solution assumes that you have a PBX with some SIP extensions installed previously. After creating the necessary using lines and objects, you need to define your PBX and provide the appropriate SIP account details in order to be able to register your application to the phone system. When you have created all the required methods for SIP calling, you need to initialize the conference room and handle the related events. AddToConference is used to add new party to the conference room and RemoveFromConference is used when the call is ended. Have a good time!

    2 people like this

    Posted: 9 years ago by warnerBro19

  • C#-Friendly Single-Case Discriminated Unions

    Single-case Discriminated Unions (https://fsharpforfunandprofit.com/posts/designing-with-types-single-case-dus/) are a lightweight way to create types for important concepts in your domain. Unfortunately, there's a few gotchas when consuming from C# to be aware of. For one, if you use the `==` or `!=` operators in C#, it will do a reference comparison, which is almost certainly not what you want for these wrapper types. By overriding `op_Equality` and `op_Inequality`, this will force it to use a structural comparison. Secondly, when using string concatenation via `+`, `String.Format`, or string interpolation, C# will implicitly convert non-string arguments to a string via `ToString`. This means if you forget to use `.Item` to unwrap your value, you will not get a compiler error, it will just implicitly call `ToString`, which by default will look like this: `Id "c148b684-2c40-4383-a1b9-0e8f37752fd0"`. By overriding `ToString`, we can make sure it will look like the raw underlying type when converted to a string: `c148b684-2c40-4383-a1b9-0e8f37752fd0`.

    2 people like this

    Posted: 6 years ago by Justin Hewlett

  • Simple C# Parser

    Simple prototype C# AST and parser using the FParsec parser combinator library. Parses a subset of C# 1.1 constructs.

    8 people like this

    Posted: 4 years ago by Phillip Trelford

  • Useful operator definition for interop with C#

    invokes op_Implicit when applied (for implicit conversions). I have found this to be very convenient when using C# libraries

    6 people like this

    Posted: 4 years ago by Faisal Waris