Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
using Northwind.ServiceModel;
using ServiceStack;
using ServiceStack.Web;
using System;
using System.IO;
namespace Northwind.ServiceInterface
{
using ServiceModel.Types;
public class VCardFormat
{
private const string VCardContentType = "text/x-vcard";
public static void Register(IAppHost appHost)
{
appHost.ContentTypes.Register(VCardContentType, SerializeToStream, DeserializeFromStream);
appHost.GlobalResponseFilters.Add((req, res, dto) =>
{
if (req.ResponseContentType == VCardContentType)
{
res.AddHeader(HttpHeaders.ContentDisposition,
string.Format("attachment;filename={0}.vcf", req.OperationName));
}
});
}
public static void SerializeToStream(IRequest req, object response, Stream stream)
{
var customerResponse = response as CustomerDetailsResponse;
using (var sw = new StreamWriter(stream))
{
if (customerResponse != null)
{
WriteCustomer(sw, customerResponse.Customer);
}
var customers = response as CustomersResponse;
if (customers != null)
{
customers.Results.ForEach(x => WriteCustomer(sw, x));
}
}
}
public static void WriteCustomer(StreamWriter sw, Customer customer)
{
sw.WriteLine("BEGIN:VCARD");
sw.WriteLine("VERSION:2.1");
sw.WriteLine("FN:" + customer.ContactName);
sw.WriteLine("ORG:" + customer.CompanyName);
sw.WriteLine("TITLE:" + customer.ContactTitle);
sw.WriteLine("EMAIL;TYPE=PREF,INTERNET:" + customer.Email);
sw.WriteLine("TEL;HOME;VOICE:" + customer.Phone);
sw.WriteLine("TEL;WORK;FAX:" + customer.Fax);
sw.WriteLine("ADR;TYPE=HOME;"
+ new[] { customer.Address, customer.City, customer.PostalCode }.Join(";"));
sw.WriteLine("END:VCARD");
}
public static object DeserializeFromStream(Type type, Stream stream)
{
throw new NotImplementedException();
}
}
}