您好,登錄后才能下訂單哦!
一個項目又開發完成了,雖然時間短問題多,但還是有一,二總結
1、kendo中如果使用 data-role="datetimepicker"日期時間選擇器,時間選擇列表總是不能初始化,需要選擇兩次日期,才會出現時間選擇列表。第三方組件啊,讓人頭痛,一一排除后,竟然在這里。
Date.prototype.toString = function (formatStr) {
// --- //
return str;
}
自定義了日期類型的方法toString("yyyy-MM-dd"),該方法本來是沒有錯誤的,但是和kendo的日期時間沖突了,將 toString 換成 format 問題解決,原來toString這個方法,kendo有另外的定義,看來自定義的名稱還是要個性化。
2、項目開發時間短,數據建模不是同一人完成的,缺乏了整體的規劃,在模塊數據交叉的地方,出現后期難以整合的問題,看來以后建模和數據庫還是要整體規劃,功能開發上可以各司其職。
3、JPUSH推送
JPUSH封裝后使用就非常簡單了。
namespace JPush
{
public class JPushUtil
{
protected const string apiBaseUrl = "https://api.jpush.cn/v3/";
static JPushUtil()
{
appkeys = ConfigurationManager.AppSettings["OwnerAppkey"];
master_secret = ConfigurationManager.AppSettings["OwnerSecret"];
}
public static string appkeys
{
get;
set;
}
public static string master_secret
{
get;
set;
}
public static string GenerateQueryToken(string appKey, string masterSecret)
{
string s = string.Format("{0}:{1}", appKey, masterSecret);
Encoding encoding = Encoding.UTF8;
try
{
byte[] bytes = encoding.GetBytes(s);
return Convert.ToBase64String(bytes);
}
catch
{
return string.Empty;
}
}
public static string Send(string data,string url="")
{
string result = "";
url = apiBaseUrl + "push";
HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpRequest.Credentials = new NetworkCredential(appkeys, master_secret);
httpRequest.Headers[HttpRequestHeader.Authorization] = "Basic " + GenerateQueryToken(appkeys, master_secret);
byte[] byteArray = null;
byteArray = Encoding.UTF8.GetBytes(data);
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.ContentLength = byteArray.Length;
Stream dataStream = httpRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = null;
try
{
response = httpRequest.GetResponse();
}
catch (WebException e)
{
response = e.Response;
}
string responseContent = string.Empty;
using (Stream responseStream = response.GetResponseStream())
{
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
responseContent = streamReader.ReadToEnd();
}
response.Close();
if (!string.IsNullOrEmpty(responseContent))
{
result = responseContent;
}
return result;
}
static object lockObj = new object();
protected static int GenerateSendIdentity()
{
lock (lockObj)
{
return (int)(((DateTime.UtcNow - new DateTime(2014, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds) % Int32.MaxValue);
}
}
public static PushResponse DPdoSend(int receiverType, string receiverValue, string title, string n_content, string param,
int time_to_live = 864000, string apns_production = "False")
{
appkeys = ConfigurationManager.AppSettings["DPappkey"];
master_secret = ConfigurationManager.AppSettings["DPsecret"];
return doSend(receiverType, receiverValue, title, n_content, param, time_to_live, apns_production);
}
public static PushResponse OwnerdoSend(int receiverType, string receiverValue, string title, string n_content, string param,
int time_to_live = 864000, string apns_production = "False")
{
appkeys = ConfigurationManager.AppSettings["OwnerAppkey"];
master_secret = ConfigurationManager.AppSettings["OwnerSecret"];
return doSend(receiverType, receiverValue, title, n_content, param, time_to_live, apns_production);
}
public static PushResponse JYdoSend(int receiverType, string receiverValue, string title, string n_content, string param,
int time_to_live = 864000, string apns_production = "False")
{
appkeys = ConfigurationManager.AppSettings["JYappkey"];
master_secret = ConfigurationManager.AppSettings["JYsecret"];
return doSend(receiverType, receiverValue, title, n_content, param, time_to_live, apns_production);
}
public static PushResponse doSend( int receiverType, string receiverValue, string title, string n_content, string param,
int time_to_live = 864000,string apns_production="False")
{
StringBuilder sb=new StringBuilder();
sb.AppendLine("{");
sb.AppendLine("\"platform\": [\"android\",\"ios\"],");
sb.AppendLine("\"audience\":{");
if(receiverType==2)
{
sb.AppendLine(" \"tag\" : [\""+receiverValue+"\"]");
}
else
{
sb.AppendLine(" \"alias\" : [\""+receiverValue.Replace(",","\",\"")+"\"]");
}
sb.AppendLine("}");
sb.AppendLine(",\"message\": {");
sb.AppendFormat(" \"msg_content\":\"{0}\",",n_content.Replace("\"","") );
sb.AppendLine();
sb.AppendFormat(" \"title\":\"{0}\",",title.Replace("\"","") );
sb.AppendLine();
sb.AppendFormat(" \"extras\": {0} ",param );
sb.AppendLine();
sb.AppendLine(" }");
sb.AppendLine(",\"options\": {");
sb.AppendFormat(" \"sendno\":{0},",GenerateSendIdentity() );
sb.AppendLine();
sb.AppendFormat(" \"time_to_live\":{0},", time_to_live);
sb.AppendLine();
sb.AppendFormat(" \"apns_production\": \"{0}\"", apns_production);
sb.AppendLine();
sb.AppendLine(" }");
sb.AppendLine("}");
PushResponse result = new PushResponse();
result.ResponseCode = -1;
try
{
string result1 = Send(sb.ToString());
JToken root = JToken.Parse(result1);
try
{
result.MessageId = root.SelectToken("msg_id").Value<string>();
}
catch
{ }
var errorNode = root.SelectToken("error");
if (errorNode == null)
{
result.SendIdentity = root.SelectToken("sendno").Value<string>();
result.ResponseCode = 0;
}
else
{
result.ResponseMessage = errorNode.SelectToken("message").Value<string>();
result.ResponseCode = errorNode.SelectToken("code").Value<int>();
}
}
catch (Exception ex)
{
throw new ST.Exceptions.CanShowException(ex.Message);
}
return result;
}
}
}
在需要的地方直接調用就OK。
4、.net下操作Redis的不明白地方
簡寫實例說明
using (IRedisClient irc = ST.Cache.RedisManage.GetClient())
{
IRedisTypedClient<MY_View> redis = irc.As<MY_View>();
var lold = redis.Lists["KEY"];
var m1 = lold.Where(a => a.ID == id).SingleOrDefault();
if (m1 != null)
{
lold.RemoveValue(m1);
}
}
Redis中<key,value>value為列表的,采用 RemoveValue,或 redis.RemoveItemFromList(lold, m1)均不能刪除,最后還是改為刪除整個鍵,然后再重新添加列表,費時費力,現在功能是完成熬,還沒找到問題癥結。只有用這個折中的辦法。
5、MVC路由的一種實現
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"M_default",
"M/{controller}/{action}/{Token}",
new { action = "Index", Token = UrlParameter.Optional },
new string[] { "ST.WEB.Areas.M" }
).DataTokens["UseNamespaceFallback"] = true;
}
DataTokens["UseNamespaceFallback"] = true,前面命名空間沒有找到控制,其它地方繼續
false是只在列出的命名空間查找,命名空間是任意的,不一定都 設置在controlls下。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。