コード例 #1
0
ファイル: FileDownloadMan.cs プロジェクト: frozen4/UnityPlus
        public static DownloadTaskErrorCode GetByUrl(
            string url,
            string hostName,
            string dest,
            int timeout,
            EventHandler callbackComplete,
            DownloadProgressHandler callbackProgress,
            out string errMsg)
        {
            DownloadTaskErrorCode errCode = DownloadTaskErrorCode.Success;

#if USE_CURL_DOWNLOADER
            FileDownloaderEx downloader = new FileDownloaderEx();
#else
            FileDownloader downloader = new FileDownloader();
#endif

            if (callbackComplete != null)
            {
                downloader.DownloadComplete += callbackComplete;
            }

            if (callbackProgress != null)
            {
                downloader.ProgressChanged += callbackProgress;
            }

            errMsg = "";

            try
            {
                downloader.Download(url, hostName, dest, timeout);
            }
            catch (WebException webException)
            {
                errMsg  = webException.Message;
                errCode = DownloadTaskErrorCode.NetworkError;
            }
            catch (ArgumentException argException)
            {
                errMsg  = argException.Message;
                errCode = DownloadTaskErrorCode.UrlArgError;
            }
            catch (IOException ioException)
            {
                errMsg  = ioException.Message;
                errCode = DownloadTaskErrorCode.IOError;
            }
            catch (Exception e)
            {
                errMsg  = e.Message;
                errCode = DownloadTaskErrorCode.Unknown;
            }

            return(errCode);
        }
コード例 #2
0
        virtual protected string BuildOutput(string resultText)
        {
            try
            {
                string outputFile = _taskSettings.SelectSingleNode("./output").InnerText;
                string outputpath = Path.Combine(_outputBase, projectName, DateTime.Now.ToString("yyyyMMdd"));
                if (!Directory.Exists(outputpath))
                {
                    Directory.CreateDirectory(outputpath);
                }

                string filepath = Path.Combine(outputpath, outputFile);
                //string filepath = @"C:\Users\wwu\WebCrawCommon\WebCrawlHelper\GeneralDailyDownload\xslt\xslt\ACE_ WealthMaster Variable Universal Life.csv";

                File.WriteAllText(filepath, resultText, Encoding.UTF8);
                return(filepath);
            }
            catch (Exception ex)
            {
                _taskErrorCode = DownloadTaskErrorCode.BuildOutputFailed;
                _lastErrorMsg  = ex.Message + ex.StackTrace;
                return(null);
            }
        }
コード例 #3
0
        virtual protected string ExtractData(string xmlData)
        {
            try
            {
                //transform realtive path to definate path
                string pathForXslt     = _taskSettings.SelectSingleNode("./transfertemplate").InnerText;
                string fullPathForXslt = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xslt", projectName, pathForXslt);
                //string fullPathForXslt = @"C:\Users\wwu\WebCrawCommon\WebCrawlHelper\GeneralDailyDownload\xslt\acelife.xslt";

                string        resultText = null;
                StringBuilder sb         = new StringBuilder();
                using (StringReader strReader = new StringReader(xmlData))
                {
                    XmlReader    xmlReader = XmlReader.Create(strReader);
                    StringWriter writer    = new StringWriter(sb);

                    XsltSettings xsltSetting = new XsltSettings(true, true);

                    XslCompiledTransform transformToCSV = new XslCompiledTransform();
                    XmlResolver          resolver       = new XmlUrlResolver();
                    transformToCSV.Load(fullPathForXslt, xsltSetting, resolver);
                    transformToCSV.Transform(xmlReader, null, writer);

                    resultText = sb.ToString();
                }


                return(resultText);
            }
            catch (Exception ex)
            {
                _taskErrorCode = DownloadTaskErrorCode.ExtractDataFailed;
                _lastErrorMsg  = ex.Message + ex.StackTrace;
                return(null);
            }
        }
