C
There are 6 entries for the tag
C
In it's most basic form, uploading a file or other data to an http form handler using managed code is quite simple using the System.Net.WebClient class.
Listing 1: SimpleWebClientUpload
public void SimpleWebClientUpload()
{
string filePath = Path.GetFullPath("TestFiles/TextFile1.txt");
var client = new WebClient();
client.UploadFile("http://localhost/myhandler.ashx", filePath);
}
It is a common case that some cookies need to be maintained between requests or perhaps a header needs to be added to the request. This is possible using the WebClient class but the technique is not immediately obvious.
The trick is to create a class that inherits WebClient ...
You can find the code @ DeadSimpleDTO.codeplex.com
New in 2.01
INotifyPropertyChanged option
One-to-many and many-to-one relationships optionally rendered
Examples:
Default options: basic property bag dto
/*
DeadSimpleDTO
default options
basic property bag dto
*/
using System;
using Northwind;
namespace Northwind
{
public partial class Orders
{
#region Properties
private Int32 _orderID;
public virtual Int32 OrderID
{
get { return _orderID; }
...
I am always a bit annoyed with myself and others when nunit is employed to perform simple code exercise.
I find this perfect for quickies and one-offs as well as for exercising code in examples. Just drop the file in and be done with it.
µUnit (uUnit.cs)
// <copyright file="uUnit.cs" company="Sky Sanders">
//
// This source is a Public Domain Dedication.
//
// http://salientqc.codeplex.com
//
// Attribution is appreciated.
//
// </copyright>
using System;
namespace Salient.QualityControl
{
/// <summary>
/// uUnit
/// A micro test runner.
///
/// For those times...
UPDATE: After using this code a bit more it has become apparent that the Sql2008 types are all string convertable and that Byte[] is a better choice for a generic reader implementation.
You may also handle single field UDT by getting the name of the system_type_id when is_user_defined = 1 in sys.columns.
date NULL = Nullable<DateTime>
DECLARE @current_column_type VARCHAR(30),
@current_column_nullable BIT,
@generated_property_type NVARCHAR(128)
SET @current_column_type = 'date'
SET @current_column_nullable = 1
-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DECLARE @fn_ctype_input_type NVARCHAR(128),
@fn_ctype_input_nullable BIT,
@fn_ctype_output_type NVARCHAR(128)
-- --> ConvertType Function - set input
SET @fn_ctype_input_type = @current_column_type
SET @fn_ctype_input_nullable = @current_column_nullable
-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
BEGIN
SET @fn_ctype_output_type = CASE @fn_ctype_input_type
...
I am working on a spike that requires fetching metadata views from Sql Server's sys and INFORMATION_SCHEMA schemas. Initially, coding a few DTO by hand was no problem but as new views are required it obviously became tedious and typo prone.
I really did not want to break out ANY ORM, I just needed to read the data and a simple reflective filler would do just fine. In any case, I found myself in a query window writing a SQL based DTO generator. It ultimately ended up including a lot of clever functionality and I will present it here but first lets start with...
A few extension methods to help out.....
// Project: Salient.Reflection
// http://salient.codeplex.com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
public static class AttributeHelpers
{
/// <summary>
/// Returns first non-inherited custom attribute of type T
/// </summary>
public static T GetCustomAttribute<T>(this ICustomAttributeProvider provider)
where T : Attribute
{
return GetCustomAttribute<T>(provider, false);
}
/// <summary>
/// Returns first custom attribute of type T in the inheritance chain
...