forked from Teknikode/Teknik
6 changed files with 42 additions and 162 deletions
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Uploader")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("Uploader")] |
||||
[assembly: AssemblyCopyright("Copyright © 2017")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)] |
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f9db28e9-efa1-4d0f-a7b3-c8f491306ce3")] |
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")] |
||||
[assembly: AssemblyFileVersion("1.0.0.0")] |
@ -1,71 +0,0 @@
@@ -1,71 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Teknik.Utilities |
||||
{ |
||||
public class Uploader |
||||
{ |
||||
public static Models.Upload SaveFile(TeknikEntities db, Config config, byte[] file, string contentType, int contentLength) |
||||
{ |
||||
return SaveFile(db, config, file, contentType, contentLength, string.Empty, null, null, 256, 128); |
||||
} |
||||
public static Models.Upload SaveFile(TeknikEntities db, Config config, byte[] file, string contentType, int contentLength, string defaultExtension) |
||||
{ |
||||
return SaveFile(db, config, file, contentType, contentLength, defaultExtension, null, null, 256, 128); |
||||
} |
||||
|
||||
public static Models.Upload SaveFile(TeknikEntities db, Config config, byte[] file, string contentType, int contentLength, string defaultExtension, string iv) |
||||
{ |
||||
return SaveFile(db, config, file, contentType, contentLength, defaultExtension, iv, null, 256, 128); |
||||
} |
||||
|
||||
public static Models.Upload SaveFile(TeknikEntities db, Config config, byte[] file, string contentType, int contentLength, string defaultExtension, string iv, string key) |
||||
{ |
||||
return SaveFile(db, config, file, contentType, contentLength, defaultExtension, iv, key, 256, 128); |
||||
} |
||||
|
||||
public static Models.Upload SaveFile(TeknikEntities db, Config config, byte[] file, string contentType, int contentLength, string defaultExtension, string iv, string key, int keySize, int blockSize) |
||||
{ |
||||
if (!Directory.Exists(config.UploadConfig.UploadDirectory)) |
||||
{ |
||||
Directory.CreateDirectory(config.UploadConfig.UploadDirectory); |
||||
} |
||||
|
||||
// Generate a unique file name that does not currently exist
|
||||
string filePath = Utility.GenerateUniqueFileName(config.UploadConfig.UploadDirectory, config.UploadConfig.FileExtension, 10); |
||||
string fileName = Path.GetFileName(filePath); |
||||
|
||||
// once we have the filename, lets save the file
|
||||
File.WriteAllBytes(filePath, file); |
||||
|
||||
// Generate a unique url
|
||||
string extension = (config.UploadConfig.IncludeExtension) ? Utility.GetDefaultExtension(contentType, defaultExtension) : string.Empty; |
||||
string url = Utility.RandomString(config.UploadConfig.UrlLength) + extension; |
||||
while (db.Uploads.Where(u => u.Url == url).FirstOrDefault() != null) |
||||
{ |
||||
url = Utility.RandomString(config.UploadConfig.UrlLength) + extension; |
||||
} |
||||
|
||||
// Now we need to update the database with the new upload information
|
||||
Models.Upload upload = db.Uploads.Create(); |
||||
upload.DateUploaded = DateTime.Now; |
||||
upload.Url = url; |
||||
upload.FileName = fileName; |
||||
upload.ContentType = (!string.IsNullOrEmpty(contentType)) ? contentType : "application/octet-stream"; |
||||
upload.ContentLength = contentLength; |
||||
upload.Key = key; |
||||
upload.IV = iv; |
||||
upload.KeySize = keySize; |
||||
upload.BlockSize = blockSize; |
||||
|
||||
db.Uploads.Add(upload); |
||||
db.SaveChanges(); |
||||
|
||||
return upload; |
||||
} |
||||
} |
||||
} |
@ -1,54 +0,0 @@
@@ -1,54 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProjectGuid>{F9DB28E9-EFA1-4D0F-A7B3-C8F491306CE3}</ProjectGuid> |
||||
<OutputType>Library</OutputType> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
<RootNamespace>Uploader</RootNamespace> |
||||
<AssemblyName>Uploader</AssemblyName> |
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> |
||||
<FileAlignment>512</FileAlignment> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>full</DebugType> |
||||
<Optimize>false</Optimize> |
||||
<OutputPath>bin\Debug\</OutputPath> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<DebugType>pdbonly</DebugType> |
||||
<Optimize>true</Optimize> |
||||
<OutputPath>bin\Release\</OutputPath> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
<ErrorReport>prompt</ErrorReport> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core" /> |
||||
<Reference Include="System.Xml.Linq" /> |
||||
<Reference Include="System.Data.DataSetExtensions" /> |
||||
<Reference Include="Microsoft.CSharp" /> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Net.Http" /> |
||||
<Reference Include="System.Xml" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="Uploader.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||
Other similar extension points exist, see Microsoft.Common.targets. |
||||
<Target Name="BeforeBuild"> |
||||
</Target> |
||||
<Target Name="AfterBuild"> |
||||
</Target> |
||||
--> |
||||
</Project> |
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Web; |
||||
|
||||
namespace Teknik.Utilities |
||||
{ |
||||
public static class StringExtensions |
||||
{ |
||||
public static string Truncate(this string value, int maxLength) |
||||
{ |
||||
if (string.IsNullOrEmpty(value)) return value; |
||||
return value.Length <= maxLength ? value : value.Substring(0, maxLength); |
||||
} |
||||
|
||||
public static string AddStringAtInterval(this string value, int interval, string insertStr) |
||||
{ |
||||
if (interval <= 0 || value.Length < interval) |
||||
return value; |
||||
|
||||
StringBuilder sb = new StringBuilder(); |
||||
|
||||
int finalIndex = 0; |
||||
for (int i = 0; i < value.Length; i = i + interval) |
||||
{ |
||||
sb.Append(value.Substring(i, interval)); |
||||
sb.Append(insertStr); |
||||
finalIndex = i; |
||||
} |
||||
|
||||
if (finalIndex + interval != value.Length) |
||||
{ |
||||
sb.Append(value.Substring(finalIndex, value.Length - finalIndex)); |
||||
} |
||||
|
||||
return sb.ToString(); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue