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 static class SymmetricExtensions | |
{ | |
private const ushort _iteration = 1000; | |
private const int _saltSize = 8; | |
public static byte[] Encrypt(this byte[] plainTextData, string password) | |
{ | |
byte[] encryptedData = null; | |
using (var provider = new RijndaelManaged()) | |
{ |
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 static Guid Hash(params object[] args) | |
{ | |
var composite = ""; | |
foreach (var a in args) | |
{ | |
composite += a.ToString(); | |
} | |
Guid result; | |
using(var md5 = new MD5CryptoServiceProvider()) |
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 static void Shuffle<T>(this T[] array, Random random) | |
{ | |
int n = array.Length; | |
while (n > 1) | |
{ | |
int k = random.Next(n--); | |
T temp = array[n]; | |
array[n] = array[k]; | |
array[k] = temp; | |
} |
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 static class Expires | |
{ | |
public static void Set(int seconds) | |
{ | |
var response = WebOperationContext.Current.OutGoingResponse; | |
if(response != null) | |
{ | |
var expires = DateTime.UtcNow.AddSeconds(seconds).ToEpireString(); |
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
using System; | |
using System.Configuration; | |
using System.IO; | |
using System.Net; | |
using System.Runtime.Serialization.Json; | |
using System.Text; | |
using System.Web; | |
using Think.Formica.Extensions; | |
namespace Think.Formica.Translation |
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
PRINT 'Checking the existence of the Version table.' | |
IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Version]') AND type IN (N'U')) | |
BEGIN | |
PRINT 'The Version table does not exist.' | |
PRINT 'Creating the Version table...' | |
CREATE TABLE [dbo].[Version] ([Current] [nvarchar](100) NOT NULL) | |
END | |
PRINT 'Checking the existence of a row in the Version table.' | |
IF NOT EXISTS (SELECT 1 FROM [dbo].[Version]) |
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 DeploymentController : Controller | |
{ | |
private DeploymentManager _manager; | |
protected DeploymentManager Manager | |
{ | |
get { return _manager ?? (_manager = new DeploymentManager()); } | |
} | |
public virtual ActionResult Delete() |
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 static class SerializationExtensions | |
{ | |
public static string Serialize(this object obj) | |
{ | |
using (var memoryStream = new MemoryStream()) | |
using (var reader = new StreamReader(memoryStream)) | |
{ | |
var serializer = new DataContractSerializer(obj.GetType()); | |
serializer.WriteObject(memoryStream, obj); | |
memoryStream.Position = 0; |
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
protected static string RemoveAllSpecialCharacters(string input) | |
{ | |
var r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled); | |
return r.Replace(input, String.Empty); | |
} | |
protected static string RemoveSelectSpecialCharacters(string input) | |
{ | |
var r = new Regex("[~#%&*{}:<>?|\".]", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled); | |
return r.Replace(input, String.Empty); |
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 BetterDefaultModelBinder : DefaultModelBinder | |
{ | |
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) | |
{ | |
var model = base.CreateModel(controllerContext, bindingContext, modelType); | |
if (model == null || model is IEnumerable) | |
return model; | |
foreach (var property in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) |