public void CreateMainMenu(string primaryParentCategoryId, Guid?parentMainMenuId, int depth) { if (depth == 0) { return; } Categories.Where(d => d.PrimaryParentCategoryId == primaryParentCategoryId).ToList().ForEach(cat => { Guid pageId; if (PageIds.TryGetValue(cat.Id, out pageId)) { var mainMenu = DataFacade.BuildNew <MainMenu>(); mainMenu.Id = GuidUtility.Create(NavigationNamespaces.MainMenuNamespaceId, cat.Id); mainMenu.PageId = WebsiteId; mainMenu.DisplayName = GetLocalizedDisplayName(cat.Id, cat.DisplayName, Culture); mainMenu.CssClassName = string.Empty; mainMenu.ParentId = parentMainMenuId; mainMenu.Url = $"~/page({pageId})"; mainMenu.PublicationStatus = GenericPublishProcessController.Draft; TruncateStrings(cat.Id, mainMenu); mainMenu = DataFacade.AddNew(mainMenu); mainMenu.PublicationStatus = GenericPublishProcessController.Published; DataFacade.Update(mainMenu); CreateMainMenu(cat.Id, mainMenu.Id, depth - 1); } }); }
public void GuidGeneration() { var name = "1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./1234567890-="; Stopwatch timer = new Stopwatch(); timer.Start(); for (int i = 0; i < 500; i++) { GuidUtility.Create(GuidUtility.DnsNamespace, name, 5); } timer.Stop(); Trace.WriteLine(timer.ElapsedMilliseconds.ToString(), "GuidGeneration 5"); timer = new Stopwatch(); timer.Start(); for (int i = 0; i < 500; i++) { GuidUtility.Create(GuidUtility.DnsNamespace, name, 3); } timer.Stop(); Trace.WriteLine(timer.ElapsedMilliseconds.ToString(), "GuidGeneration 3"); }
private Guid GetDeterministicEventId(string json) { var assemblyGuid = GetExecutingAssemblyGuid(); var deterministicEventId = GuidUtility.Create(assemblyGuid, json); return(deterministicEventId); }
public void NewCustomNodeSaveAndLoadPt2() { var newPaths = new List <string> { Path.Combine(Path.GetTempPath(), "NewCustomNodeSaveAndLoad") }; ViewModel.Model.PreferenceSettings.CustomPackageFolders = newPaths; var loader = ViewModel.Model.GetPackageManagerExtension().PackageLoader; loader.LoadNewCustomNodesAndPackages(newPaths, ViewModel.Model.CustomNodeManager); // This unit test is a follow-up of NewCustomNodeSaveAndLoadPt1 test to make sure the newly created // custom node will be loaded once DynamoCore restarted var funcguid = GuidUtility.Create(GuidUtility.UrlNamespace, "NewCustomNodeSaveAndLoad"); var functionnode = ViewModel.Model.CustomNodeManager.CreateCustomNodeInstance(funcguid, "testnode", true); Assert.IsTrue(functionnode.IsCustomFunction); Assert.IsFalse(functionnode.IsInErrorState); Assert.AreEqual(functionnode.OutPorts.Count, 2); ViewModel.CurrentSpace.AddAndRegisterNode(functionnode); var nodeingraph = ViewModel.CurrentSpace.Nodes.FirstOrDefault(); Assert.NotNull(nodeingraph); Assert.IsTrue(nodeingraph.State == ElementState.Active); //remove custom node from definitions folder var savePath = Path.Combine(Path.GetTempPath(), "NewCustomNodeSaveAndLoad", "NewCustomNodeSaveAndLoad.dyf"); File.Delete(savePath); }
public void CreateVersion5FromPythonOrg() { // run the test case from the Python implementation (http://docs.python.org/library/uuid.html#uuid-example) Guid guid = GuidUtility.Create(GuidUtility.DnsNamespace, "python.org", 5); Assert.AreEqual(new Guid("886313e1-3b8a-5372-9b90-0c9aee199e5d"), guid); }
protected override async Task WriteMessagesAsync(IEnumerable <IPersistentRepresentation> messages) { try { foreach (var grouping in messages.GroupBy(x => x.PersistenceId)) { var stream = grouping.Key; var representations = grouping.OrderBy(x => x.SequenceNr).ToArray(); var expectedVersion = (int)representations.First().SequenceNr - 2; var events = representations.Select(x => { var eventId = GuidUtility.Create(GuidUtility.IsoOidNamespace, string.Concat(stream, x.SequenceNr)); var data = _serializer.ToBinary(x); var meta = new byte[0]; var payload = x.Payload; if (payload.GetType().GetProperty("Metadata") != null) { var propType = payload.GetType().GetProperty("Metadata").PropertyType; meta = _serializer.ToBinary(payload.GetType().GetProperty("Metadata").GetValue(x.Payload)); } return(new EventData(eventId, x.Payload.GetType().FullName, true, data, meta)); }); await _connection.AppendToStreamAsync(stream, expectedVersion < 0?ExpectedVersion.NoStream : expectedVersion, events); } } catch (Exception e) { _log.Error(e, "Error writing messages to store"); throw; } }
public void CreateVersion3FromWidgetsCom() { // run the test case from RFC 4122 Appendix B, as updated by http://www.rfc-editor.org/errata_search.php?rfc=4122 Guid guid = GuidUtility.Create(GuidUtility.DnsNamespace, "www.widgets.com", 3); Assert.AreEqual(new Guid("3d813cbb-47fb-32ba-91df-831e1593ac29"), guid); }
public void CreateVersion3FromPythonOrg() { // run the test case from the Python implementation (http://docs.python.org/library/uuid.html#uuid-example) Guid guid = GuidUtility.Create(GuidUtility.DnsNamespace, "python.org", 3); Assert.AreEqual(new Guid("6fa459ea-ee8a-3ca4-894e-db77e160355e"), guid); }
private Guid CreateGuid() { var bytes = new byte[32]; random.NextBytes(bytes); return(GuidUtility.Create(GuidUtility.IsoOidNamespace, bytes)); }
internal static NeoVirtFSContent NewCache(ReadOnlySpan <byte> path, ObjectId nodeObj) { var fileuuid = GuidUtility.Create(GuidUtility.UrlNamespace, path.ToArray()); var fileg = fileuuid.ToString().ToLower(); // 8478e36a-669c-11ec-8541-17df4f57891e // 0123456789012345678901234567890123456789 // 000000000011111111112222222222333333333 // Ultimately will need real pool mechanism here // Original scheme was absurd - the 3 digit is 4096. If we're sufficiently event driven and reactive then this shouldn't get // out of hand -- it should handle millions of physical cache files without too much difficulty, and really if they're annealled // quickly enough there should never be that many on a given filesystem //var cacheFile = $"/ua/NeoVirtCache/{fileg.Substring(0, 2)}/{fileg.Substring(2, 2)}/{fileg.Substring(4, 2)}/{fileg.Substring(6, 2)}/{fileg}_{nodeObj}"; var cacheFile = $"/ua/NeoVirtCache/{fileg.Substring(0, 3)}/{fileg}_{nodeObj}"; var rec = new NeoVirtFSContent { CachePoolGuid = fileuuid, ContentType = VirtFSContentTypes.CachePool, CacheFile = Encoding.UTF8.GetBytes(cacheFile) }; return(rec); }
public Function CreateNodeFromXml(XmlElement nodeElement, SaveContext context, ElementResolver resolver) { XmlNode idNode = nodeElement.ChildNodes.Cast <XmlNode>() .LastOrDefault(subNode => subNode.Name.Equals("ID")); if (idNode == null || idNode.Attributes == null) { return(null); } string id = idNode.Attributes[0].Value; string name = nodeElement.Attributes["nickname"].Value; Guid funcId; if (!Guid.TryParse(id, out funcId)) { funcId = GuidUtility.Create(GuidUtility.UrlNamespace, name); } var node = customNodeManager.CreateCustomNodeInstance(funcId, name /*, isTestMode*/); node.Deserialize(nodeElement, context); return(node); }
public void NewCustomNodeSaveAndLoadPt1() { var funcguid = GuidUtility.Create(GuidUtility.UrlNamespace, "NewCustomNodeSaveAndLoad"); //first create a new custom node. this.ViewModel.ExecuteCommand(new DynamoModel.CreateCustomNodeCommand(funcguid, "testnode", "testcategory", "atest", true)); var outnode1 = new Output(); outnode1.Symbol = "out1"; var outnode2 = new Output(); outnode1.Symbol = "out2"; var numberNode = new DoubleInput(); numberNode.Value = "5"; this.ViewModel.CurrentSpace.AddAndRegisterNode(numberNode); this.ViewModel.CurrentSpace.AddAndRegisterNode(outnode1); this.ViewModel.CurrentSpace.AddAndRegisterNode(outnode2); new ConnectorModel(numberNode.OutPorts.FirstOrDefault(), outnode1.InPorts.FirstOrDefault(), Guid.NewGuid()); new ConnectorModel(numberNode.OutPorts.FirstOrDefault(), outnode2.InPorts.FirstOrDefault(), Guid.NewGuid()); var savePath = Path.Combine(this.ViewModel.Model.PathManager.DefinitionDirectories.FirstOrDefault(), "NewCustomNodeSaveAndLoad.dyf"); //save it to the definitions folder so it gets loaded at startup. this.ViewModel.CurrentSpace.Save(savePath); //assert the filesaved Assert.IsTrue(File.Exists(savePath)); Assert.IsFalse(string.IsNullOrEmpty(File.ReadAllText(savePath))); }
public override void LoadNode(XmlNode nodeElement) { XmlNode idNode = nodeElement.ChildNodes.Cast <XmlNode>() .LastOrDefault(subNode => subNode.Name.Equals("ID")); if (idNode == null || idNode.Attributes == null) { return; } string id = idNode.Attributes[0].Value; string nickname = nodeElement.Attributes["nickname"].Value; Guid funcId; if (!Guid.TryParse(id, out funcId) && nodeElement.Attributes != null) { funcId = GuidUtility.Create(GuidUtility.UrlNamespace, nickname); } if (!VerifyFuncId(ref funcId, nickname)) { LoadProxyCustomNode(funcId, nickname); } Definition = this.dynamoModel.CustomNodeManager.GetFunctionDefinition(funcId); }
/// <summary> /// Converts the objects string representation to a guid. /// </summary> public static Guid ToGuid(this object value) { if (value == null) { throw new ArgumentNullException("value"); } return(GuidUtility.Create(Constants.GuidNamespace, value.ToString())); }
private Guid GetSessionId(IProtocolHandler handler) { var guid = handler.EtpVersion == EtpVersion.v11 ? GuidUtility.Create(handler.Session.SessionId, v11.ProtocolNames.GetProtocolName(handler.Protocol)) : GuidUtility.Create(handler.Session.SessionId, v12.ProtocolNames.GetProtocolName(handler.Protocol)); SessionIds[guid] = guid; return(guid); }
public void CustomNodeSaveDoesNotChangeName() { var funcguid = GuidUtility.Create(GuidUtility.UrlNamespace, "NewCustomNodeSaveAndLoad"); //first create a new custom node. this.ViewModel.ExecuteCommand(new DynamoModel.CreateCustomNodeCommand(funcguid, "testnode", "testcategory", "atest", true)); var outnode1 = new Output(); outnode1.Symbol = "out1"; var outnode2 = new Output(); outnode1.Symbol = "out2"; var cbn = new CodeBlockNodeModel(this.ViewModel.EngineController.LibraryServices); cbn.SetCodeContent("5;", this.ViewModel.CurrentSpace.ElementResolver); ViewModel.FocusCustomNodeWorkspace(funcguid); this.ViewModel.CurrentSpace.AddAndRegisterNode(cbn); this.ViewModel.CurrentSpace.AddAndRegisterNode(outnode1); this.ViewModel.CurrentSpace.AddAndRegisterNode(outnode2); new ConnectorModel(cbn.OutPorts.FirstOrDefault(), outnode1.InPorts.FirstOrDefault(), Guid.NewGuid()); new ConnectorModel(cbn.OutPorts.FirstOrDefault(), outnode2.InPorts.FirstOrDefault(), Guid.NewGuid()); var savePath = GetNewFileNameOnTempPath("dyf"); this.ViewModel.SaveAs(savePath); //assert the filesaved Assert.IsTrue(File.Exists(savePath)); Assert.IsFalse(string.IsNullOrEmpty(File.ReadAllText(savePath))); // get file path and name of file var fileName = Path.GetFileName(savePath); string extension = Path.GetExtension(savePath); if (extension == ".dyn" || extension == ".dyf") { fileName = Path.GetFileNameWithoutExtension(savePath); } Assert.IsTrue(ViewModel.CurrentSpace is CustomNodeWorkspaceModel); //close the customNode so we can reopen it. this.ViewModel.Model.RemoveWorkspace(ViewModel.CurrentSpace); // load ViewModel.OpenCommand.Execute(savePath); ViewModel.FocusCustomNodeWorkspace(funcguid); Assert.IsTrue(ViewModel.CurrentSpace is CustomNodeWorkspaceModel); //assert the current workspace is the customNode. Assert.IsTrue(File.Exists(savePath)); Assert.AreEqual("testnode", ViewModel.Model.CurrentWorkspace.Name); }
public static Guid GetAllStreamKey(this Type hubType) { var allStreamKeyAttribute = hubType.GetCustomAttribute <HubAllStreamKeyAttribute>(); if (allStreamKeyAttribute == null) { return(GuidUtility.Create(OrleansSignalRConstants.DefaultAllStreamKey, GetHubName(hubType))); } return(allStreamKeyAttribute.Guid); }
public void WHEN_name_is_null2_SHOULD_throw_ArgumentNullException() { //Arrange string name = null; //Act var ex = Assert.Throws <ArgumentNullException>(() => GuidUtility.Create(GetRandom.Guid(), name, GetRandom.Int())); //Assert ex.ParamName.Should().ContainEquivalentOf("name"); }
public void LoadProjects() { this.parsedProjects = Directory.GetFiles(this.sourcesFolder, "*.zip", SearchOption.TopDirectoryOnly) .Select(f => new ZipProject { FilePath = f, FileName = Path.GetFileName(f), Guid = GuidUtility.Create(GuidUtility.UrlNamespace, f.Substring(this.sourcesFolder.Length).TrimStart('\\')) }) .ToList(); }
public void WHEN_parameters_ok_and_the_same_SHOULD_give_same_guids(string guid, string name) { //Arrange var uid = new Guid(guid); //Act var guid1 = GuidUtility.Create(uid, name); var guid2 = GuidUtility.Create(uid, name); //Assert guid1.Should().Be(guid2, "same parameters are expected to give the same result"); }
public void WHEN_guid_are_same_but_not_names_SHOULD_give_different_guids(string guid, string name1, string name2) { //Arrange var uid = guid == null?GetRandom.Guid() : new Guid(guid); //Act var guid1 = GuidUtility.Create(uid, name1); var guid2 = GuidUtility.Create(uid, name2); //Assert guid1.Should().NotBe(guid2); }
public void WHEN_version_is_not_3_or_5_SHOULD_throw_ArgumentOutOfRangeException(int version) { //Arrange string name = GetRandom.String(7); //Act var ex = Assert.Throws <ArgumentOutOfRangeException>(() => GuidUtility.Create(GetRandom.Guid(), name, version)); //Assert ex.ParamName.Should().ContainEquivalentOf("version"); }
private void CompareWorkspacesDifferentGuids(WorkspaceComparisonData a, WorkspaceComparisonData b) { var nodeDiff = a.NodeTypeMap.Select(x => x.Value).Except(b.NodeTypeMap.Select(x => x.Value)); if (nodeDiff.Any()) { Assert.Fail("The workspaces don't have the same number of nodes. The json workspace is missing: " + string.Join(",", nodeDiff.Select(i => i.ToString()))); } Assert.AreEqual(a.NodeCount, b.NodeCount, "The workspaces don't have the same number of nodes."); Assert.AreEqual(a.ConnectorCount, b.ConnectorCount, "The workspaces don't have the same number of connectors."); foreach (var kvp in a.InportCountMap) { var countA = kvp.Value; //convert the old guid to the new guid var newGuid = GuidUtility.Create(GuidUtility.UrlNamespace, this.modelsGuidToIdMap[kvp.Key]); var countB = b.InportCountMap[newGuid]; Assert.AreEqual(countA, countB, string.Format("One {0} node has {1} inports, while the other has {2}", a.NodeTypeMap[kvp.Key], countA, countB)); } foreach (var kvp in a.OutportCountMap) { var countA = kvp.Value; //convert the old guid to the new guid var newGuid = GuidUtility.Create(GuidUtility.UrlNamespace, this.modelsGuidToIdMap[kvp.Key]); var countB = b.OutportCountMap[newGuid]; Assert.AreEqual(countA, countB, string.Format("One {0} node has {1} outports, while the other has {2}", a.NodeTypeMap[kvp.Key], countA, countB)); } foreach (var kvp in a.NodeDataMap) { var valueA = kvp.Value; //convert the old guid to the new guid var newGuid = GuidUtility.Create(GuidUtility.UrlNamespace, this.modelsGuidToIdMap[kvp.Key]); var valueB = b.NodeDataMap[newGuid]; Assert.AreEqual(a.NodeTypeMap[kvp.Key], b.NodeTypeMap[newGuid]); try { // When values are geometry, sometimes the creation // of the string representation for forming this message // fails. Assert.AreEqual(valueA, valueB, string.Format("Node Type:{0} value, {1} is not equal to {2}", a.NodeTypeMap[kvp.Key], valueA, valueB)); } catch { continue; } } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = JValue.Load(reader); Guid deterministicGuid; if (!Guid.TryParse(obj.Value <string>(), out deterministicGuid)) { Console.WriteLine("the id was not a guid, converting to a guid"); deterministicGuid = GuidUtility.Create(GuidUtility.UrlNamespace, obj.Value <string>()); Console.WriteLine(obj + " becomes " + deterministicGuid); } return(deterministicGuid); }
public void FileDict() { var stopwatch = new Stopwatch(); stopwatch.Start(); IEnumerable <string> modFiles = new List <string>(); IEnumerable <string> modConfigs = new List <string>(); try { modFiles = Directory.EnumerateFiles(@"mods", "", SearchOption.TopDirectoryOnly); } catch (DirectoryNotFoundException) { Console.WriteLine("Mods folder doesn't exist."); } try { modConfigs = Directory.EnumerateFiles(@"config", "", SearchOption.AllDirectories); } catch (DirectoryNotFoundException) { Console.WriteLine("Config folder doesn't exist."); } foreach (var file in modFiles) { #if DEBUG Console.WriteLine($"Generating hash: {file}"); #endif ModList.Add(new FileHash() { Id = GuidUtility.Create(NamespaceId, file), Path = file, Hash = CalculateMd5(file) }); } foreach (var config in modConfigs) { #if DEBUG Console.WriteLine($"Generating hash: {config}"); #endif ConfigList.Add(new FileHash() { Id = GuidUtility.Create(NamespaceId, config), Path = config, Hash = CalculateMd5(config) }); } stopwatch.Stop(); Console.WriteLine("Generating " + (ModList.Count + ConfigList.Count) + " hashes took: " + stopwatch.ElapsedMilliseconds + "ms"); }
static WFPUtility() { string machineName = string.Empty; try { machineName = System.Environment.MachineName; } catch { machineName = "Unknown"; } INSTALLED_FILTER_ID = GuidUtility.Create(GuidUtility.UrlNamespace, Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\" + machineName); }
private PwUuid GetUuid(string name) { Guid guid; if (Id == default(Guid) || string.IsNullOrEmpty(name)) { guid = Guid.NewGuid(); } else { guid = GuidUtility.Create(Id, name); } return(new PwUuid(guid.ToByteArray())); }
public void Test1() { // Guid nsDNS = new Guid("6ba7b810-9dad-11d1-80b4-00c04fd430c8") // Guid nsRoot = Guid.Create(nsDNS, "myapp.example.com", 5) // Guid nsFoo = Guid.Create(nsRoot, "Foo", 5) var nsRoot1 = GuidUtility.Create(GuidUtility.DnsNamespace, "kaylumah.nl", 5); var nsRoot2 = GuidUtility.Create(GuidUtility.DnsNamespace, "app.kaylumah.nl", 5); var nsRoot3 = GuidUtility.Create(GuidUtility.DnsNamespace, "kaylumah.nl/other", 5); var title = "2020/08/01/kaylumah-the-new-home-for-blogs-written-by-max-hamulyak.html"; var id1a = GuidUtility.Create(nsRoot1, title, 5); var id1b = GuidUtility.Create(nsRoot1, title, 5); var id2 = GuidUtility.Create(nsRoot2, title, 5); var id3 = GuidUtility.Create(nsRoot3, title, 5); }
protected string CreateDbRecordId <TDocument>(DocumentTypeMapping <TDocument> mapping, params string[] values) { if (values.Length == 0) { throw new ArgumentException("At least one value required", nameof(values)); } // The db record id must be globally unique. That is ensured by generating a GUID here that is based off // a string that includes the service name, store name and document name as well as the document id and // version. Having the id generated deterministically like this allows us to ensure that multiple clients // for the same store, fails when racing on updating a particular document (with the same id). var prefix = CreateContentKey(mapping); return(GuidUtility.Create(GuidUtility.UrlNamespace, prefix + "_" + string.Join("_", values)).ToString()); }
private void CompareWorkspaceViewsDifferentGuids(WorkspaceViewComparisonData a, WorkspaceViewComparisonData b) { //first compare the model data serializationTestUtils.CompareWorkspacesDifferentGuids(a, b, this.modelsGuidToIdMap); Assert.IsTrue(Math.Abs(a.X - b.X) < .00001, "The workspaces don't have the same X offset."); Assert.IsTrue(Math.Abs(a.X - b.X) < .00001, "The workspaces don't have the same Y offset."); Assert.IsTrue(Math.Abs(a.Zoom - b.Zoom) < .00001, "The workspaces don't have the same Zoom."); Assert.AreEqual(a.Camera, b.Camera); Assert.AreEqual(a.Guid, b.Guid); Assert.AreEqual(a.NodeViewCount, b.NodeViewCount, "The workspaces don't have the same number of node views."); Assert.AreEqual(a.ConnectorViewCount, b.ConnectorViewCount, "The workspaces don't have the same number of connector views."); Assert.AreEqual(a.AnnotationMap.Count, b.AnnotationMap.Count); foreach (var annotationKVP in a.AnnotationMap) { var valueA = annotationKVP.Value; //convert the old guid to the new guid var newGuid = GuidUtility.Create(GuidUtility.UrlNamespace, this.modelsGuidToIdMap[annotationKVP.Key]); var valueB = b.AnnotationMap[newGuid]; //set the id explicitly since we know it will have changed and should be this id. valueB.Id = valueA.Id.ToString(); //check at least that number of referenced nodes is correct. Assert.AreEqual(valueB.Nodes.Count(), valueA.Nodes.Count()); //ignore this list because all node ids will have changed. valueB.Nodes = valueA.Nodes; Assert.AreEqual(valueA, valueB); } foreach (var kvp in a.NodeViewDataMap) { var valueA = kvp.Value; //convert the old guid to the new guid var newGuid = GuidUtility.Create(GuidUtility.UrlNamespace, this.modelsGuidToIdMap[kvp.Key]); var valueB = b.NodeViewDataMap[newGuid]; //set the id explicitly since we know it will have changed and should be this id. valueB.ID = valueA.ID.ToString(); Assert.AreEqual(valueA, valueB, string.Format("Node View Data:{0} value, {1} is not equal to {2}", a.NodeViewDataMap[kvp.Key].Name, valueA, valueB)); } }