コード例 #4
0
 public DownloadTaskErrorInfo(DownloadTaskErrorCode errorCode, Int32 innerErrorCode, String errorMessage)
 {
     this.errorCode      = errorCode;
     this.innerErrorCode = innerErrorCode;
     this.errorMessage   = errorMessage;
 }
コード例 #5
0
    //第一阶段更新,取得本地版本和服务器版本,下载服务器版本信息
    public static IEnumerable UpdateCoroutinePhase1()
    {
        //初始化
        UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.Total, 0.0f);
        UpdateInfoUtil.SetProgress(UPDATE_PROGRESS.File, 0.0f);
        UpdateInfoUtil.SetCanPlay(false);

        //取得本地版本
        UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateStatus_TryGetLocalVersion);
        yield return(null);

        var code = Patcher.Instance.GetLocalVersion();

        if (code != UpdateRetCode.success)       //无法取得本地版本
        {
            UpdateInfoUtil.SetCanPlay(false);
            yield return(new WaitForSeconds(1.0f));

            UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateState_GetLocalVersionErr);

            Patcher.Instance.LogString("GetLocalVersion Failed!");
            yield return(code);
        }
        else
        {
            //设置本地版本
            UpdateInfoUtil.SetVersion(UPDATE_VERSION.Local, Patcher.Instance.m_CurrentVersion);
        }

        //log
        Patcher.Instance.LogString(HobaText.Format("Client Current Version: {0}", Patcher.Instance.m_CurrentVersion.ToString()));
        Patcher.Instance.LogString(HobaText.Format("FreeDiskSpace: {0}", OSUtility.GetFreeDiskSpace()));

        //检查磁盘空间

        /*
         * UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateStatus_TryCheckFreeSpace);
         * yield return null;
         * code = Patcher.Instance.CheckDiskFreeSpace(nCheckFreeSpaceMB * 1024 * 1024);
         * if (code != UpdateRetCode.success)
         * {
         *  UpdateInfoUtil.SetCanPlay(false);
         *  yield return new WaitForSeconds(1.0f);
         *
         *  UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateState_DiskSpaceFullErr);
         *
         *  Patcher.Instance.LogString("CheckDiskFreeSpace Failed!");
         *  yield return code;
         * }
         */

        //test

        /*
         * string url = "https://www.google.com";
         * string hostName = UpdateUtility.GetHostName(url);
         * string errMsg1;
         * var code1 = UpdateUtility.GetByUrl(url, hostName, System.IO.Path.Combine(EntryPoint.Instance.DocPath, "google.txt"), 10, null, null, out errMsg1);
         * Patcher.Instance.LogString(HobaText.Format("Download Test: {0} {1} {2}", url, code1, errMsg1));
         */

        if (!EntryPoint.Instance.SkipUpdate)             //配置跳过更新
        {
            //DNS解析, 忽略解析错误
            UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateStatus_TryDNSResolving);
            yield return(null);

            string errUpdateServer;
            string errClientServer;
            code = Patcher.Instance.DNSResolving(2, out errUpdateServer, out errClientServer);
            if (!string.IsNullOrEmpty(errUpdateServer))
            {
                Patcher.Instance.LogString("UpdateServer DNSResolving Error : " + errUpdateServer);
            }
            if (!string.IsNullOrEmpty(errClientServer))
            {
                Patcher.Instance.LogString("errClientServer DNSResolving Error : " + errClientServer);
            }

            Patcher.Instance.LogString(string.Format("IP URL UpdateServer1: {0}, UpdateServer2: {1}, UpdateServer3: {2}",
                                                     Patcher.Instance.strUpdateServerDir1, Patcher.Instance.strUpdateServerDir2, Patcher.Instance.strUpdateServerDir3));
            Patcher.Instance.LogString(string.Format("IP URL ClientServer: {0}", Patcher.Instance.strClientServerDir));
            Patcher.Instance.LogString(string.Format("IP URL DynamicServer : {0}", Patcher.Instance.strDynamicServerDir));
            Patcher.Instance.LogString(string.Format("IP URL DynamicAccountRole : {0}", Patcher.Instance.strDynamicAccountRoleDir));

            //从服务器获取version.txt
            UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateStatus_TryGetNewVersion);
            yield return(null);

            string errMsg    = "";
            string savedFile = Patcher.Instance.strGameNewVerFile;

            DownloadTaskErrorCode dlCode = DownloadTaskErrorCode.Unknown;
            {
                //为了方便部署,内网version.txt用和更新资源jup同一目录,也就是cdn
                if (dlCode != DownloadTaskErrorCode.Success && !string.IsNullOrEmpty(Patcher.Instance.strUpdateServerDir1))
                {
                    string url1      = Patcher.Instance.strUpdateServerDir1 + UpdateConfig.VersionConfigRelativePath;
                    string hostName1 = Patcher.Instance.strUpdateServerHostName1;

                    int nTryConnect = 0;            //尝试多次连接
                    while (dlCode != DownloadTaskErrorCode.Success && nTryConnect < DownloadMan.maxTryConnect)
                    {
                        ++nTryConnect;
                        int timeout = (int)((float)DownloadMan.reqTimeOut * nTryConnect / DownloadMan.maxTryConnect);
                        dlCode = Patcher.Instance.FetchServerVersionFile(url1, hostName1, savedFile, timeout, out errMsg);
                    }
                }

                if (dlCode != DownloadTaskErrorCode.Success && !string.IsNullOrEmpty(Patcher.Instance.strUpdateServerDir2))
                {
                    string url2      = Patcher.Instance.strUpdateServerDir2 + UpdateConfig.VersionConfigRelativePath;
                    string hostName2 = Patcher.Instance.strUpdateServerHostName2;

                    int nTryConnect = 0;            //尝试多次连接
                    while (dlCode != DownloadTaskErrorCode.Success && nTryConnect < DownloadMan.maxTryConnect)
                    {
                        ++nTryConnect;
                        int timeout = (int)((float)DownloadMan.reqTimeOut * nTryConnect / DownloadMan.maxTryConnect);
                        dlCode = Patcher.Instance.FetchServerVersionFile(url2, hostName2, savedFile, DownloadMan.reqTimeOut, out errMsg);
                    }
                }

                if (dlCode != DownloadTaskErrorCode.Success && !string.IsNullOrEmpty(Patcher.Instance.strUpdateServerDir3))
                {
                    string url3      = Patcher.Instance.strUpdateServerDir3 + UpdateConfig.VersionConfigRelativePath;
                    string hostName3 = Patcher.Instance.strUpdateServerHostName3;

                    int nTryConnect = 0;            //尝试多次连接
                    while (dlCode != DownloadTaskErrorCode.Success && nTryConnect < DownloadMan.maxTryConnect)
                    {
                        ++nTryConnect;
                        int timeout = (int)((float)DownloadMan.reqTimeOut * nTryConnect / DownloadMan.maxTryConnect);
                        dlCode = Patcher.Instance.FetchServerVersionFile(url3, hostName3, savedFile, DownloadMan.reqTimeOut, out errMsg);
                    }
                }
            }


            if (dlCode != DownloadTaskErrorCode.Success)
            {
                UpdateInfoUtil.SetCanPlay(false);
                yield return(new WaitForSeconds(1.0f));

                UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateState_GetNewVersionErr);

                if (dlCode == DownloadTaskErrorCode.Md5Dismatch)
                {
                    code = UpdateRetCode.md5_not_match;
                }
                else
                {
                    code = UpdateRetCode.download_fail;
                }

                Patcher.Instance.LogString("FetchServerVersionFile Failed! DownloadTaskErrorCode: " + dlCode + ": " + errMsg);

                yield return(code);
            }

            //读取游戏新版本信息
            code = Patcher.Instance.TryGetLatestVersionFromServer();
        }
        else
        {
            //读取游戏新版本信息
            code = UpdateRetCode.success;
        }

        if (code != UpdateRetCode.success)
        {
            UpdateInfoUtil.SetCanPlay(false);
            yield return(new WaitForSeconds(1.0f));

            UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateState_GetNewVersionErr);

            Patcher.Instance.LogString("GetVersionMan Failed!");
            yield return(code);
        }
        else
        {
            //设置服务器版本
            UpdateInfoUtil.SetVersion(UPDATE_VERSION.Server, Patcher.Instance.m_VersionMan.VerLastest);
        }

        //log
        Patcher.Instance.LogString(HobaText.Format("Server Version: {0}", Patcher.Instance.m_VersionMan.VerLastest.ToString()));

        UpdateInfoUtil.SetDownloadTotalSize(GameUpdateMan.Instance.GetDownloadTotalSize());

        UpdateInfoUtil.SetCanPlay(false);
        UpdateInfoUtil.SetStateString(UPDATE_STATE.UpdateStatus_SuccessGetVersions);
        yield return(code);
    }
