项目开发收尾总结(片段)

  • Post author:
  • Post category:其他


一个项目又开发完成了,虽然时间短问题多,但还是有一,二总结

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、比较类的两个实例相等

A、首先继承IEquatable<T>接口

B、重写Equals方法

C、必须重写GetHashCode方法

如:public class Select_CARBaseInfo_View : IEquatable<Select_CARBaseInfo_View>

{


public Guid ID { get; set; }

public bool Equals(Select_CARBaseInfo_View other)

{


return this.ID == other.ID;

}

public override int GetHashCode()

{


return ID.GetHashCode();

}

6、linq to entity 中 toString(), split()等不能识别方法的解决办法

A、用SqlFunction解决

B、Expression树

如:cc集合和 Rental_Room_ID字符串的交集大于0,即CC中有Rental_Room_ID中某几个ID相同

Expression<Func<ST.Model.Rental_Renter, bool>> where = r => cc.Intersect(r.Rental_Room_ID.Split(‘,’)).Count()>0;

var q=_Renter.LoadEntities(a => true);

var p = q.Where(where.Compile()).Select(a => a.Name).ToList();

转载于:https://blog.51cto.com/9760247/1740579


关闭菜单