This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Your ValuesController.cs | |
//Version 1 | |
string uri = Url.Route("Default", new { controller="Home", action="MyAction", id = 1 }); | |
string absoluteUrl = new Uri(Request.RequestUri, uri).AbsoluteUri; | |
//http://localhost/Home/MyAction/1 | |
//Version 2 | |
string uri = Url.Route("DefaultApi", new { id = 1 }); | |
string absoluteUrl = new Uri(Request.RequestUri, uri).AbsoluteUri; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HttpResponseMessage GetText() | |
{ | |
try | |
{ | |
string content = "Hello"; | |
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); | |
result.Content = new StringContent(content); | |
//a text file is actually an octet-stream (pdf, etc) | |
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ICryptoService cryptoService = new PBKDF2(); | |
private void SetNewPassword(User user, string newPassword) | |
{ | |
//a new password hash is generated from a generated salt with the default settings | |
user.Password = cryptoService.Compute(newPassword); | |
//assigning the generated salt to the user | |
user.PasswordSalt = cryptoService.Salt; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ICryptoService cryptoService = new PBKDF2(); | |
private const int SALT_SIZE = 16; | |
private const int HASH_ITERATIONS = 50; | |
private void SetNewPassword(User user, string newPassword) | |
{ | |
//a new password hash is generated from a generated salt with the passed settings | |
user.Password = user.Password = cryptoService.Compute(newPassword, SALT_SIZE, HASH_ITERATIONS); | |
//assigning the generated salt to the user | |
user.PasswordSalt = cryptoService.Salt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ICryptoService cryptoService = new PBKDF2(); | |
private bool ValidatePassword(User user, string password) | |
{ | |
//hash the password with the saved salt for that user | |
string hashed = cryptoService.Compute(password, user.PasswordSalt); | |
//return true if both hashes are the same | |
return hashed == user.Password; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HttpHeaderAttribute : ActionFilterAttribute | |
{ | |
/// <summary> | |
/// The name of the Http Header | |
/// </summary> | |
public string Name { get; set; } | |
/// <summary> | |
/// The value of the Http Header | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpHeader("Access-Control-Allow-Origin", "*")] | |
public class UserController : ApiController | |
{ | |
public IEnumerable<string> Get() | |
{ | |
return new List<string> { "User1", "User2" }; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IRepository<T> where T : class | |
{ | |
/// <summary> | |
/// Gets all objects from database | |
/// </summary> | |
IQueryable<T> All(); | |
/// <summary> | |
/// Gets objects from database by filter. | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Grid x:Name="LayoutRoot" VerticalAlignment="Stretch"> | |
<Canvas x:Name="viewfinderCanvas"> | |
<Canvas.Background> | |
<VideoBrush x:Name="viewfinderBrush"> | |
<VideoBrush.RelativeTransform> | |
<CompositeTransform x:Name="previewTransform" CenterX=".5" CenterY=".5" /> | |
</VideoBrush.RelativeTransform> | |
</VideoBrush> | |
</Canvas.Background> | |
</Canvas> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class CameraView : PhoneApplicationPage | |
{ | |
private PhotoCamera cam; | |
public CameraView() | |
{ | |
InitializeComponent(); | |
activateCamera(); | |
} | |
private void activateCamera() |