Esempio n. 1
0
        void CachedFileUpdaterUI_FileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args)
        {
            fileUpdateRequest         = args.Request;
            fileUpdateRequestDeferral = fileUpdateRequest.GetDeferral();
            switch (cachedFileUpdaterUI.UIStatus)
            {
            case UIStatus.Hidden:
                if (fileUpdateRequest.File.Name.Contains("ConflictingFile"))
                {
                    fileUpdateRequest.Status = FileUpdateStatus.UserInputNeeded;
                }
                else
                {
                    fileUpdateRequest.Status = FileUpdateStatus.Complete;
                }
                fileUpdateRequestDeferral.Complete();
                break;

            case UIStatus.Visible:
                break;

            case UIStatus.Unavailable:
                fileUpdateRequest.Status = FileUpdateStatus.Failed;
                fileUpdateRequestDeferral.Complete();
                break;
            }
        }
Esempio n. 2
0
        private static MultipartFormDataContent BuildMultipartContent <T>(FileUpdateRequest <T> fileRequest) where T : ApiResource
        {
            MultipartFormDataContent content = new MultipartFormDataContent();

            string byteArrayContentName    = fileRequest.GetBytesPropertyName();
            IEnumerable <byte[]> bytess    = fileRequest.GetBytess();
            IEnumerable <string> fileNames = fileRequest.GetFileNames();

            int num = 0;

            foreach (string fileName in fileNames)
            {
                byte[] bytes = bytess.ElementAt(num++);

                ByteArrayContent byteArrayContent = new ByteArrayContent(bytes);
                content.Add(byteArrayContent, byteArrayContentName, fileName);
            }

            //request.GetParameters().ForEach(kv =>
            //{
            //    content.Add(new StringContent(kv.Value), kv.Key);
            //});

            content.Add(new StringContent(SerializeUtil.ToJson(fileRequest), Encoding.UTF8, "application/json"));

            return(content);
        }
Esempio n. 3
0
        public void Activate(CachedFileUpdaterActivatedEventArgs args)
        {
            // cache CachedFileUpdaterUI
            cachedFileUpdaterUI = args.CachedFileUpdaterUI;

            // Currently, the Desktop device family activates the app in the background. Other device families
            // use a background task activation. We need to handle both cases.
            //
            // We can check to see if there is UI on activation to determine which case we are in, because
            // we receive the FileUpdateRequest differently.
            //
            // If activated in the foreground (visible), then the FileUpdateRequest is passed explicitly as
            // part of the activation.
            //
            // If activated in the background (not visible), then we subscribe to the FileUpdateRequested
            // and UIRequest events. The FileUpdateRequest is received as part of the FileUpdatedRequested event,
            // and UIRequested is raised when user input is needed to resolve a conflict.

            bool isForegroundActivated = (cachedFileUpdaterUI.UIStatus == UIStatus.Visible);

            if (isForegroundActivated)
            {
                fileUpdateRequest         = cachedFileUpdaterUI.UpdateRequest;
                fileUpdateRequestDeferral = cachedFileUpdaterUI.GetDeferral();
            }
            else
            {
                cachedFileUpdaterUI.FileUpdateRequested += CachedFileUpdaterUI_FileUpdateRequested;
                cachedFileUpdaterUI.UIRequested         += CachedFileUpdaterUI_UIRequested;
            }

            switch (cachedFileUpdaterUI.UpdateTarget)
            {
            case CachedFileTarget.Local:
                scenarios = new List <Scenario> {
                    new Scenario()
                    {
                        Title = "Get latest version", ClassType = typeof(FilePickerContracts.CachedFileUpdater_Local)
                    }
                };
                break;

            case CachedFileTarget.Remote:
                scenarios = new List <Scenario> {
                    new Scenario()
                    {
                        Title = "Remote file update", ClassType = typeof(FilePickerContracts.CachedFileUpdater_Remote)
                    }
                };
                break;
            }

            if (isForegroundActivated)
            {
                Window.Current.Content = this;
                this.OnNavigatedTo(null);
                Window.Current.Activate();
            }
        }
