//control action
public class TestController : ApiController
{
[MyAuthFilter]
public string test(string str)
{
return str.Trim();
}
}//control action
public class TestController : ApiController
{
[MyAuthFilter]
public string test(string str)
{
return str.Trim();
}
}上线时间:20151214
扩展下载地址:http://efbulkinsert.codeplex.com/
注意同时安装依赖项目,不然会报错,还有,程序中有同一个dll的其他版本,那就可能一次安装不上,得一个一个安装依赖的dll
Install-Package EntityFramework.MappingAPI -Version 6.0.0.7 Install-Package EntityFramework.BulkInsert-ef6
Code:
using System;
using System.Diagnostics;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
public static PerformanceCounter cpu;
//public static ComputerInfo cif;
static void Main(string[] args)
{
cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total");
// cif = new ComputerInfo();
MEMORY_INFO MemInfo;
MemInfo = new MEMORY_INFO();
while(true)
{
GlobalMemoryStatus(ref MemInfo);
Console.WriteLine(MemInfo.dwMemoryLoad.ToString() + "%的内存正在使用");
var percentage = cpu.NextValue();
Console.WriteLine(percentage + "%的CPU正在使用
");
System.Threading.Thread.Sleep(2000);
}
}
[DllImport("kernel32")]
public static extern void GetSystemDirectory(StringBuilder SysDir, int count);
[DllImport("kernel32")]
public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);
[DllImport("kernel32")]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
[DllImport("kernel32")]
public static extern void GetSystemTime(ref SYSTEMTIME_INFO stinfo);
}
//定义CPU的信息结构
[StructLayout(LayoutKind.Sequential)]
public struct CPU_INFO
{
public uint dwOemId;
public uint dwPageSize;
public uint lpMinimumApplicationAddress;
public uint lpMaximumApplicationAddress;
public uint dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public uint dwProcessorLevel;
public uint dwProcessorRevision;
}
//定义内存的信息结构
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_INFO
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}
//定义系统时间的信息结构
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME_INFO
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}
}code:
public string Test()
{
Stopwatch w = new Stopwatch();
w.Start();
StringBuilder sb = new StringBuilder();
string str = RunCmdForJobs("systeminfo");
string[] lines = str.Split(new string[] { "
" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string line in lines)
{
string[] temp = line.Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries);
if (temp.Length == 2)
sb.AppendFormat("{0}:{1}<br/>", temp[0], temp[1].Trim(' '));
else if (temp.Length == 1)
sb.AppendFormat("{0}<br/>", temp[0]);
}
//sb.Append(str);
w.Stop();
sb.AppendFormat("用时(毫秒):{0}<br/>", w.ElapsedMilliseconds);
return sb.ToString();
}
/// <summary>
/// 执行cmd命令
/// 多命令请使用批处理命令连接符:
/// <![CDATA[
/// &:同时执行两个命令
/// |:将上一个命令的输出,作为下一个命令的输入
/// &&:当&&前的命令成功时,才执行&&后的命令
/// ||:当||前的命令失败时,才执行||后的命令]]>
/// 其他请百度
/// </summary>
public static string RunCmdForJobs(string cmdText)
{
string strOutput = "";
var cmd = cmdText + " &exit"; //说明:不管命令是否成功均执行exit命令,否则当调用ReadToEnd()方法时,会处于假死状态
using (var p = new System.Diagnostics.Process())
{
p.StartInfo.FileName = "C:\Windows\system32\cmd.exe";
p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
p.StartInfo.RedirectStandardInput = true; //接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true; //由调用程序获取输出信息
p.StartInfo.RedirectStandardError = true; //重定向标准错误输出
p.StartInfo.CreateNoWindow = true; //不显示程序窗口
p.Start(); //启动程序
//向cmd窗口写入命令
p.StandardInput.WriteLine(cmd);
p.StandardInput.AutoFlush = true;
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit(); //等待程序执行完退出进程
p.Close();
}
return strOutput;
}.Net Code:
public string Index()
{
StringBuilder sb = new StringBuilder();
string OrgStr="http://down.qq.com/ava/full/W_full/AVA_Client_Ver_1230_full.exe";
string ThunderStr="thunder://QUFodHRwOi8vZG93bi5xcS5jb20vYXZhL2Z1bGwvV19mdWxsL0FWQV9DbGllbnRfVmVyXzEyMzBfZnVsbC5leGVaWg==";
string QQdlStr="qqdl://aHR0cDovL2Rvd24ucXEuY29tL2F2YS9mdWxsL1dfZnVsbC9BVkFfQ2xpZW50X1Zlcl8xMjMwX2Z1bGwuZXhl";
string FlashGetStr="flashget://W0ZMQVNIR0VUXWh0dHA6Ly9kb3duLnFxLmNvbS9hdmEvZnVsbC9XX2Z1bGwvQVZBX0NsaWVudF9WZXJfMTIzMF9mdWxsLmV4ZVtGTEFTSEdFVF0=&";
string orgAddr = GetOriginalString(QQdlStr);//原地址
sb.AppendFormat("{0}<br>", orgAddr);
string thunderAddr = "AA" + orgAddr + "ZZ";
thunderAddr = "thunder://" + EncodeBase64(thunderAddr);
sb.AppendFormat("{0}<br>", thunderAddr);
string qqdlAddr = "qqdl://" + EncodeBase64(orgAddr);
sb.AppendFormat("{0}<br>", qqdlAddr);
string flashGetAddr = string.Format("{0}{1}{0}", "[FLASHGET]", orgAddr);
flashGetAddr = "flashget://" + EncodeBase64(flashGetAddr) + "&";
sb.AppendFormat("{0}<br>", flashGetAddr);
return sb.ToString();
}
public string EncodeBase64(string orgStr)
{
try
{
return Convert.ToBase64String(Encoding.Default.GetBytes(orgStr));
}
catch
{
return "";
}
}
public string DecodeBase64(string encodeStr)
{
try
{
return Encoding.Default.GetString(Convert.FromBase64String(encodeStr));
}
catch
{
return "";
}
}
public string GetOriginalString(string str)
{
string thunderPrefix="thunder://";
string qqdlPrefix = "qqdl://";
string flashgetPrefix = "flashget://";
if(str.StartsWith("http://")||str.StartsWith("https://"))
{
return str;
}
else if (str.StartsWith(thunderPrefix))
{
string thunderAddr = str.Substring(thunderPrefix.Length);//去掉前缀
thunderAddr = DecodeBase64(thunderAddr);//base64解码
thunderAddr = thunderAddr.Substring(2, thunderAddr.Length - 4);//去掉前两个A,后两个Z
return thunderAddr;
}
else if(str.StartsWith(qqdlPrefix))
{
string qqdlAddr = str.Substring(qqdlPrefix.Length);
qqdlAddr = DecodeBase64(qqdlAddr);//base64解码
return qqdlAddr;
}
else if (str.StartsWith(flashgetPrefix))
{
string flashgetAddr = str.Substring(flashgetPrefix.Length);
flashgetAddr = flashgetAddr.Substring(0,flashgetAddr.Length-1);//去掉最后一个&号
flashgetAddr = DecodeBase64(flashgetAddr);
flashgetAddr = flashgetAddr.Substring(10,flashgetAddr.Length-20);//去掉前后的[FLASHGET]
return flashgetAddr;
}
return "";
}接口文件:
//IDataCache.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ypsuit.common
{
public interface IDataCache
{
/// <summary>
/// 获取缓存
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="key">缓存key</param>
/// <returns></returns>
T Get<T>(string key);
T Get<T>(string key,string depFile);
/// <summary>
/// 写入缓存
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="key">缓存key</param>
/// <param name="value">缓存值</param>
/// <returns>返回值,表示:是否写入成功</returns>
bool Set<T>(string key, T value);
/// <summary>
/// 写入缓存,设置过期时间点
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="key">缓存key</param>
/// <param name="value">缓存值</param>
/// <param name="expiresAt">过期时间点</param>
/// <returns>返回值,表示:是否写入成功</returns>
bool Set<T>(string key, T value, DateTime expiresAt);
/// <summary>
/// 写入缓存,设置过期秒数
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="key">缓存key</param>
/// <param name="value">缓存值</param>
/// <param name="expiresSecond">过期秒数</param>
/// <returns>返回值,表示:是否写入成功</returns>
bool Set<T>(string key, T value, int expiresSecond);
bool Set<T>(string key, T value, string depFile);
/// <summary>
/// 删除缓存
/// </summary>
/// <param name="key">缓存key</param>
/// <returns></returns>
int Delete(string key);
/// <summary>
/// 删除多个缓存
/// </summary>
/// <param name="keys">缓存key数组</param>
/// <returns></returns>
int Delete(string[] keys);
}
}//封装类代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Qiniu.Conf;
using Qiniu.RS;
using Qiniu.RPC;
using Qiniu.RSF;
using Qiniu.IO;
using Qiniu.IO.Resumable;
using System.IO;
using System.Web;
using System.Drawing.Imaging;
using Qiniu.FileOp;
using System.Net;
//要先引用qiniu的dll文件
namespace ypsuit.common.QiniuHelper
{
public class QiniuHelper
{
/// <summary>
/// cdnPath为网站服务器本地路径,本地备份一份,再上传到七牛空间一份
/// </summary>
private static readonly string cdnPath = DataHelper.GetAbsolutePath(CommonFun.GetConfigData(DataConfigKey.Qiniu.ToString(), DataConfigAttr.CDN_PATH.ToString()));
/// <summary>
/// 空间名
/// </summary>
public static readonly string bucket = CommonFun.GetConfigData(DataConfigKey.Qiniu.ToString(), DataConfigAttr.BUCKET.ToString());
/// <summary>
/// 七牛外域名
/// </summary>
public static readonly string Domain = CommonFun.GetConfigData(DataConfigKey.Qiniu.ToString(), DataConfigAttr.DOMAIN.ToString());
/// <summary>
/// 在网站/程序初始化时调用一次
/// </summary>
public static void Init()
{
//设置权限key
Qiniu.Conf.Config.ACCESS_KEY = CommonFun.GetConfigData(DataConfigKey.Qiniu.ToString(), DataConfigAttr.ACCESS_KEY.ToString());
//设置密匙key
Qiniu.Conf.Config.SECRET_KEY = CommonFun.GetConfigData(DataConfigKey.Qiniu.ToString(), DataConfigAttr.SECRET_KEY.ToString());
}
#region 查看单个文件属性信息
/// <summary>
/// 查看单个文件属性信息
/// </summary>
/// <param name="bucket">七牛云存储空间名</param>
/// <param name="key">文件key</param>
public static void Stat(string bucket, string key)
{
RSClient client = new RSClient();
Entry entry = client.Stat(new EntryPath(bucket, key));
if (entry.OK)
{
Console.WriteLine("Hash: " + entry.Hash);
Console.WriteLine("Fsize: " + entry.Fsize);
Console.WriteLine("PutTime: " + entry.PutTime);
Console.WriteLine("MimeType: " + entry.MimeType);
Console.WriteLine("Customer: " + entry.Customer);
}
else
{
Console.WriteLine("Failed to Stat");
}
}
#endregion
/// <summary>
/// 复制单个文件
/// </summary>
/// <param name="bucketSrc">需要复制的文件所在的空间名</param>
/// <param name="keySrc">需要复制的文件key</param>
/// <param name="bucketDest">目标文件所在的空间名</param>
/// <param name="keyDest">标文件key</param>
public static void Copy(string bucketSrc, string keySrc, string bucketDest, string keyDest)
{
RSClient client = new RSClient();
CallRet ret = client.Copy(new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest));
if (ret.OK)
{
Console.WriteLine("Copy OK");
}
else
{
Console.WriteLine("Failed to Copy");
}
}
/// <summary>
/// 移动单个文件
/// </summary>
/// <param name="bucketSrc">需要移动的文件所在的空间名</param>
/// <param name="keySrc">需要移动的文件</param>
/// <param name="bucketDest">目标文件所在的空间名</param>
/// <param name="keyDest">目标文件key</param>
public static void Move(string bucketSrc, string keySrc, string bucketDest, string keyDest)
{
Console.WriteLine("
===> Move {0}:{1} To {2}:{3}",
bucketSrc, keySrc, bucketDest, keyDest);
RSClient client = new RSClient();
new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest);
CallRet ret = client.Move(new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest));
if (ret.OK)
{
Console.WriteLine("Move OK");
}
else
{
Console.WriteLine("Failed to Move");
}
}
/// <summary>
/// 删除单个文件
/// </summary>
/// <param name="bucket">文件所在的空间名</param>
/// <param name="key">文件key</param>
public static void Delete(string bucket, string key)
{
//Console.WriteLine("
===> Delete {0}:{1}", bucket, key);
RSClient client = new RSClient();
CallRet ret = client.Delete(new EntryPath(bucket, key));
//if (ret.OK)
//{
// Console.WriteLine("Delete OK");
//}
//else
//{
// Console.WriteLine("Failed to delete");
//}
}
/// <summary>
/// 批量获取文件信息
/// </summary>
/// <param name="bucket"></param>
/// <param name="keys"></param>
public static void BatchStat(string bucket, string[] keys)
{
RSClient client = new RSClient();
List<EntryPath> EntryPaths = new List<EntryPath>();
foreach (string key in keys)
{
Console.WriteLine("
===> Stat {0}:{1}", bucket, key);
EntryPaths.Add(new EntryPath(bucket, key));
}
client.BatchStat(EntryPaths.ToArray());
}
/// <summary>
/// 批量复制
/// </summary>
/// <param name="bucket"></param>
/// <param name="keys"></param>
public static void BatchCopy(string bucket, string[] keys)
{
List<EntryPathPair> pairs = new List<EntryPathPair>();
foreach (string key in keys)
{
EntryPathPair entry = new EntryPathPair(bucket, key, Guid.NewGuid().ToString());
pairs.Add(entry);
}
RSClient client = new RSClient();
client.BatchCopy(pairs.ToArray());
}
/// <summary>
/// 批量移动
/// </summary>
/// <param name="bucket"></param>
/// <param name="keys"></param>.Net Code:
public class UploadEventArgs : EventArgs//作为事件的参数,必须派生自EventArgs基类
{
public UploadEventArgs(int percent)
{
this.Percent = percent;
}
public int Percent { get; set; }
}
public class Upload
{
public event EventHandler<UploadEventArgs> Uploading;//定义事件,上传中实时通知上传进度
public int Percent{get;private set;}
public Upload()
{
Percent = 0;
}
public void DoUpload()
{
UploadEventArgs ev=new UploadEventArgs(0);
while(Percent<100)
{
//上传文件代码简单,就不写出了
System.Threading.Thread.Sleep(1000);
Percent+=15;
if (Percent > 100) Percent = 100;
ev.Percent=Percent;
Uploading(this, ev);
}
}
}
public class FileToUpload
{
private string fileName;
public FileToUpload(string filename)
{
this.fileName = filename;
}
public void GetStatus(object sender, UploadEventArgs e)
{
Console.WriteLine("file:{0},UploadPercent:{1}", fileName, e.Percent);
}
}
public class EventTest
{
public void test()
{
var upload = new Upload();
var file = new FileToUpload("001.dox");
upload.Uploading += file.GetStatus;
upload.DoUpload();
}
}code smith 模版(要下载code smith软件使用):
//生成注释部分代码
Powered By Z-BlogPHP 1.7.3
Copyright 2024-2027 pukuimin Rights Reserved.
粤ICP备17100155号