Exemple #1
0
        /// <summary>
        /// Populate schedule info and delete needUpdatedItems info
        /// </summary>
        private void Upload()
        {
            GetLockBefore();

            //Task: get lock
            var getLockTask = AsyncFuture <UFEPacket> .Current;

            while (!getLockTask.IsCompleted && !_IsCancel)
            {
                getLockTask.Wait(50);
            }

            if (getLockTask.IsCancelled)
            {
                _waitForm.Cancel(false);
                return;
            }

            if (IsCancel)
            {
                _waitForm.SafeClose();
                return;
            }

            //get task failure
            if (!getLockTask.IsSuccessed)
            {
                if (getLockTask.Packet.ActionError != null)
                {
                    _waitForm.Error(Resource.GetFormatString(Resource.Strings.UploadGetLockFailed, getLockTask.Packet.ActionError.Message));
                }
                else
                {
                    _waitForm.Error(Resource.GetString(Resource.Strings.UploadGetLockFailedNoParameter));
                }
                return;
            }

            _waitForm.Info(Resource.GetString(Resource.Strings.UploadGetLockSuccessful));
            _waitForm.Info(Resource.GetString(Resource.Strings.UploadSchedulerPopulateStart));
            try
            {
                Saver.Populate();
            }
            catch (Exception ex)
            {
                _waitForm.Error(Resource.GetFormatString(Resource.Strings.UploadSchedulerPopulateException, ex.Message), ex);
                return;
            }

            _waitForm.Debug(Resource.GetString(Resource.Strings.UploadSchedulerSaveStart));
            try
            {
                Saver.Save();
            }
            catch (Exception ex)
            {
                _waitForm.Error(Resource.GetString(Resource.Strings.UploadSchedulerSaveException), ex);
                return;
            }

            if (IsCancel)
            {
                _waitForm.SafeClose();
                return;
            }

            _waitForm.Debug(Resource.GetString(Resource.Strings.UploadSchedulerSaveEnd));

            if (!Saver.IsSaveSucessed)
            {
                _waitForm.Error(Resource.GetString(Resource.Strings.UploadSchedulerSaveFailed));
                return;
            }

            List <UfeFile> deleteItems = Saver.DeletedItems;

            if (deleteItems != null && deleteItems.Count > 0)
            {
                var items = from item in deleteItems
                            select new { Id = item.Id, Type = item.Type };
                var deleteTask = _sign.Controller.FileManager.DeleteFile(items.ToArray());

                while (!deleteTask.IsCompleted && !_IsCancel)
                {
                    deleteTask.Wait(50);
                }

                if (deleteTask.IsCancelled)
                {
                    _waitForm.Cancel(false);
                    return;
                }

                if (IsCancel)
                {
                    _waitForm.SafeClose();
                    return;
                }

                //get task failure
                if (!deleteTask.IsSuccessed)
                {
                    return;
                }
            }


            _files = Saver.Files;
            int count = _files.Count;

            if (count < 1)
            {
                _waitForm.Error(Resource.GetString(Resource.Strings.UploadSchedulerEmpty));
                return;
            }

            var libFiles = new List <UfeFile>();

            //Get library files
            foreach (var item in _files)
            {
                if (item.Type >= FileType.Message)
                {
                    libFiles.Add(item);
                }
            }

            if (libFiles.Count < 1)
            {
                _waitForm.Error(Resource.GetString(Resource.Strings.UploadSchedulerLibraryFileEmpty));
                return;
            }

            //Upload library files command
            _waitForm.Info(Resource.GetString(Resource.Strings.UploadSchedulerUploadStart));

            _sign.Controller.SendAsync(Commands.UploadFile, p =>
            {
                _waitForm.EnabledCancelButton = false;
                InternalUploadCallback(p);
            }, libFiles);
        }
