Exemple #1
0
        public void DownloadStateChanged(CDownload sender, EDownloadStatus state)
        {
            lock (this)
            {
                if (!AllDownloads.Contains(sender))
                {
                    return;
                }
                switch (state)
                {
                case EDownloadStatus.started:
                    if (!RunningDownloads.Contains(sender))
                    {
                        RunningDownloads.Add(sender);
                    }
                    break;

                case EDownloadStatus.failed:
                case EDownloadStatus.canceled:
                case EDownloadStatus.timeout:
                case EDownloadStatus.finished:
                    RunningDownloads.Remove(sender);
                    AllDownloads.Remove(sender);
                    AllDownloadsByFileName.Remove(sender.FullFileName);
                    StartNextDownload();
                    break;
                }
                if (DownloadListener != null)
                {
                    DownloadListener.DownloadStateChanged(sender, state);
                }
            }
        }
 void DownloadFile(File file)
 {
     json = Encoding.UTF8.GetString(file.Content);
     Debug.Log("Downloading json " + json);
     textForWalls     = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
     keyfile          = file;
     textForWallReady = new Dictionary <EWall, bool>()
     {
         { EWall.kWall3, true }, { EWall.kWall4, true }, { EWall.kWall6, true },
     };
     fileStatus = EDownloadStatus.kDownloaded;
 }
 void Update()
 {
     if (fileStatus == EDownloadStatus.kDownloadRequested)
     {
         fileStatus = EDownloadStatus.kInProgress;
         GoogleDriveFiles.List().Send().OnDone += RefreshFileList;
     }
     if (fileStatus == EDownloadStatus.kFilesListRefreshed)
     {
         fileStatus = EDownloadStatus.kInProgress;
         keyfile    = files[0];
         GoogleDriveFiles.Download(keyfile.Id).Send().OnDone += DownloadFile;
     }
     if (hasChanges && !(textForWalls is null) && fileStatus == EDownloadStatus.kDownloaded)
     {
         UpdateFile();
     }
 }
Exemple #4
0
        public void OnStatusChenged(Download d, EDownloadStatus oldstatus, EDownloadStatus newstatus)
        {
            if (Deserializing) return;

            if (MainForm != null &&
                !MainForm.Disposing &&
                !MainForm.IsDisposed &&
                MainForm.InvokeRequired)
            {
                try
                {
                    MainForm.Invoke((Action<Download, EDownloadStatus, EDownloadStatus>)OnStatusChengedA,
                        new object[] { d, oldstatus, newstatus });
                }
                catch (Exception) { }
            }
            else
                OnStatusChengedA(d, oldstatus, newstatus);
        }
 void RefreshFileList(FileList fileList)
 {
     files = fileList.Files;
     Debug.Log("File list refreshed, found " + files.Count.ToString() + " files");
     fileStatus = EDownloadStatus.kFilesListRefreshed;
 }
Exemple #6
0
        public void OnStatusChengedA(Download d, EDownloadStatus oldstatus, EDownloadStatus newstatus)
        {
            if (Deserializing) return;

            if (newstatus == EDownloadStatus.Running)
            {
                if (RunningDownloads.Contains(d)) return;
                RunningDownloads.Add(d);
                DownloaderState = EDownloaderState.Running;
            }
            else if (newstatus == EDownloadStatus.Completed)
            {
                if (!RunningDownloads.Contains(d)) return;
                RunningDownloads.Remove(d);
                if (IsCompleted())
                    OnAllompleted();
                else if (RunningDownloads.Count < MaxParalelDownloads)
                    StartNext();
            }
            else if (newstatus == EDownloadStatus.Stopped)
            {
                if (!RunningDownloads.Contains(d)) return;
                RunningDownloads.Remove(d);

                if (d.Reseting)
                    d.ResetA();

                if (d.Removing)
                    d.RemoveA();

                if(DownloaderState == EDownloaderState.Stopping)
                {
                    if(RunningDownloads.Count == 0)
                        DownloaderState = EDownloaderState.Stopped;
                }
                else if (DownloaderState == EDownloaderState.Running)
                {
                    if (IsCompleted())
                        OnAllompleted();
                    else if (RunningDownloads.Count < MaxParalelDownloads)
                        StartNext();
                }
            }
            else if (newstatus == EDownloadStatus.Error)
            {
                if (!RunningDownloads.Contains(d)) return;
                RunningDownloads.Remove(d);
                if (DownloaderState == EDownloaderState.Stopping)
                {
                    if (RunningDownloads.Count == 0)
                        DownloaderState = EDownloaderState.Stopped;
                }
                else if (DownloaderState == EDownloaderState.Running)
                {
                    if (IsCompleted())
                        OnAllompleted();
                    else if (RunningDownloads.Count < MaxParalelDownloads)
                        StartNext();
                }
            }
        }
Exemple #7
0
 public StatusChengeEventArgs(EDownloadStatus oldstatus, EDownloadStatus newstatus)
 {
     OldStatus = oldstatus;
     NewStatus = newstatus;
 }