コード例 #1
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);
 }
コード例 #2
0
ファイル: Peer.cs プロジェクト: sheepfriend/p2p-player
        /// <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;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Constructor of the class. It builds the TransportProtocol sublayer, initializing its common
        /// attributes using the app settings in xml file.
        /// </summary>
        /// <param name="uri">The URI of the transport layer</param>
        /// <param name="trackRepository">The repository used to represent tracks over the network</param>
        public TransportProtocol(Uri uri, Persistence.Repository trackRepository)
        {
            AppSettingsReader asr = new AppSettingsReader();
            int poolSize          = (int)asr.GetValue("ThreadPoolSize", typeof(int));

            this.threadPool      = new ThreadPool(poolSize);
            this.nextArrived    += new NextArrivedHandler(this.writeOnStream);
            this.chunkLength     = ((int)asr.GetValue("ChunkLength", typeof(int)));
            this.myAddress       = uri;
            this.trackRepository = trackRepository;
            log.Info("Initialized Transport Layer with " + poolSize + " worker threads");
        }
コード例 #4
0
 /// <summary>
 /// Constructor of the class. It builds the TransportProtocol sublayer, initializing its common
 /// attributes using the app settings in xml file.
 /// </summary>
 /// <param name="uri">The URI of the transport layer</param>
 /// <param name="trackRepository">The repository used to represent tracks over the network</param>
 public TransportProtocol(Uri uri, Persistence.Repository trackRepository)
 {
     AppSettingsReader asr = new AppSettingsReader();
     int poolSize = (int)asr.GetValue("ThreadPoolSize", typeof(int));
     this.threadPool = new ThreadPool(poolSize);
     this.nextArrived += new NextArrivedHandler(this.writeOnStream);
     this.chunkLength = ((int)asr.GetValue("ChunkLength", typeof(int)));
     this.myAddress = uri;
     this.trackRepository = trackRepository;
     log.Info("Initialized Transport Layer with " + poolSize + " worker threads");
 }
コード例 #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);
 }
コード例 #6
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 }");
 }
コード例 #7
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);
 }
コード例 #8
0
ファイル: Peer.cs プロジェクト: zencoders/sambatyon
 /// <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;
         }
     }
 }
コード例 #9
0
 public ImagePersistanceHandler()
 {
     SystemCollection = Repository.GetInstance;
     CommentFunctions = new CommentPersistanceHandler();
 }