Ejemplo n.º 1
0
        /// <summary>
        /// Peer Constructor. It initialize configuration according to the options passed, initialize the
        /// local stream, creates the databases and resolves the IP address using Dns class.
        /// </summary>
        /// <param name="single">Indicates if the peer have to run kademlia layer in single bootstrap</param>
        /// <param name="btpNode">Address of the suggested bootstrap node.</param>
        public Peer(bool single = false, string btpNode = "")
        {
            log.Debug("Initializing peer structure");
            this.ConfOptions            = new Dictionary <string, string>();
            this.ConfOptions["udpPort"] = PeerLibrary.Properties.Settings.Default.udpPort;
            this.ConfOptions["kadPort"] = PeerLibrary.Properties.Settings.Default.kademliaPort;
            this.localStream            = new MemoryStream();
            this.single  = single;
            this.btpNode = btpNode;
            AppSettingsReader asr = new AppSettingsReader();

            Persistence.RepositoryConfiguration conf = new Persistence.RepositoryConfiguration(new { data_dir = (string)asr.GetValue("TrackRepository", typeof(string)) });
            this.trackRep = Persistence.RepositoryFactory.GetRepositoryInstance("Raven", conf);
//            this.peerAddress = "127.0.0.1";
            IPHostEntry IPHost = Dns.GetHostEntry(Dns.GetHostName());

            IPAddress[] listaIP = IPHost.AddressList;
            foreach (IPAddress ip in listaIP)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    this.peerAddress = ip.ToString();
                    break;
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This example shows how to instantiate a new raven repository
 /// </summary>
 public static void LoadRavenExample()
 {
     ExampleHelper.ExampleMethodPrint("Generate Raven Repository Instance", MethodInfo.GetCurrentMethod());
     Persistence.RepositoryConfiguration conf = new Persistence.RepositoryConfiguration(new { data_dir = "..\\..\\Resource\\Database" });
     _trackRep = Persistence.RepositoryFactory.GetRepositoryInstance("Raven", conf);
     Console.WriteLine(_trackRep.GetType().FullName + " - " + _trackRep.RepositoryType);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor for the Kademlia Repository. This begins with compiling regular expressions for whitespace and semanticless
 /// words and setting timespan sing the given values (if they are not passed, it uses the default). Then instantiates the
 /// repository of the fiven type and creates two indexes over the instantiatied repository. The first index is used to
 /// find keywords with an empty tag list; the second one is used to query keyword using tag identifier. Both indexes are
 /// necessary in order to cleanly delete resources and keywords from the repository
 /// </summary>
 /// <param name="repType">Name of the repository type. The default repository type is RavenDB ("Raven")</param>
 /// <param name="conf">Repository Configureation</param>
 /// <param name="elementValidity">Validity period of a Dht Element. Default value is 24 hours (1 day). The validity must
 /// be expressed in timespan format as described in MSDN reference for this type.</param>
 /// <param name="semanticFilter">Regular expression that will be used to remove semanticless word.</param>
 public KademliaRepository(string repType = "Raven",
                           RepositoryConfiguration conf = null,
                           string elementValidity       = "1",
                           string semanticFilter        = KademliaRepository.DefaultSemanticFilterRegexString)
 {
     log.Debug("Semantic Filter Regex used is " + DefaultSemanticFilterRegexString);
     if (!(TimeSpan.TryParse(elementValidity, out this._elementValidity)))
     {
         this._elementValidity = new TimeSpan(24, 0, 0);
     }
     this._semanticRegex   = new Regex(DefaultSemanticFilterRegexString, RegexOptions.Compiled | RegexOptions.IgnoreCase);
     this._whiteSpaceRegex = new Regex(@"[ ]{2,}", RegexOptions.Compiled);
     this._repository      = RepositoryFactory.GetRepositoryInstance(repType, conf);
     this._repository.CreateIndex("KademliaKeywords/KeysByTag",
                                  "from key in docs.KademliaKeywords\nfrom tag in key.Tags\nselect new { Kid = key.Id , Tid = tag}");
     this._repository.CreateIndex("KademliaKeywords/EmptyKeys",
                                  "from key in docs.KademliaKeywords\nwhere key.Tags.Count() == 0\nselect new { key.Id }");
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Metodo statico per ottenere un'istanza di un repository di un tipo specificato.
 /// Se tutto va a buon fine il metodo ritornerà un oggetto delle classe Persistence.RepositoryImpl.TipoRepository derivata
 /// dalla classe astratta Persistence.Repository.
 /// Se viene richiesto un tipo di repository non disponibile verrà sollevata un'eccezione; è quindi preferibile, nel caso in
 /// cui non si sia sicuri della disponibilità di un tipo di repository, usare il metodo IsValidRepositoryType della Factory.
 /// </summary>
 /// <example>
 /// Persistence.Repository repo=Persistence.RepositoryFactory("raven");
 /// Console.Writeline(repo.RepositoryType); //raven
 /// </example>
 /// <param name="repType">Stringa rappresentante il tipo di repository richiesto.</param>
 /// <returns>Un'istanza del repository del tipo richiesto.</returns>
 /// <exception cref="System.TypeLoadException">Eccezione sollevata nel caso ci siano errori nel caricamento della classe
 /// del repository o nell'invocazione del suo costruttore di default.</exception>
 /// <exception cref="System.ArgumentException">Eccezione sollevata nel caso in cui la stringa contenente il tipo di repository
 /// richiesto risulti vuota</exception>
 /// <exception cref="System.ArgumentNullException">Eccezione sollevata nel caso in cui la stringa contenente il tipo di
 /// repository richiesto risulti essere nulla</exception>
 public static Repository GetRepositoryInstance(String repType, RepositoryConfiguration config)
 {
     if (repType != null)
     {
         if (repType.Length != 0)
         {
             String className = _generateRepositoryClassName(repType);
             try
             {
                 Type   reflectedRepository = Type.GetType(className, true, true);
                 Type[] args = new Type[1] {
                     config.GetType()
                 };
                 Object[] param = new Object[1] {
                     config
                 };
                 object     rep  = reflectedRepository.GetConstructor(args).Invoke(param);
                 Repository inst = rep as Repository;
                 if (inst.RepositoryType.Equals(repType))
                 {
                     return(inst);
                 }
                 else
                 {
                     throw new TypeLoadException("Type " + inst.RepositoryType + " is different from the expected " + repType + "!");
                 }
             }
             catch (Exception ex)
             {
                 throw new TypeLoadException("Unable to load repository class " + className, ex);
             }
         }
         else
         {
             throw new ArgumentException("Repository Type Name must not be Empty!");
         }
     }
     else
     {
         throw new ArgumentNullException("Repository Type Name must not be NULL!");
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// This example shows how to instantiate a new raven repository
 /// </summary>
 public static void LoadRavenExample()
 {
     ExampleHelper.ExampleMethodPrint("Generate Raven Repository Instance", MethodInfo.GetCurrentMethod());
     Persistence.RepositoryConfiguration conf = new Persistence.RepositoryConfiguration(new { data_dir = "..\\..\\Resource\\Database" });
     _trackRep= Persistence.RepositoryFactory.GetRepositoryInstance("Raven",conf);
     Console.WriteLine(_trackRep.GetType().FullName+" - " + _trackRep.RepositoryType);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Repository Constructor that initializes the repository of the given type.
 /// </summary>
 /// <param name="repType">Name of the repository Type</param>
 /// <param name="conf">Configuration for the repository</param>
 public TrackRepository(string repType, RepositoryConfiguration conf)
 {
     this._repository = RepositoryFactory.GetRepositoryInstance(repType, conf);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Peer Constructor. It initialize configuration according to the options passed, initialize the
 /// local stream, creates the databases and resolves the IP address using Dns class.
 /// </summary>
 /// <param name="single">Indicates if the peer have to run kademlia layer in single bootstrap</param>
 /// <param name="btpNode">Address of the suggested bootstrap node.</param>
 public Peer(bool single = false, string btpNode = "")
 {
     log.Debug("Initializing peer structure");
     this.ConfOptions = new Dictionary<string, string>();
     this.ConfOptions["udpPort"] = PeerLibrary.Properties.Settings.Default.udpPort;
     this.ConfOptions["kadPort"] = PeerLibrary.Properties.Settings.Default.kademliaPort;
     this.localStream = new MemoryStream();
     this.single = single;
     this.btpNode = btpNode;
     AppSettingsReader asr = new AppSettingsReader();
     Persistence.RepositoryConfiguration conf = new Persistence.RepositoryConfiguration(new { data_dir = (string)asr.GetValue("TrackRepository", typeof(string)) });
     this.trackRep = Persistence.RepositoryFactory.GetRepositoryInstance("Raven", conf);
     //            this.peerAddress = "127.0.0.1";
     IPHostEntry IPHost = Dns.GetHostEntry(Dns.GetHostName());
     IPAddress[] listaIP = IPHost.AddressList;
     foreach (IPAddress ip in listaIP)
     {
         if (ip.AddressFamily == AddressFamily.InterNetwork)
         {
             this.peerAddress = ip.ToString();
             break;
         }
     }
 }