Monday, February 6, 2017
Encryption in Javascript
<script src="Scripts/tripledes.js"></script>
<script src="Scripts/mode-ecb.js"></script>
function encrypt() {
var keyHex =
CryptoJS.enc.Utf8.parse("mkadm11n");
var crypted =
CryptoJS.DES.encrypt("Message",
keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
}
Monday, January 9, 2017
Insert 1M Records by SQL Server
declare @id int
declare @accountID bigint
declare @IP varchar(20)
select @id = 1
while @id <= 1000000
begin
//Insert 1st Table
INSERT INTO tblE2Account values('TestAccount' + CAST(@id AS VARCHAR(10)) , 'TestName',14,1,'E2TestBY',GETDATE(),'E2TestBY',GETDate(), NULL,0,0,'63,119','10.101.1.115',2)
// Take ID
Select @accountID = Max(E2AccountId) From tblE2Account where CreatedBy='E2TestBY'
// Take ID and put in next Insert
INSERT INTO tblE2IP values('999.9.9.'+ CAST(@id AS VARCHAR(10)) , '23.1167,113.25','No Hostname','Kuala Lumpur','Kuala Lumpur','MY','59200','AS38199 Macro Lynx Sdn Bhd, Internet Service Provider, Malaysia',1,1,'E2TestBY',GETDATE(),NULL,NULL)
Select @IP = '999.9.9.' + CAST(@id AS VARCHAR(10))
INSERT INTO tblE2Transaction values(@IP, null, 2,14,@accountID,1,'1010017387,20.00,0','E2TestBY',GETDATE(),NULL,NULL)
select @id = @id + 1
end
//Avarage 30k records int 20 mins
//Avarage 30k records int 20 mins
Dictionary
static readonly Dictionary<string, DeviceType> MappedDeviceType;
static fnMapDeviceType()
{
MappedDeviceType = new Dictionary<string, DeviceType>();
MappedDeviceType.Add("Windows NT 6.3", DeviceType.Windows);
MappedDeviceType.Add("Windows NT 6.3; WOW64", DeviceType.Windows);
MappedDeviceType.Add("Windows NT 10.0", DeviceType.Windows);
MappedDeviceType.Add("Windows NT 10.0; WOW64", DeviceType.Windows);
MappedDeviceType.Add("CPU iPhone OS 9_3_2 like Mac OS X", DeviceType.Iphone);
}
public static DeviceType MapDeviceType(string device)
{
DeviceType mapValue = DeviceType.Unknown;
if (!string.IsNullOrWhiteSpace(device))
{
if (Enum.TryParse(device, true, out mapValue))
return mapValue;
if (MappedDeviceType.TryGetValue(device,
out mapValue))
return mapValue;
}
return mapValue;
}
---------------------
//Contain en with key
---------------------
//Contain en with key
string word = "en/my";
var mappingA = new Dictionary<string, string>()
{
{ "en", "en-gb" },
{ "cn", "cn-zh" },
};
string listPerson = mappingA.Where(x =>
word.Contains(x.Key)).Select(y => y.Value).FirstOrDefault();
Tuesday, December 6, 2016
WCF Data Access Layer
Entity Framework
It's an Object Relational Mapping (ORM) Tool.
Entity Framework 3 Approach
Database First approach
Create database with tables, columns, relations etc. and Entity framework will generate Model classes (Business entities) and Data Access Layer code.
Model First approach
Model classes and relationship between them will be defined manually using Model designer in Visual studio, and Entity Framework will generate Data Access Layer and Database with tables, columns, relations automatically.
Code First approach
Manually POCO classes (simple .NET classes) will be created. Relationship between those classes will be defined by means of code.When the application executes for the first time Entity framework will generate Data Access Layer and Database with tables, columns and relations automatically in the database server.
DBSet
The collection of all the entities that query from the database.
It's an Object Relational Mapping (ORM) Tool.
- Communicate with Database
- Map database data to object-oriented data.
Entity Framework 3 Approach
Database First approach
Create database with tables, columns, relations etc. and Entity framework will generate Model classes (Business entities) and Data Access Layer code.
Model First approach
Model classes and relationship between them will be defined manually using Model designer in Visual studio, and Entity Framework will generate Data Access Layer and Database with tables, columns, relations automatically.
Code First approach
Manually POCO classes (simple .NET classes) will be created. Relationship between those classes will be defined by means of code.When the application executes for the first time Entity framework will generate Data Access Layer and Database with tables, columns and relations automatically in the database server.
DBSet
The collection of all the entities that query from the database.
Monday, December 5, 2016
Web API VS WCF SOAP
Consume data on HTTP from clients like mobile, JavaScript, Windows applications, etc.
WebAPI is the technology by which you can expose data over HTTP following REST principles.
WebAPI is the technology by which you can expose data over HTTP following REST principles.
|
|
WCF SOAP
|
WEB API
|
|
Size
|
Heavyweight because
of complicated WSDL structure.
|
Light weight, only
the necessary information is transferred.
|
|
Protocol
|
Independent of
protocols.
|
Only for HTTP
protocol
|
|
Formats
|
To parse SOAP
message, client needs to understand WSDL format.
|
Output of WebAPI is
simple string messages, JSON, simple XML format, etc. So writing parsing
logic for that is very easy.
|
|
Principles
|
SOAP follows WS-*
specification.
|
WebAPI follows REST
principles. (Please refer to REST in WCF chapter.)
|
WCF and WebAPI also can implement REST, why WebAPI
WCF was brought into implement SOA, the intention was never to implement REST. WebAPI is built from scratch and the only goal is to create HTTP services using REST. Due to the one point focus for creating REST service, WebAPI is more preferred.
Subscribe to:
Posts (Atom)