Esempio n. 1
0
        protected void btnImport_OnClick(object sender, EventArgs e)
        {
            if (fileUploadCtl.HasFile)
            {
                var fileName = Path.GetFileName(fileUploadCtl.FileName);

                fileUploadCtl.PostedFile.SaveAs(Server.MapPath(@"../ImportedList/" + fileName));

                var lines = File.ReadAllText(Server.MapPath(@"../ImportedList/" + fileName));

                var listOfUrls = lines.Split(',');

                foreach (var url in listOfUrls)
                {
                    string type = string.Empty;

                    switch (url.Substring(url.LastIndexOf('.'), 4).ToLower())
                    {
                    case ".zip":
                        type = "Zip";
                        break;

                    case ".xml":
                        type = "Xml";
                        break;
                    }

                    var sourceUrl = new SourceURL
                    {
                        Url       = url,
                        Type      = type,
                        EntryIP   = CommonFunctions.GetIpAddress(),
                        EntryDate = DateTime.Today,
                        IsActive  = true,
                        EntryId   = Convert.ToString(Session["USER_KEY"]),
                    };

                    try
                    {
                        using (var dataContext = new EPGDataModel())
                        {
                            dataContext.SourceURLs.Add(sourceUrl);
                            dataContext.SaveChanges();
                            sourceUrl.ActiveChannels = GetActiveChannels(sourceUrl.Url, sourceUrl.Srno);
                            dataContext.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        lblMsg.Text = "One or more Urls in text files already exsists in database.";
                    }
                }
                lblMsg.Text = "List Imported successfully!";
                BindGrid();
            }
        }
Esempio n. 2
0
        protected void btnAdd_OnClick(object sender, EventArgs e)
        {
            grid.InnerHtml = "";
            lblMsg.Text    = "";
            using (var dataContext = new EPGDataModel())
            {
                var source = new SourceURL
                {
                    Url       = txtSourceURLAdd.Text,
                    Type      = ddlSourceType.SelectedValue,
                    IsActive  = true,
                    EntryDate = DateTime.Today,
                    EntryId   = Convert.ToString(Session["USER_KEY"]),
                    EntryIP   = CommonFunctions.GetIpAddress()
                };
                dataContext.SourceURLs.Add(source);
                dataContext.SaveChanges();
                source.ActiveChannels = GetActiveChannels(source.Url, source.Srno);
                dataContext.SaveChanges();
            }

            lblMsg.Text = "Record added successfully!";
            BindGrid();
        }
Esempio n. 3
0
            private void ReadNetByte()
            {
                FileStream ttempfile = null;

                try
                {
                    long thaveindex = 0;
                    if (File.Exists(TempFile))
                    {
                        if (!mIsClear)
                        {
                            ttempfile  = System.IO.File.OpenWrite(TempFile);
                            thaveindex = ttempfile.Length;
                            ttempfile.Seek(thaveindex, SeekOrigin.Current);
                        }
                        else
                        {
                            File.Delete(TempFile);
                            thaveindex = 0;
                        }
                    }

                    mReqest         = (HttpWebRequest)HttpWebRequest.Create(SourceURL);
                    mReqest.Timeout = 5000;

                    if (SourceURL.Contains("https://"))
                    {
                        ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                    }

                    if (thaveindex > 0)
                    {
                        mReqest.AddRange((int)thaveindex);
                    }

                    int tindex = 0;
                    while (tindex++ < 4 && mThreadRuning)
                    {
                        try
                        {
                            mResponse = mReqest.GetResponse();
                            break;
                        }
                        catch (System.Exception _error)
                        {
                            DLog.LogFormat("ReadNetByte 获取Response失败,尝试次数{0},error = {1}", tindex, _error);
                        }
                    }

                    if (mResponse == null)
                    {
                        throw new System.NullReferenceException("ReadNetByte 获取Response失败.");
                    }

                    mHttpStream   = mResponse.GetResponseStream();
                    ContentLength = mResponse.ContentLength;

                    if (ttempfile == null)
                    {
                        ttempfile = System.IO.File.Create(TempFile);
                    }

                    int    tcount    = 0;
                    int    tlen      = 1024;
                    byte[] tbuffer   = new byte[tlen];
                    int    tReadSize = 0;
                    tReadSize = mHttpStream.Read(tbuffer, 0, tlen);
                    while (tReadSize > 0 && mThreadRuning)
                    {
                        DownLoadedLength += tReadSize;
                        ttempfile.Write(tbuffer, 0, tReadSize);
                        tReadSize = mHttpStream.Read(tbuffer, 0, tlen);

                        if (++tcount >= 512)
                        {
                            ttempfile.Flush();
                            tcount = 0;
                        }
                    }
                }
                catch (System.Exception _error)
                {
                    Error = _error.ToString();
                }

                if (ttempfile != null)
                {
                    ttempfile.Close();
                }

                if (DownLoadedLength == ContentLength)
                {
                    if (File.Exists(TempFile))
                    {
                        if (File.Exists(CompleteFile))
                        {
                            File.Delete(CompleteFile);
                        }
                        File.Move(TempFile, CompleteFile);
                    }
                }
                else
                {
                    if (Error == null)
                    {
                        Error = "文件未能完成下载.Stream 被中断.";
                    }
                }

                CloseHttpClient();
                mIsDone = true;
            }
Esempio n. 4
0
 public override int GetHashCode()
 {
     return(((int)MediaId << 2) ^ SourceURL.GetHashCode());
 }
Esempio n. 5
0
        private void ReadNetByte()
        {
            Error = string.Format("[URL] = {0},[Error] = Can not completed.Stream erro.", SourceURL);
            long       tdownloadSize     = 0;
            long       tneedDownLoadSize = 0;
            FileStream ttempfile         = null;

            try
            {
                if (!Directory.Exists(TempPath))
                {
                    Directory.CreateDirectory(TempPath);
                }
                if (!Directory.Exists(DestinationPath))
                {
                    Directory.CreateDirectory(DestinationPath);
                }

                long thaveindex      = 0;
                bool isFirst         = !File.Exists(TempFile);
                bool isClearDownload = isFirst || mIsClear;
                if (isClearDownload)
                {
                    if (!isFirst)
                    {
                        File.Delete(TempFile);
                    }
                    thaveindex = 0;
                }
                else
                {
                    if (!isFirst)
                    {
                        ttempfile  = System.IO.File.OpenWrite(TempFile);
                        thaveindex = ttempfile.Length;
                        ttempfile.Seek(thaveindex, SeekOrigin.Current);
                    }
                }

                mReqest         = (HttpWebRequest)HttpWebRequest.Create(SourceURL);
                mReqest.Timeout = 20000;

                if (SourceURL.Contains("https://"))
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                }

                if (thaveindex > 0)
                {
                    mReqest.AddRange((int)thaveindex);
                }

                string rspError = null;
                try
                {
                    mResponse = mReqest.GetResponse();
                }
                catch (System.Exception _error)
                {
                    rspError = _error.Message;
                }

                if (mResponse == null || rspError != null)
                {
                    string terro = string.Format("ReadNetByte Get Response fail.[Error] = {0}", rspError);
                    throw new System.NullReferenceException(terro);
                }

                mHttpStream       = mResponse.GetResponseStream();
                tneedDownLoadSize = mResponse.ContentLength;

                DownLoadedLength = thaveindex;
                if (isClearDownload)
                {
                    ContentLength = tneedDownLoadSize;
                }

                if (ttempfile == null)
                {
                    ttempfile = System.IO.File.Create(TempFile);
                }


                int    tcount    = 0;
                int    tlen      = 1024;
                byte[] tbuffer   = new byte[tlen];
                int    tReadSize = 0;
                tReadSize = mHttpStream.Read(tbuffer, 0, tlen);
                while (tReadSize > 0 && mThreadRuning)
                {
                    DownLoadedLength += tReadSize;
                    tdownloadSize    += tReadSize;

                    ttempfile.Write(tbuffer, 0, tReadSize);
                    tReadSize = mHttpStream.Read(tbuffer, 0, tlen);

                    if (++tcount >= 512)
                    {
                        ttempfile.Flush();
                        tcount = 0;
                    }
                }
            }
            catch (System.Exception _error)
            {
                Error = string.Format("[URL] = {0},[Error] = {1}", SourceURL, _error.Message);
            }

            if (ttempfile != null)
            {
                ttempfile.Close();
            }

            try
            {
                if (tdownloadSize == tneedDownLoadSize)
                {
                    DownLoadComplete();
                }
                else
                {
                    if (string.IsNullOrEmpty(Error))
                    {
                        Error = string.Format("[URL] = {0},[Error] = Can not completed.Stream erro.", SourceURL);
                    }
                }
            }
            catch (System.Exception erro)
            {
                Error = string.Format("[URL] = {0},[Error] = {1}", SourceURL, erro.Message);
            }

            FinishedThread();
        }