Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, February 15, 2019

Linux Mono C#



$mono-csc searchmono.cs /out:seachmono -r:/usr/lib/mono/4.5/System.Web.dll

Compiling with mySql connector library
$mono-csc mysqlmono.cs /out:mysqlmono -r:System.Data.dll -r:/path/.nuget/packages/mysql.data/8.0.13/lib/net452/MySql.Data.dll


References:
[1] Example https://www.codeproject.com/Articles/9407/Introduction-to-Mono-Your-first-Mono-app
[2] Converter tools
     http://converter.telerik.com/
     https://codeconverter.icsharpcode.net/
     https://www.carlosag.net/tools/codetranslator/
[3] Mysql Connection https://www.mono-project.com/docs/database-access/providers/mysql/

Tuesday, November 27, 2018

ASP.NET MVC Mono

Settings at 11/2018

.Net Framework 4.5.2 using project properties
Mysql.Data.Entity using NuGet(6.10.8)

Setup Web.config

<!--Added--> 
<configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections> 
<connectionStrings> 
  <add name="ferredb" connectionString="server=127.0.0.1;Port=3306;Database=ferre;Uid=root;Pwd=Microsoft;" providerName="MySql.Data.MySqlClient"/> </connectionStrings> 
<!--Added--> 
<entityFramework> 
<providers> 
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
  </provider> 
</providers> 
</entityFramework> 
<!--Added--> 
<system.data> 
<DbProviderFactories> <remove invariant="MySql.Data.MySqlClient" /> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/> 
 </DbProviderFactories> 
</system.data>

Fix version of entry System.Web.Mvc.MvcWebRazorHostFactory at views/Web.config


Classes

//Ado
using System;
using System.Data.Entity;
using MySQLEntity.Models;

namespace MySQLEntity.Entity
{

public class MyDb : DbContext
{
public MyDb() : base("ferredb")
//public MyDb() : base(nameOrConnectionString: "ferredb")
{
}
public DbSet<Usuario> Usuarios { get; set; }
}


}


//Entity
using System;
//Added
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;


namespace MySQLEntity.Models
{
        [Table("Users")]
        public class Usuario
        {
            [Key]
            public string usuario { get; set; }
            public string apenom  { get; set; }
        }

}



Controller Snippet code

public ActionResult Index()
{
  MyDb db = new MyDb();
  var Model=db.Usuarios.ToList();
  return View(Model);
}

View Snippet code


@foreach (var item in Model)
{


<div> @item.usuario @item.apenom </div>
}

Action results
Types

References:
[1] MySQL EntityFramework web.config https://iyalovoi.wordpress.com/2015/04/06/entity-framework-with-mysql-on-mac-os/
[2] Action results
https://www.c-sharpcorner.com/article/different-types-of-action-results-in-asp-net-mvc/
[3] ViewBag better than DataView http://www.tutorialsteacher.com/mvc/viewbag-in-asp.net-mvc


Wednesday, February 12, 2014

C# Todo sobre puertos Serial(COM) y Paralelo(LPT )

How to program Read,Write parallel port in C#?
http://sandeep-aparajit.blogspot.com/2008/08/io-how-to-program-readwrite-parallel.html

Parallel port
http://www.epanorama.net/circuits/parallel_output.html
http://www.epanorama.net/circuits/parallel_output_es.html

I/O Ports Uncensored - 1 - Controlling LEDs (Light Emiting Diodes) with Parallel Port
http://www.codeproject.com/KB/cs/csppleds.aspx?df=100&forumid=21021&exp=0&select=974134

I/O Ports Uncensored Part 2 - Controlling LCDs (Liquid Crystal Displays) and VFDs (Vacuum Fluorescent Displays) with Parallel Port
http://www.codeproject.com/KB/cs/cspplcds.aspx

How to Capture LPT Port(s) to Intercept DOS Print Requests
http://www.codeproject.com/KB/system/LPTCapture.aspx

Recursos:
Lpt Monitor y muchos otros muy útiles
http://neil.fraser.name/software/
Com Monitor
http://www.serial-port-monitor.com/
Drivers para dispositivos varios controlados por puertos LPT o COM
http://www.kitsrus.com/software.html

Wednesday, June 12, 2013

C# Send/Read SMS using MT6225(Chine) Cellular

Code works over Windows XP/Sp2 + VS2008, problem is on Windows 7/x64


First you need download/install driver for Windows 7 from [1], after that download c# sample from [2].
for understand code, you need know At commands, that code only send AT command to Comx for interchange information with the cellular phone.
Same usually commands:

AT 
  (if result is OK, then connection is good)
AT+CMGF=1
    (Set message format  0:New/1:Read)
AT+CMGF?
    (Read current setting)
AT+CMGF=?
    (Show list possible values) 
AT+CMGL="ALL"
    (List of all messages)

Classic sequence:
AT+CMGF=1
AT+CMGL="ALL"

References:
[1] MT6225 for W7/x64 Driver http://hotfile.com/dl/42358552/cb0f022/MTK6227_Driver__For_XP__Vista.rar
[2] C# Source Code for test http://www.elguille.info/colabora/NET2006/mauro_melgar_envio_sms.htm
[3] AT Commands http://www.telit.com/module/infopool/download.php?id=542


Thursday, March 07, 2013

C# Export to Excel



