/// <summary> /// Load a cell from disk into memory. /// </summary> /// <param name="part">The partition where this cell belongs</param> /// <param name="fileName">The name of the file holding the persisted cell</param> /// <exception cref="FileFormatException">The cell file is malformed</exception> /// <exception cref="EndOfStreamException">The cell file is too short</exception> internal Cell(Partition part, string fileName, bool partial) { this.part = part; this.fileName = fileName; var fileLength = new FileInfo(fileName).Length; using (var br = new BinaryReader(new BufferedStream(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)))) { this.baseUID = br.ReadInt64(); this.epoch = br.ReadInt32(); this.numUrls = br.ReadInt64(); this.supraUID = this.baseUID + this.numUrls; this.urlCell = new UrlCell(this, br); this.linkCell = new LinkCell[2]; this.linkCell[0] = new LinkCell(this, br); this.linkCell[1] = new LinkCell(this, br); long numHdrBytes = br.BaseStream.Position; this.urlCell.startPos = numHdrBytes; this.linkCell[0].startPos = this.urlCell.startPos + this.urlCell.numBytes; this.linkCell[1].startPos = this.linkCell[0].startPos + this.linkCell[0].numBytes; var expectedSize = numHdrBytes + this.urlCell.numBytes + (partial ? 0L : this.linkCell[0].numBytes + this.linkCell[1].numBytes); if (fileLength != expectedSize) { throw new FileFormatException(fileName + " is wrong size"); } } }
internal Partition part; // the partition containing this cell #endregion Fields #region Constructors /// <summary> /// Load a cell from disk into memory. /// </summary> /// <param name="part">The partition where this cell belongs</param> /// <param name="fileName">The name of the file holding the persisted cell</param> /// <exception cref="FileFormatException">The cell file is malformed</exception> /// <exception cref="EndOfStreamException">The cell file is too short</exception> internal Cell(Partition part, string fileName, bool partial) { this.part = part; this.fileName = fileName; var fileLength = new FileInfo(fileName).Length; using (var br = new BinaryReader(new BufferedStream(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)))) { this.baseUID = br.ReadInt64(); this.epoch = br.ReadInt32(); this.numUrls = br.ReadInt64(); this.supraUID = this.baseUID + this.numUrls; this.urlCell = new UrlCell(this, br); this.linkCell = new LinkCell[2]; this.linkCell[0] = new LinkCell(this, br); this.linkCell[1] = new LinkCell(this, br); long numHdrBytes = br.BaseStream.Position; this.urlCell.startPos = numHdrBytes; this.linkCell[0].startPos = this.urlCell.startPos + this.urlCell.numBytes; this.linkCell[1].startPos = this.linkCell[0].startPos + this.linkCell[0].numBytes; var expectedSize = numHdrBytes + this.urlCell.numBytes + (partial ? 0L : this.linkCell[0].numBytes + this.linkCell[1].numBytes); if (fileLength != expectedSize) { throw new FileFormatException(fileName + " is wrong size"); } } }
/// <summary> /// 设置跟随推荐接口 /// 有 使用消息配置卡券(cardCellData) 和 使用消息配置URL(urlCellData) 两种方式 /// 注意:cardCellData和urlCellData必须也只能选择一个,不可同时为空 /// </summary> /// <param name="cardId">卡券ID</param> /// <param name="cardCellData">使用消息配置卡券数据</param> /// <param name="urlCellData">使用消息配置URL数据</param> /// <param name="timeOut"></param> /// <returns></returns> public JsonResult RecommendSet(string cardId, CardCell cardCellData = null, UrlCell urlCellData = null, int timeOut = Config.TIME_OUT) { var accessToken = _api.GetAccessToken(); var url = string.Format("https://api.weixin.qq.com/card/update?access_token={0}", accessToken); var data = new { card_id = cardId, member_card = new { base_info = new { modify_msg_operation = new { card_cell = cardCellData, url_cell = urlCellData } } } }; return(Post <JsonResult>(url, data, timeOut)); }
/// <summary> /// 设置跟随推荐接口 /// 有 使用消息配置卡券(cardCellData) 和 使用消息配置URL(urlCellData) 两种方式 /// 注意:cardCellData和urlCellData必须也只能选择一个,不可同时为空 /// </summary> /// <param name="accessTokenOrAppId"></param> /// <param name="cardId">卡券ID</param> /// <param name="cardCellData">使用消息配置卡券数据</param> /// <param name="urlCellData">使用消息配置URL数据</param> /// <param name="timeOut"></param> /// <returns></returns> public static WxJsonResult RecommendSet(string accessTokenOrAppId, string cardId, CardCell cardCellData = null, UrlCell urlCellData = null, int timeOut = Config.TIME_OUT) { return(ApiHandlerWapper.TryCommonApi(accessToken => { var urlFormat = string.Format("https://api.weixin.qq.com/card/update?access_token={0}", accessToken); var data = new { card_id = cardId, member_card = new { base_info = new { modify_msg_operation = new { card_cell = cardCellData, url_cell = urlCellData } } } }; return CommonJsonSend.Send <WxJsonResult>(null, urlFormat, data, timeOut: timeOut); }, accessTokenOrAppId)); }