public override void Execute() { base.Execute(); if (TargetFileInfo != null && IsSingleObject) { var d = _gatherer.GatherDependencies(_toExport[0]); var shareDefinitions = d.ToShareDefinitionWithChildren(_shareManager); string serial = JsonConvertExtensions.SerializeObject(shareDefinitions, _repositoryLocator); File.WriteAllText(TargetFileInfo.FullName, serial); return; } if (TargetDirectoryInfo == null) { throw new Exception("No output directory set"); } foreach (var o in _toExport) { var d = _gatherer.GatherDependencies(o); var filename = QuerySyntaxHelper.MakeHeaderNameSensible(o.ToString()) + ".sd"; var shareDefinitions = d.ToShareDefinitionWithChildren(_shareManager); string serial = JsonConvertExtensions.SerializeObject(shareDefinitions, _repositoryLocator); var f = Path.Combine(TargetDirectoryInfo.FullName, filename); File.WriteAllText(f, serial); } }
public async Task <Dictionary <string, List <string> > > GetAvailableParametersAsync(string document) { try { if (!document.Contains(JsonOpener) || !document.Contains(DocsParam)) { return(new Dictionary <string, List <string> >()); } var(jsonBeginningIndex, jsonEndingIndex, insideJsonSection) = GetJsonBeginEndIndexesAndPureJson(document); if (jsonBeginningIndex < 0 || jsonEndingIndex <= 0 || string.IsNullOrWhiteSpace(insideJsonSection)) { return(new Dictionary <string, List <string> >()); } var pureJson = insideJsonSection.Replace(DocsParam, "").Trim(); if (!JsonConvertExtensions.TryDeserializeObject <Dictionary <string, List <string> > >(pureJson, out var availableParameters)) { throw new UserFriendlyException("ERROR-20200327: Cannot validate JSON content for `AvailableParameters`!"); } return(await Task.FromResult(availableParameters)); } catch (Exception) { Logger.LogWarning("Unable to parse parameters of document."); return(new Dictionary <string, List <string> >()); } }
private void btnLoadPlan_Click(object sender, EventArgs e) { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Plans (*.plan)|*.plan"; if (ofd.ShowDialog() == DialogResult.OK) { var fi = new FileInfo(ofd.FileName); var json = File.ReadAllText(fi.FullName); _planManager = (ForwardEngineerANOCataloguePlanManager) JsonConvertExtensions.DeserializeObject(json, typeof(ForwardEngineerANOCataloguePlanManager), Activator.RepositoryLocator); if (_planManager.StartDate != null) { tbStartDate.Text = _planManager.StartDate.Value.ToString(); } cbDateBasedLoad.Checked = _planManager.DateColumn != null; ddDateColumn.SelectedItem = _planManager.DateColumn; } } catch (Exception exception) { ExceptionViewer.Show(exception); } }
public virtual async Task <NavigationNode> GetNavigationAsync(GetNavigationDocumentInput input) { var project = await _projectRepository.GetAsync(input.ProjectId); var navigationDocument = await GetDocumentWithDetailsDtoAsync( project, project.NavigationDocumentName, input.LanguageCode, input.Version ); if (!JsonConvertExtensions.TryDeserializeObject <NavigationNode>(navigationDocument.Content, out var navigationNode)) { throw new UserFriendlyException($"Cannot validate navigation file '{project.NavigationDocumentName}' for the project {project.Name}."); } var leafs = navigationNode.Items.GetAllNodes(x => x.Items) .Where(x => !x.Path.IsNullOrWhiteSpace()) .ToList(); foreach (var leaf in leafs) { var cacheKey = CacheKeyGenerator.GenerateDocumentUpdateInfoCacheKey(project, leaf.Path, input.LanguageCode, input.Version); var documentUpdateInfo = await DocumentUpdateCache.GetAsync(cacheKey); if (documentUpdateInfo != null) { leaf.CreationTime = documentUpdateInfo.CreationTime; leaf.LastUpdatedTime = documentUpdateInfo.LastUpdatedTime; leaf.LastSignificantUpdateTime = documentUpdateInfo.LastSignificantUpdateTime; } } return(navigationNode); }
public async Task <ActionResult> DownloadFiles(string downloadData, int degreeOfParallelism) { ResponseMessage response = new ResponseMessage { Success = true, Message = "Download Cancelled!" }; if (!string.IsNullOrEmpty(downloadData)) { var fileData = new DownloadModel { DataUrl = JsonConvert.DeserializeObject <List <DataUrl> >(downloadData), PathToDownload = FilesData.MapPathFolder(FilesData.DownloadFiles), degreeOfParallelism = degreeOfParallelism, }; FilesData.CreateDirectoryIfNotExists(FilesData.DownloadFiles); if (fileData.DataUrl.Any()) { response = (ResponseMessage)await _fileServices.DownloadFiles(fileData); } } return(Json(new { data = JsonConvertExtensions.GetJsonConvert(response) }, JsonRequestBehavior.AllowGet)); }
public async Task <DocumentParametersDto> GetParametersAsync(GetParametersDocumentInput input) { var project = await _projectRepository.GetAsync(input.ProjectId); try { if (string.IsNullOrWhiteSpace(project.ParametersDocumentName)) { return(await Task.FromResult <DocumentParametersDto>(null)); } var document = await GetDocumentWithDetailsDtoAsync( project, project.ParametersDocumentName, input.LanguageCode, input.Version ); if (!JsonConvertExtensions.TryDeserializeObject <DocumentParametersDto>(document.Content, out var documentParameters)) { throw new UserFriendlyException( $"Cannot validate document parameters file '{project.ParametersDocumentName}' for the project {project.Name}."); } return(documentParameters); } catch (DocumentNotFoundException) { Logger.LogWarning($"Parameter file ({project.ParametersDocumentName}) not found!"); return(new DocumentParametersDto()); } }
protected async Task <T> PostAsync <T>(string relativeUri, object data) { RestRequest request = new RestRequest(relativeUri, Method.POST); request.AddParameter(String.Empty, JsonConvertExtensions.SerializeObjectCamelCase(data), ParameterType.RequestBody); return(await this.ExecuteRequestAsync <T>(request).ConfigureAwait(false)); }
protected async Task <T> PostAsync <T>(string relativeUri, object data) { return(await ExecuteRequestAsync <T>( await _client.PostAsync(relativeUri, new StringContent( JsonConvertExtensions.SerializeObjectCamelCase(data), Encoding.UTF8, "application/json"))) .ConfigureAwait(false)); }
protected async Task <T> PostAsync <T>(string relativeUri, object data) { var jsonData = JsonConvertExtensions.SerializeObjectCamelCase(data); var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); HttpRequestMessage httpRequest = this.CreateHttpRequest(HttpMethod.Post, relativeUri, content); var response = await this._httpClient.SendAsync(httpRequest).ConfigureAwait(false); return(await this.ProcessHttpResponseMessage <T>(response).ConfigureAwait(false)); }
protected async Task <T> PostAsync <T>(string relativeUri, object data) { var jsonData = JsonConvertExtensions.SerializeObjectCamelCase(data); var response = await this._httpClient .PostAsync(relativeUri, new StringContent(jsonData, Encoding.UTF8, "application/json")) .ConfigureAwait(false); return(await this.ProcessHttpResponseMessage <T>(response).ConfigureAwait(false)); }
public async Task PullAllAsync(PullAllDocumentInput input) { var project = await _projectRepository.GetAsync(input.ProjectId); var navigationDocument = await GetDocumentAsync( project, project.NavigationDocumentName, input.LanguageCode, input.Version ); if (!JsonConvertExtensions.TryDeserializeObject <NavigationNode>(navigationDocument.Content, out var navigation)) { throw new UserFriendlyException($"Cannot validate navigation file '{project.NavigationDocumentName}' for the project {project.Name}."); } var leafs = navigation.Items.GetAllNodes(x => x.Items) .Where(x => x.IsLeaf && !x.Path.IsNullOrWhiteSpace()) .ToList(); var source = _documentStoreFactory.Create(project.DocumentStoreType); var documents = new List <Document>(); foreach (var leaf in leafs) { if (leaf.Path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || leaf.Path.StartsWith("https://", StringComparison.OrdinalIgnoreCase) || (leaf.Path.StartsWith("{{") && leaf.Path.EndsWith("}}"))) { continue; } try { var sourceDocument = await source.GetDocumentAsync(project, leaf.Path, input.LanguageCode, input.Version); documents.Add(sourceDocument); } catch (Exception e) { Logger.LogException(e); } } foreach (var document in documents) { await _documentRepository.DeleteAsync(document.ProjectId, document.Name, document.LanguageCode, document.Version); await _documentRepository.InsertAsync(document, true); await UpdateDocumentUpdateInfoCache(document); } }
public void Test_JsonConvertExtension_TryDesrialize_Failure() { // Arrange var notDeserializable = "asdasdasdasd"; // Act var result = JsonConvertExtensions.TryDeserialize <ExampleModel>(notDeserializable); // Assert result.Should().BeNull(); }
public async Task <LanguageConfig> GetLanguageListAsync(Project project, string version) { var path = Path.Combine(project.GetFileSystemPath(), DocsDomainConsts.LanguageConfigFileName); var configJsonContent = await FileHelper.ReadAllTextAsync(path); if (!JsonConvertExtensions.TryDeserializeObject <LanguageConfig>(configJsonContent, out var languageConfig)) { throw new UserFriendlyException($"Cannot validate language config file '{DocsDomainConsts.LanguageConfigFileName}' for the project {project.Name}."); } return(languageConfig); }
protected async Task DeleteAsync(string relativeUri, object data = null) { HttpRequestMessage httpRequest = this.CreateHttpRequest(HttpMethod.Delete, relativeUri); if (data != null) { var jsonData = JsonConvertExtensions.SerializeObjectCamelCase(data); var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); httpRequest.Content = content; } var response = await this._httpClient.SendAsync(httpRequest).ConfigureAwait(false); await this.ProcessHttpResponseMessage <object>(response).ConfigureAwait(false); }
public async Task <TokenResponse> GetAccessTokenAsync(TokenRequest request) { var jsonData = JsonConvertExtensions.SerializeObjectSnakeCase(request); var response = await this._httpClient .PostAsync(TokenEndPoint, new StringContent(jsonData, Encoding.UTF8, "application/json")) .ConfigureAwait(false); var resultContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); return(JsonConvert.DeserializeObject <TokenResponse>(resultContent, new JsonSerializerSettings { ContractResolver = new SnakeCasePropertyNamesContractResolver() })); }
public void Test_JsonConvertExtension_TryDesrialize_Success() { // Arrange var example = new ExampleModel { Prop1 = "a", Prop2 = "b" }; // Act var serializedVersion = JsonConvert.SerializeObject(example); var result = JsonConvertExtensions.TryDeserialize <ExampleModel>(serializedVersion); // Assert result.Should().NotBeNull(); result.Prop1.Should().Be(example.Prop1); result.Prop2.Should().Be(example.Prop2); }
public async Task <LanguageConfig> GetLanguageListAsync(Project project, string version) { var token = project.GetGitHubAccessTokenOrNull(); var rootUrl = project.GetGitHubUrl(version); var userAgent = project.GetGithubUserAgentOrNull(); var url = CalculateRawRootUrl(rootUrl) + DocsDomainConsts.LanguageConfigFileName; var configAsJson = await DownloadWebContentAsStringAsync(url, token, userAgent); if (!JsonConvertExtensions.TryDeserializeObject <LanguageConfig>(configAsJson, out var languageConfig)) { throw new UserFriendlyException($"Cannot validate language config file '{DocsDomainConsts.LanguageConfigFileName}' for the project {project.Name} - v{version}."); } return(languageConfig); }
public void Test_SerializeObject_ShareAttribute() { Dictionary <RelationshipAttribute, Guid> d = new Dictionary <RelationshipAttribute, Guid>(); var json = JsonConvertExtensions.SerializeObject(d, RepositoryLocator); var obj = (Dictionary <RelationshipAttribute, Guid>)JsonConvertExtensions.DeserializeObject(json, typeof(Dictionary <RelationshipAttribute, Guid>), RepositoryLocator); Assert.AreEqual(0, obj.Count); //now add a key d.Add(new RelationshipAttribute(typeof(string), RelationshipType.SharedObject, "fff"), Guid.Empty); json = JsonConvertExtensions.SerializeObject(d, RepositoryLocator); obj = (Dictionary <RelationshipAttribute, Guid>)JsonConvertExtensions.DeserializeObject(json, typeof(Dictionary <RelationshipAttribute, Guid>), RepositoryLocator); Assert.AreEqual(1, obj.Count); }
private void btnSavePlan_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Plans (*.plan)|*.plan"; if (sfd.ShowDialog() == DialogResult.OK) { var fi = new FileInfo(sfd.FileName); var cmdAnoTablesToo = new ExecuteCommandExportObjectsToFileUI(Activator, Activator.RepositoryLocator.CatalogueRepository.GetAllObjects <ANOTable>().ToArray(), fi.Directory); cmdAnoTablesToo.ShowInExplorer = false; if (!cmdAnoTablesToo.IsImpossible) { cmdAnoTablesToo.Execute(); } var json = JsonConvertExtensions.SerializeObject(_planManager, Activator.RepositoryLocator); File.WriteAllText(fi.FullName, json); } }
public void CreateANOVersion_TestSkippingTables(bool tableInfoAlreadyExistsForSkippedTable, bool putPlanThroughSerialization) { var dbFrom = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(TestDatabaseNames.GetConsistentName("CreateANOVersion_TestSkippingTables_From")); var dbTo = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(TestDatabaseNames.GetConsistentName("CreateANOVersion_TestSkippingTables_To")); dbFrom.Create(true); dbTo.Create(true); try { var tblFromHeads = dbFrom.CreateTable("Heads", new[] { new DatabaseColumnRequest("SkullColor", "varchar(10)"), new DatabaseColumnRequest("Vertebrae", "varchar(25)") }); var cols = new[] { new DatabaseColumnRequest("SpineColor", "varchar(10)"), new DatabaseColumnRequest("Vertebrae", "varchar(25)") }; var tblFromNeck = dbFrom.CreateTable("Necks", cols); //Necks table already exists in the destination so will be skipped for migration but still needs to be imported var tblToNeck = dbTo.CreateTable("Necks", cols); TableInfo fromHeadsTableInfo; ColumnInfo[] fromHeadsColumnInfo; TableInfo fromNeckTableInfo; ColumnInfo[] fromNeckColumnInfo; TableInfo toNecksTableInfo = null; ColumnInfo[] toNecksColumnInfo = null; TableInfoImporter i1 = new TableInfoImporter(CatalogueRepository, tblFromHeads); i1.DoImport(out fromHeadsTableInfo, out fromHeadsColumnInfo); TableInfoImporter i2 = new TableInfoImporter(CatalogueRepository, tblFromNeck); i2.DoImport(out fromNeckTableInfo, out fromNeckColumnInfo); //Table already exists but does the in Catalogue reference exist? if (tableInfoAlreadyExistsForSkippedTable) { TableInfoImporter i3 = new TableInfoImporter(CatalogueRepository, tblToNeck); i3.DoImport(out toNecksTableInfo, out toNecksColumnInfo); } //Create a JoinInfo so the query builder knows how to connect the tables new JoinInfo(CatalogueRepository, fromHeadsColumnInfo.Single(c => c.GetRuntimeName().Equals("Vertebrae")), fromNeckColumnInfo.Single(c => c.GetRuntimeName().Equals("Vertebrae")), ExtractionJoinType.Inner, null ); var cataEngineer = new ForwardEngineerCatalogue(fromHeadsTableInfo, fromHeadsColumnInfo, true); Catalogue cata; CatalogueItem[] cataItems; ExtractionInformation[] extractionInformations; cataEngineer.ExecuteForwardEngineering(out cata, out cataItems, out extractionInformations); var cataEngineer2 = new ForwardEngineerCatalogue(fromNeckTableInfo, fromNeckColumnInfo, true); cataEngineer2.ExecuteForwardEngineering(cata); //4 extraction informations in from Catalogue (2 from Heads and 2 from Necks) Assert.AreEqual(cata.GetAllExtractionInformation(ExtractionCategory.Any).Count(), 4); //setup ANOTable on head var anoTable = new ANOTable(CatalogueRepository, ANOStore_ExternalDatabaseServer, "ANOSkullColor", "C"); anoTable.NumberOfCharactersToUseInAnonymousRepresentation = 10; anoTable.SaveToDatabase(); anoTable.PushToANOServerAsNewTable("varchar(10)", new ThrowImmediatelyCheckNotifier()); //////////////////The actual test!///////////////// var planManager = new ForwardEngineerANOCataloguePlanManager(RepositoryLocator, cata); //ano the table SkullColor var scPlan = planManager.GetPlanForColumnInfo(fromHeadsColumnInfo.Single(col => col.GetRuntimeName().Equals("SkullColor"))); scPlan.ANOTable = anoTable; scPlan.Plan = Plan.ANO; if (putPlanThroughSerialization) { var asString = JsonConvertExtensions.SerializeObject(planManager, RepositoryLocator); planManager = (ForwardEngineerANOCataloguePlanManager)JsonConvertExtensions.DeserializeObject(asString, typeof(ForwardEngineerANOCataloguePlanManager), RepositoryLocator); } //not part of serialization planManager.TargetDatabase = dbTo; planManager.SkippedTables.Add(fromNeckTableInfo);//skip the necks table because it already exists (ColumnInfos may or may not exist but physical table definetly does) var engine = new ForwardEngineerANOCatalogueEngine(RepositoryLocator, planManager); if (!tableInfoAlreadyExistsForSkippedTable) { var ex = Assert.Throws <Exception>(engine.Execute); Assert.IsTrue(Regex.IsMatch(ex.InnerException.Message, "Found '0' ColumnInfos called")); Assert.IsTrue(Regex.IsMatch(ex.InnerException.Message, "[Necks].[SpineColor]")); return; } else { engine.Execute(); } var newCata = CatalogueRepository.GetAllObjects <Catalogue>().Single(c => c.Name.Equals("ANOHeads")); Assert.IsTrue(newCata.Exists()); var newCataItems = newCata.CatalogueItems; Assert.AreEqual(newCataItems.Count(), 4); //should be extraction informations //all extraction informations should point to the new table location Assert.IsTrue(newCataItems.All(ci => ci.ExtractionInformation.SelectSQL.Contains(dbTo.GetRuntimeName()))); //these columns should all exist Assert.IsTrue(newCataItems.Any(ci => ci.ExtractionInformation.SelectSQL.Contains("SkullColor"))); Assert.IsTrue(newCataItems.Any(ci => ci.ExtractionInformation.SelectSQL.Contains("SpineColor"))); Assert.IsTrue(newCataItems.Any(ci => ci.ExtractionInformation.SelectSQL.Contains("Vertebrae"))); //actually there will be 2 copies of this one from Necks one from Heads //new ColumnInfo should have a reference to the anotable Assert.IsTrue(newCataItems.Single(ci => ci.Name.Equals("ANOSkullColor")).ColumnInfo.ANOTable_ID == anoTable.ID); var newSpineColorColumnInfo = newCataItems.Single(ci => ci.Name.Equals("ANOSkullColor")).ColumnInfo; //table info already existed, make sure the new CatalogueItems point to the same columninfos / table infos Assert.IsTrue(newCataItems.Select(ci => ci.ColumnInfo).Contains(newSpineColorColumnInfo)); } finally { dbFrom.Drop(); dbTo.Drop(); } }
public void GatherAndShare_ANOTable_Test(bool goViaJson) { var anoserver = new ExternalDatabaseServer(CatalogueRepository, "MyGatherAndShareTestANOServer", new ANOStorePatcher()); var anoTable = new ANOTable(CatalogueRepository, anoserver, "ANOMagad", "N"); Assert.AreEqual(anoTable.Server_ID, anoserver.ID); Gatherer g = new Gatherer(RepositoryLocator); Assert.IsTrue(g.CanGatherDependencies(anoTable)); var gObj = g.GatherDependencies(anoTable); //root should be the server Assert.AreEqual(gObj.Object, anoserver); Assert.AreEqual(gObj.Children.Single().Object, anoTable); //get the sharing definitions var shareManager = new ShareManager(RepositoryLocator); ShareDefinition defParent = gObj.ToShareDefinition(shareManager, new List <ShareDefinition>()); ShareDefinition defChild = gObj.Children.Single().ToShareDefinition(shareManager, new List <ShareDefinition>(new [] { defParent })); //make it look like we never had it in the first place shareManager.GetNewOrExistingExportFor(anoserver).DeleteInDatabase(); shareManager.GetNewOrExistingExportFor(anoTable).DeleteInDatabase(); anoTable.DeleteInDatabase(); anoserver.DeleteInDatabase(); if (goViaJson) { var sParent = JsonConvertExtensions.SerializeObject(defParent, RepositoryLocator); var sChild = JsonConvertExtensions.SerializeObject(defChild, RepositoryLocator); defParent = (ShareDefinition)JsonConvertExtensions.DeserializeObject(sParent, typeof(ShareDefinition), RepositoryLocator); defChild = (ShareDefinition)JsonConvertExtensions.DeserializeObject(sChild, typeof(ShareDefinition), RepositoryLocator); } var anoserverAfter = new ExternalDatabaseServer(shareManager, defParent); Assert.IsTrue(anoserverAfter.Exists()); //new instance Assert.AreNotEqual(anoserverAfter.ID, anoserver.ID); //same properties Assert.AreEqual(anoserverAfter.Name, anoserver.Name); Assert.AreEqual(anoserverAfter.CreatedByAssembly, anoserver.CreatedByAssembly); Assert.AreEqual(anoserverAfter.Database, anoserver.Database); Assert.AreEqual(anoserverAfter.DatabaseType, anoserver.DatabaseType); Assert.AreEqual(anoserverAfter.Username, anoserver.Username); Assert.AreEqual(anoserverAfter.Password, anoserver.Password); var anoTableAfter = new ANOTable(shareManager, defChild); //new instance Assert.AreNotEqual(anoTableAfter.ID, anoTable.ID); Assert.AreNotEqual(anoTableAfter.Server_ID, anoTable.Server_ID); //same properties Assert.AreEqual(anoTableAfter.NumberOfCharactersToUseInAnonymousRepresentation, anoTable.NumberOfCharactersToUseInAnonymousRepresentation); Assert.AreEqual(anoTableAfter.Suffix, anoTable.Suffix); //change a property and save it anoTableAfter.Suffix = "CAMMELS!"; CatalogueRepository.SaveToDatabase(anoTableAfter); //anoTableAfter.SaveToDatabase(); <- this decides to go check the ANOTable exists on the server refernced which is immaginary btw >< thats why we have the above line instead //reimport (this time it should be an update, we import the share definitions and it overrdies our database copy (sharing is UPSERT) var anoTableAfter2 = new ANOTable(shareManager, defChild); Assert.AreEqual(anoTableAfter.ID, anoTableAfter2.ID); Assert.AreEqual("N", anoTableAfter2.Suffix); Assert.AreEqual(ChangeDescription.DatabaseCopyDifferent, anoTableAfter.HasLocalChanges().Evaluation); anoTableAfter.DeleteInDatabase(); anoserverAfter.DeleteInDatabase(); foreach (ObjectImport o in RepositoryLocator.CatalogueRepository.GetAllObjects <ObjectImport>()) { o.DeleteInDatabase(); } }
public void GatherAndShare_Catalogue_Test(bool goViaJson) { //Setup some objects under Catalogue that we can share var cata = new Catalogue(CatalogueRepository, "Cata"); cata.Periodicity = Catalogue.CataloguePeriodicity.BiMonthly; cata.SaveToDatabase(); var catalogueItem1 = new CatalogueItem(CatalogueRepository, cata, "Ci1"); var catalogueItem2 = new CatalogueItem(CatalogueRepository, cata, "Ci2"); var tableInfo = new TableInfo(CatalogueRepository, "Myt"); var colInfo = new ColumnInfo(CatalogueRepository, "[Mt].[C1]", "varchar(10)", tableInfo); catalogueItem1.ColumnInfo_ID = colInfo.ID; catalogueItem1.SaveToDatabase(); var ei = new ExtractionInformation(CatalogueRepository, catalogueItem1, colInfo, "UPPER(C1) as Fish"); //the logging server has a system default so should have been populated Assert.IsNotNull(cata.LiveLoggingServer_ID); //Catalogue sharing should be allowed Gatherer g = new Gatherer(RepositoryLocator); Assert.IsTrue(g.CanGatherDependencies(cata)); //gather the objects depending on Catalogue as a tree var gObj = g.GatherDependencies(cata); Assert.AreEqual(2, gObj.Children.Count); //both cata items var lmd = new LoadMetadata(CatalogueRepository); cata.LoadMetadata_ID = lmd.ID; cata.SaveToDatabase(); //get the share definition var shareManager = new ShareManager(RepositoryLocator); var shareDefinition = gObj.ToShareDefinitionWithChildren(shareManager); if (goViaJson) { var json = shareDefinition.Select(s => JsonConvertExtensions.SerializeObject(s, RepositoryLocator)).ToList(); shareDefinition = json.Select( j => JsonConvertExtensions.DeserializeObject(j, typeof(ShareDefinition), RepositoryLocator)) .Cast <ShareDefinition>() .ToList(); } //make a local change cata.Name = "fishfish"; cata.SubjectNumbers = "123"; cata.LoadMetadata_ID = null; cata.Periodicity = Catalogue.CataloguePeriodicity.Unknown; cata.SaveToDatabase(); lmd.DeleteInDatabase(); //import the saved copy shareManager.ImportSharedObject(shareDefinition); //revert the memory copy and check it got overwritten with the original saved values cata.RevertToDatabaseState(); Assert.AreEqual("Cata", cata.Name); var exports = CatalogueRepository.GetAllObjects <ObjectExport>(); Assert.IsTrue(exports.Any()); //now delete and report foreach (var d in exports) { d.DeleteInDatabase(); } //make a local change including Name cata.Name = "fishfish"; cata.SaveToDatabase(); //test importing the Catalogue properties only shareManager.ImportPropertiesOnly(cata, shareDefinition[0]); //import the defined properties but not name Assert.AreEqual("fishfish", cata.Name); Assert.AreEqual(Catalogue.CataloguePeriodicity.BiMonthly, cata.Periodicity); //reset this though Assert.IsNull(cata.LoadMetadata_ID); cata.SaveToDatabase(); cata.DeleteInDatabase(); //none of these should now exist thanks to cascade deletes Assert.IsFalse(cata.Exists()); Assert.IsFalse(catalogueItem1.Exists()); Assert.IsFalse(catalogueItem2.Exists()); //import the saved copy var newObjects = shareManager.ImportSharedObject(shareDefinition).ToArray(); Assert.AreEqual("Cata", ((Catalogue)newObjects[0]).Name); Assert.AreEqual("Ci1", ((CatalogueItem)newObjects[1]).Name); Assert.AreEqual("Ci2", ((CatalogueItem)newObjects[2]).Name); }
public override void Execute() { base.Execute(); if (IsSingleObject) { //Extract a single object (to file) if (TargetFileInfo == null && BasicActivator.IsInteractive) { TargetFileInfo = BasicActivator.SelectFile("Path to output share definition to", "Share Definition", "*.sd"); if (TargetFileInfo == null) { return; } } } else { if (TargetDirectoryInfo == null && BasicActivator.IsInteractive) { TargetDirectoryInfo = BasicActivator.SelectDirectory("Output Directory"); if (TargetDirectoryInfo == null) { return; } } } if (TargetFileInfo != null && IsSingleObject) { var d = _gatherer.GatherDependencies(_toExport[0]); var shareDefinitions = d.ToShareDefinitionWithChildren(_shareManager); string serial = JsonConvertExtensions.SerializeObject(shareDefinitions, _repositoryLocator); File.WriteAllText(TargetFileInfo.FullName, serial); return; } if (TargetDirectoryInfo == null) { throw new Exception("No output directory set"); } foreach (var o in _toExport) { var d = _gatherer.GatherDependencies(o); var filename = QuerySyntaxHelper.MakeHeaderNameSensible(o.ToString()) + ".sd"; var shareDefinitions = d.ToShareDefinitionWithChildren(_shareManager); string serial = JsonConvertExtensions.SerializeObject(shareDefinitions, _repositoryLocator); var f = Path.Combine(TargetDirectoryInfo.FullName, filename); File.WriteAllText(f, serial); } if (ShowInExplorer && TargetDirectoryInfo != null) { UsefulStuff.GetInstance().ShowFolderInWindowsExplorer(TargetDirectoryInfo); } }
/// <summary> /// Deserializes the json which must be the contents of a .sd file i.e. a ShareDefinitionList /// </summary> /// <param name="json"></param> /// <returns></returns> public List <ShareDefinition> GetShareDefinitionList(string json) { return((List <ShareDefinition>)JsonConvertExtensions.DeserializeObject(json, typeof(List <ShareDefinition>), RepositoryLocator)); }
public ActionResult CancelDownload() { var response = _fileServices.CancelDownload(); return(Json(new { data = JsonConvertExtensions.GetJsonConvert(response) }, JsonRequestBehavior.AllowGet)); }
public async void SendToAllRemotes <T>(T[] toSendAll, Action callback = null) where T : IMapsDirectlyToDatabaseTable { listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Ready to send " + toSendAll.Length + " " + typeof(T).Name + " items to all remotes.")); var done = new Dictionary <string, int>(); foreach (var remoteRDMP in remotes) { listener.OnProgress(this, new ProgressEventArgs(remoteRDMP.Name, new ProgressMeasurement(0, ProgressType.Records, toSendAll.Length), new TimeSpan())); } var tasks = new List <Task>(); foreach (var remote in remotes) { done.Add(remote.Name, 0); foreach (var toSend in toSendAll) { if (!_gatherer.CanGatherDependencies(toSend)) { throw new Exception("Type " + typeof(T) + " is not supported yet by Gatherer and therefore cannot be shared"); } var share = _gatherer.GatherDependencies(toSend).ToShareDefinitionWithChildren(_shareManager); var json = JsonConvertExtensions.SerializeObject(share, _repositoryLocator); var handler = new HttpClientHandler() { Credentials = new NetworkCredential(remote.Username, remote.GetDecryptedPassword()) }; HttpResponseMessage result; var apiUrl = remote.GetUrlFor <T>(); RemoteRDMP remote1 = remote; T toSend1 = toSend; var sender = new Task(() => { using (var client = new HttpClient(handler)) { try { result = client.PostAsync(new Uri(apiUrl), new StringContent(json, Encoding.UTF8, "text/plain")).Result; if (result.IsSuccessStatusCode) { listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Sending " + toSend1 + " to " + remote1.Name + " completed.")); } else { listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, "Error sending " + toSend1 + " to " + remote1.Name + ": " + result.ReasonPhrase + " - " + result.Content.ReadAsStringAsync().Result)); } lock (done) { listener.OnProgress(this, new ProgressEventArgs(remote1.Name, new ProgressMeasurement(++done[remote1.Name], ProgressType.Records, toSendAll.Length), new TimeSpan())); } } catch (Exception ex) { listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Error, "Error sending " + toSend1 + " to " + remote1.Name, ex)); listener.OnProgress(this, new ProgressEventArgs(remote1.Name, new ProgressMeasurement(1, ProgressType.Records, 1), new TimeSpan())); } } }); sender.Start(); tasks.Add(sender); } } await Task.WhenAll(tasks); if (callback != null) { callback(); } }