Exemple #2
0
        /// <summary>
        /// Populate libraries and delete needUpdatedItems info
        /// </summary>
        private void Upload()
        {
            GetLockBefore();

            //Task: get lock
            var getLockTask = AsyncFuture <UFEPacket> .Current;

            while (!getLockTask.IsCompleted && !_IsCancel)
            {
                getLockTask.Wait(50);
            }

            if (getLockTask.IsCancelled)
            {
                _waitForm.Cancel(false);
                return;
            }

            if (IsCancel)
            {
                _waitForm.SafeClose();
                return;
            }

            //get task failure
            if (!getLockTask.IsSuccessed)
            {
                if (getLockTask.Packet.ActionError != null)
                {
                    _waitForm.Error(Resource.GetFormatString(Resource.Strings.UploadGetLockFailed, getLockTask.Packet.ActionError.Message));
                }
                else
                {
                    _waitForm.Error(Resource.GetString(Resource.Strings.UploadGetLockFailedNoParameter));
                }
                return;
            }

            //_waitForm.Info("Get Lock Successed.");
            _waitForm.Info(Resource.GetString(Resource.Strings.UploadGetLockSuccessful));
            //_waitForm.Info("OnDoUpload.");
            _waitForm.Info(Resource.GetString(Resource.Strings.UploadSchedulerPopulateStart));
            try
            {
                //Populate SchedulerInfo
                _scheduleSaver.Populate();
            }
            catch (Exception ex)
            {
                //_waitForm.Error("Populate failed:" + ex.Message, ex);
                _waitForm.Error(Resource.GetFormatString(Resource.Strings.UploadSchedulerPopulateException, ex.Message), ex);
                return;
            }

            //_waitForm.Debug("schedule Saver Start.");
            _waitForm.Debug(Resource.GetString(Resource.Strings.UploadSchedulerSaveStart));
            try
            {
                //Save(Generate) SchedulerInfo
                _scheduleSaver.Save();
            }
            catch (Exception ex)
            {
                //_waitForm.Error("Schedule saved failed.", ex);
                _waitForm.Error(Resource.GetString(Resource.Strings.UploadSchedulerSaveException), ex);
                return;
            }

            if (IsCancel)
            {
                //_waitForm.Info(Resource.GetString(Resource.Strings.UploadFailed));
                //_waitForm.Close();
                _waitForm.SafeClose();
                return;
            }

            //_waitForm.Debug("schedule Saver End.");
            _waitForm.Debug(Resource.GetString(Resource.Strings.UploadSchedulerSaveEnd));

            //Save failure
            if (!_scheduleSaver.IsSaveSucessed)
            {
                //_waitForm.Error("Schedule Saved Failed.");
                _waitForm.Error(Resource.GetString(Resource.Strings.UploadSchedulerSaveFailed));
                return;
            }

            List <UfeFile> deleteItems = _scheduleSaver.DeletedItems;

            if (deleteItems != null && deleteItems.Count > 0)
            {
                var items = from item in deleteItems
                            select new { Id = item.Id, Type = item.Type };
                var deleteTask = _sign.Controller.FileManager.DeleteFile(items.ToArray());

                while (!deleteTask.IsCompleted && !_IsCancel)
                {
                    deleteTask.Wait(50);
                }

                if (deleteTask.IsCancelled)
                {
                    _waitForm.Cancel(false);
                    return;
                }

                if (IsCancel)
                {
                    //_waitForm.Info(Resource.GetString(Resource.Strings.UploadFailed));
                    //IsCancel = false;
                    _waitForm.SafeClose();
                    return;
                }

                //get task failure
                if (!deleteTask.IsSuccessed)
                {
                    //_waitForm.Error("Get lock Failed:" + getLockTask.Packet.ActionError.Message);
                    //if(_sign.Controller.Connection.State== ConnectionState.Opened && _sign.Controller.Connection.User.Status == UserStatus.Online)
                    //    MsgBox.Information(Resource.GetString(Resource.Strings.GetLockFailure));
                    //if (getLockTask.Packet.ActionError != null)
                    //    _waitForm.Error(Resource.GetFormatString(Resource.Strings.UploadGetLockFailed, getLockTask.Packet.ActionError.Message));
                    //else
                    //    _waitForm.Error(Resource.GetString(Resource.Strings.UploadGetLockFailedNoParameter));
                    return;
                }
            }


            _files = _scheduleSaver.Files;
            int count = _files.Count;

            if (count < 1)
            {
                //_waitForm.Error("Schedule is empty!");
                _waitForm.Error(Resource.GetString(Resource.Strings.UploadSchedulerEmpty));
                return;
            }

            var libFiles = new List <UfeFile>();

            //Get library files
            foreach (var item in _files)
            {
                if (item.Type >= FileType.Message)
                {
                    libFiles.Add(item);
                }
            }

            if (libFiles.Count < 1)
            {
                //_waitForm.Error("Library file count == null.");
                _waitForm.Error(Resource.GetString(Resource.Strings.UploadSchedulerLibraryFileEmpty));
                return;
            }

            //Upload library files command
            //_waitForm.Info("Do Upload Start.");
            _waitForm.Info(Resource.GetString(Resource.Strings.UploadSchedulerUploadStart));

            _sign.Controller.SendAsync(Commands.UploadFile, p =>
            {
                _waitForm.EnabledCancelButton = false;
                InternalUploadCallback(p);
            }, libFiles);
        }