References:
[1] EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx). http://epplus.codeplex.com/
[2] C# Class for Export DataTable To Excel with Interop http://alandjackson.wordpress.com/2011/01/07/c-export-to-excel-with-interop/
[3] Version of POI Java project at http://poi.apache.org/. POI is an open source project which can help you read/write xls, doc, ppt files. http://npoi.codeplex.com/releases
[4] Sample of NPOI http://www.leniel.net/2009/07/creating-excel-spreadsheets-xls-xlsx-c.html#sthash.5qgu3AiY.dpbs
[5] Good sample for export to excel file http://www.codeproject.com/Articles/20228/Using-C-to-Create-an-Excel-Document

Wednesday, December 28, 2011

Caller ID

References:

http://www.compartir-tecnologias.es/call-id-y-c-ayuda-206872292.html

Code
http://www.codeproject.com/KB/dotnet/CShart_TAPI_3x.aspx
http://stackoverflow.com/questions/3128204/how-detect-caller-id-from-phone-line
http://www.forosdelweb.com/f29/modem-con-identificador-llamadas-caller-id-con-c-694795/
http://intellitechture.com/The-basics-of-System-IO-Ports-SerialPort/
http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.tapi/2006-06/msg00106.html
Test Modem
http://stackoverflow.com/questions/1200921/how-to-get-caller-id-in-c

Thursday, November 24, 2011

Wednesday, September 14, 2011

Wednesday, December 15, 2010

ASP.NET C# Upload from URL

using System.Net;
WebClient wc = new WebClient();

wc.DownloadFile("http://sourcefile.ext", "drive:\\path\\targetfile.ext");



References:
[1] http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=115

Thursday, December 02, 2010

SQL Server Analysis Service

Working with Microsoft Analysis Services (SSAS) / MSOLAP / MDX Queries
http://developer.klipfolio.com/developer/cookbook_item/item-64


Running the Analysis Services Deployment Wizard

http://msdn.microsoft.com/en-us/library/ms174817.aspx

Building a SQL Server Analysis Services .ASDatabase file from a Visual Studio SSAS Project
http://agilebi.com/ddarden/2009/05/31/building-a-sql-server-analysis-services-asdatabase-file-from-a-as-project/

Resources
[1] http://sqlsrvanalysissrvcs.codeplex.com/
[2] SQL Server software
http://www.todotegusta.com/2010/05/microsoft-sql-server-2008-r2-standard-edition-x86-y-x64/

Wednesday, November 24, 2010

C# Smtp Client using gmail account


using System;
using System.Collections.Generic;
using System.Text;

using System.Net.Mail;
using System.Net;

namespace SmtpMail
{
class Program
{

static void Main(string[] args)
{
try
{
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("compelligencelocal@gmail.com", "xxxxx"),
EnableSsl = true
};
client.Send("myusername@gmail.com", "manager_27@hotmail.com", "test", "testbody");
Console.WriteLine("Sent");
Console.ReadLine();

}
catch (Exception ex)
{
Console.WriteLine( ex.Message );
}

}
}
}

Monday, May 24, 2010

C# Resize image


public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
{
System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);

// Prevent using images internal thumbnail
FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

if (OnlyResizeIfWider)
{
if (FullsizeImage.Width <= NewWidth)
{
NewWidth = FullsizeImage.Width;
}
}

int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
if (NewHeight > MaxHeight)
{
// Resize with height instead
NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
NewHeight = MaxHeight;
}

System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

// Clear handle to original file so that we can overwrite it if necessary
FullsizeImage.Dispose();

// Save resized picture
NewImage.Save(NewFile);
}


Resources
=========
C#: Resize An Image While Maintaining Aspect Ratio and Maximum Height

http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing

Thursday, May 13, 2010

Trabajando con Delegados en C#

Codigo 1
==========================================
public delegate void DelegateType(string message);


Codigo 2
==========================================

public static void Method(string message)
{
System.Console.WriteLine(message);
}

Función cualquiera con la misma firma que DelegateType es decir void xxx(string yyy)

Codigo 3
==========================================

DelegateType handler = Method; //Esto es posible xq DelegateType es una referencia
//a funciones con la firma void xxx(string yyy).

handler("Hello World"); //Llama a Method

Codigo 4
==========================================

public void MethodWithCallback(int param1, int param2, DelegateType callback)
{
callback("The number is: " + (param1 + param2).ToString());
}


Codigo 5
==========================================
MethodWithCallback(1, 2, handler); //Llamada enviando una referencia a Method

Codigo 6
==========================================
public void Method1(string message) { }
public void Method2(string message) { }

DelegateType d1 = Method1;
DelegateType d2 = Method2;
DelegateType d3 = Method;
DelegateType allMethodsDelegate = d1 + d2;//assigna referencia a d1 y d2
allMethodsDelegate += d3; //agrega referencia a una tercera funcion


Codigo 8
==========================================
allMethodsDelegate -= d1; //elimina d1 de la lista de referencias
DelegateType oneMethodDelegate = allMethodsDelegate - d2; //Copia todos menos d2

Codigo 9
==========================================
int invocationCount = d1.GetInvocationList().GetLength(0); //Cantidad de referencias

Codigo 10
==========================================


using System.Reflection;

namespace DemoDelegate
{
public delegate void D();

public class ComprobaciónDelegados

{

public static void Main()
{

Type t = typeof(ComprobaciónDelegados);
MethodInfo m = t.GetMethod("Metodo1");
D obj = (D) Delegate.CreateDelegate(typeof(D), m);
obj();
}



public static void Metodo1()

{ Console.WriteLine("Ejecutado Método1"); }



public static void Metodo2(string s)

{ Console.WriteLine("Ejecutado Método2");
}

}
}

Firefox open multiple private window

    /opt/firefox/firefox-bin --profile $(mktemp -d) --private-window www.google.com www.bing.com