Ejemplo n.º 1
0
        private void DoChangeLanguage(string cultureName)
        {
            if (ChangeLanguageAction != null)
            {
                ChangeLanguageAction(cultureName);

                var notification = new Notification
                {
                    Content = "Language changed. You may need to restart this application for some texts to update.".Localize()
                };
                CommonNotifyRequest.Raise(notification);
            }

            GuiCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.ThreeLetterWindowsLanguageName;
        }
 private void RaiseItemDuplicateInteractionRequest(IList selectedItemsList)
 {
     // initial checks
     if (selectedItemsList == null)
     {
         CommonNotifyRequest.Raise(new Notification {
             Content = "Select import job to duplicate.".Localize(), Title = "Error".Localize(null, LocalizationScope.DefaultCategory)
         });
     }
     else
     {
         var selectedItems = selectedItemsList.Cast <VirtualListItem <IImportJobViewModel> >();
         ItemDuplicate(selectedItems.Select(x => (IViewModelDetailBase)x.Data).ToList());
     }
 }
        private void RaiseImportJobRunInteractionRequest(object item)
        {
            // initial checks
            if (item == null)
            {
                CommonNotifyRequest.Raise(new Notification {
                    Content = "Select import job to run.".Localize(), Title = "Error".Localize(null, LocalizationScope.DefaultCategory)
                });
            }
            else
            {
                var it        = ((VirtualListItem <IImportJobViewModel>)item).Data.InnerItem;
                var jobEntity = new ImportEntity {
                    ImportJob = it
                };
                var itemVM = _runVmFactory.GetViewModelInstance(
                    new KeyValuePair <string, object>("jobEntity", jobEntity)
                    );

                var confirmation = new ConditionalConfirmation(itemVM.Validate)
                {
                    Content = itemVM, Title = "Run Import Job".Localize()
                };
                CommonConfirmRequest.Raise(confirmation, async(x) =>
                {
                    if (x.Confirmed)
                    {
                        await Task.Run(() =>
                        {
                            var id = Guid.NewGuid().ToString();

                            var statusUpdate = new StatusMessage
                            {
                                ShortText       = string.Format("File '{0}' import.".Localize(), Path.GetFileName(jobEntity.SourceFile)),
                                StatusMessageId = id
                            };
                            EventSystem.Publish(statusUpdate);

                            var progress              = new Progress <ImportProgress>();
                            progress.ProgressChanged += ImportProgressChanged;
                            PerformImportAsync(id, jobEntity, progress);
                        });
                    }
                });
            }
        }
        private void DoClearCache()
        {
            var confirmation = new ConditionalConfirmation
            {
                Title   = "Refresh locally cached Commerce Manager texts".Localize(),
                Content = "Are you sure you want to clear all locally cached Commerce Manager texts?".Localize()
            };

            CommonConfirmRequest.Raise(confirmation,
                                       async xx =>
            {
                if (xx.Confirmed)
                {
                    ShowLoadingAnimation = true;
                    try
                    {
                        await Task.Run(() =>
                        {
                            _elementRepository.Clear();

                            // force Elements re-caching
                            _elementRepository.Elements();

                            _elementRepository.SetStatusDate();

                            // force values update
                            LocalizationManager.UpdateValues();

                            // update available languages menu
                            SendCulturesToShell();
                        });

                        var notification = new Notification();
                        // notification.Title = "Done";
                        notification.Content = "All locally cached texts were removed. You may need to restart this application for the changes to take effect."
                                               .Localize();
                        CommonNotifyRequest.Raise(notification);
                    }
                    finally
                    {
                        ShowLoadingAnimation = false;
                    }
                }
            });
        }
Ejemplo n.º 5
0
        private void RaiseUploadRequest()
        {
            if (ParentItem.Parent == null)
            {
                CommonNotifyRequest.Raise(new Notification
                {
                    Content = "Can not upload files to the root. Please select a folder first.".Localize(),
                    Title   = "Error".Localize(null, LocalizationScope.DefaultCategory)
                });
                return;
            }

            IEnumerable <FileType> fileTypes = new[] {
                new FileType("all files".Localize(), ".*"),
                new FileType("jpg image".Localize(), ".jpg"),
                new FileType("bmp image".Localize(), ".bmp"),
                new FileType("png image".Localize(), ".png"),
                new FileType("Report".Localize(), ".rld"),
                new FileType("Report".Localize(), ".rldc")
            };

            if (fileDialogService == null)
            {
                fileDialogService = new System.Waf.VirtoCommerce.ManagementClient.Services.FileDialogService();
            }

            var result = fileDialogService.ShowOpenFileDialog(this, fileTypes);

            if (result.IsValid)
            {
                var delimiter = !string.IsNullOrEmpty(ParentItem.InnerItemID) && !ParentItem.InnerItemID.EndsWith(NamePathDelimiter) ? NamePathDelimiter : string.Empty;
                // construct new FolderItemId
                var fileInfo = new FileInfo(result.FileName);
                var fileName = string.Format("{0}{1}{2}", ParentItem.InnerItemID, delimiter, fileInfo.Name);

                var canUpload  = true;
                var fileExists = SelectedFolderItems.OfType <IFileSearchViewModel>().Any(x => x.InnerItem.FolderItemId.EndsWith(NamePathDelimiter + fileInfo.Name, StringComparison.OrdinalIgnoreCase));
                if (fileExists)
                {
                    CommonConfirmRequest.Raise(new ConditionalConfirmation
                    {
                        Title   = "Upload file".Localize(),
                        Content = string.Format("There is already a file with the same name in this location.\nDo you want to overwrite and replace the existing file '{0}'?".Localize(), fileInfo.Name)
                    }, (x) =>
                    {
                        canUpload = x.Confirmed;
                    });
                }

                if (canUpload)
                {
                    ShowLoadingAnimation = true;

                    var worker = new BackgroundWorker();
                    worker.DoWork += (o, ea) =>
                    {
                        var id   = o.GetHashCode().ToString();
                        var item = new StatusMessage {
                            ShortText = "File upload in progress".Localize(), StatusMessageId = id
                        };
                        EventSystem.Publish(item);

                        using (var info = new UploadStreamInfo())
                            using (var fileStream = new FileStream(result.FileName, FileMode.Open, FileAccess.Read))
                            {
                                info.FileName       = fileName;
                                info.FileByteStream = fileStream;
                                info.Length         = fileStream.Length;
                                _assetRepository.Upload(info);
                            }
                    };

                    worker.RunWorkerCompleted += (o, ea) =>
                    {
                        ShowLoadingAnimation = false;

                        var item = new StatusMessage
                        {
                            StatusMessageId = o.GetHashCode().ToString()
                        };

                        if (ea.Cancelled)
                        {
                            item.ShortText = "File upload was canceled!".Localize();
                            item.State     = StatusMessageState.Warning;
                        }
                        else if (ea.Error != null)
                        {
                            item.ShortText = string.Format("Failed to upload file: {0}".Localize(), ea.Error.Message);
                            item.Details   = ea.Error.ToString();
                            item.State     = StatusMessageState.Error;
                        }
                        else
                        {
                            item.ShortText = "File uploaded".Localize();
                            item.State     = StatusMessageState.Success;

                            RefreshCommand.Execute();
                        }

                        EventSystem.Publish(item);
                    };

                    worker.RunWorkerAsync();
                }
            }
        }