/// <summary> /// Make a mesage to store the given data. /// </summary> /// <param name="nodeID">The sender identificator</param> /// <param name="request">The StoreResponse message that originated this message</param> /// <param name="theData">The CompleteTag to store</param> /// <param name="originalPublication">The publication datetime</param> /// <param name="nodeEndpoint">The sender node's kademlia address</param> /// <param name="transportUri">The sender node's transport uri</param> public StoreData(ID nodeID, StoreResponse request, CompleteTag theData, DateTime originalPublication, Uri nodeEndpoint, Uri transportUri) : base(nodeID, request, nodeEndpoint) { this.data = theData; this.publication = originalPublication; this.transportUri = transportUri; }
/// <summary> /// This example uses the <c>Store</c> method to insert a new resource in the repository /// </summary> public static void StoreExample() { ExampleHelper.ExampleMethodPrint("Store a Tag and linking it with a peer URI", MethodInfo.GetCurrentMethod()); _repository.StoreResource(tag, new Uri("http://*****:*****@"..\..\Resource\SevenMP3.mp3"); _repository.StoreResource(anotherTag, new Uri("http://localhost:28182"), DateTime.Now); }
/// <summary> /// Main Constructor of the resource. This initializes the fields with the given values /// </summary> /// <param name="tag">Tag Information</param> /// <param name="urls">List of supplier urls</param> public KademliaResource(CompleteTag tag, params DhtElement[] urls) : this() { this.Tag = tag; if (urls.Length != 0) { foreach (DhtElement e in urls) { this.Urls.Add(e); } // this.Urls.Union<DhtElement>(urls, new DhtElementComparer()); } }
/// <summary> /// This example shows how to read complete tag from file and write it to the console. /// </summary> private static void CompleteTagReadAndWrite() { ExampleHelper.ExampleMethodPrint("Generating Complete Tag From File and Read it",MethodInfo.GetCurrentMethod()); CompleteTag tag = new CompleteTag(@"..\..\Resource\SevenMP3.mp3"); Console.WriteLine("Hash: " + tag.FileHash); Console.WriteLine("Title: " + tag.Title); Console.WriteLine("Artist: " + tag.Artist); Console.WriteLine("Album: " + tag.Album); Console.WriteLine("Genre: " + tag.Genre); Console.WriteLine("Year: " + tag.Year); Console.WriteLine("Track: " + tag.Track); Console.WriteLine("Length: " + tag.Length); Console.WriteLine("File Size: " + tag.FileSize); Console.WriteLine("Channels: " + tag.Channels); Console.WriteLine("Bitrate: " + tag.Bitrate); Console.WriteLine("Sample Rate: " + tag.SampleRate); //Console.WriteLine("Specific Tag: " + tag.SpecificTag.GetType().FullName); }
/// <summary> /// This example shows how to build a <c>CompleteTag</c> and a <c>LightTag</c>. /// </summary> private static void CompleteToLightTag() { ExampleHelper.ExampleMethodPrint("Generating Light Tag from Complete Tag and Read it", MethodInfo.GetCurrentMethod()); CompleteTag tag = new CompleteTag(@"..\..\Resource\SevenMP3.mp3"); Console.WriteLine("Read info from Complete Tag"); Console.WriteLine("Title: " + tag.Title); Console.WriteLine("Artist: " + tag.Artist); Console.WriteLine("Album: " + tag.Album); LightTag miniTag = new LightTag(tag); Console.WriteLine("Read info from Light Tag"); Console.WriteLine("Title. " + miniTag.Title); Console.WriteLine("Artist: " + miniTag.Artist); Console.WriteLine("Album: " + miniTag.Album); Console.WriteLine("Raw Byte Length: " + miniTag.RawData.Length); Console.WriteLine("Raw Byte : " + miniTag.ToString()); }
/// <summary> /// This example shows how to read complete tag from file and write it to the console. /// </summary> private static void CompleteTagReadAndWrite() { ExampleHelper.ExampleMethodPrint("Generating Complete Tag From File and Read it", MethodInfo.GetCurrentMethod()); CompleteTag tag = new CompleteTag(@"..\..\Resource\SevenMP3.mp3"); Console.WriteLine("Hash: " + tag.FileHash); Console.WriteLine("Title: " + tag.Title); Console.WriteLine("Artist: " + tag.Artist); Console.WriteLine("Album: " + tag.Album); Console.WriteLine("Genre: " + tag.Genre); Console.WriteLine("Year: " + tag.Year); Console.WriteLine("Track: " + tag.Track); Console.WriteLine("Length: " + tag.Length); Console.WriteLine("File Size: " + tag.FileSize); Console.WriteLine("Channels: " + tag.Channels); Console.WriteLine("Bitrate: " + tag.Bitrate); Console.WriteLine("Sample Rate: " + tag.SampleRate); //Console.WriteLine("Specific Tag: " + tag.SpecificTag.GetType().FullName); }
/// <summary> /// Generates a clean list (without semanticless words) of keyword related to the given tag /// </summary> /// <param name="tag">Tag for whom we want to generate the keywords</param> /// <returns>A clean array of related keywords</returns> private string[] generatePrimaryKey(CompleteTag tag) { List <string> pkList = new List <string>(); StringBuilder sb = new StringBuilder(); sb.Append(tag.Title); sb.Append(" "); sb.Append(tag.Artist); sb.Append(" "); sb.Append(tag.Album); string[] keywords = DiscardSemanticlessWords(sb.ToString()).Split(' '); UTF8Encoding enc = new UTF8Encoding(); //Questo è solo un esercizio di stile ! /*Parallel.ForEach<string,List<string> >(keywords, * () => new List<string>(), * (key,loop,sublist) => * { * sublist.Add(key); * return sublist; * }, * (finalResult) => pkList.AddRange(finalResult) * );*/ for (int k = 0; k < keywords.Length; k++) { string key = null; if (keywords[k].Length > 32) { key = keywords[k].Substring(0, 32).ToLower(); } else { key = keywords[k].ToLower(); } if (!pkList.Contains(key)) { pkList.Add("kademliakeywords/" + key); } } return(pkList.ToArray()); }
public JsonResult SaveTag(string completeTagDetails, string completeTags) { JavaScriptSerializer serializer = new JavaScriptSerializer(); // conver from string to object CompleteTag completeTag = serializer.Deserialize <CompleteTag>(completeTags); List <CompleteTagDetail> completeTagDetail = serializer.Deserialize <List <CompleteTagDetail> >(completeTagDetails); bool status = false; string message = string.Empty; try { completeTag.ID = null; completeTag.Date = DateTime.Now; context.CompleteTags.Add(completeTag); foreach (var ctd in completeTagDetail) { ctd.ID = null; context.CompleteTagDetails.Add(ctd); } context.SaveChanges(); status = true; } catch (Exception ex) { status = false; message = ex.Message; } return(Json(new { status = status, message = message })); }
public void StoreResource(CompleteTag tag, Uri uri, DateTime publicationTime) { }
/// <summary> /// Generates a clean list (without semanticless words) of keyword related to the given tag /// </summary> /// <param name="tag">Tag for whom we want to generate the keywords</param> /// <returns>A clean array of related keywords</returns> private string[] generatePrimaryKey(CompleteTag tag) { List<string> pkList = new List<string>(); StringBuilder sb = new StringBuilder(); sb.Append(tag.Title); sb.Append(" "); sb.Append(tag.Artist); sb.Append(" "); sb.Append(tag.Album); string[] keywords = DiscardSemanticlessWords(sb.ToString()).Split(' '); UTF8Encoding enc = new UTF8Encoding(); //Questo è solo un esercizio di stile ! /*Parallel.ForEach<string,List<string> >(keywords, () => new List<string>(), (key,loop,sublist) => { sublist.Add(key); return sublist; }, (finalResult) => pkList.AddRange(finalResult) );*/ for (int k = 0; k < keywords.Length; k++) { string key = null; if (keywords[k].Length > 32) { key = keywords[k].Substring(0, 32).ToLower(); } else { key = keywords[k].ToLower(); } if (!pkList.Contains(key)) pkList.Add("kademliakeywords/"+key); } return pkList.ToArray(); }
/// <summary> /// Stores a tag as resource into the kademlia repository. If the resource already exists the method tries to add the /// given Url (with the desired publication time) to the list of suppliers for that resource; if the url is already known /// the method does nothing. If the resource is new first the method adds it to the repository and then generates a set of /// keywords related to the new resource. For each generated keyword, if this is already in the repository the tag /// identifier (that is the resource identifier too) will be added to the related tags list, if the keyword doesn't exist /// it will be created and its related tags list will contains only the new resource. /// </summary> /// <param name="tag">Tag to store in the kademlia resource</param> /// <param name="peer">Url of the supplier</param> /// <param name="pubtime">Publication TIme</param> /// <returns>False if something went wrong, true otherwise</returns> public bool StoreResource(CompleteTag tag, Uri peer, DateTime pubtime) { KademliaResource rs = new KademliaResource(); Console.WriteLine("Storing resource from peer " + peer); DhtElement dhtElem = new DhtElement(peer, pubtime, this._elementValidity); RepositoryResponse resp = _repository.GetByKey <KademliaResource>(tag.TagHash, rs); if (resp == RepositoryResponse.RepositoryLoad) { if (!rs.Urls.Contains(dhtElem)) { _repository.ArrayAddElement(rs.Id, "Urls", dhtElem); } else { log.Debug("Urls " + peer.ToString() + " already known"); } } else if (resp == RepositoryResponse.RepositoryMissingKey) { rs = new KademliaResource(tag, dhtElem); if (_repository.Save(rs) == RepositoryResponse.RepositorySuccess) { List <string> pks = new List <string>(generatePrimaryKey(tag)); List <KademliaKeyword> keys = new List <KademliaKeyword>(); if (_repository.GetByKeySet(pks.ToArray(), keys) > 0) { foreach (KademliaKeyword k in keys) { if (!k.Tags.Contains(rs.Id)) { _repository.ArrayAddElement(k.Id, "Tags", rs.Id); } pks.Remove(k.Id); } foreach (String pk in pks) { KademliaKeyword localKey = new KademliaKeyword(pk, rs.Id); _repository.Save(localKey); } } else { log.Error("Unexpected reposnde while getting keywords"); return(false); } } else { log.Error("Unexpected response while inserting Tag with key " + tag.TagHash); return(false); } } else { log.Error("Unexpected response while testing presence of the key " + tag.TagHash); return(false); } return(true); }
/// <summary> /// Costruttore che permette di estrarre un Tag alleggerito da un tag completo. /// </summary> /// <param name="tag">Tag Completo da cui estrarre i dati</param> public LightTag(CompleteTag tag) : this() { this.SetTagData(tag.Title, tag.Artist, tag.Album); }
/// <summary> /// Stores a tag as resource into the kademlia repository. If the resource already exists the method tries to add the /// given Url (with the desired publication time) to the list of suppliers for that resource; if the url is already known /// the method does nothing. If the resource is new first the method adds it to the repository and then generates a set of /// keywords related to the new resource. For each generated keyword, if this is already in the repository the tag /// identifier (that is the resource identifier too) will be added to the related tags list, if the keyword doesn't exist /// it will be created and its related tags list will contains only the new resource. /// </summary> /// <param name="tag">Tag to store in the kademlia resource</param> /// <param name="peer">Url of the supplier</param> /// <param name="pubtime">Publication TIme</param> /// <returns>False if something went wrong, true otherwise</returns> public bool StoreResource(CompleteTag tag, Uri peer,DateTime pubtime) { KademliaResource rs = new KademliaResource(); Console.WriteLine("Storing resource from peer " + peer); DhtElement dhtElem = new DhtElement(peer, pubtime, this._elementValidity); RepositoryResponse resp = _repository.GetByKey<KademliaResource>(tag.TagHash, rs); if ( resp == RepositoryResponse.RepositoryLoad) { if (!rs.Urls.Contains(dhtElem)) { _repository.ArrayAddElement(rs.Id, "Urls", dhtElem); } else { log.Debug("Urls "+peer.ToString()+" already known"); } } else if (resp == RepositoryResponse.RepositoryMissingKey) { rs = new KademliaResource(tag, dhtElem); if (_repository.Save(rs) == RepositoryResponse.RepositorySuccess) { List<string> pks = new List<string>(generatePrimaryKey(tag)); List<KademliaKeyword> keys = new List<KademliaKeyword>(); if (_repository.GetByKeySet(pks.ToArray(), keys) > 0) { foreach (KademliaKeyword k in keys) { if (!k.Tags.Contains(rs.Id)) { _repository.ArrayAddElement(k.Id, "Tags", rs.Id); } pks.Remove(k.Id); } foreach (String pk in pks) { KademliaKeyword localKey = new KademliaKeyword(pk,rs.Id); _repository.Save(localKey); } } else { log.Error("Unexpected reposnde while getting keywords"); return false; } } else { log.Error("Unexpected response while inserting Tag with key " + tag.TagHash); return false; } } else { log.Error("Unexpected response while testing presence of the key " + tag.TagHash); return false; } return true; }
/// <summary> /// This example uses the <c>Store</c> method to insert a new resource in the repository /// </summary> public static void StoreExample() { ExampleHelper.ExampleMethodPrint("Store a Tag and linking it with a peer URI", MethodInfo.GetCurrentMethod()); _repository.StoreResource(tag, new Uri("http://*****:*****@"..\..\Resource\SevenMP3.mp3"); _repository.StoreResource(anotherTag,new Uri("http://localhost:28182"),DateTime.Now); }
/// <summary> /// Creates a new <see cref="Submodule"/> with the given information /// </summary> /// <param name="solutionPath">The path to the current opend solution</param> /// <param name="subModuleInformation">The <see cref="string"/> /// that contains informations of the submodule</param> internal Submodule(string solutionPath, string subModuleInformation) { ShowSlimInformations = true; if (string.IsNullOrEmpty(subModuleInformation)) { return; } var lineSplit = subModuleInformation.TrimStart().Split(' '); CompleteId = lineSplit.FirstOrDefault(); Name = lineSplit.ElementAtOrDefault(1) ?? "???"; CompleteTag = lineSplit.ElementAtOrDefault(2) ?? "???"; CompleteId = !string.IsNullOrEmpty(CompleteId) ? CompleteId.Replace("U", string.Empty) .Replace("+", string.Empty) .Replace("-", string.Empty) .TrimStart() : "???"; ShortId = CompleteId.Substring(0, 7); SetSubModuleStatus(solutionPath, subModuleInformation); SetBackgroundColor(); // TODO: this if is useless, should be remove? if (string.IsNullOrEmpty(CompleteTag)) { ChangeHealthStatus(HealthStatus.Unknown); return; } CompleteTag = CompleteTag.TrimStart('(').TrimEnd(')'); if (CompleteTag.EndsWith("HEAD", StringComparison.Ordinal)) { ChangeHealthStatus(HealthStatus.Head); return; } if (CompleteId.StartsWith(CompleteTag, StringComparison.Ordinal)) { ChangeHealthStatus(HealthStatus.Okay); return; } if (CompleteTag.StartsWith("heads", StringComparison.Ordinal) && !CompleteTag.Contains("-")) { ChangeHealthStatus(HealthStatus.Okay); return; } var splittedTag = CompleteTag.Split('-'); if ((splittedTag.Length - 2) < 1) { ChangeHealthStatus(HealthStatus.Unknown); return; } int numberOfAdditionalCommits; int.TryParse(splittedTag.ElementAtOrDefault(splittedTag.Length - 2), out numberOfAdditionalCommits); NumberOfAdditionalCommits = numberOfAdditionalCommits; ChangeHealthStatus(NumberOfAdditionalCommits == 0 ? HealthStatus.Unknown : HealthStatus.Warning); }