private async Task <bool> ValidateDocumentWebResourceDependencyXml(ConnectionData connectionData, XDocument doc) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ValidatingXmlForFieldFormat1, WebResource.Schema.Attributes.dependencyxml); ContentComparerHelper.ClearRoot(doc); bool validateResult = await WebResourceRepository.ValidateXmlDocumentAsync(connectionData, _iWriteToOutput, doc); if (!validateResult) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ValidatingXmlForFieldFailedFormat1, WebResource.Schema.Attributes.dependencyxml); _iWriteToOutput.ActivateOutputWindow(connectionData); var dialogResult = MessageBoxResult.Cancel; var thread = new Thread(() => { dialogResult = MessageBox.Show(Properties.MessageBoxStrings.ContinueOperation, Properties.MessageBoxStrings.QuestionTitle, MessageBoxButton.OKCancel, MessageBoxImage.Question); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); if (dialogResult != MessageBoxResult.OK) { return(false); } } return(true); }
public void EnsureRegistered() { var webResourceId = WebResourceRepository.FirstOrDefault(r => r.Uuid == WebResourceUuids.Vk, r => r.Id); if (webResourceId == 0) { var resource = new WebResource { Uuid = WebResourceUuids.Vk, Name = WebResourceName, Url = WebResourceUrl, ImageUrl = WebResourceImageUrl }; WebResourceRepository.Save(resource); UnitOfWork.Commit(); webResourceId = resource.Id; } var isProviderRegistered = PersonMetaProviderRepository.Any(r => r.Uuid == PersonMetaProviderUuid); if (!isProviderRegistered) { PersonMetaProviderRepository.Save(new PersonMetaProvider { Uuid = PersonMetaProviderUuid, Name = typeof(VkWatch).FullName, WebResourceId = webResourceId }); UnitOfWork.Commit(); } }
private async Task PerformDownloadWebResourceAsync(Guid idWebResource, string name, Func <Task <IOrganizationServiceExtented> > getService) { if (!this.IsControlsEnabled) { return; } ToggleControls(false, Properties.OutputStrings.ExportingWebResourceContentFormat1, name); var service = await getService(); if (service != null) { WebResourceRepository webResourceRepository = new WebResourceRepository(service); var webresource = await webResourceRepository.GetByIdAsync(idWebResource, ColumnSetInstances.AllColumns); this._iWriteToOutput.WriteToOutput(service.ConnectionData, "Starting downloading {0}", webresource.Name); string filePath = await CreateFileWithContentAsync(service.ConnectionData.Name, webresource); this._iWriteToOutput.WriteToOutput(service.ConnectionData, "Web-resource '{0}' has downloaded to {1}.", webresource.Name, filePath); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); } ToggleControls(true, Properties.OutputStrings.ExportingWebResourceContentCompletedFormat1, name); }
private async Task PerformExportDescriptionToFile(Guid idWebResource, string name, Func <Task <IOrganizationServiceExtented> > getService) { if (!this.IsControlsEnabled) { return; } ToggleControls(false, Properties.OutputStrings.CreatingEntityDescription); var service = await getService(); if (service != null) { WebResourceRepository webResourceRepository = new WebResourceRepository(service); var webresource = await webResourceRepository.GetByIdAsync(idWebResource, ColumnSetInstances.AllColumns); var description = await EntityDescriptionHandler.GetEntityDescriptionAsync(webresource, service.ConnectionData); string filePath = await CreateDescriptionFileAsync(service.ConnectionData, webresource.Name, EntityFileNameFormatter.Headers.EntityDescription, description); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); } ToggleControls(true, Properties.OutputStrings.CreatingEntityDescriptionCompleted); }
private void DisplayWebResourceName() { string name = cmBName.Text?.Trim() ?? string.Empty; name = WebResourceRepository.GenerateWebResouceName(name, this._publisherPrefix); txtBFinalName.Text = name; }
public WebResourceService(IOrganizationService service) { if (service == null) { throw new ArgumentNullException("service"); } _webResourceRepo = new WebResourceRepository(service); }
private async Task PerformExportXmlToFileAsync(Guid idWebResource, Func <Task <IOrganizationServiceExtented> > getService, string fieldName, string fieldTitle, FileExtension extension) { if (!this.IsControlsEnabled) { return; } ToggleControls(false, Properties.OutputStrings.ExportingXmlFieldToFileFormat1, fieldTitle); var service = await getService(); if (service != null) { var repository = new WebResourceRepository(service); var webResource = await repository.GetByIdAsync(idWebResource, ColumnSetInstances.AllColumns); string xmlContent = webResource.GetAttributeValue <string>(fieldName); if (!string.IsNullOrEmpty(xmlContent)) { if (string.Equals(fieldName, WebResource.Schema.Attributes.dependencyxml, StringComparison.InvariantCultureIgnoreCase)) { xmlContent = ContentComparerHelper.FormatXmlByConfiguration( xmlContent , _commonConfig , XmlOptionsControls.WebResourceDependencyXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlSchema , webResourceName: webResource.Name ); } else if (string.Equals(fieldName, WebResource.Schema.Attributes.contentjson, StringComparison.InvariantCultureIgnoreCase)) { xmlContent = ContentComparerHelper.FormatJson(xmlContent); } } string filePath = await CreateFileAsync(service.ConnectionData, webResource.Name, fieldTitle, xmlContent, extension); if (!File.Exists(filePath)) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, Report.Schema.EntityLogicalName, webResource.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(null); } this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); } ToggleControls(true, Properties.OutputStrings.ExportingXmlFieldToFileCompletedFormat1, fieldName); }
public void Set(long webResourceId, string accountId) { if (!WebResourceRepository.Any(r => r.Id == webResourceId)) { throw new ArgumentException("Not exist.", nameof(webResourceId)); } var validAccountId = WebResourceAccountIdValidator.GetValidAccountId(webResourceId, accountId); if (validAccountId == null) { throw new ArgumentException("Invalid.", nameof(accountId)); } var personId = MetaAccountRepository.FirstOrDefault( a => a.AccountId == validAccountId && a.WebResourceId == webResourceId, a => a.PersonId); if (personId == 0) { var person = new Person(); PersonService.Save(person); UnitOfWork.Commit(); personId = person.Id; var account = new MetaAccount { PersonId = personId, Type = MetaType.Created, AccountId = validAccountId, WebResourceId = webResourceId }; MetaAccountService.Save(account); UnitOfWork.Commit(); } if (WatchRepository.Any(w => w.PersonId == personId && w.WebResourceId == webResourceId)) { return; } Save(new Watch { PersonId = personId, WebResourceId = webResourceId }); }
private async Task <Tuple <bool, WebResource> > GetWebResourceByAttribute(IOrganizationServiceExtented service, CommonConfiguration commonConfig, string webResourceName) { var repositoryWebResource = new WebResourceRepository(service); var webResource = await repositoryWebResource.FindByExactNameAsync(webResourceName, ColumnSetInstances.AllColumns); if (webResource == null) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionWebResourceWasNotFoundFormat2, service.ConnectionData.Name, webResourceName); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); WindowHelper.OpenWebResourceExplorer(_iWriteToOutput, service, commonConfig); } return(Tuple.Create(webResource != null, webResource)); }
private void FillSolutionComponentFromSchemaName(ICollection <SolutionComponent> result, string webResourceName, int?behavior) { if (string.IsNullOrEmpty(webResourceName)) { return; } var repository = new WebResourceRepository(_service); var entity = repository.FindByExactName(webResourceName, ColumnSetInstances.None); if (entity != null) { FillSolutionComponentInternal(result, entity.Id, behavior); } }
private async Task PerformShowingDifferenceDescriptionAsync(LinkedEntities <WebResource> linked, bool showAllways) { if (!this.IsControlsEnabled) { return; } ToggleControls(false, Properties.OutputStrings.ShowingDifferenceEntityDescription); var service1 = await GetService1(); var service2 = await GetService2(); if (service1 != null && service2 != null) { var repository1 = new WebResourceRepository(service1); var repository2 = new WebResourceRepository(service2); var webResource1 = await repository1.GetByIdAsync(linked.Entity1.Id, ColumnSetInstances.AllColumns); var webResource2 = await repository2.GetByIdAsync(linked.Entity2.Id, ColumnSetInstances.AllColumns); var desc1 = await EntityDescriptionHandler.GetEntityDescriptionAsync(webResource1); var desc2 = await EntityDescriptionHandler.GetEntityDescriptionAsync(webResource2); if (showAllways || desc1 != desc2) { string filePath1 = await CreateDescriptionFileAsync(service1.ConnectionData, webResource1.Name, EntityFileNameFormatter.Headers.EntityDescription, desc1); string filePath2 = await CreateDescriptionFileAsync(service2.ConnectionData, webResource2.Name, EntityFileNameFormatter.Headers.EntityDescription, desc2); if (File.Exists(filePath1) && File.Exists(filePath2)) { await this._iWriteToOutput.ProcessStartProgramComparerAsync(service1.ConnectionData, filePath1, filePath2, Path.GetFileName(filePath1), Path.GetFileName(filePath2), service2.ConnectionData); } else { this._iWriteToOutput.PerformAction(service1.ConnectionData, filePath1); this._iWriteToOutput.PerformAction(service2.ConnectionData, filePath2); } } } ToggleControls(true, Properties.OutputStrings.ShowingDifferenceEntityDescriptionCompleted); }
private async Task PerformShowingDifferenceContentAsync(LinkedEntities <WebResource> linked, bool showAllways) { if (!this.IsControlsEnabled) { return; } ToggleControls(false, Properties.OutputStrings.ShowingDifferenceWebResourcesFormat1, linked.Entity1.Name); var service1 = await GetService1(); var service2 = await GetService2(); if (service1 != null && service2 != null) { var repository1 = new WebResourceRepository(service1); var repository2 = new WebResourceRepository(service2); var webResource1 = await repository1.GetByIdAsync(linked.Entity1.Id, ColumnSetInstances.AllColumns); var webResource2 = await repository2.GetByIdAsync(linked.Entity2.Id, ColumnSetInstances.AllColumns); if (showAllways || webResource1.Content != webResource2.Content) { string filePath1 = await CreateFileWithContentAsync(service1.ConnectionData.Name, webResource1); string filePath2 = await CreateFileWithContentAsync(service2.ConnectionData.Name, webResource2); if (File.Exists(filePath1) && File.Exists(filePath2)) { await this._iWriteToOutput.ProcessStartProgramComparerAsync(service1.ConnectionData, filePath1, filePath2, Path.GetFileName(filePath1), Path.GetFileName(filePath2), service2.ConnectionData); } else { this._iWriteToOutput.PerformAction(service1.ConnectionData, filePath1); this._iWriteToOutput.PerformAction(service2.ConnectionData, filePath2); } } } ToggleControls(true, Properties.OutputStrings.ShowingDifferenceWebResourcesCompletedFormat1, linked.Entity1.Name); }
private string CreateFileWithContent(string connectionName, WebResource webresource) { var webResourceFileName = WebResourceRepository.GetWebResourceFileName(webresource); var contentWebResource = webresource.Content ?? string.Empty; if (!string.IsNullOrEmpty(contentWebResource)) { var array = Convert.FromBase64String(contentWebResource); string localFileName = string.Format("{0}.{1}", connectionName, webResourceFileName); string filePath = Path.Combine(_commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(localFileName)); File.WriteAllBytes(filePath, array); return(filePath); } return(string.Empty); }
public void FetchOnline(IEnumerable <long> personIds) { if (personIds == null) { throw new ArgumentNullException(nameof(personIds)); } if (personIds.Count() > MaxStackSize) { throw new ArgumentException($"Maximum count is \"{MaxStackSize}\".", nameof(personIds)); } var webResourceId = WebResourceRepository.Single(r => r.Uuid == WebResourceUuids.Vk, r => r.Id); var providerId = PersonMetaProviderRepository.Single(p => p.Uuid == PersonMetaProviderUuid, p => p.Id); var personAccountDict = MetaAccountRepository.Select(a => a.WebResourceId == webResourceId && personIds.Contains(a.PersonId)) .GroupBy(a => a.PersonId) .ToDictionary(g => g.Key, g => g.Select(a => a.AccountId)); var allAccountIds = personAccountDict.SelectMany(pa => pa.Value).ToArray(); var accountOnlineSnapshotDict = VkApiConnector.FetchOnlineSnapshots(allAccountIds).Result; foreach (var accountSnapshot in accountOnlineSnapshotDict) { var personId = personAccountDict.First(p => p.Value.Any(a => a == accountSnapshot.Key)).Key; var onlineSnapshots = accountOnlineSnapshotDict[accountSnapshot.Key]; foreach (var onlineSnapshot in onlineSnapshots) { var todayOnlineDataSnapshot = MetaDataSnapshotRepository.GetOrFetchDataSnapshot(providerId, personId, accountSnapshot.Key, onlineSnapshot.Time, (int)VkSnapshotType.Online); var snapshots = todayOnlineDataSnapshot.GetSnapshots <VkOnlineSnapshot>().Append(onlineSnapshot).ToArray(); todayOnlineDataSnapshot.SetSnapshots(snapshots); MetaDataSnapshotRepository.Save(todayOnlineDataSnapshot); } } UnitOfWork.Commit(); }
private async Task OpeningWebResource(CommonConfiguration commonConfig, ConnectionData connectionData, SelectedFile selectedFile, ActionOpenComponent action) { if (!File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.FileNotExistsFormat1, selectedFile.FilePath); return; } var service = await ConnectAndWriteToOutputAsync(connectionData); if (service == null) { return; } // Репозиторий для работы с веб-ресурсами WebResourceRepository webResourceRepository = new WebResourceRepository(service); WebResource webresource = await webResourceRepository.FindByNameAsync(selectedFile.FriendlyFilePath, selectedFile.Extension); if (webresource != null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.WebResourceFoundedByNameFormat2, webresource.Id.ToString(), webresource.Name); connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { Guid?webId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (webId.HasValue) { webresource = await webResourceRepository.GetByIdAsync(webId.Value); } if (webresource != null) { this._iWriteToOutput.WriteToOutput(connectionData, "Web-resource not founded by name. Last link web-resource is selected for opening."); connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { this._iWriteToOutput.WriteToOutput(connectionData, "Web-resource not founded by name and has not Last link."); this._iWriteToOutput.WriteToOutput(connectionData, "Starting Custom Web-resource selection form."); bool?dialogResult = null; Guid?selectedWebResourceId = null; string selectedPath = string.Empty; var t = new Thread((ThreadStart)(() => { try { var form = new Views.WindowWebResourceSelectOrCreate(this._iWriteToOutput, service, selectedFile, webId); dialogResult = form.ShowDialog(); selectedWebResourceId = form.SelectedWebResourceId; } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(connectionData, ex); } })); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (dialogResult.GetValueOrDefault()) { if (selectedWebResourceId.HasValue) { this._iWriteToOutput.WriteToOutput(connectionData, "Custom Web-resource is selected."); webresource = await webResourceRepository.GetByIdAsync(selectedWebResourceId.Value); connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { this._iWriteToOutput.WriteToOutput(connectionData, "!Warning. WebResource not exists. name: {0}.", selectedFile.Name); } } else { this._iWriteToOutput.WriteToOutput(connectionData, "Opening was cancelled."); return; } } } if (webresource == null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.WebResourceNotFoundedByNameFormat1, selectedFile.FileName); return; } if (action == ActionOpenComponent.OpenInWeb) { service.UrlGenerator.OpenSolutionComponentInWeb(Entities.ComponentType.WebResource, webresource.Id); } else if (action == ActionOpenComponent.OpenDependentComponentsInWeb) { connectionData.OpenSolutionComponentDependentComponentsInWeb(Entities.ComponentType.WebResource, webresource.Id); } else if (action == ActionOpenComponent.OpenDependentComponentsInExplorer) { WindowHelper.OpenSolutionComponentDependenciesExplorer( _iWriteToOutput , service , null , commonConfig , (int)ComponentType.WebResource , webresource.Id , null); } else if (action == ActionOpenComponent.OpenSolutionsContainingComponentInExplorer) { WindowHelper.OpenExplorerSolutionExplorer( _iWriteToOutput , service , commonConfig , (int)ComponentType.WebResource , webresource.Id , null ); } }
private async Task CreatingLastLinkWebResourceMultiple(IOrganizationServiceExtented service, List <SelectedFile> selectedFiles) { if (!selectedFiles.Any()) { return; } WebResourceRepository webResourceRepository = new WebResourceRepository(service); foreach (var selectedFile in selectedFiles) { if (!File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.FileNotExistsFormat1, selectedFile.FilePath); continue; } var idLastLink = service.ConnectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); bool?dialogResult = null; Guid?selectedWebResourceId = null; bool showNext = false; var t = new Thread((ThreadStart)(() => { try { var form = new Views.WindowWebResourceSelectOrCreate(this._iWriteToOutput, service, selectedFile, idLastLink); form.ShowSkipButton(); dialogResult = form.ShowDialog(); selectedWebResourceId = form.SelectedWebResourceId; showNext = form.ShowNext; } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(service.ConnectionData, ex); } })); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (dialogResult.GetValueOrDefault()) { if (selectedWebResourceId.HasValue) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.WebResourceIsSelected); var webresource = await webResourceRepository.GetByIdAsync(selectedWebResourceId.Value); service.ConnectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); service.ConnectionData.Save(); } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.WebResourceNotFoundedByNameFormat1, selectedFile.Name); } } else if (!showNext) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.CreatingLastLinkWasCanceled); return; } } }
private async void btnCreateNewWebResource_Click(object sender, RoutedEventArgs e) { if (!this.IsControlsEnabled) { return; } ToggleControls(false, Properties.WindowStatusStrings.PreparingCreatingNewWebResource); var extension = _file.Extension; if (string.IsNullOrEmpty(extension) || !WebResourceRepository.IsSupportedExtension(extension)) { ToggleControls(true, Properties.WindowStatusStrings.CreatingNewWebResourceDeniedFormat1, extension); var message = string.Format(Properties.MessageBoxStrings.FileExtensionIsNotAllowedForWebResourceFormat1, extension); MessageBox.Show(message, Properties.MessageBoxStrings.InformationTitle, MessageBoxButton.OK, MessageBoxImage.Information); return; } Solution solution = null; if (!string.IsNullOrEmpty(_connectionData.LastSelectedSolutionsUniqueName.FirstOrDefault()) && this.ForAllOther) { var repositorySolution = new SolutionRepository(_service); solution = await repositorySolution.GetSolutionByUniqueNameAsync(_connectionData.LastSelectedSolutionsUniqueName.FirstOrDefault()); } if (solution == null) { var formSelectSolution = new WindowSolutionSelect(_iWriteToOutput, _service); formSelectSolution.ShowForAllOther(); var dialogResult = formSelectSolution.ShowDialog().GetValueOrDefault(); _connectionData.AddLastSelectedSolution(formSelectSolution.SelectedSolution?.UniqueName); if (!dialogResult) { this.ForAllOther = false; ToggleControls(true, Properties.WindowStatusStrings.CreatingNewWebResourceCanceled); return; } solution = formSelectSolution.SelectedSolution; _connectionData.AddLastSelectedSolution(solution?.UniqueName); this.ForAllOther = !string.IsNullOrEmpty(_connectionData.LastSelectedSolutionsUniqueName.FirstOrDefault()) && formSelectSolution.ForAllOther; } if (solution == null) { this.ForAllOther = false; ToggleControls(true, Properties.WindowStatusStrings.SolutionForCreatingNewWebResouceNotSelected); return; } this._iWriteToOutput.WriteToOutputSolutionUri(_connectionData, solution.UniqueName, solution.Id); var formWebResourceInfo = new WindowWebResourceCreate(_file.FileName, _file.FriendlyFilePath, solution.UniqueName, solution.PublisherCustomizationPrefix); { var dialogResult = formWebResourceInfo.ShowDialog().GetValueOrDefault(); if (!dialogResult) { ToggleControls(true, Properties.WindowStatusStrings.CreatingNewWebResourceCanceled); return; } } var name = formWebResourceInfo.WebResourceName; var displayName = formWebResourceInfo.WebResourceDisplayName; var description = formWebResourceInfo.WebResourceDescription; name = WebResourceRepository.GenerateWebResouceName(name, solution.PublisherCustomizationPrefix); UpdateStatus(Properties.WindowStatusStrings.CreatingNewWebResourceFormat1, name); WebResourceRepository repository = new WebResourceRepository(_service); try { Guid id = await repository.CreateNewWebResourceAsync(name, displayName, description, extension, solution.UniqueName); this.SelectedWebResourceId = id; this.DialogResult = true; this.Close(); ToggleControls(true, Properties.WindowStatusStrings.CreatingNewWebResourceCompletedFormat1, name); } catch (Exception ex) { ToggleControls(true, Properties.WindowStatusStrings.CreatingNewWebResourceFailed, name); this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } }
private async Task ShowExistingWebResources(Guid?lastLinkedWebResource = null) { if (!this.IsControlsEnabled) { return; } ToggleControls(false, Properties.WindowStatusStrings.LoadingWebResources); this.trVWebResources.Dispatcher.Invoke(() => { this.trVWebResources.ItemsSource = null; this.trVWebResources.Items.Clear(); }); string textName = string.Empty; txtBFilter.Dispatcher.Invoke(() => { textName = txtBFilter.Text.Trim().ToLower(); }); List <WebResource> list = null; WebResourceRepository repository = new WebResourceRepository(this._service); try { list = await repository.GetListAllAsync(textName, new ColumnSet(WebResource.Schema.Attributes.name, WebResource.Schema.Attributes.webresourcetype, WebResource.Schema.Attributes.ismanaged, WebResource.Schema.Attributes.ishidden)); if (lastLinkedWebResource.HasValue && this._lastWebResource == null) { this._lastWebResource = await repository.GetByIdAsync(lastLinkedWebResource.Value); string name = this._lastWebResource?.Name; bool isEnabled = this._lastWebResource != null; Visibility visibility = isEnabled ? Visibility.Visible : Visibility.Collapsed; this.Dispatcher.Invoke(() => { txtBLastLink.Text = name; btnSelectLastLink.IsEnabled = lblLastLink.IsEnabled = txtBLastLink.IsEnabled = sepLastLink.IsEnabled = isEnabled; btnSelectLastLink.Visibility = lblLastLink.Visibility = txtBLastLink.Visibility = sepLastLink.Visibility = visibility; toolStrip.UpdateLayout(); }); } } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); list = new List <WebResource>(); } LoadWebResources(list); ToggleControls(true, Properties.WindowStatusStrings.LoadingWebResourcesCompletedFormat1, list.Count()); }
private async Task DifferenceWebResources(SelectedFile selectedFile, bool isCustom, ConnectionData connectionData, CommonConfiguration commonConfig) { if (connectionData == null) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection); return; } if (!File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.FileNotExistsFormat1, selectedFile.FilePath); return; } this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM); this._iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription()); // Подключаемся к CRM. var service = await QuickConnection.ConnectAsync(connectionData); if (service == null) { _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name); return; } this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint); // Репозиторий для работы с веб-ресурсами WebResourceRepository webResourceRepository = new WebResourceRepository(service); WebResource webresource = null; if (isCustom) { Guid?webId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); bool?dialogResult = null; Guid?selectedWebResourceId = null; string selectedPath = string.Empty; var t = new Thread(() => { try { var form = new Views.WindowWebResourceSelectOrCreate(this._iWriteToOutput, service, connectionData, selectedFile, webId); dialogResult = form.ShowDialog(); selectedWebResourceId = form.SelectedWebResourceId; } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(connectionData, ex); } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (dialogResult.GetValueOrDefault() == false) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.DifferenceWasCancelled); return; } if (selectedWebResourceId.HasValue) { this._iWriteToOutput.WriteToOutput(connectionData, "Custom Web-resource is selected."); webresource = await webResourceRepository.GetByIdAsync(selectedWebResourceId.Value); connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { this._iWriteToOutput.WriteToOutput(connectionData, "!Warning. WebResource not exists. name: {0}.", selectedFile.Name); } } else { webresource = await webResourceRepository.FindByNameAsync(selectedFile.FriendlyFilePath, selectedFile.Extension); if (webresource != null) { this._iWriteToOutput.WriteToOutput(connectionData, "Web-resource founded by name."); connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { Guid?webId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (webId.HasValue) { webresource = await webResourceRepository.GetByIdAsync(webId.Value); } if (webresource != null) { this._iWriteToOutput.WriteToOutput(connectionData, "Web-resource not founded by name. Last link web-resource is selected for difference."); connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { this._iWriteToOutput.WriteToOutput(connectionData, "Web-resource not founded by name and has not Last link."); this._iWriteToOutput.WriteToOutput(connectionData, "Starting Custom Web-resource selection form."); bool?dialogResult = null; Guid?selectedWebResourceId = null; string selectedPath = string.Empty; var t = new Thread(() => { try { var form = new Views.WindowWebResourceSelectOrCreate(this._iWriteToOutput, service, connectionData, selectedFile, webId); dialogResult = form.ShowDialog(); selectedWebResourceId = form.SelectedWebResourceId; } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(connectionData, ex); } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (dialogResult.GetValueOrDefault()) { if (selectedWebResourceId.HasValue) { this._iWriteToOutput.WriteToOutput(connectionData, "Custom Web-resource is selected."); webresource = await webResourceRepository.GetByIdAsync(selectedWebResourceId.Value); connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); connectionData.Save(); } else { this._iWriteToOutput.WriteToOutput(connectionData, "!Warning. WebResource not exists. name: {0}.", selectedFile.Name); } } else { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.DifferenceWasCancelled); return; } } } } if (webresource == null) { this._iWriteToOutput.WriteToOutput(connectionData, "Web-resource not founded in CRM: {0}", selectedFile.FileName); return; } string filePath1 = selectedFile.FilePath; string fileTitle1 = selectedFile.FileName; string filePath2 = string.Empty; string fileTitle2 = string.Empty; { var contentWebResource = webresource.Content ?? string.Empty; var array = Convert.FromBase64String(contentWebResource); filePath2 = FileOperations.GetNewTempFilePath(webresource.Name, selectedFile.Extension); File.WriteAllBytes(filePath2, array); fileTitle2 = connectionData.Name + "." + selectedFile.FileName + " - " + filePath2; } this._iWriteToOutput.ProcessStartProgramComparer(filePath1, filePath2, fileTitle1, fileTitle2); }
> > ComparingFilesAndWebResources( IWriteToOutput _iWriteToOutput , List <SelectedFile> selectedFiles , ConnectionData connectionData , bool withDetails) { if (connectionData == null) { _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection); return(null); } var dictFilesEqualByTextNotContent = new List <Tuple <SelectedFile, WebResource> >(); var dictFilesNotEqualByText = new List <Tuple <SelectedFile, WebResource, ContentCopareResult> >(); _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM); _iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription()); // Подключаемся к CRM. var service = await QuickConnection.ConnectAsync(connectionData); if (service == null) { _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name); return(null); } _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint); bool isconnectionDataDirty = false; List <string> listNotExistsOnDisk = new List <string>(); List <string> listNotFoundedInCRMNoLink = new List <string>(); int countEqualByContent = 0; FormatTextTableHandler tableEqualByText = new FormatTextTableHandler(); tableEqualByText.SetHeader("FriendlyFilePath", "WebResourceName"); FormatTextTableHandler tableDifferent = new FormatTextTableHandler(); if (withDetails) { tableDifferent.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); } else { tableDifferent.SetHeader("FriendlyFilePath", "WebResourceName"); } FormatTextTableHandler tableDifferentOnlyInserts = new FormatTextTableHandler(); tableDifferentOnlyInserts.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)"); FormatTextTableHandler tableDifferentOnlyDeletes = new FormatTextTableHandler(); tableDifferentOnlyDeletes.SetHeader("FriendlyFilePath", "WebResourceName", "-Deletes", "(-Length)"); FormatTextTableHandler tableDifferentComplexChanges = new FormatTextTableHandler(); tableDifferentComplexChanges.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); FormatTextTableHandler tableDifferentMirror = new FormatTextTableHandler(); tableDifferentMirror.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); FormatTextTableHandler tableDifferentMirrorWithInserts = new FormatTextTableHandler(); tableDifferentMirrorWithInserts.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); FormatTextTableHandler tableDifferentMirrorWithDeletes = new FormatTextTableHandler(); tableDifferentMirrorWithDeletes.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); FormatTextTableHandler tableLastLinkEqualByContent = new FormatTextTableHandler(); tableLastLinkEqualByContent.SetHeader("FriendlyFilePath", "WebResourceName"); FormatTextTableHandler listLastLinkEqualByText = new FormatTextTableHandler(); listLastLinkEqualByText.SetHeader("FriendlyFilePath", "WebResourceName"); FormatTextTableHandler tableLastLinkDifferent = new FormatTextTableHandler(); if (withDetails) { tableLastLinkDifferent.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); } else { tableLastLinkDifferent.SetHeader("FriendlyFilePath", "WebResourceName"); } FormatTextTableHandler tableLastLinkDifferentOnlyInserts = new FormatTextTableHandler(); tableLastLinkDifferentOnlyInserts.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)"); FormatTextTableHandler tableLastLinkDifferentOnlyDeletes = new FormatTextTableHandler(); tableLastLinkDifferentOnlyDeletes.SetHeader("FriendlyFilePath", "WebResourceName", "-Deletes", "(-Length)"); FormatTextTableHandler tableLastLinkDifferentComplexChanges = new FormatTextTableHandler(); tableLastLinkDifferentComplexChanges.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); FormatTextTableHandler tableLastLinkDifferentMirror = new FormatTextTableHandler(); tableLastLinkDifferentMirror.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); FormatTextTableHandler tableLastLinkDifferentMirrorWithInserts = new FormatTextTableHandler(); tableLastLinkDifferentMirrorWithInserts.SetHeader("FriendlyFilePath", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); FormatTextTableHandler tableLastLinkDifferentMirrorWithDeletes = new FormatTextTableHandler(); tableLastLinkDifferentMirrorWithDeletes.SetHeader("FriendlyFilePath", "WebResourceName", "+Inserts", "(+Length)", "-Deletes", "(-Length)"); // Репозиторий для работы с веб-ресурсами WebResourceRepository webResourceRepository = new WebResourceRepository(service); var groups = selectedFiles.GroupBy(sel => sel.Extension); foreach (var gr in groups) { var names = gr.Select(sel => sel.FriendlyFilePath).ToArray(); var dict = webResourceRepository.FindMultiple(gr.Key, names , new ColumnSet( WebResource.Schema.EntityPrimaryIdAttribute , WebResource.Schema.Attributes.name , WebResource.Schema.Attributes.webresourcetype , WebResource.Schema.Attributes.content )); foreach (var selectedFile in gr) { if (!File.Exists(selectedFile.FilePath)) { listNotExistsOnDisk.Add(selectedFile.FilePath); continue; } string urlShowDifference = string.Format("{0}:///{1}?ConnectionId={2}", UrlCommandFilter.PrefixShowDifference, selectedFile.FilePath.Replace('\\', '/'), connectionData.ConnectionId.ToString()); string name = selectedFile.FriendlyFilePath.ToLower(); var webresource = WebResourceRepository.FindWebResourceInDictionary(dict, name, gr.Key); if (webresource != null) { // Запоминается файл isconnectionDataDirty = true; connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); var contentWebResource = webresource.Content ?? string.Empty; var arrayFile = File.ReadAllBytes(selectedFile.FilePath); var contentFile = Convert.ToBase64String(arrayFile); if (string.Equals(contentFile, contentWebResource)) { countEqualByContent++; } else { var arrayWebResource = Convert.FromBase64String(contentWebResource); var nameWebResource = webresource.Name; var compare = ContentCoparerHelper.CompareByteArrays(selectedFile.Extension, arrayFile, arrayWebResource, withDetails); if (compare.IsEqual) { tableEqualByText.AddLine(selectedFile.UrlFriendlyFilePath, nameWebResource); dictFilesEqualByTextNotContent.Add(Tuple.Create(selectedFile, webresource)); } else { dictFilesNotEqualByText.Add(Tuple.Create(selectedFile, webresource, compare)); if (withDetails) { string[] values = new string[] { selectedFile.UrlFriendlyFilePath, nameWebResource , string.Format("+{0}", compare.Inserts) , string.Format("(+{0})", compare.InsertLength) , string.Format("-{0}", compare.Deletes) , string.Format("(-{0})", compare.DeleteLength) , urlShowDifference }; tableDifferent.AddLine(values); if (compare.IsOnlyInserts) { tableDifferentOnlyInserts.AddLine(selectedFile.UrlFriendlyFilePath , string.Format("+{0}", compare.Inserts) , string.Format("(+{0})", compare.InsertLength) , urlShowDifference ); } if (compare.IsOnlyDeletes) { tableDifferentOnlyDeletes.AddLine(selectedFile.UrlFriendlyFilePath , string.Format("-{0}", compare.Deletes) , string.Format("(-{0})", compare.DeleteLength) , urlShowDifference ); } if (compare.IsComplexChanges) { tableDifferentComplexChanges.AddLine(values); } if (compare.IsMirror) { tableDifferentMirror.AddLine(values); } if (compare.IsMirrorWithInserts) { tableDifferentMirrorWithInserts.AddLine(values); } if (compare.IsMirrorWithDeletes) { tableDifferentMirrorWithDeletes.AddLine(values); } } else { tableDifferent.AddLine(selectedFile.UrlFriendlyFilePath, nameWebResource, urlShowDifference); } } } } else { Guid?webId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (webId.HasValue) { webresource = await webResourceRepository.GetByIdAsync(webId.Value); if (webresource != null) { // Запоминается файл isconnectionDataDirty = true; connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); var contentWebResource = webresource.Content ?? string.Empty; var nameWebResource = webresource.Name; var arrayFile = File.ReadAllBytes(selectedFile.FilePath); var contentFile = Convert.ToBase64String(arrayFile); if (string.Equals(contentFile, contentWebResource)) { tableLastLinkEqualByContent.AddLine(selectedFile.UrlFriendlyFilePath, nameWebResource); } else { var arrayWebResource = Convert.FromBase64String(contentWebResource); var compare = ContentCoparerHelper.CompareByteArrays(selectedFile.Extension, arrayFile, arrayWebResource); if (compare.IsEqual) { listLastLinkEqualByText.AddLine(selectedFile.UrlFriendlyFilePath, nameWebResource); dictFilesEqualByTextNotContent.Add(Tuple.Create(selectedFile, webresource)); } else { dictFilesNotEqualByText.Add(Tuple.Create(selectedFile, webresource, compare)); if (withDetails) { string[] values = new string[] { selectedFile.UrlFriendlyFilePath, nameWebResource , string.Format("+{0}", compare.Inserts) , string.Format("(+{0})", compare.InsertLength) , string.Format("-{0}", compare.Deletes) , string.Format("(-{0})", compare.DeleteLength) , urlShowDifference }; tableLastLinkDifferent.AddLine(values); if (compare.IsOnlyInserts) { tableLastLinkDifferentOnlyInserts.AddLine(selectedFile.UrlFriendlyFilePath, nameWebResource , string.Format("+{0}", compare.Inserts) , string.Format("(+{0})", compare.InsertLength) , urlShowDifference ); } if (compare.IsOnlyDeletes) { tableLastLinkDifferentOnlyDeletes.AddLine(selectedFile.UrlFriendlyFilePath, nameWebResource , string.Format("-{0}", compare.Deletes) , string.Format("(-{0})", compare.DeleteLength) , urlShowDifference ); } if (compare.IsComplexChanges) { tableLastLinkDifferentComplexChanges.AddLine(values); } if (compare.IsMirror) { tableLastLinkDifferentMirror.AddLine(values); } if (compare.IsMirrorWithInserts) { tableLastLinkDifferentMirrorWithInserts.AddLine(values); } if (compare.IsMirrorWithDeletes) { tableLastLinkDifferentMirrorWithDeletes.AddLine(values); } } else { tableLastLinkDifferent.AddLine(selectedFile.UrlFriendlyFilePath, nameWebResource, urlShowDifference); } } } } else { connectionData.RemoveMapping(selectedFile.FriendlyFilePath); listNotFoundedInCRMNoLink.Add(selectedFile.UrlFriendlyFilePath); } } else { listNotFoundedInCRMNoLink.Add(selectedFile.UrlFriendlyFilePath); } } } } if (isconnectionDataDirty) { //Сохранение настроек после публикации connectionData.Save(); } var tabSpacer = " "; if (tableDifferent.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File and web-resource are DIFFERENT by content: {0}", tableDifferent.Count); tableDifferent.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableDifferentOnlyInserts.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File and web-resource are DIFFERENT by content WITH ONLY INSERTS: {0}", tableDifferentOnlyInserts.Count); tableDifferentOnlyInserts.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableDifferentOnlyDeletes.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File and web-resource are DIFFERENT by content WITH ONLY DELETES: {0}", tableDifferentOnlyDeletes.Count); tableDifferentOnlyDeletes.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableDifferentComplexChanges.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File and web-resource are DIFFERENT by content WITH COMPLEX CHANGES: {0}", tableDifferentComplexChanges.Count); tableDifferentComplexChanges.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableDifferentMirror.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File and web-resource are DIFFERENT by content WITH MIRROR CHANGES: {0}", tableDifferentMirror.Count); tableDifferentMirror.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableDifferentMirrorWithInserts.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File and web-resource are DIFFERENT by content WITH MIRROR CHANGES AND INSERTS: {0}", tableDifferentMirrorWithInserts.Count); tableDifferentMirrorWithInserts.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableDifferentMirrorWithDeletes.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File and web-resource are DIFFERENT by content WITH MIRROR CHANGES AND DELETES: {0}", tableDifferentMirrorWithDeletes.Count); tableDifferentMirrorWithDeletes.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (listNotFoundedInCRMNoLink.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM: {0}", listNotFoundedInCRMNoLink.Count); listNotFoundedInCRMNoLink.Sort(); listNotFoundedInCRMNoLink.ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableLastLinkDifferent.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link, files DIFFERENT: {0}", tableLastLinkDifferent.Count); tableLastLinkDifferent.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableLastLinkDifferentOnlyInserts.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link, files DIFFERENT WITH ONLY INSERTS: {0}", tableLastLinkDifferentOnlyInserts.Count); tableLastLinkDifferentOnlyInserts.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableLastLinkDifferentOnlyDeletes.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link, files DIFFERENT WITH ONLY DELETES: {0}", tableLastLinkDifferentOnlyDeletes.Count); tableLastLinkDifferentOnlyDeletes.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableLastLinkDifferentComplexChanges.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link, files DIFFERENT WITH COMPLEX CHANGES: {0}", tableLastLinkDifferentComplexChanges.Count); tableLastLinkDifferentComplexChanges.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableLastLinkDifferentMirror.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link, files DIFFERENT WITH MIRROR CHANGES: {0}", tableLastLinkDifferentMirror.Count); tableLastLinkDifferentMirror.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableLastLinkDifferentMirrorWithInserts.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link, files DIFFERENT WITH MIRROR CHANGES AND INSERTS: {0}", tableLastLinkDifferentMirrorWithInserts.Count); tableLastLinkDifferentMirrorWithInserts.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableLastLinkDifferentMirrorWithDeletes.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link, files DIFFERENT WITH MIRROR CHANGES AND DELETES: {0}", tableLastLinkDifferentMirrorWithDeletes.Count); tableLastLinkDifferentMirrorWithDeletes.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (listLastLinkEqualByText.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link, files EQUALS BY TEXT: {0}", listLastLinkEqualByText.Count); listLastLinkEqualByText.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableLastLinkEqualByContent.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link, files EQUALS BY CONTENT: {0}", tableLastLinkEqualByContent.Count); tableLastLinkEqualByContent.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (listNotExistsOnDisk.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.FileNotExistsFormat1, listNotExistsOnDisk.Count); listNotExistsOnDisk.Sort(); listNotExistsOnDisk.ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (tableEqualByText.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File and web-resource EQUALS BY TEXT: {0}", tableEqualByText.Count); tableEqualByText.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (countEqualByContent > 0) { if (countEqualByContent == selectedFiles.Count) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "All files and web-resources EQUALS BY CONTENT: {0}", countEqualByContent); } else { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File and web-resource EQUALS BY CONTENT: {0}", countEqualByContent); } } return(Tuple.Create(service, dictFilesEqualByTextNotContent, dictFilesNotEqualByText)); }
private async Task ShowExistingWebResources() { if (!this.IsControlsEnabled) { return; } ToggleControls(false, Properties.OutputStrings.LoadingWebResources); string textName = string.Empty; bool? hidden = null; bool? managed = null; int? webResourceType = null; this.Dispatcher.Invoke(() => { this._itemsSource.Clear(); textName = txtBFilter.Text.Trim().ToLower(); if (cmBManaged.SelectedItem is ComboBoxItem comboBoxItemManaged && comboBoxItemManaged.Tag != null && comboBoxItemManaged.Tag is bool boolManaged ) { managed = boolManaged; } if (cmBHidden.SelectedItem is ComboBoxItem comboBoxItemHidden && comboBoxItemHidden.Tag != null && comboBoxItemHidden.Tag is bool boolHidden ) { hidden = boolHidden; } if (cmBType.SelectedItem is WebResource.Schema.OptionSets.webresourcetype webresourcetype) { webResourceType = (int)webresourcetype; } }); IEnumerable <LinkedEntities <WebResource> > list = Enumerable.Empty <LinkedEntities <WebResource> >(); try { var service1 = await GetService1(); var service2 = await GetService2(); if (service1 != null && service2 != null) { var columnSet = new ColumnSet ( WebResource.Schema.Attributes.name , WebResource.Schema.Attributes.displayname , WebResource.Schema.Attributes.webresourcetype , WebResource.Schema.Attributes.ismanaged , WebResource.Schema.Attributes.ishidden ); List <LinkedEntities <WebResource> > temp = new List <LinkedEntities <WebResource> >(); if (service1.ConnectionData.ConnectionId != service2.ConnectionData.ConnectionId) { var repository1 = new WebResourceRepository(service1); var repository2 = new WebResourceRepository(service2); var task1 = repository1.GetListSupportsTextAsync(textName, webResourceType, managed, hidden, columnSet); var task2 = repository2.GetListSupportsTextAsync(textName, webResourceType, managed, hidden, columnSet); var list1 = await task1; var list2 = await task2; foreach (var webresource1 in list1) { var webresource2 = list2.FirstOrDefault(c => string.Equals(c.Name, webresource1.Name, StringComparison.InvariantCultureIgnoreCase)); if (webresource2 == null) { continue; } temp.Add(new LinkedEntities <WebResource>(webresource1, webresource2)); } } else { var repository1 = new WebResourceRepository(service1); var task1 = repository1.GetListSupportsTextAsync(textName, webResourceType, managed, hidden, columnSet); var list1 = await task1; foreach (var webresource1 in list1) { temp.Add(new LinkedEntities <WebResource>(webresource1, null)); } } list = temp; } } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(null, ex); } list = FilterList(list, textName); LoadEntities(list); }
> > FindFilesNotExistsInCrm( IWriteToOutput _iWriteToOutput , List <SelectedFile> selectedFiles , ConnectionData connectionData) { if (connectionData == null) { _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection); return(null); } _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM); _iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription()); // Подключаемся к CRM. var service = await QuickConnection.ConnectAsync(connectionData); if (service == null) { _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name); return(null); } _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint); bool isconnectionDataDirty = false; var listNotFoundedInCrmNoLink = new List <SelectedFile>(); var listNotFoundedInCrmWithLink = new List <Tuple <SelectedFile, WebResource> >(); List <string> listNotExistsOnDisk = new List <string>(); // Репозиторий для работы с веб-ресурсами WebResourceRepository webResourceRepository = new WebResourceRepository(service); var groups = selectedFiles.GroupBy(sel => sel.Extension); foreach (var gr in groups) { var names = gr.Select(sel => sel.FriendlyFilePath).ToArray(); var dict = webResourceRepository.FindMultiple(gr.Key, names , new ColumnSet( WebResource.Schema.EntityPrimaryIdAttribute , WebResource.Schema.Attributes.name , WebResource.Schema.Attributes.webresourcetype )); foreach (var selectedFile in gr) { if (!File.Exists(selectedFile.FilePath)) { listNotExistsOnDisk.Add(selectedFile.FilePath); continue; } string name = selectedFile.FriendlyFilePath.ToLower(); var webresource = WebResourceRepository.FindWebResourceInDictionary(dict, name, gr.Key); if (webresource != null) { // Запоминается файл isconnectionDataDirty = true; connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); } else { Guid?webId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (webId.HasValue) { webresource = await webResourceRepository.GetByIdAsync(webId.Value, new ColumnSet(true)); if (webresource != null) { listNotFoundedInCrmWithLink.Add(Tuple.Create(selectedFile, webresource)); isconnectionDataDirty = true; connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); } else { connectionData.RemoveMapping(selectedFile.FriendlyFilePath); listNotFoundedInCrmNoLink.Add(selectedFile); } } else { listNotFoundedInCrmNoLink.Add(selectedFile); } } } } if (isconnectionDataDirty) { //Сохранение настроек после публикации connectionData.Save(); } var tabSpacer = " "; if (listNotFoundedInCrmNoLink.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM: {0}", listNotFoundedInCrmNoLink.Count); listNotFoundedInCrmNoLink.Sort(); listNotFoundedInCrmNoLink.ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (listNotFoundedInCrmWithLink.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "File NOT FOUNDED in CRM, but has Last Link: {0}", listNotFoundedInCrmWithLink.Count); FormatTextTableHandler tableLastLinkDifferent = new FormatTextTableHandler(); tableLastLinkDifferent.SetHeader("FriendlyFilePath", "WebResourceName"); listNotFoundedInCrmWithLink.ForEach(i => tableLastLinkDifferent.AddLine(i.Item1.FriendlyFilePath, i.Item2.Name)); tableLastLinkDifferent.GetFormatedLines(true).ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (listNotExistsOnDisk.Count > 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.FileNotExistsFormat1, listNotExistsOnDisk.Count); listNotExistsOnDisk.Sort(); listNotExistsOnDisk.ForEach(item => _iWriteToOutput.WriteToOutput(connectionData, tabSpacer + item)); } if (listNotFoundedInCrmNoLink.Count + listNotFoundedInCrmWithLink.Count == 0) { _iWriteToOutput.WriteToOutput(connectionData, string.Empty); _iWriteToOutput.WriteToOutput(connectionData, "No files not exists in Crm"); } return(Tuple.Create(service, listNotFoundedInCrmNoLink, listNotFoundedInCrmWithLink)); }
private async Task ShowingWebResourcesDependentComponents(ConnectionData connectionData, CommonConfiguration commonConfig, List <SelectedFile> selectedFiles) { var service = await ConnectAndWriteToOutputAsync(connectionData); if (service == null) { return; } StringBuilder content = new StringBuilder(); content.AppendLine(Properties.OutputStrings.ConnectingToCRM); content.AppendLine(connectionData.GetConnectionDescription()); content.AppendFormat(Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint).AppendLine(); var descriptor = new SolutionComponentDescriptor(service); descriptor.WithUrls = true; descriptor.WithManagedInfo = true; descriptor.WithSolutionsInfo = true; var descriptorHandler = new DependencyDescriptionHandler(descriptor); var dependencyRepository = new DependencyRepository(service); bool isconnectionDataDirty = false; List <string> listNotExistsOnDisk = new List <string>(); List <string> listNotFoundedInCRMNoLink = new List <string>(); List <string> listLastLinkEqualByContent = new List <string>(); List <SolutionComponent> webResourceNames = new List <SolutionComponent>(); Dictionary <SolutionComponent, string> webResourceDescriptions = new Dictionary <SolutionComponent, string>(); WebResourceRepository repositoryWebResource = new WebResourceRepository(service); FormatTextTableHandler tableWithoutDependenComponents = new FormatTextTableHandler(); tableWithoutDependenComponents.SetHeader("FilePath", "Web Resource Name", "Web Resource Type"); var groups = selectedFiles.GroupBy(sel => sel.Extension); foreach (var gr in groups) { var names = gr.Select(sel => sel.FriendlyFilePath).ToArray(); var dict = repositoryWebResource.FindMultiple(gr.Key, names); foreach (var selectedFile in gr) { if (File.Exists(selectedFile.FilePath)) { string name = selectedFile.FriendlyFilePath.ToLower(); var webresource = WebResourceRepository.FindWebResourceInDictionary(dict, name, gr.Key); if (webresource == null) { Guid?webId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (webId.HasValue) { webresource = await repositoryWebResource.GetByIdAsync(webId.Value); if (webresource != null) { listLastLinkEqualByContent.Add(selectedFile.FriendlyFilePath); } } } if (webresource != null) { // Запоминается файл isconnectionDataDirty = true; connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); var coll = await dependencyRepository.GetDependentComponentsAsync((int)ComponentType.WebResource, webresource.Id); var desc = await descriptorHandler.GetDescriptionDependentAsync(coll); if (!string.IsNullOrEmpty(desc)) { var component = new SolutionComponent() { ComponentType = new OptionSetValue((int)ComponentType.WebResource), ObjectId = webresource.Id, }; webResourceNames.Add(component); webResourceDescriptions.Add(component, desc); } else { tableWithoutDependenComponents.AddLine(selectedFile.FriendlyFilePath, webresource.Name, "'" + webresource.FormattedValues[WebResource.Schema.Attributes.webresourcetype] + "'"); } } else { connectionData.RemoveMapping(selectedFile.FriendlyFilePath); listNotFoundedInCRMNoLink.Add(selectedFile.FriendlyFilePath); } } else { listNotExistsOnDisk.Add(selectedFile.FilePath); } } } if (isconnectionDataDirty) { //Сохранение настроек после публикации connectionData.Save(); } FindsController.WriteToContentList(listNotFoundedInCRMNoLink, content, "File NOT FOUNDED in CRM: {0}"); FindsController.WriteToContentList(listLastLinkEqualByContent, content, "Files NOT FOUNDED in CRM, but has Last Link: {0}"); FindsController.WriteToContentList(listNotExistsOnDisk, content, Properties.OutputStrings.FileNotExistsFormat1); FindsController.WriteToContentList(tableWithoutDependenComponents.GetFormatedLines(true), content, "Files without dependent components: {0}"); FindsController.WriteToContentDictionary(descriptor, content, webResourceNames, webResourceDescriptions, "WebResource dependent components: {0}"); commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string fileName = string.Format("{0}.WebResourceDependent at {1}.txt", connectionData.Name, DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")); string filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CreatedFileWithWebResourcesDependentComponentsFormat1, filePath); this._iWriteToOutput.PerformAction(service.ConnectionData, filePath); }
private async Task PerformShowingDifferenceSingleXmlAsync(LinkedEntities <WebResource> linked, bool showAllways, string fieldName, string fieldTitle, FileExtension extension) { if (!this.IsControlsEnabled) { return; } ToggleControls(false, Properties.OutputStrings.ShowingDifferenceXmlForFieldFormat1, fieldName); try { var service1 = await GetService1(); var service2 = await GetService2(); if (service1 != null && service2 != null) { var repository1 = new WebResourceRepository(service1); var repository2 = new WebResourceRepository(service2); var webResource1 = await repository1.GetByIdAsync(linked.Entity1.Id, ColumnSetInstances.AllColumns); var webResource2 = await repository2.GetByIdAsync(linked.Entity2.Id, ColumnSetInstances.AllColumns); string xml1 = webResource1.GetAttributeValue <string>(fieldName); string xml2 = webResource2.GetAttributeValue <string>(fieldName); if (showAllways || !ContentComparerHelper.CompareXML(xml1, xml2, false).IsEqual) { if (!string.IsNullOrEmpty(xml1)) { if (string.Equals(fieldName, WebResource.Schema.Attributes.dependencyxml, StringComparison.InvariantCultureIgnoreCase)) { xml1 = ContentComparerHelper.FormatXmlByConfiguration( xml1 , _commonConfig , XmlOptionsControls.WebResourceDependencyXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlSchema , webResourceName: webResource1.Name ); } else if (string.Equals(fieldName, WebResource.Schema.Attributes.contentjson, StringComparison.InvariantCultureIgnoreCase)) { xml1 = ContentComparerHelper.FormatJson(xml1); } } if (!string.IsNullOrEmpty(xml2)) { if (string.Equals(fieldName, WebResource.Schema.Attributes.dependencyxml, StringComparison.InvariantCultureIgnoreCase)) { xml2 = ContentComparerHelper.FormatXmlByConfiguration( xml2 , _commonConfig , XmlOptionsControls.WebResourceDependencyXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.WebResourceDependencyXmlSchema , webResourceName: webResource2.Name ); } else if (string.Equals(fieldName, WebResource.Schema.Attributes.contentjson, StringComparison.InvariantCultureIgnoreCase)) { xml2 = ContentComparerHelper.FormatJson(xml2); } } string filePath1 = await CreateFileAsync(service1.ConnectionData, webResource1.Name, fieldTitle, xml1, extension); string filePath2 = await CreateFileAsync(service2.ConnectionData, webResource2.Name, fieldTitle, xml2, extension); if (!File.Exists(filePath1)) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service1.ConnectionData.Name, Report.Schema.EntityLogicalName, webResource1.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(null); } if (!File.Exists(filePath2)) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service2.ConnectionData.Name, Report.Schema.EntityLogicalName, webResource2.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(null); } if (File.Exists(filePath1) && File.Exists(filePath2)) { await this._iWriteToOutput.ProcessStartProgramComparerAsync(service1.ConnectionData, filePath1, filePath2, Path.GetFileName(filePath1), Path.GetFileName(filePath2), service2.ConnectionData); } else { this._iWriteToOutput.PerformAction(service1.ConnectionData, filePath1); this._iWriteToOutput.PerformAction(service2.ConnectionData, filePath2); } } } ToggleControls(true, Properties.OutputStrings.ShowingDifferenceXmlForFieldCompletedFormat1, fieldName); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(null, ex); ToggleControls(true, Properties.OutputStrings.ShowingDifferenceXmlForFieldFailedFormat1, fieldName); } }
private async Task UpdatingContentAndPublish(IOrganizationServiceExtented service, List <SelectedFile> selectedFiles) { // Менеджер для публикации в CRM. PublishManager publishHelper = new PublishManager(this._iWriteToOutput, service); // Репозиторий для работы с веб-ресурсами WebResourceRepository webResourceRepository = new WebResourceRepository(service); bool allForOther = false; var groups = selectedFiles.GroupBy(sel => sel.Extension); foreach (var gr in groups) { var names = gr.Select(sel => sel.FriendlyFilePath).ToArray(); var dict = webResourceRepository.FindMultiple(gr.Key, names); foreach (var selectedFile in gr) { if (File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "Try to find web-resource by name: {0}. Searching...", selectedFile.Name); string key = selectedFile.FriendlyFilePath.ToLower(); var contentFile = Convert.ToBase64String(File.ReadAllBytes(selectedFile.FilePath)); var webresource = WebResourceRepository.FindWebResourceInDictionary(dict, key, gr.Key); if (webresource != null) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "WebResource founded by name. WebResourceId: {0} Name: {1}", webresource.Id, webresource.Name); } if (webresource == null) { if (selectedFile.FileName.StartsWith(service.ConnectionData.Name + ".")) { string newFileName = selectedFile.FileName.Replace(service.ConnectionData.Name + ".", string.Empty); string newFilePath = Path.Combine(Path.GetDirectoryName(selectedFile.FilePath), newFileName); var newSelectedFile = new SelectedFile(newFilePath, selectedFile.SolutionDirectoryPath); var newDict = webResourceRepository.FindMultiple(newSelectedFile.Extension, new[] { newSelectedFile.FriendlyFilePath }); webresource = WebResourceRepository.FindWebResourceInDictionary(newDict, newSelectedFile.FriendlyFilePath.ToLower(), newSelectedFile.Extension); if (webresource != null) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "WebResource founded by name with Connection Prefix. WebResourceId: {0} Name: {1}", webresource.Id, webresource.Name); } } } if (webresource == null) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "WebResource not founded by name. FileName: {0}. Open linking dialog...", selectedFile.Name); Guid?webId = service.ConnectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath); bool?dialogResult = null; Guid?selectedWebResourceId = null; var t = new Thread(() => { try { var form = new Views.WindowWebResourceSelectOrCreate(this._iWriteToOutput, service, selectedFile, webId); form.ShowCreateButton(allForOther); dialogResult = form.ShowDialog(); allForOther = form.ForAllOther; selectedWebResourceId = form.SelectedWebResourceId; } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(service.ConnectionData, ex); } }); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (string.IsNullOrEmpty(service.ConnectionData?.LastSelectedSolutionsUniqueName?.FirstOrDefault())) { allForOther = false; } service.ConnectionData.Save(); if (dialogResult.GetValueOrDefault()) { if (selectedWebResourceId.HasValue) { webresource = await webResourceRepository.GetByIdAsync(selectedWebResourceId.Value); } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "!Warning. WebResource not linked. name: {0}.", selectedFile.Name); } } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "Updating Content and Publishing was cancelled."); return; } } if (webresource != null) { // Запоминается файл service.ConnectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath); publishHelper.Add(new ElementForPublish(selectedFile, webresource)); } } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, "File not founded: {0}", selectedFile.FilePath); } } } //Сохранение настроек после публикации service.ConnectionData.Save(); publishHelper.UpdateContentAndPublish(); }
private async Task ThreeFileDifferenceWebResources(SelectedFile selectedFile, ConnectionData connectionData1, ConnectionData connectionData2, ShowDifferenceThreeFileType differenceType, CommonConfiguration commonConfig) { if (connectionData1 == null) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.NoCRMConnection1); return; } if (connectionData2 == null) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.NoCRMConnection2); return; } if (differenceType == ShowDifferenceThreeFileType.ThreeWay) { if (!File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FileNotExistsFormat1, selectedFile.FilePath); return; } } this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.ConnectingToCRM); this._iWriteToOutput.WriteToOutput(null, string.Empty); this._iWriteToOutput.WriteToOutput(null, connectionData1.GetConnectionDescription()); this._iWriteToOutput.WriteToOutput(null, string.Empty); this._iWriteToOutput.WriteToOutput(null, connectionData2.GetConnectionDescription()); var task1 = QuickConnection.ConnectAsync(connectionData1); var task2 = QuickConnection.ConnectAsync(connectionData2); var service1 = await task1; var service2 = await task2; if (service1 == null) { _iWriteToOutput.WriteToOutput(connectionData1, Properties.OutputStrings.ConnectionFailedFormat1, connectionData1.Name); return; } if (service2 == null) { _iWriteToOutput.WriteToOutput(connectionData2, Properties.OutputStrings.ConnectionFailedFormat1, connectionData2.Name); return; } this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.CurrentServiceEndpointConnectionFormat2, connectionData1.Name, service1.CurrentServiceEndpoint); this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.CurrentServiceEndpointConnectionFormat2, connectionData2.Name, service2.CurrentServiceEndpoint); // Репозиторий для работы с веб-ресурсами WebResourceRepository webResourceRepository1 = new WebResourceRepository(service1); WebResourceRepository webResourceRepository2 = new WebResourceRepository(service2); var taskWebResource1 = webResourceRepository1.FindByNameAsync(selectedFile.FriendlyFilePath, selectedFile.Extension); var taskWebResource2 = webResourceRepository2.FindByNameAsync(selectedFile.FriendlyFilePath, selectedFile.Extension); WebResource webresource1 = await taskWebResource1; WebResource webresource2 = await taskWebResource2; if (webresource1 != null) { this._iWriteToOutput.WriteToOutput(null, "{0}: WebResource founded by name.", connectionData1.Name); connectionData1.AddMapping(webresource1.Id, selectedFile.FriendlyFilePath); connectionData1.Save(); } else { Guid?webId = connectionData1.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (webId.HasValue) { webresource1 = await webResourceRepository1.GetByIdAsync(webId.Value); if (webresource1 != null) { this._iWriteToOutput.WriteToOutput(null, "{0}: WebResource not founded by name. Last link WebResource is selected for difference.", connectionData1.Name); connectionData1.AddMapping(webresource1.Id, selectedFile.FriendlyFilePath); connectionData1.Save(); } } } if (webresource2 != null) { this._iWriteToOutput.WriteToOutput(null, "{0}: WebResource founded by name.", connectionData2.Name); connectionData2.AddMapping(webresource2.Id, selectedFile.FriendlyFilePath); connectionData2.Save(); } else { Guid?webId = connectionData2.GetLastLinkForFile(selectedFile.FriendlyFilePath); if (webId.HasValue) { webresource2 = await webResourceRepository2.GetByIdAsync(webId.Value); if (webresource2 != null) { this._iWriteToOutput.WriteToOutput(null, "{0}: WebResource not founded by name. Last link WebResource is selected for difference.", connectionData2.Name); connectionData2.AddMapping(webresource2.Id, selectedFile.FriendlyFilePath); connectionData2.Save(); } } } if (!File.Exists(selectedFile.FilePath)) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FileNotExistsFormat1, selectedFile.FilePath); } if (webresource1 == null) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.WebResourceNotFoundedInConnectionFormat2, connectionData1.Name, selectedFile.FileName); } if (webresource2 == null) { this._iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.WebResourceNotFoundedInConnectionFormat2, connectionData2.Name, selectedFile.FileName); } // string fileLocalPath, string fileLocalTitle, string filePath1, string fileTitle1, string filePath2, string fileTitle2, string fileLocalPath = selectedFile.FilePath; string fileLocalTitle = selectedFile.FileName; string filePath1 = string.Empty; string fileTitle1 = string.Empty; string filePath2 = string.Empty; string fileTitle2 = string.Empty; if (webresource1 != null) { var contentWebResource1 = webresource1.Content ?? string.Empty; var array = Convert.FromBase64String(contentWebResource1); filePath1 = FileOperations.GetNewTempFilePath(webresource1.Name, selectedFile.Extension); fileTitle1 = connectionData1.Name + "." + selectedFile.FileName + " - " + filePath1; File.WriteAllBytes(filePath1, array); } if (webresource2 != null) { var contentWebResource2 = webresource2.Content ?? string.Empty; var array = Convert.FromBase64String(contentWebResource2); filePath2 = FileOperations.GetNewTempFilePath(webresource2.Name, selectedFile.Extension); fileTitle2 = connectionData2.Name + "." + selectedFile.FileName + " - " + filePath2; File.WriteAllBytes(filePath2, array); } switch (differenceType) { case ShowDifferenceThreeFileType.OneByOne: ShowDifferenceOneByOne(commonConfig, fileLocalPath, fileLocalTitle, filePath1, fileTitle1, filePath2, fileTitle2); break; case ShowDifferenceThreeFileType.TwoConnections: this._iWriteToOutput.ProcessStartProgramComparer(filePath1, filePath2, fileTitle1, fileTitle2); break; case ShowDifferenceThreeFileType.ThreeWay: ShowDifferenceThreeWay(commonConfig, fileLocalPath, fileLocalTitle, filePath1, fileTitle1, filePath2, fileTitle2); break; default: break; } }