Esempio n. 4
0
 public void Update(FileUpdateRequest model, int creadtedBy)
 {
     _dataProvider.ExecuteNonQuery("dbo.Files_Update", inputParamMapper : delegate(SqlParameterCollection parms)
     {
         parms.AddWithValue("@Id", model.Id);
         parms.AddWithValue("@Name", model.Name);
         parms.AddWithValue("@Url", model.Url);
         parms.AddWithValue("@FileType", model.FileType);
         parms.AddWithValue("@CreatedBy", creadtedBy);
     });
 }
        private void FileIsCurrentButton_Click(object sender, RoutedEventArgs e)
        {
            FileUpdateRequest         fileUpdateRequest         = CachedFileUpdaterPage.Current.fileUpdateRequest;
            FileUpdateRequestDeferral fileUpdateRequestDeferral = CachedFileUpdaterPage.Current.fileUpdateRequestDeferral;

            OutputFileAsync(fileUpdateRequest.File);

            fileUpdateRequest.Status = FileUpdateStatus.Complete;
            fileUpdateRequestDeferral.Complete();

            UpdateUI(CachedFileUpdaterPage.Current.cachedFileUpdaterUI.UIStatus);
        }
        /// <exception cref="System.ApiException"></exception>
        public Task UploadAsync(string fileSuffix, IEnumerable <byte[]> fileDatas, IEnumerable <TRes> resources)
        {
            EnsureInternet();

            string suffix = fileSuffix.StartsWith(".", System.StringComparison.InvariantCulture) ? fileSuffix : "." + fileSuffix;

            var fileNames = resources.Select(r => $"{r.Id}{fileSuffix}").ToList();

            FileUpdateRequest <TRes> request = new FileUpdateRequest <TRes>(fileDatas, fileNames, resources);

            return(ApiClient.UpdateAsync(request));
        }
        private void OverwriteButton_Click(object sender, RoutedEventArgs e)
        {
            FileUpdateRequest         fileUpdateRequest         = CachedFileUpdaterPage.Current.fileUpdateRequest;
            FileUpdateRequestDeferral fileUpdateRequestDeferral = CachedFileUpdaterPage.Current.fileUpdateRequestDeferral;

            // update the remote version of file...
            // Printing the file content
            this.OutputFileAsync(fileUpdateRequest.File);

            fileUpdateRequest.Status = FileUpdateStatus.Complete;
            fileUpdateRequestDeferral.Complete();

            UpdateUI(CachedFileUpdaterPage.Current.cachedFileUpdaterUI.UIStatus);
        }
        private async void ProvideUpdatedVersionButton_Click(object sender, RoutedEventArgs e)
        {
            FileUpdateRequest         fileUpdateRequest         = CachedFileUpdaterPage.Current.fileUpdateRequest;
            FileUpdateRequestDeferral fileUpdateRequestDeferral = CachedFileUpdaterPage.Current.fileUpdateRequestDeferral;

            await FileIO.AppendTextAsync(fileUpdateRequest.File, String.Format(@"{0}New content added @ {1}", System.Environment.NewLine, DateTime.Now.ToString()));

            OutputFileAsync(fileUpdateRequest.File);

            fileUpdateRequest.Status = FileUpdateStatus.Complete;
            fileUpdateRequestDeferral.Complete();

            UpdateUI(CachedFileUpdaterPage.Current.cachedFileUpdaterUI.UIStatus);
        }
Esempio n. 9
0
        public void Update(FileUpdateRequest model)
        {
            string procName = "[dbo].[Files_Update]";

            _data.ExecuteNonQuery(procName,

                                  inputParamMapper : delegate(SqlParameterCollection col)
            {
                col.AddWithValue("@Id", model.Id);

                AddCommonParams(model, col);
            },
                                  returnParameters: null);
        }
Esempio n. 10
0
 protected override async Task HandleInternal(CachedFileUpdaterActivatedEventArgs args)
 {
     if (args.CachedFileUpdaterUI.UIStatus == UIStatus.Visible)
     {
         // Normal Activation
         fileUpdateRequest         = args.CachedFileUpdaterUI.UpdateRequest;
         fileUpdateRequestDeferral = args.CachedFileUpdaterUI.GetDeferral();
     }
     else
     {
         // Background
         args.CachedFileUpdaterUI.FileUpdateRequested += OnFileUpdateRequested;
         args.CachedFileUpdaterUI.UIRequested         += OnUIRequested;
     }
     await Task.CompletedTask;
 }
