Beispiel #1
0
        private void FetchFile(string serverName, string localPath, int size)
        {
            // will throw an exception if the file could not be downloaded
            EnsureAllFolders(localPath);
            byte[] complete = new byte[size - 1 + 1];
            int    start    = 0;       // on a failure we can restart at the current position

            do
            {
                Globals.Root.Log.WriteLine("Start fetch: " + serverName + " -> " + localPath);
                try
                {
                    while (start < size)
                    {
                        int    length = Math.Min(MAXSYNCHRONOUSCHUNK, size - start);
                        byte[] data   = m_Server.FetchChunk(Server.Software, serverName, start, length);
                        Array.Copy(data, 0, complete, start, length);
                        start += length;
                        AsyncProgress(0, length);
                        Application.DoEvents();
                    }
                    System.IO.File.WriteAllBytes(localPath, complete);
                    AsyncProgress(1, 0);
                    return;
                }
                catch (System.Net.WebException exMissing)
                {
                    if (exMissing.Status == System.Net.WebExceptionStatus.ProtocolError)
                    {
                        // indicates that a complete response was returned, but it did not have a success status code
                        if ((int)((System.Net.HttpWebResponse)exMissing.Response).StatusCode == 599)
                        {
                            // indicates that the file is not available on the update server
                            throw new Exception("UpdateFileMissing");
                        }
                        if (m_Retries >= 10)
                        {
                            throw;
                        }
                        WaitRetry(Strings.Item("Update_Download_Failed"), 30);
                    }
                    else
                    {
                        if (m_Retries >= 10)
                        {
                            throw;
                        }
                        WaitRetry(Strings.Item("Update_Download_Failed"), 30);
                    }
                }
            } while (true);
        }