internal void OnStartTransfer(UpLoadInfo upLoadConfigInfo)
 {
     if (this.StartTransfer != null)
     {
         this.StartTransfer(new StartTransferEventArgs(upLoadConfigInfo.ProjectId,
                                                       upLoadConfigInfo.FileName, upLoadConfigInfo.SaveName, upLoadConfigInfo.FileSize, upLoadConfigInfo.TransferPos,
                                                       upLoadConfigInfo.TransferLength));
     }
 }
Esempio n. 2
0
 public override void ExecuteCommand(UpLoadClientEngine session, TransferCommandInfo commandInfo)
 {
     try
     {
         UpLoadInfo ServerConfigInfo = SerializeHelp.Deserialize <UpLoadInfo>(commandInfo.Data);
         long       CurrentPos       = ServerConfigInfo.TransferPos + ServerConfigInfo.TransferedLength;
         long       TransferedLength = ServerConfigInfo.TransferedLength;
         long       TransferLength   = ServerConfigInfo.TransferLength;
         session.m_fileStream.Position = CurrentPos;
         session.UpLoadInfo            = ServerConfigInfo;
         session.OnTransferStart();
         while (TransferedLength < TransferLength)
         {
             lock (session.lockobj)
             {
                 if (session == null)
                 {
                     return;
                 }
                 if (session.StatusCode == 1)
                 {
                     session.StatusCode = 2;
                     session.m_StopEvent.Set();
                     return;
                 }
                 int length = session.m_fileStream.Read(session.readBuffer, 0, session.PacketSize);
                 session.SendData(UpLoadOP.DoData, session.readBuffer, 0, length);
                 TransferedLength += length;
                 session.UpLoadInfo.TransferedLength = TransferedLength;
                 session.OnTransferStep(TransferLength, TransferedLength, length);
             }
         }
         session.SendData(UpLoadOP.DoEnd, new byte[] { 1 }, 0, 1);
         new Action(() =>
         {
             session.m_EndEvent.WaitOne(5000);
             session.DoEnd();
         }).BeginInvoke(null, null);
     }
     catch (Exception ex)
     {
         //Log.Error(ex.ToString());
         ex.ToString();
         //error to do;
     }
 }
Esempio n. 3
0
 public override void ExecuteCommand(TransferSession session, BinaryRequestInfo requestInfo)
 {
     try
     {
         UpLoadInfo ClientConfigInfo = SerializeHelp.Deserialize <UpLoadInfo>(requestInfo.Body);
         string     saveName         = Path.GetFullPath(ClientConfigInfo.SaveName);
         if (File.Exists(saveName))
         {
             File.Delete(saveName);
         }
         session.UpLoadEngine.OnStartTransfer(ClientConfigInfo);
         session.UpLoadEngine.DoUpLoad(ClientConfigInfo);
     }
     catch (System.Exception ex)
     {
         log4net.LogManager.GetLogger("DoCover").Error(ex.Message);
     }
 }
        internal void DoUpLoad(UpLoadInfo ClientConfigInfo)
        {
            string saveName     = Path.GetFullPath(ClientConfigInfo.SaveName);
            string saveTempName = saveName + TransferCommon.Config.TempSuffix;

            TransferCommon.UpLoadInfo ServerConfigInfo = null;
            string configName   = ClientConfigInfo.SaveName + TransferCommon.Config.ConfigSuffix;
            string saveNamePath = Path.GetDirectoryName(saveName);

            if (!Directory.Exists(saveNamePath))
            {
                Directory.CreateDirectory(saveNamePath);
            }
            if (File.Exists(saveTempName))
            {
                this.m_fileStream = new FileStream(saveTempName, FileMode.Open, FileAccess.Write);
                if (File.Exists(configName))
                {
                    ServerConfigInfo = SerializeHelp.DeserializeFromFile <UpLoadInfo>(configName);
                }
            }
            else
            {
                this.m_fileStream = new FileStream(saveTempName, FileMode.Create, FileAccess.Write);
                this.m_fileStream.SetLength(ClientConfigInfo.FileSize);
            }
            if (ServerConfigInfo == null)
            {
                ServerConfigInfo = ClientConfigInfo;
                SerializeHelp.SerializeToFile <UpLoadInfo>(ServerConfigInfo, configName);
            }
            //如果客户端传来的已上传大小与服务端的已上传大小不一致
            //if(ServerConfigInfo.TransferedLength!= ClientConfigInfo.TransferedLength)
            //{

            //}
            //如果客户端传来的文件大小与服务端的文件大小不一致
            //to do something
            this.UpLoadInfo            = ServerConfigInfo;
            this.m_fileStream.Position = ServerConfigInfo.TransferPos + ServerConfigInfo.TransferedLength;
            byte[] data = SerializeHelp.Serialize <UpLoadInfo>(ServerConfigInfo);
            this.SendData(UpLoadOP.DoUpLoad, data, 0, data.Length);
        }
 public void Dispose()
 {
     if (m_EndEvent != null)
     {
         m_EndEvent.Reset();
         m_EndEvent = null;
     }
     if (this.m_fileStream != null)
     {
         this.m_fileStream.Close();
         this.m_fileStream = null;
     }
     if (UpLoadInfo != null)
     {
         UpLoadInfo = null;
     }
     if (TransferStep != null)
     {
         TransferStep = null;
     }
     if (TransferComplete != null)
     {
         TransferComplete = null;
     }
     if (StartTransfer != null)
     {
         StartTransfer = null;
     }
     if (StopTransfer != null)
     {
         StopTransfer = null;
     }
     if (this.Session != null)
     {
         this.Session.Close();
         this.Session = null;
     }
 }
