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();
				}
			}
		}
		private void OnStatusMessageReceived(StatusMessage message)
		{
			var statusVM = Messages.FirstOrDefault(x => x.StatusMessageId == message.StatusMessageId);
			if (statusVM == null)
			{
				var item = new StatusMessageViewModel
					{
						ShortText = message.ShortText,
						StatusMessageId = message.StatusMessageId,
						Progress = message.CanReportProgress ? message.Progress : 100,
						IsProgressVisible = message.CanReportProgress,
						State = message.State,
						Details = message.Details
					};

				Messages.Add(item);

				// display details for the very first message
				if (!_hasFirstMessageReceived)
				{
					_hasFirstMessageReceived = true;
					IsDetailsVisible = true;
				}
			}
			else
			{
				statusVM.Details = message.Details;
				if (!string.IsNullOrEmpty(message.ShortText))
					statusVM.ShortText = message.ShortText;
				if (statusVM.IsProgressVisible)
					statusVM.Progress = message.Progress;
				statusVM.State = message.State;
			}

			UpdateStatuses();
		}
 private void ExportProgressChanged(object sender, OperationStatus e)
 {
     if (e != null)
     {
         if (e.OperationState != OperationState.Finished)
         {
             var statusUpdate = new StatusMessage
             {
                 ShortText =
                     string.Format("Catalog '{0}' export. Processed {1} items.".Localize(), InnerItem.CatalogId, e.Processed),
                 StatusMessageId = e.OperationId
             };
             EventSystem.Publish(statusUpdate);
         }
         else
         {
             if (e.Errors != null && e.Errors.Count > 0)
             {
                 var statusUpdate = new StatusMessage
                 {
                     ShortText = string.Format("Catalog '{0}' exported with errors".Localize(), InnerItem.CatalogId),
                     StatusMessageId = e.OperationId,
                     Details = e.Errors.Cast<object>()
                                .Where(val => val != null)
                                .Aggregate(string.Empty, (current, val) => current + (val.ToString() + Environment.NewLine)),
                     State = StatusMessageState.Error
                 };
                 EventSystem.Publish(statusUpdate);
             }
             else
             {
                 var statusUpdate = new StatusMessage
                 {
                     ShortText = string.Format("Catalog '{0}' exported successfully".Localize(), InnerItem.CatalogId),
                     StatusMessageId = e.OperationId,
                     State = StatusMessageState.Success
                 };
                 EventSystem.Publish(statusUpdate);
             }
         }
     }
 }
        private void RaiseExportItemCommand()
        {
            var catalogType = EntityType.Catalog;
            var assetType = EntityType.ItemAsset;
            //var testLocalization = EntityType.Localization;
            var operationId = _exportService.ExportData(new List<EntityType>() { catalogType, assetType }, "tratata", new Dictionary<string, object>() { { "CatalogId", InnerItem.CatalogId }, { "SourceLanguage", "en-US" }, { "TargetLanguage", "ru-RU" } });

            var statusUpdate = new StatusMessage
            {
                ShortText = string.Format("Catalog '{0}' export.".Localize(), InnerItem.CatalogId),
                StatusMessageId = operationId
            };
            EventSystem.Publish(statusUpdate);

            var progress = new Progress<OperationStatus>();
            progress.ProgressChanged += ExportProgressChanged;
            PerformExportAsync(operationId, progress);
        }
        public override void Delete(ICatalogRepository repository, InteractionRequest<Confirmation> commonConfirmRequest, InteractionRequest<Notification> errorNotifyRequest, Action onSuccess)
        {
            var countBuffer = new List<string>();

            // count: categories in Catalog
            int itemCount = repository.Categories.Where(x => x.CatalogId == InnerItem.CatalogId).Count();
            if (itemCount > 0)
            {
                countBuffer.Add(string.Format("contains {0} category(ies)".Localize(), itemCount));
            }

            // count: items in Catalog
            itemCount = repository.Items.Where(x => x.CatalogId == InnerItem.CatalogId).Count();
            if (itemCount > 0)
            {
                countBuffer.Add(string.Format("has {0} item(s)".Localize(), itemCount));
            }

            var content = string.Empty;
            var warnings = countBuffer.Select(x => "\n\t- " + x).ToArray();
            if (warnings.Length > 0)
            {
                content = string.Format("ATTENTION: This Catalog {0}.\n\n".Localize(), string.Join("", warnings));
            }
            content += string.Format("Are you sure you want to delete Catalog '{0}'?".Localize(), DisplayName);

            var item = LoadItem(InnerItem.CatalogId, repository);
            var itemVM = _catalogDeleteVmFactory.GetViewModelInstance(
                new KeyValuePair<string, object>("item", item),
                new KeyValuePair<string, object>("contentText", content));

            var confirmation = new ConditionalConfirmation(itemVM.Validate)
            {
                Content = itemVM,
                Title = "Delete confirmation".Localize(null, LocalizationScope.DefaultCategory)
            };
            commonConfirmRequest.Raise(confirmation, async (x) =>
            {
                if (x.Confirmed)
                {
                    await Task.Run(() =>
                    {
                        repository.Remove(item);

                        // report status
                        var id = Guid.NewGuid().ToString();
                        var statusUpdate = new StatusMessage { ShortText = string.Format("A Catalog '{0}' deletion in progress".Localize(), DisplayName), StatusMessageId = id };
                        EventSystem.Publish(statusUpdate);

                        try
                        {
                            repository.UnitOfWork.Commit();
                            statusUpdate = new StatusMessage { ShortText = string.Format("A Catalog '{0}' deleted successfully".Localize(), DisplayName), StatusMessageId = id, State = StatusMessageState.Success };
                            EventSystem.Publish(statusUpdate);
                        }
                        catch (Exception e)
                        {
                            statusUpdate = new StatusMessage
                            {
                                ShortText = string.Format("Failed to delete Catalog '{0}'".Localize(), DisplayName),
                                Details = e.ToString(),
                                StatusMessageId = id,
                                State = StatusMessageState.Error
                            };
                            EventSystem.Publish(statusUpdate);
                        }
                    });

                    onSuccess();
                }
            });
        }
        public override void Delete(ICatalogRepository repository, InteractionRequest<Confirmation> commonConfirmRequest, InteractionRequest<Notification> errorNotifyRequest, Action onSuccess)
        {
            var countBuffer = new List<string>();
            int itemCount;

            // count: items in category. Don't try counting items for VirtualCatalog (nor linked category in it). 
            var isThisCategoryInRealCatalog = CatalogHomeViewModel.GetCatalog(this) is catalogModel.Catalog;
            if (isThisCategoryInRealCatalog)
            {
                // checking current category and level 1 (direct) subcategories.
                itemCount = repository.Items
                                      .Where(x =>
                                          x.CategoryItemRelations.Any(y =>
                                              y.CategoryId == InnerItem.CategoryId || y.Category.ParentCategoryId == InnerItem.CategoryId))
                                      .Count();

                if (itemCount > 0)
                {
                    countBuffer.Add(string.Format("has {0} item(s), won't be deleted".Localize(), itemCount));
                }
            }

            // count: direct sub-categories
            itemCount = repository.Categories
                .Where(x => x.ParentCategoryId == InnerItem.CategoryId)
                .Count();

            if (itemCount > 0)
            {
                countBuffer.Add(string.Format("has {0} sub-category(ies), will be deleted".Localize(), itemCount));
            }

            if (isThisCategoryInRealCatalog)
            {
                // count: linked categories			
                itemCount = repository.Categories
                    .OfType<LinkedCategory>()
                    .Where(x => x.LinkedCategoryId == InnerItem.CategoryId)
                    .Count();

                if (itemCount > 0)
                {
                    countBuffer.Add(string.Format("is coupled with {0} Linked Category(ies), will be deleted".Localize(), itemCount));
                }
            }

            // construct nice message
            var typeName = ((InnerItem is Category) ? "category" : "linked category").Localize();
            var content = string.Empty;
            var warnings = countBuffer.Select(x => "\n\t- " + x).ToArray();
            if (warnings.Length > 0)
            {
                content = string.Format("ATTENTION: This {0} {1}.\n\n".Localize(), typeName, string.Join("", warnings));
            }

            content += string.Format("Are you sure you want to delete {0} '{1}'?".Localize(), typeName, DisplayName);

            var confirmation = new ConditionalConfirmation
            {
                Content = content,
                Title = "Delete confirmation".Localize(null, LocalizationScope.DefaultCategory)
            };

            commonConfirmRequest.Raise(confirmation, async (x) =>
            {
                if (x.Confirmed)
                {
                    await Task.Run(() =>
                    {
                        // Removing item by attaching makes DataServiceRequest exception.
                        var categoryItem = repository.Categories.Where(c => c.CategoryId == InnerItem.CategoryId).FirstOrDefault();
                        //repository.Attach(InnerItem);
                        repository.Remove(categoryItem);

                        // report status
                        var id = Guid.NewGuid().ToString();
                        var item = new StatusMessage { ShortText = string.Format("A {0} '{1}' deletion in progress".Localize(), typeName, DisplayName), StatusMessageId = id };
                        EventSystem.Publish(item);

                        try
                        {
                            if (DeleteSeoKeywords())
                            {
                                repository.UnitOfWork.Commit();
                            }
                            item = new StatusMessage { ShortText = string.Format("A {0} '{1}' deleted successfully".Localize(), typeName, DisplayName), StatusMessageId = id, State = StatusMessageState.Success };
                            EventSystem.Publish(item);
                        }
                        catch (Exception e)
                        {
                            item = new StatusMessage
                            {
                                ShortText = string.Format("Failed to delete {0} '{1}'".Localize(), typeName, DisplayName),
                                Details = e.ToString(),
                                StatusMessageId = id,
                                State = StatusMessageState.Error
                            };
                            EventSystem.Publish(item);
                        }
                    });

                    var parentHierarchyVM = (HierarchyViewModelBase)Parent;
                    parentHierarchyVM.Refresh();
                }
            });
        }
		public override void Delete(ICatalogRepository repository, InteractionRequest<Confirmation> commonConfirmRequest, InteractionRequest<Notification> errorNotifyRequest, Action onSuccess)
		{
			var content = string.Empty;

			// count: categories in VirtualCatalog
			var itemCount = repository.Categories
				.Where(x => x.CatalogId == InnerItem.CatalogId)
				.Count();

			if (itemCount > 0)
			{
				content = string.Format("ATTENTION: This Virtual Catalog contains {0} category(ies).\n\n", itemCount);
			}

			content += string.Format("Are you sure you want to delete Virtual Catalog '{0}'?", DisplayName);

			var item = repository.Catalogs.Where(x => x.CatalogId == InnerItem.CatalogId).Single();
			var itemVM = _catalogDeleteVmFactory.GetViewModelInstance(
				new KeyValuePair<string, object>("item", item),
				new KeyValuePair<string, object>("contentText", content));

			var confirmation = new ConditionalConfirmation(itemVM.Validate)
			{
				Content = itemVM,
				Title = "Delete confirmation"
			};
			commonConfirmRequest.Raise(confirmation, async (x) =>
			{
				if (x.Confirmed)
				{
					await Task.Run(() =>
						{
							repository.Remove(item);

							// report status
							var id = Guid.NewGuid().ToString();
							var statusUpdate = new StatusMessage { ShortText = string.Format("A Virtual Catalog '{0}' deletion in progress", DisplayName), StatusMessageId = id };
							EventSystem.Publish(statusUpdate);

							try
							{
								repository.UnitOfWork.Commit();
								statusUpdate = new StatusMessage { ShortText = string.Format("A Virtual Catalog '{0}' deleted successfully", DisplayName), StatusMessageId = id, State = StatusMessageState.Success };
								EventSystem.Publish(statusUpdate);
							}
							catch (Exception e)
							{
								statusUpdate = new StatusMessage
								{
									ShortText = string.Format("Failed to delete Virtual Catalog '{0}'", DisplayName),
									Details = e.ToString(),
									StatusMessageId = id,
									State = StatusMessageState.Error
								};
								EventSystem.Publish(statusUpdate);
							}
						});

					onSuccess();
				}
			});
		}