Esempio n. 11
0
        private async void RenameButton_Click(object sender, RoutedEventArgs e)
        {
            FileUpdateRequest         fileUpdateRequest         = CachedFileUpdaterPage.Current.fileUpdateRequest;
            FileUpdateRequestDeferral fileUpdateRequestDeferral = CachedFileUpdaterPage.Current.fileUpdateRequestDeferral;

            StorageFile file = await fileUpdateRequest.File.CopyAsync(ApplicationData.Current.LocalFolder, fileUpdateRequest.File.Name, NameCollisionOption.GenerateUniqueName);

            CachedFileUpdater.SetUpdateInformation(file, "CachedFile", ReadActivationMode.NotNeeded, WriteActivationMode.AfterWrite, CachedFileOptions.RequireUpdateOnAccess);
            fileUpdateRequest.UpdateLocalFile(file);

            this.OutputFileAsync(file);

            fileUpdateRequest.Status = FileUpdateStatus.CompleteAndRenamed;
            fileUpdateRequestDeferral.Complete();

            UpdateUI(CachedFileUpdaterPage.Current.cachedFileUpdaterUI.UIStatus);
        }
        async void _cachedFileUpdaterUI_FileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args)
        {
            _fileUpdateRequest = args.Request;
            FileUpdateRequestDeferral fileUpdateRequestDeferral = _fileUpdateRequest.GetDeferral();

            if (_cachedFileUpdaterUI.UpdateTarget == CachedFileTarget.Local) // 由 CachedFileUpdater 更新 CachedFile(CachedFileTarget.Local 方式)
            {
                // 开始激活 CachedFileUpdater 时,是 UIStatus.Hidden 状态的
                if (_cachedFileUpdaterUI.UIStatus == UIStatus.Hidden)
                {
                    // 下面针对两种方式分别写示例

                    // 方式一:直接更新文件,并设置为 FileUpdateStatus.Complete 状态,最后完成
                    if (DateTime.Now.Second % 2 == 0)
                    {
                        await FileIO.AppendTextAsync(_fileUpdateRequest.File, Environment.NewLine + "由 CachedFileUpdater 更新:" + DateTime.Now.ToString());

                        _fileUpdateRequest.Status = FileUpdateStatus.Complete;
                        fileUpdateRequestDeferral.Complete();
                    }
                    // 方式二:设置为 FileUpdateStatus.UserInputNeeded 状态,并完成,之后会再次触发这个事件,并且变为 UIStatus.Visible 状态,弹出本页界面,
                    // 这样的话可以在用户做一些操作之后再更新文件(参见下面的 btnUpdate_Click 部分)
                    else
                    {
                        _fileUpdateRequest.Status = FileUpdateStatus.UserInputNeeded;
                        fileUpdateRequestDeferral.Complete();
                    }
                }
            }
            else if (_cachedFileUpdaterUI.UpdateTarget == CachedFileTarget.Remote) // 由 app 更新 CachedFile(CachedFileTarget.Remote 方式)
            {
                // 这里可以拿到 app 更新后的文件的结果
                string textContent = await FileIO.ReadTextAsync(_fileUpdateRequest.File);

                // 但是这里不能修改这个文件,否则会报错
                // await FileIO.AppendTextAsync(_fileUpdateRequest.File, Environment.NewLine + "由 CachedFileUpdater 更新:" + DateTime.Now.ToString());

                // CachedFileUpdater 返回给 app 一个 FileUpdateStatus 状态
                _fileUpdateRequest.Status = FileUpdateStatus.Complete;
                fileUpdateRequestDeferral.Complete();
            }
        }
Esempio n. 13
0
        void CachedFileUpdaterUI_FileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args)
        {
            fileUpdateRequest         = args.Request;
            fileUpdateRequestDeferral = fileUpdateRequest.GetDeferral();
            switch (cachedFileUpdaterUI.UIStatus)
            {
            case UIStatus.Hidden:
                fileUpdateRequest.Status = FileUpdateStatus.UserInputNeeded;
                fileUpdateRequestDeferral.Complete();
                break;

            case UIStatus.Visible:
                break;

            case UIStatus.Unavailable:
                fileUpdateRequest.Status = FileUpdateStatus.Failed;
                fileUpdateRequestDeferral.Complete();
                break;
            }
        }
Esempio n. 14
0
        public ActionResult <ItemResponse <int> > Update(FileUpdateRequest model)
        {
            int          iCode    = 200;
            BaseResponse response = null;

            try
            {
                _service.Update(model);

                response = new SuccessResponse();
            }
            catch (Exception ex)
            {
                iCode = 500;
                base.Logger.LogError(ex.ToString());
                response = new ErrorResponse($"Generic Error: {ex.Message}");
            }

            return(StatusCode(iCode, response));
        }
Esempio n. 15
0
 public ActionResult <SuccessResponse> Update(int id, FileUpdateRequest model)
 {
     try
     {
         if (id == model.Id)
         {
             _fileService.Update(model, _authService.GetCurrentUserId());
             SuccessResponse resp = new SuccessResponse();
             return(Ok200(resp));
         }
         else
         {
             return(NotFound404(new ErrorResponse("Bad Request: Body Id does not match url")));
         }
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.ToString());
         return(StatusCode(500, new ErrorResponse(ex.Message)));
     }
 }
Esempio n. 16
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            ShowToast("SampleFileProviderBackgroundTask.Run fired ");

            var taskDeferral = taskInstance.GetDeferral();

            CachedFileUpdaterTriggerDetails cachedFileUpdaterTriggerDetails = (CachedFileUpdaterTriggerDetails)taskInstance.TriggerDetails;

            FileUpdateRequest fileUpdateRequest = cachedFileUpdaterTriggerDetails.UpdateRequest;

            if (cachedFileUpdaterTriggerDetails.UpdateRequest.File.Name.Contains("ConflictingFile"))
            {
                fileUpdateRequest.UserInputNeededMessage = "Need to Launch the app to resolve an update conflict.";
                fileUpdateRequest.Status = FileUpdateStatus.UserInputNeeded;
            }
            else
            {
                fileUpdateRequest.Status = FileUpdateStatus.Complete;
            }

            taskDeferral.Complete();
        }
Esempio n. 17
0
        private void OnFileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args)
        {
            switch (sender.UIStatus)
            {
            case UIStatus.Hidden:
                fileUpdateRequest         = args.Request;
                fileUpdateRequestDeferral = fileUpdateRequest.GetDeferral();
                // process cached file
                fileUpdateRequestDeferral.Complete();
                break;

            case UIStatus.Visible:
                // use the class fields

                fileUpdateRequestDeferral.Complete();
                break;

            case UIStatus.Unavailable:
                fileUpdateRequest.Status = FileUpdateStatus.Failed;
                fileUpdateRequestDeferral.Complete();
                break;
            }
        }