コード例 #6
0
        virtual protected bool ValidateDataForm()
        {
            //
            _taskErrorCode = DownloadTaskErrorCode.NoError;
            _lastErrorMsg  = "";
            //
            string      configfile = ConfigurationManager.AppSettings["ProjectConfigFile"];
            XmlDocument config     = new XmlDocument();

            config.Load(configfile);

            //string str = "dailydownload/project/tasks/task[@name='" + taskName + "']";
            //XmlNode nTask = config.SelectSingleNode("dailydownload/project/tasks/task[@name='"+taskName+"']");

            string xpath           = config.SelectSingleNode("dailydownload/project[@name = '" + projectName + "']/tasks/task[@name='" + taskName + "']/validation/table").Attributes["xpath"].Value.ToString();
            string xpathForColumns = "./validation/table[1]/column";

            //string xpath = "//table[@id='fundListTable']/tbody/tr[1]/th";
            //string xpathForColumns = "./validation/table[@id='fundListTable']/column";
            XmlNodeList dataPoints;

            if ("" == xpath)
            {
                dataPoints = null;
            }
            else
            {
                dataPoints = _pageContent.SelectNodes(xpath);
            }

            XmlNodeList tableColumns = _taskSettings.SelectNodes(xpathForColumns);

            if (0 == tableColumns.Count)
            {
                _taskErrorCode = DownloadTaskErrorCode.NoValidation;
                _lastErrorMsg  = "No validation is required.";
                return(true);
            }
            if (null == dataPoints[0])
            {
                _taskErrorCode = DownloadTaskErrorCode.NoNodesSelected;
                _lastErrorMsg  = "No Nodes Selected.";
                return(false);
            }
            else if (dataPoints.Count != tableColumns.Count)
            {
                _taskErrorCode = DownloadTaskErrorCode.ChangeInNumOfColumns;
                _lastErrorMsg  = "Num of Columns has been changed.";
                return(false);
            }
            else
            {
                int i = 0;
                foreach (XmlNode node in dataPoints)
                {
                    if (node.InnerText.Trim().Replace("&nbsp;", "").Replace("\n", "\\n") == tableColumns[i].InnerXml && i < tableColumns.Count)
                    {
                        i++;
                        continue;
                    }
                    else
                    {
                        _taskErrorCode = DownloadTaskErrorCode.ChangeInOrderOfColumns;
                        _lastErrorMsg  = "Order of Columns has been changed.";
                        return(false);
                    }
                }
                return(true);
            }
        }
コード例 #7
0
ファイル: FileDownloadManager.cs プロジェクト: fengqk/Art
		public DownloadTaskErrorInfo(DownloadTaskErrorCode errorCode, Int32 innerErrorCode, String errorMessage)
		{
			this.errorCode = errorCode;
			this.innerErrorCode = innerErrorCode;
			this.errorMessage = errorMessage;
		}