private static void OnComplete(Task <bool> t1, object gzipExtract)
        {
            GZipExtract gz = (GZipExtract)gzipExtract;

            if (gz.EventListener == null)
            {
                return;
            }
            switch (t1.Status)
            {
            case TaskStatus.RanToCompletion:
                if (t1.Result)
                {
                    gz.EventListener(gz, ESimpleEvent.finished);
                }
                else
                {
                    gz.LogError("failed to extract: " + gz.GZipFileName);
                    gz.EventListener(gz, ESimpleEvent.failed);
                }
                break;

            case TaskStatus.Faulted:
                gz.LogError("failed to extract: " + gz.GZipFileName);
                gz.LogError(t1.Exception.InnerException.Message);
                gz.EventListener(gz, ESimpleEvent.failed);
                break;
            }
        }
Exemple #2
0
        private void StartExtractA()
        {
            NeedGoodGonfigData();

            string url             = URL;
            string GzFileName      = "";
            string GzFullFileName  = "";
            string XMLFileName     = "";
            string XMLFullFileName = "";

            GzFileName      = Utils.GetFileNameFromURL(url);
            GzFullFileName  = TopManager.DownloadFolder + "\\" + GzFileName;
            XMLFileName     = Utils.RemoveExt(GzFileName) + ".xml";
            XMLFullFileName = TopManager.TempFolder + "\\" + XMLFileName;
            if (!File.Exists(GzFullFileName))
            {
                DoError("File [" + GzFileName + "] not found");
                return;
            }
            if (Utils.GetExt(GzFileName).ToLower() == "xml")
            {
                File.Copy(GzFullFileName, XMLFullFileName, true);
                OnGZipExtractEvent(null, ESimpleEvent.finished);
                return;
            }
            GzipExtract = new GZipExtract(GzFullFileName, XMLFullFileName, OnGZipExtractEvent);
        }
Exemple #3
0
        public GZipExtract(string gzipFileName, string targetFile, GZipExtractEventListener eventListener)
        {
            Started       = true;
            GZipFileName  = gzipFileName;
            TargetFile    = targetFile;
            EventListener = eventListener;
            if (!File.Exists(gzipFileName))
            {
                DoError("File not found: " + gzipFileName);
            }
            if (Utils.GetFileSize(gzipFileName) < 1)
            {
                DoError("Empty file: " + gzipFileName);
            }

            Task <bool> t = new Task <bool>(
                (object gzipExtract) =>
            {
                GZipExtract gz = (GZipExtract)gzipExtract;
                return(Decompress(gz.GZipFileName, gz.TargetFile));
                //return ExtractGZipA(gz.GZipFileName, gz.TargetFile);
            }
                , this);

            t.ContinueWith(OnComplete, this);

            if (eventListener != null)
            {
                eventListener(this, ESimpleEvent.started);
            }

            t.Start();
        }
Exemple #4
0
 public void ClearState()
 {
     lock (this)
     {
         if (TaskState == ESimpleEvent.started)
         {
             DoError("busy");
         }
         ScheduledTasks.Clear();
         CancelToken  = false;
         State        = ESourceState.None;
         TaskState    = ESimpleEvent.none;
         SubTaskState = ESimpleEvent.none;
         Downloader   = null;
         GzipExtract  = null;
         Progress     = 0;
     }
 }
Exemple #5
0
        void OnGZipExtractEvent(GZipExtract gzipExtract, ESimpleEvent gzipExtractEvent)
        {
            lock (this)
            {
                switch (gzipExtractEvent)
                {
                case ESimpleEvent.started:
                    OnStateChanged(ESourceState.GzExtractStarted);
                    break;

                case ESimpleEvent.failed:
                case ESimpleEvent.canceled:
                    OnStateChanged(ESourceState.GzFailed);
                    break;

                case ESimpleEvent.finished:
                    OnStateChanged(ESourceState.GzFinished);
                    break;
                }
            }
            OnSubTaskEvent(gzipExtractEvent);
        }