private static void AddMediaInformationToBuffer(MediaNodeModel model, ref List <byte> buffer) { // Add media type buffer.Add((byte)model.MediaType); // Add Franchise buffer.AddRange(Encoding.UTF8.GetBytes(model.Franchise)); // Add the genres foreach (string genre in model.Genres.OrderBy(x => x)) { buffer.AddRange(Encoding.UTF8.GetBytes(genre)); } }
/// <summary> /// Creates a BasicNodeModel based on the given INode. /// </summary> /// <exception cref="ArgumentException">If the INode could not be parsed</exception> /// <param name="node">The INode from which to create the BasicNodeModel</param> /// <returns>The created BasicNodeModel or null if an error occurred</returns> public static BasicNodeModel FromINode(INode node) { BasicNodeModel result = null; try { NodeContentType contentType = (NodeContentType)Enum.Parse(typeof(NodeContentType), node.Labels[0]); if (contentType == NodeContentType.Company) { result = new CompanyNodeModel(); } else if (contentType == NodeContentType.Media) { result = new MediaNodeModel { // Media properties MediaType = node.Labels.Count > 2 ? (NodeMediaType)Enum.Parse(typeof(NodeMediaType), node.Labels[1]) : 0, Franchise = node.Properties.ContainsKey("franchise") ? node.Properties["franchise"].As <string>() : null, Genres = node.Properties.ContainsKey("genres") ? node.Properties["genres"].As <List <string> >() : new List <string>() }; } else if (contentType == NodeContentType.Person) { result = new PersonNodeModel { // Person properties FamilyName = node.Properties.ContainsKey("familyName") ? node.Properties["familyName"].As <string>() : null, GivenName = node.Properties.ContainsKey("givenName") ? node.Properties["givenName"].As <string>() : null, Status = node.Properties.ContainsKey("status") ? (PersonStatus)Enum.Parse(typeof(PersonStatus), node.Properties["status"].As <string>()) : 0 }; // If the family and given name was not populated and there is a common name, if (((PersonNodeModel)result).FamilyName == null && ((PersonNodeModel)result).GivenName == null && node.Properties.ContainsKey("commonName")) { // Parse the names out of the common name string[] nameParts = node.Properties["commonName"].As <string>().Split(' '); string givenName = ""; string familyName = ""; for (int i = 0; i < nameParts.Length; i++) { if (i != nameParts.Length - 1) { givenName += $"{nameParts[i]} "; } else { familyName = nameParts[i]; } } ((PersonNodeModel)result).GivenName = givenName.Trim(); ((PersonNodeModel)result).FamilyName = familyName; } } // Basic properties result.Id = Guid.Parse(node.Properties["id"].As <string>()); result.ContentType = contentType; result.ReleaseDate = node.Properties.ContainsKey("releaseDate") ? node.Properties["releaseDate"].As <long>() : default(long?); result.DeathDate = node.Properties.ContainsKey("deathDate") ? node.Properties["deathDate"].As <long>() : default(long?); result.CommonName = node.Properties.ContainsKey("commonName") ? node.Properties["commonName"].As <string>() : null; result.OtherNames = node.Properties.ContainsKey("otherNames") ? node.Properties["otherNames"].As <List <string> >() : new List <string>(); result.PartialHash = node.Properties.ContainsKey("partialHash") ? node.Properties["partialHash"].As <string>() : ""; result.FullHash = node.Properties.ContainsKey("fullHash") ? node.Properties["fullHash"].As <string>() : ""; } catch (Exception e) { throw new ArgumentException("Failed to parse the given node: (Type: " + node.Labels[0] + " Id: " + node.Properties["id"].As <string>(), e); } return(result); }