Пример #1
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            var directoryInfo = new DirectoryInfo(@"C:\Users\anton\Desktop\Train");

            Analyzer analyzer = new StandardAnalyzer(luceneVersion);

            Lucene.Net.Store.Directory directory = new RAMDirectory();
            var luceneService = new LuceneService(directory, analyzer, new LuceneTools.LuceneConfig {
                LuceneVersion = luceneVersion
            });
            var indexer             = new TextFileIndexer();
            var provisioningService = new ProvisionService(luceneService, indexer);
            var vectorTokenizer     = new VectorTokenizer(analyzer);

            provisioningService.ProvisionFromDirectory(directoryInfo);
            DirectoryInfo testDirectory = new DirectoryInfo(@"C:\Users\anton\Desktop\Test");

            var testDoc = testDirectory.GetFiles().Select(t => indexer.ProcessDocument(t.FullName)).FirstOrDefault();

            var scam = new ScamAlgorithm(vectorTokenizer, luceneService, new ScamConfig());

            foreach (var doc in scam.GetScore(testDoc, DetectionStrategy.ByDocument))
            {
                if (doc.Value > 0.1)
                {
                    Console.WriteLine($"Doc: {doc.Key}, Score = {doc.Value}");
                }
            }

            Console.WriteLine();
            foreach (var doc in scam.GetScore(testDoc, DetectionStrategy.ByPhrase))
            {
                if (doc.Value > 0.1)
                {
                    Console.WriteLine($"Doc: {doc.Key}, Score = {doc.Value}");
                }
            }
        }
Пример #2
0
        public HostInformation GetHomeServer(string Username)
        {
            Member member = GetDomainMemberByName(Username);

            if (member != null)
            {
                HostNode host = member.HomeServer;
                if (host != null)
                {
                    return(new HostInformation(host));
                }

                // Call the provision service to provision this
                // user to a host
                HostInfo info = ProvisionService.ProvisionUser(Username);
                if (info != null)
                {
                    return(new HostInformation(info));
                }
            }

            return(null);
        }
Пример #3
0
        public Simias.Host.HostInfo GetHomeServer(string user)

        {
            Simias.Server.EnterpriseDomain enterpriseDomain =
                new Simias.Server.EnterpriseDomain(false);
            if (enterpriseDomain == null)
            {
                throw new SimiasException("Enterprise server domain does not exist.");
            }

            Store store = Store.GetStore();

            Simias.Storage.Domain domain = store.GetDomain(enterpriseDomain.ID);
            if (domain == null)
            {
                throw new SimiasException("Enterprise server domain does not exist.");
            }

            // find user
            Member   member = domain.GetMemberByName(user);
            HostNode hNode  = member.HomeServer;

            if (hNode == null)
            {
                if (HostNode.GetLocalHost().IsMasterHost)
                {
                    return(ProvisionService.ProvisionUser(user));
                }
                else
                {
                    return(null);
                    //need to get the home server from master.
                }
            }

            return(new Simias.Host.HostInfo(hNode));
        }
Пример #4
0
        /// <summary>
        /// Construct a Host domain.
        /// </summary>
        /// <param name="domain">The enterprise domain.</param>
        public HostProvider(Domain domain)
        {
            hostDomain = domain;

            // Check if this is the master server.
            bool master = (hostDomain.Role == SyncRoles.Master) ? true : false;

            // Get the HostDomain
            // If the HostNode does not exist create it.
            lock (typeof(HostProvider))
            {
                // Check if the host node exists.
                string hName = Store.Config.Get(ServerSection, ServerNameKey);

                // Make sure a master host can run without any pre-configured settings
                // so if the public address wasn't configured get a non-loopback local
                // address and configure the public address with it.
                string publicAddress = Store.Config.Get(ServerSection, PublicAddressKey);
                if (publicAddress == null || publicAddress == String.Empty)
                {
                    // Get the first non-localhost address
                    string[] addresses = MyDns.GetHostAddresses();
                    foreach (string addr in addresses)
                    {
                        if (IPAddress.IsLoopback(IPAddress.Parse(addr)) == false)
                        {
                            publicAddress = addr;
                            break;
                        }
                    }
                }

                string privateAddress = Store.Config.Get(ServerSection, PrivateAddressKey);
                if (privateAddress == null || privateAddress == String.Empty)
                {
                    if (publicAddress != null)
                    {
                        privateAddress = publicAddress;
                    }
                }

                string masterAddress = Store.Config.Get(ServerSection, MasterAddressKey);
                Member mNode         = hostDomain.GetMemberByName(hName);
                host = (mNode == null) ? null : new HostNode(mNode);
                if (host == null)
                {
                    Console.Error.WriteLine("Checking if the host node exists.");
                    HostNode hn = HostNode.GetLocalHost();
                    if (hn == null)
                    {
                        Console.Error.WriteLine("Host node is null.");
                    }
                    else
                    {
                        Console.Error.WriteLine("Host node ID is: {0} and public url is: {1}", hn.ID, hn.PublicUrl);
                    }
                    host = hn;
                }

                if (host == null)
                {
                    Console.Error.WriteLine("Host node is null. Creating the host node.");
                    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                    if (master == true)
                    {
                        host              = new HostNode(hName, System.Guid.NewGuid().ToString(), publicAddress, privateAddress, rsa);
                        host.Rights       = Simias.Storage.Access.Rights.Admin;
                        host.IsMasterHost = true;
                    }
                    else
                    {
                        host       = SlaveSetup.GetHost(Store.StorePath);
                        host.Proxy = true;
                        rsa        = SlaveSetup.GetKeys(Store.StorePath);
                        // TODO remove
                        Property p = new Property(PropertyTags.HostAddress, new Uri(masterAddress));
                        p.LocalProperty = true;
                        hostDomain.Properties.AddNodeProperty(p);
                        // END TODO
                    }

                    host.IsLocalHost = true;
                    hostDomain.Commit(new Node[] { hostDomain, host });

                    // Now Associate this host with the local identity.
                    store.AddDomainIdentity(hostDomain.ID, host.UserID, rsa.ToXmlString(true), Simias.Storage.CredentialType.PPK);
                    SlaveSetup.DeleteTempSetupFiles(Store.StorePath);
                }
                else
                {
                    Console.Error.WriteLine("Host is not null. Updating the host node.");
                    if (host.IsMasterHost == true)
                    {
                        // Make sure the address has not changed.
                        bool hostChanged = false;
                        if (host.PublicUrl != publicAddress)
                        {
                            host.PublicUrl = publicAddress;
                            hostChanged    = true;
                        }
                        if (host.PrivateUrl != privateAddress)
                        {
                            host.PrivateUrl = privateAddress;
                            hostChanged     = true;
                        }

                        if (hostChanged == true)
                        {
                            hostDomain.Commit(host);
                        }
                    }
                }
            }

            if (master == true)
            {
                // Register the ProvisionUser Provider.
                ProvisionService.RegisterProvider(new LoadBalanceProvisionUserProvider());
                //ProvisionService.RegisterProvider( new MasterHostProvisionProvider() );
            }
            else
            {
                // Now start the sync process for the domain.
                Thread syncThread = new Thread(new ThreadStart(SyncDomain));
                syncThread.IsBackground = true;
                syncThread.Name         = "Domain Sync Thread";
                syncThread.Start();
            }
        }