Esempio n. 6
0
 protected void btn_downLoad_Click(object sender, EventArgs e)
 {
     try
     {
         if (!string.IsNullOrEmpty(fileName))
         {
             MediaType  mt         = MediaType.file;                             //file型多媒体文件
             string     filePath   = Server.MapPath("/image") + "\\" + fileName; //上传文件路径
             string     token      = VerifyLegal.GetAccess_Token();
             UpLoadInfo uploadFile = WxUpLoad(filePath, token, mt);              //上传临时多媒体文件,返回mediaId
             if (uploadFile != null)
             {
                 string mediaId = uploadFile.media_id;
                 ReturnInfo.pushMessage_File(curUserId, System.Configuration.ConfigurationManager.AppSettings["CorpAppId"], mediaId);//向指定用户发送file型消息
                 btn_downLoad.Hidden = true;
                 label_result.Hidden = false;
                 label_result.Text   = "文件下载完成!";
             }
             else
             {
                 btn_downLoad.Hidden = true;
                 label_result.Hidden = false;
                 label_result.Text   = "文件下载失败!";
                 return;
             }
         }
         else
         {
             Alert.ShowInTop("文件丢失,请重试!");
             return;
         }
     }
     catch (Exception ex)
     {
         Alert.ShowInTop(ex.Message);
     }
 }
Esempio n. 7
0
        public static void start(string monthkey, string user)
        {
            string          filePath = @"\\10.176.49.189\test1\";
            string          fileURL  = "http://boptest.rrd.com/test1/";
            string          strConn  = @"Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + filePath + "Report Mapping.xlsx;Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";
            OleDbConnection conn     = new OleDbConnection(strConn);

            conn.Open();
            DataTable dt1 = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

            string           strExcel;
            OleDbDataAdapter myCommand = null;
            DataSet          ds        = null;
            string           tmp       = dt1.Rows[0]["TABLE_NAME"].ToString();

            strExcel  = String.Format("select * from {0}", String.Format("[{0}]", tmp));
            myCommand = new OleDbDataAdapter(strExcel, strConn);
            ds        = new DataSet();
            myCommand.Fill(ds, "table1");
            DataTable ExcelTable = ds.Tables[0];

            conn.Close();
            AccessToken at = new AccessToken();

            str_AccessToken = at.getAccessToken(str_corpid, str_corpsecret);

            DateTime nowtime = DateTime.Now;

            string year1 = nowtime.Year.ToString();
            string year  = nowtime.Year.ToString().Substring(2, 2);
            string month = nowtime.Month.ToString();

            if (month.Length < 2)
            {
                month = "0" + month;
            }
            //微信中直接传年月过来(eg:201606)
            if (monthkey.Length == 6)
            {
                year1 = monthkey.Substring(0, 4);
                year  = monthkey.Substring(2, 2);
                month = monthkey.Substring(4, 2);
            }
            if (monthkey == "Currentmonthkey")
            {
            }
            if (monthkey == "Lastmonthkey")
            {
                nowtime = DateTime.Now;
                nowtime = nowtime.AddMonths(-1);
                year1   = nowtime.Year.ToString();
                year    = nowtime.Year.ToString().Substring(2, 2);
                month   = nowtime.Month.ToString();
                if (month.Length < 2)
                {
                    month = "0" + month;
                }
            }
            if (monthkey == "monthagokey")
            {
                nowtime = DateTime.Now;
                nowtime = nowtime.AddMonths(-2);
                year1   = nowtime.Year.ToString();
                year    = nowtime.Year.ToString().Substring(2, 2);
                month   = nowtime.Month.ToString();
                if (month.Length < 2)
                {
                    month = "0" + month;
                }
            }
            DataView dataView = ExcelTable.DefaultView;

            DataTable dataTableDistinct = dataView.ToTable(true, "Name");

            if (user == "")
            {
                for (int i = 0; i < dataTableDistinct.Rows.Count; i++)
                {
                    string account = Convert.ToString(dataTableDistinct.Rows[i][0]);

                    string strJson1 = "";
                    string strJson  = "";
                    strJson = strJson + "{";
                    strJson = strJson + "\"touser\":\"" + account + "\",";
                    //strJson = strJson + "\"touser\":\"kevin\",";
                    strJson = strJson + "\"msgtype\":\"mpnews\",";
                    strJson = strJson + "\"agentid\":\"5\",";
                    strJson = strJson + "\"mpnews\":{";
                    strJson = strJson + "\"articles\":[";


                    DataRow[] dataRow    = ExcelTable.Select("Name='" + account + "'");
                    string    strJsonImg = "";
                    Boolean   bl         = false;
                    for (int j = 0; j < dataRow.Length; j++)
                    {
                        string name       = Convert.ToString(dataRow[j][2]);
                        string title      = name.Split('_')[1];
                        String fileName   = year + month + "_" + name + ".jpg";
                        string ImgName    = filePath + fileName;
                        string ImgNameURL = fileURL + fileName;

                        if (!System.IO.File.Exists(@"D:\WebSite\RRD_SalesForecast_Portal\RRD.BC.Portal.web\test1\" + fileName))
                        {
                            continue;
                        }
                        else
                        {
                            UpLoadInfo media_UpLoadInfo = WxUpLoad(ImgName, str_AccessToken, EnumMediaType.image);

                            string media_id = media_UpLoadInfo.media_id;

                            if (j == 0)
                            {
                                strJson1 = strJson1 + "{";
                                strJson1 = strJson1 + "\"title\":\"RRD Efficiency Metrics " + year1 + month + "\",";
                                strJson1 = strJson1 + "\"thumb_media_id\":\"" + media_id + "\",";
                                strJson1 = strJson1 + "\"author\":\"RR Donnelley\",";
                            }

                            strJsonImg = strJsonImg + "<div>" + title + "</div><div><img  src='" + ImgNameURL + "'/></div>";
                            bl         = true;
                        }
                    }
                    if (!bl)
                    {
                        UpLoadInfo media_UpLoadInfo = WxUpLoad(filePath + "nullImage.jpg", str_AccessToken, EnumMediaType.image);
                        string     media_id         = media_UpLoadInfo.media_id;
                        strJson1   = strJson1 + "{";
                        strJson1   = strJson1 + "\"title\":\"RRD Efficiency Metrics使用指南\",";
                        strJson1   = strJson1 + "\"thumb_media_id\":\"" + media_id + "\",";
                        strJson1   = strJson1 + "\"author\":\"RR Donnelley\",";
                        strJsonImg = "<div>" + monthkey + "</div><div><img  src='" + fileURL + "nullImage.jpg" + "'/></div>";
                    }
                    strJson1 = strJson1 + "\"content\":\"" + strJsonImg + "\",";


                    if (bl)
                    {
                        strJson1 = strJson1 + "\"digest\":\"RRD Efficiency Metrics " + year1 + month + "\",";
                    }
                    else
                    {
                        strJson1 = strJson1 + "\"digest\":\"RRD Efficiency Metrics使用指南\",";
                    }
                    strJson1 = strJson1 + "\"show_cover_pic\":\"0\"";
                    strJson1 = strJson1 + "}";
                    strJson  = strJson + strJson1;
                    strJson  = strJson + "]";
                    strJson  = strJson + "},";
                    strJson  = strJson + "\"safe\":\"1\"";
                    strJson  = strJson + "}";
                    at.GetPage("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + str_AccessToken, strJson);
                }
            }
            else
            {
                string account = user;

                string strJson1 = "";
                string strJson  = "";
                strJson = strJson + "{";
                strJson = strJson + "\"touser\":\"" + account + "\",";
                //strJson = strJson + "\"touser\":\"kevin\",";
                strJson = strJson + "\"msgtype\":\"mpnews\",";
                strJson = strJson + "\"agentid\":\"5\",";
                strJson = strJson + "\"mpnews\":{";
                strJson = strJson + "\"articles\":[";


                DataRow[] dataRow    = ExcelTable.Select("Name='" + account + "'");
                string    strJsonImg = "";
                Boolean   bl         = false;

                for (int j = 0; j < dataRow.Length; j++)
                {
                    string name       = Convert.ToString(dataRow[j][2]);
                    string title      = name.Split('_')[1];
                    String fileName   = year + month + "_" + name + ".jpg";
                    string ImgName    = filePath + fileName;
                    string ImgNameURL = fileURL + fileName;

                    if (!System.IO.File.Exists(@"D:\WebSite\RRD_SalesForecast_Portal\RRD.BC.Portal.web\test1\" + fileName))
                    {
                        continue;
                    }
                    else
                    {
                        UpLoadInfo media_UpLoadInfo = WxUpLoad(ImgName, str_AccessToken, EnumMediaType.image);
                        string     media_id         = media_UpLoadInfo.media_id;
                        if (j == 0)
                        {
                            strJson1 = strJson1 + "{";
                            strJson1 = strJson1 + "\"title\":\"RRD Efficiency Metrics " + year1 + month + "\",";
                            strJson1 = strJson1 + "\"thumb_media_id\":\"" + media_id + "\",";
                            strJson1 = strJson1 + "\"author\":\"RR Donnelley\",";
                        }
                        strJsonImg = strJsonImg + "<div>" + title + "</div><div><img  src='" + ImgNameURL + "'/></div>";
                        bl         = true;
                    }
                }
                if (!bl)
                {
                    UpLoadInfo media_UpLoadInfo = WxUpLoad(filePath + "nullImage.jpg", str_AccessToken, EnumMediaType.image);
                    string     media_id         = media_UpLoadInfo.media_id;
                    strJson1   = strJson1 + "{";
                    strJson1   = strJson1 + "\"title\":\"RRD Efficiency Metrics使用指南\",";
                    strJson1   = strJson1 + "\"thumb_media_id\":\"" + media_id + "\",";
                    strJson1   = strJson1 + "\"author\":\"RR Donnelley\",";
                    strJsonImg = "<div>" + monthkey + "</div><div><img  src='" + fileURL + "nullImage.jpg" + "'/></div>";
                }

                strJson1 = strJson1 + "\"content\":\"" + strJsonImg + "\",";

                if (bl)
                {
                    strJson1 = strJson1 + "\"digest\":\"RRD Efficiency Metrics " + year1 + month + "\",";
                }
                else
                {
                    strJson1 = strJson1 + "\"digest\":\"RRD Efficiency Metrics使用指南\",";
                }
                strJson1 = strJson1 + "\"show_cover_pic\":\"0\"";
                strJson1 = strJson1 + "}";
                strJson  = strJson + strJson1;
                strJson  = strJson + "]";
                strJson  = strJson + "},";
                strJson  = strJson + "\"safe\":\"1\"";
                strJson  = strJson + "}";
                at.GetPage("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + str_AccessToken, strJson);
            }
        }