Inheritance: BroadcastData
Example #1
0
 /// <summary>
 /// Returns true if the two databases are on the same server (do not have to be on the same database).  Also confirms that the access
 /// credentials are compatible.
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 protected bool AreOnSameServer(DiscoveredServer a, DiscoveredServer b)
 {
     return
         (string.Equals(a.Name, b.Name, StringComparison.CurrentCultureIgnoreCase) &&
          a.DatabaseType == b.DatabaseType &&
          a.ExplicitUsernameIfAny == b.ExplicitUsernameIfAny &&
          a.ExplicitPasswordIfAny == b.ExplicitPasswordIfAny);
 }
Example #2
0
        public void Test_ExpectDatabase(DatabaseType type, bool upperCase)
        {
            var helper = ImplementationManager.GetImplementation(type).GetServerHelper();
            var server = new DiscoveredServer(helper.GetConnectionStringBuilder("loco", "db", "frank", "kangaro"));
            var db     = server.ExpectDatabase("omg");

            Assert.AreEqual(upperCase?"OMG":"omg", db.GetRuntimeName());
        }
        public void EqualityTest_DiscoveredServer_AreNotEqual(string constr1, DatabaseType type1, string constr2, DatabaseType type2)
        {
            var s1 = new DiscoveredServer(constr1, type1);
            var s2 = new DiscoveredServer(constr2, type2);

            Assert.AreNotEqual(s1, s2);
            Assert.AreNotEqual(s1.ExpectDatabase("MyDb"), s2.ExpectDatabase("MyDb"));
        }
Example #4
0
        public DatabaseTests()
        {
            var opts = new PlatformDatabaseCreationOptions()
            {
                ServerName = TestDatabaseSettings.ServerName,
                Prefix     = TestDatabaseNames.Prefix
            };


            RepositoryLocator = new PlatformDatabaseCreationRepositoryFinder(opts);


            Console.WriteLine("Expecting Unit Test Catalogue To Be At Server=" + CatalogueRepository.DiscoveredServer.Name + " Database=" + CatalogueRepository.DiscoveredServer.GetCurrentDatabase());
            Assert.IsTrue(CatalogueRepository.DiscoveredServer.Exists(), "Catalogue database does not exist, run 'rdmp.exe install ...' to create it (Ensure that servername and prefix in TestDatabases.txt match those you provide to CreateDatabases.exe e.g. 'rdmp.exe install localhost\\sqlexpress TEST_')");
            Console.WriteLine("Found Catalogue");

            Console.WriteLine("Expecting Unit Test Data Export To Be At Server=" + DataExportRepository.DiscoveredServer.Name + " Database= " + DataExportRepository.DiscoveredServer.GetCurrentDatabase());
            Assert.IsTrue(DataExportRepository.DiscoveredServer.Exists(), "Data Export database does not exist, run 'rdmp.exe install ...' to create it (Ensure that servername and prefix in TestDatabases.txt match those you provide to CreateDatabases.exe e.g. 'rdmp.exe install localhost\\sqlexpress TEST_')");
            Console.WriteLine("Found DataExport");

            Console.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            RunBlitzDatabases(RepositoryLocator);

            var defaults = CatalogueRepository.GetServerDefaults();

            DataQualityEngineConnectionString = CreateServerPointerInCatalogue(defaults, TestDatabaseNames.Prefix, PlatformDatabaseCreation.DefaultDQEDatabaseName, PermissableDefaults.DQE, new DataQualityEnginePatcher());
            UnitTestLoggingConnectionString   = CreateServerPointerInCatalogue(defaults, TestDatabaseNames.Prefix, PlatformDatabaseCreation.DefaultLoggingDatabaseName, PermissableDefaults.LiveLoggingServer_ID, new LoggingDatabasePatcher());
            DiscoveredServerICanCreateRandomDatabasesAndTablesOn = new DiscoveredServer(CreateServerPointerInCatalogue(defaults, TestDatabaseNames.Prefix, null, PermissableDefaults.RAWDataLoadServer, null));

            _discoveredSqlServer = new DiscoveredServer(
                new SqlConnectionStringBuilder()
            {
                DataSource         = TestDatabaseSettings.ServerName,
                IntegratedSecurity = true
            });

            if (TestDatabaseSettings.MySql != null)
            {
                var builder = new MySqlConnectionStringBuilder(TestDatabaseSettings.MySql);

                foreach (string k in builder.Keys)
                {
                    if (k == "server" || k == "database" || k == "user id" || k == "password")
                    {
                        continue;
                    }

                    new ConnectionStringKeyword(CatalogueRepository, DatabaseType.MySql, k, builder[k].ToString());
                }
                _discoveredMySqlServer = new DiscoveredServer(builder);
            }

            if (TestDatabaseSettings.Oracle != null)
            {
                _discoveredOracleServer = new DiscoveredServer(TestDatabaseSettings.Oracle, DatabaseType.Oracle);
            }
        }
        public void WorkedExampleTest()
        {
            //pick some tags that we are interested in (determines the table schema created)
            var toCreate = new ImageTableTemplate()
            {
                Columns = new[] {
                    new ImageColumnTemplate(DicomTag.SOPInstanceUID),
                    new ImageColumnTemplate(DicomTag.Modality)
                    {
                        AllowNulls = true
                    },
                    new ImageColumnTemplate(DicomTag.PatientID)
                    {
                        AllowNulls = true
                    }
                }
            };

            //load the Sql Server implementation of FAnsi
            ImplementationManager.Load <MicrosoftSQLImplementation>();

            //decide where you want to create the table
            var server = new DiscoveredServer(@"Server=localhost\sqlexpress;Database=mydb;Integrated Security=true;", FAnsi.DatabaseType.MicrosoftSQLServer);
            var db     = server.ExpectDatabase("test");

            //create the table
            var tbl = db.CreateTable("MyCoolTable", toCreate.GetColumns(FAnsi.DatabaseType.MicrosoftSQLServer));

            //add a column for where the image is on disk
            tbl.AddColumn("FileLocation", new DatabaseTypeRequest(typeof(string), 500), true, 500);

            //Create a DataTable in memory for the data we read from disk
            DataTable dt = new DataTable();

            dt.Columns.Add("SOPInstanceUID");
            dt.Columns.Add("Modality");
            dt.Columns.Add("PatientID");
            dt.Columns.Add("FileLocation");

            //Load some dicom files and copy tag data into DataTable (where tag exists)
            foreach (string file in Directory.EnumerateFiles(@"C:\temp\TestDicomFiles", "*.dcm", SearchOption.AllDirectories))
            {
                var dcm = DicomFile.Open(file);
                var ds  = dcm.Dataset;

                dt.Rows.Add(

                    DicomTypeTranslaterReader.GetCSharpValue(dcm.Dataset, DicomTag.SOPInstanceUID),
                    ds.Contains(DicomTag.Modality) ? DicomTypeTranslaterReader.GetCSharpValue(dcm.Dataset, DicomTag.Modality) : DBNull.Value,
                    ds.Contains(DicomTag.PatientID) ? DicomTypeTranslaterReader.GetCSharpValue(dcm.Dataset, DicomTag.PatientID) : DBNull.Value,
                    file);
            }

            //put the DataTable into the database
            using (var insert = tbl.BeginBulkInsert())
                insert.Upload(dt);
        }
Example #6
0
        public ANOTransformer(ANOTable anoTable, IDataLoadEventListener listener = null)
        {
            _externalDatabaseServer = anoTable.Server;

            _server = DataAccessPortal.GetInstance().ExpectServer(_externalDatabaseServer, DataAccessContext.DataLoad);

            _anoTable = anoTable;
            _listener = listener;
        }
        public SelfCertifyingDataAccessPoint(DiscoveredServer server)
        {
            Server       = server.Name;
            Database     = server.GetCurrentDatabase()?.GetRuntimeName();
            DatabaseType = server.DatabaseType;

            Username = server.ExplicitUsernameIfAny;
            Password = server.ExplicitPasswordIfAny;
        }
Example #8
0
        public void ServerHelper_GetCurrentDatabase_WhenNoneSpecified(DatabaseType type)
        {
            var helper  = ImplementationManager.GetImplementation(type).GetServerHelper();
            var builder = helper.GetConnectionStringBuilder("");
            var server  = new DiscoveredServer(builder);

            Assert.AreEqual(null, server.Name);
            Assert.AreEqual(null, server.GetCurrentDatabase());
        }
Example #9
0
 /// <summary>
 /// Runs the supplied SQL and puts it out to the file specified (in the outputDirectory), will deal with stripping separators etc automatically
 /// </summary>
 /// <param name="server"></param>
 /// <param name="sql">Some SQL you want to run (instead of a specific table)</param>
 /// <param name="outputName">The name of the csv file you would like to create in the outputDirectory.  Do not include.csv in your string it will be put on automatically</param>
 /// <param name="outputDirectory"></param>
 /// <param name="separator"></param>
 /// <param name="dateTimeFormat"></param>
 public ExtractTableVerbatim(DiscoveredServer server, string sql, string outputName, DirectoryInfo outputDirectory, string separator, string dateTimeFormat)
 {
     _specificSQL          = sql;
     _specificSQLTableName = outputName;
     _outputDirectory      = outputDirectory;
     _separator            = separator;
     _dateTimeFormat       = dateTimeFormat ?? GetDefaultDateTimeFormat();
     _server = server;
 }
Example #10
0
        /// <summary>
        /// Runs the DLE using a custom names for RAW/STAGING.  Pass in the load to execute and the files/directories to process
        /// in the batch.
        /// </summary>
        /// <param name="lmd"></param>
        /// <param name="payload"></param>
        /// <returns>The exit code of the data load after it completes</returns>
        private ExitCodeType RunDLE(LoadMetadata lmd, object payload)
        {
            var catalogueRepository = (CatalogueRepository)lmd.Repository;

            //ensures that RAW/STAGING always have unique names
            _configuration = new HICDatabaseConfiguration(lmd, _namer);
            _configuration.UpdateButDoNotDiff = new Regex("^MessageGuid");

            var logManager = catalogueRepository.GetDefaultLogManager();

            logManager.CreateNewLoggingTaskIfNotExists(lmd.GetDistinctLoggingTask());

            // Create the pipeline to pass into the DataLoadProcess object
            var dataLoadFactory = new HICDataLoadFactory(lmd, _configuration, new HICLoadConfigurationFlags(),
                                                         catalogueRepository, logManager);

            var stagingCreator = _namer as ICreateAndDestroyStagingDuringLoads;

            if (stagingCreator != null)
            {
                stagingCreator.CreateStaging(lmd.GetDistinctLiveDatabaseServer());
            }

            var listener = new NLogThrowerDataLoadEventListener(NLog.LogManager.GetCurrentClassLogger());

            IDataLoadExecution execution = dataLoadFactory.Create(listener);

            IExternalDatabaseServer raw = catalogueRepository.GetServerDefaults().GetDefaultFor(PermissableDefaults.RAWDataLoadServer);

            DiscoveredServer liveDb = lmd.GetDistinctLiveDatabaseServer();

            //do we want to try to cut down the time it takes to do RAW=>STAGING by using INSERT INTO  instead of running anonymisation/migration pipeline
            if (_useInsertIntoForRawMigration)
            {
                //if it is on the same server swap out the migration engine for INSERT INTO
                if (raw == null || (raw.Server != null && raw.Server.Equals(liveDb.Name) && raw.DatabaseType == liveDb.DatabaseType))
                {
                    listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "SWAPPING RAW=>STAGING migration strategy to INSERT INTO"));
                    SwapMigrateRAWToStagingComponent(execution.Components);
                }
                else
                {
                    //Cannot use because different servers / DatabaseTypes.
                    listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Warning, "CANNOT SWAP RAW=>STAGING migration strategy to INSERT INTO because RAW is on '" + raw.Server + "' (" + raw.DatabaseType + ") and STAGING is on '" + liveDb.Name + "' (" + liveDb.DatabaseType + ")"));
                }
            }
            else
            {
                listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Flag is false for SWAP RAW=>STAGING migration strategy to INSERT INTO So won't do it"));
            }

            var procedure = new DataLoadProcess(_repositoryLocator, lmd, null, logManager, listener, execution, _configuration);

            ExitCodeType exitCode = procedure.Run(new GracefulCancellationToken(), payload);

            return(exitCode);
        }
Example #11
0
        /// <summary>
        /// Gets an empty database on the test server of the appropriate DBMS
        /// </summary>
        /// <param name="type">The DBMS you want a server of (a valid connection string must exist in TestDatabases.txt)</param>
        /// <param name="dbnName">null for default test database name (recommended unless you are testing moving data from one database to another on the same test server)</param>
        /// <param name="server"></param>
        /// <param name="database"></param>
        /// <param name="justDropTablesIfPossible">Determines behaviour when the test database already exists.  False to drop and recreate it. True to just drop tables (faster)</param>
        /// <returns></returns>
        protected DiscoveredDatabase GetCleanedServer(DatabaseType type, string dbnName, out DiscoveredServer server, out DiscoveredDatabase database, bool justDropTablesIfPossible = false)
        {
            switch (type)
            {
            case DatabaseType.MicrosoftSQLServer:
                server = new DiscoveredServer(DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Builder);
                break;

            case DatabaseType.MySql:
                server = _discoveredMySqlServer == null ? null : new DiscoveredServer(_discoveredMySqlServer.Builder);
                break;

            case DatabaseType.Oracle:
                server = _discoveredOracleServer == null ? null : new DiscoveredServer(_discoveredOracleServer.Builder);
                break;

            default:
                throw new ArgumentOutOfRangeException("type");
            }

            if (server == null)
            {
                Assert.Inconclusive();
            }

            //the microsoft one should exist! others are optional
            if (!server.Exists() && type != DatabaseType.MicrosoftSQLServer)
            {
                Assert.Inconclusive();
            }

            server.TestConnection();

            database = server.ExpectDatabase(dbnName);

            if (justDropTablesIfPossible && database.Exists())
            {
                foreach (var t in database.DiscoverTables(true))
                {
                    t.Drop();
                }
                foreach (var t in database.DiscoverTableValuedFunctions())
                {
                    t.Drop();
                }
            }
            else
            {
                database.Create(true);
            }

            server.ChangeDatabase(dbnName);

            Assert.IsTrue(database.Exists());

            return(database);
        }
Example #12
0
        private void SetTargetServer(DiscoveredServer target, string reason)
        {
            if (TargetServer != null)
            {
                throw new InvalidOperationException("You are only supposed to pick a target server once");
            }

            TargetServer = target;
            _log.AppendLine($"Picked TargetServer as {target} because {reason}");
        }
Example #13
0
        public TriggerImplementer(DiscoveredTable table, bool createDataLoadRunIDAlso = true)
        {
            _server       = table.Database.Server;
            _table        = table;
            _archiveTable = _table.Database.ExpectTable(table.GetRuntimeName() + "_Archive", table.Schema);
            _columns      = table.DiscoverColumns();
            _primaryKeys  = _columns.Where(c => c.IsPrimaryKey).ToArray();

            _createDataLoadRunIdAlso = createDataLoadRunIDAlso;
        }
        public override void LoadExtraText(string s)
        {
            _arguments = Helper.LoadDictionaryFromString(s);

            DatabaseType = (DatabaseType)Enum.Parse(typeof(DatabaseType), _arguments[DatabaseTypeKey]);

            var server = new DiscoveredServer(Server, Database, DatabaseType, null, null);

            _table = server.ExpectDatabase(Database).ExpectTable(_arguments[TableKey]);
        }
Example #15
0
        private void CleanupTruncateCommand()
        {
            var lds = new DiscoveredServer(UnitTestLoggingConnectionString);

            using (var con = lds.GetConnection())
            {
                con.Open();
                lds.GetCommand("DELETE FROM DataLoadTask where LOWER(dataSetID) like '%truncate%'", con).ExecuteNonQuery();
                lds.GetCommand("DELETE FROM DataSet where LOWER(dataSetID) like '%truncate%'", con).ExecuteNonQuery();
            }
        }
Example #16
0
        private void SetServer()
        {
            if (_server == null)
            {
                //it's a legit dataset being extracted?
                _server = Request.Catalogue.GetDistinctLiveDatabaseServer(DataAccessContext.DataExport, false);

                //expect a database called called tempdb
                _tempDb = _server.ExpectDatabase(TemporaryDatabaseName);
            }
        }
Example #17
0
 public CohortIdentificationTaskExecution(IDataAccessPoint cacheServerIfAny, string countSQL, string cumulativeSQL, CancellationTokenSource cancellationTokenSource, int subQueries, int subqueriesCached, bool isResultsForRootContainer, DiscoveredServer target)
 {
     _cacheServerIfAny        = cacheServerIfAny;
     SubQueries               = subQueries;
     SubqueriesCached         = subqueriesCached;
     CountSQL                 = countSQL;
     CumulativeSQL            = cumulativeSQL;
     _cancellationTokenSource = cancellationTokenSource;
     _target = target;
     IsResultsForRootContainer = isResultsForRootContainer;
 }
Example #18
0
        public override void Setup(IMappingTableOptions options)
        {
            _options   = options;
            _swapTable = options.Discover();
            _server    = _swapTable.Database.Server;

            if (!_swapTable.Exists())
            {
                throw new ArgumentException($"Swap table '{_swapTable.GetFullyQualifiedName()}' did not exist on server '{_server}'");
            }
        }
        private void StartAuditIfExists(string tableName)
        {
            if (LoggingServer != null)
            {
                _loggingDatabaseSettings = DataAccessPortal.GetInstance().ExpectServer(LoggingServer, DataAccessContext.Logging);
                var logManager = new LogManager(_loggingDatabaseSettings);
                logManager.CreateNewLoggingTaskIfNotExists("Internal");

                _dataLoadInfo            = (DataLoadInfo)logManager.CreateDataLoadInfo("Internal", GetType().Name, "Loading table " + tableName, "", false);
                _loggingDatabaseListener = new ToLoggingDatabaseDataLoadEventListener(logManager, _dataLoadInfo);
            }
        }
Example #20
0
        public void Example_TableCreation()
        {
            //Load implementation assemblies that are relevant to your application
            ImplementationManager.Load(
                typeof(FAnsi.Implementations.MicrosoftSQL.MicrosoftSQLImplementation).Assembly,
                typeof(FAnsi.Implementations.Oracle.OracleImplementation).Assembly,
                typeof(FAnsi.Implementations.MySql.MySqlImplementation).Assembly);

            //Create some test data
            DataTable dt = new DataTable();

            dt.Columns.Add("Name");
            dt.Columns.Add("DateOfBirth");

            dt.Rows.Add("Frank", "2001-01-01");
            dt.Rows.Add("Dave", "2001-01-01");

            //Create a server object
            //var server = new DiscoveredServer(@"server=localhost\sqlexpress;Trusted_Connection=True;", DatabaseType.MicrosoftSQLServer);
            var server = new DiscoveredServer(@"Server=localhost;Uid=root;Pwd=zombie;SSL-Mode=None", DatabaseType.MySql);

            //Find the database
            var database = server.ExpectDatabase("FAnsiTests");

            //Or create it
            if (!database.Exists())
            {
                database.Create();
            }

            //Create a table that can store the data in dt
            var table = database.CreateTable("MyTable", dt);

            //Table has 2 rows in it
            Console.WriteLine("Table {0} has {1} rows", table.GetFullyQualifiedName(), table.GetRowCount());
            Console.WriteLine("Column Name is of type {0}", table.DiscoverColumn("Name").DataType.SQLType);
            Console.WriteLine("Column DateOfBirth is of type {0}", table.DiscoverColumn("DateOfBirth").DataType.SQLType);

            using (DbConnection con = server.GetConnection())
            {
                con.Open();
                DbCommand    cmd = server.GetCommand("Select * from " + table.GetFullyQualifiedName(), con);
                DbDataReader r   = cmd.ExecuteReader();

                while (r.Read())
                {
                    Console.WriteLine(string.Join(",", r["Name"], r["DateOfBirth"]));
                }
            }

            //Drop the table afterwards
            table.Drop();
        }
Example #21
0
        private int GetDataTaskId(string dataTask, DiscoveredServer server, DbConnection con)
        {
            using (var cmd = server.GetCommand("SELECT ID FROM DataLoadTask WHERE name = @name", con))
            {
                var p = cmd.CreateParameter();
                p.ParameterName = "@name";
                p.Value         = dataTask;
                cmd.Parameters.Add(p);

                return(Convert.ToInt32(cmd.ExecuteScalar()));
            }
        }
Example #22
0
        public void TestLastLoadStatusassemblage_MostRecent()
        {
            var        server = new DiscoveredServer(UnitTestLoggingConnectionString);
            LogManager lm     = new LogManager(server);

            var mostRecent = lm.GetArchivalDataLoadInfos(_dataLoadTaskName).First();
            var all        = lm.GetArchivalDataLoadInfos(_dataLoadTaskName).ToArray();

            all = all.OrderByDescending(d => d.StartTime).ToArray();

            Assert.AreEqual(mostRecent.StartTime, all[0].StartTime);
        }
Example #23
0
        /// <summary>
        /// Update the database <paramref name="server"/> to redact the <paramref name="failure"/>.
        /// </summary>
        /// <param name="server">Where to connect to get the data, can be null if <see cref="RulesOnly"/> is true</param>
        /// <param name="failure">The failure to redact/create a rule for</param>
        /// <param name="usingRule">Pass null to create a new rule or give value to reuse an existing rule</param>
        public void Update(DiscoveredServer server, Failure failure, IsIdentifiableRule usingRule)
        {
            //theres no rule yet so create one (and add to RedList.yaml)
            if (usingRule == null)
            {
                usingRule = Add(failure, RuleAction.Report);
            }

            //if we are running in rules only mode we don't need to also update the database
            if (RulesOnly)
            {
                return;
            }

            var syntax = server.GetQuerySyntaxHelper();

            //the fully specified name e.g. [mydb]..[mytbl]
            string tableName = failure.Resource;

            var tokens = tableName.Split('.', StringSplitOptions.RemoveEmptyEntries);

            var db = tokens.First();

            tableName = tokens.Last();

            if (string.IsNullOrWhiteSpace(db) || string.IsNullOrWhiteSpace(tableName) || string.Equals(db, tableName))
            {
                throw new NotSupportedException($"Could not understand table name {failure.Resource}, maybe it is not full specified with a valid database and table name?");
            }

            db        = syntax.GetRuntimeName(db);
            tableName = syntax.GetRuntimeName(tableName);

            DiscoveredTable table = server.ExpectDatabase(db).ExpectTable(tableName);

            //if we've never seen this table before
            if (!_primaryKeys.ContainsKey(table))
            {
                var pk = table.DiscoverColumns().SingleOrDefault(k => k.IsPrimaryKey);
                _primaryKeys.Add(table, pk);
            }

            using (var con = server.GetConnection())
            {
                con.Open();

                foreach (var sql in UpdateStrategy.GetUpdateSql(table, _primaryKeys, failure, usingRule))
                {
                    var cmd = server.GetCommand(sql, con);
                    cmd.ExecuteNonQuery();
                }
            }
        }
Example #24
0
    public override void OnReceivedBroadcast(string aFromAddress, string aRawData)
    {
        BroadcastData data = new BroadcastData();

        data.FromString(aRawData);

        // DEBUG LOG
        broadcastLogCounter += 1;
        receivedBroadcastLog.Enqueue(broadcastLogTokens[broadcastLogCounter % broadcastLogTokens.Length] + " " + aRawData);
        if (receivedBroadcastLog.Count > maxLogLines)
        {
            receivedBroadcastLog.Dequeue();
        }

        var server = new DiscoveredServer(data);

        server.rawData   = aRawData;
        server.ipAddress = aFromAddress;
        server.timestamp = Time.time;

        bool newData = false;

        if (!discoveredServers.ContainsKey(aFromAddress))
        {
            // New server
            discoveredServers.Add(aFromAddress, server);
            Debug.Log(server.ipAddress);
            newData = true;
        }
        else
        {
            if (discoveredServers[aFromAddress].rawData != aRawData)
            {
                // Old server with new info
                discoveredServers[aFromAddress] = server;
                newData = true;
            }
            else
            {
                // Just update the timestamp
                discoveredServers[aFromAddress].timestamp = Time.time;
                newData = false;
            }
        }

        networkManager.OnReceivedBroadcast(aFromAddress, aRawData);

        if (newData)
        {
            networkManager.OnDiscoveredServer(server);
        }
    }
Example #25
0
        public ExtractTableVerbatim(DiscoveredServer server, string[] tableNames, DirectoryInfo outputDirectory, string separator, string dateTimeFormat)
        {
            if (tableNames.Length == 0)
            {
                throw new ArgumentException("You must select at least one table to extract");
            }

            _tableNames      = tableNames;
            _outputDirectory = outputDirectory;
            _separator       = separator;
            _dateTimeFormat  = dateTimeFormat ?? GetDefaultDateTimeFormat();
            _server          = server;
        }
Example #26
0
        private IEnumerable <string> GetForeignKeys(DiscoveredServer server)
        {
            using (var con = server.GetConnection())
            {
                con.Open();
                var r = server.GetCommand(@"select name from sys.foreign_keys where delete_referential_action = 0", con).ExecuteReader();

                while (r.Read())
                {
                    yield return((string)r["name"]);
                }
            }
        }
        public void EqualityTest_DiscoveredTable_AreNotEqual(DatabaseType type1, string constr1, string dbname1, string tablename1, string schema1, DatabaseType type2, string constr2, string dbname2, string tablename2, string schema2)
        {
            var s1 = new DiscoveredServer(constr1, type1);
            var s2 = new DiscoveredServer(constr2, type2);

            var db1 = s1.ExpectDatabase(dbname1);
            var db2 = s2.ExpectDatabase(dbname2);

            var t1 = db1.ExpectTable(tablename1, schema1);
            var t2 = db2.ExpectTable(tablename2, schema2);

            Assert.AreNotEqual(t1, t2);
        }
        private void HandlePublishedSingletons(LightweightRpcFrame responseFrame)
        {
            var response = ServiceDiscoveryOperations.DiscoverySerializer.Deserialize <RpcPublishedSingletonsResponse>(responseFrame.Payload);

            if (response != null && response.ClientId == this.clientId && response.ConnectionInfo != null)
            {
                bool isNewServer = false;
                bool changed     = false;

                DiscoveredServer?discoveredServer;
                ImmutableArray <DiscoveredService> oldServices = ImmutableArray <DiscoveredService> .Empty;
                lock (this.syncRoot)
                {
                    if (!this.discoveredServers.TryGetValue(response.ConnectionInfo.ServerId, out discoveredServer))
                    {
                        discoveredServer = new DiscoveredServer(response.ConnectionInfo);
                        this.discoveredServers.Add(response.ConnectionInfo.ServerId, discoveredServer);
                        changed = isNewServer = true;
                    }


                    if (responseFrame.MessageNumber > discoveredServer.RequestNoLastFound)
                    {
                        oldServices = discoveredServer.Services;
                        if (discoveredServer.UpdateServicesLocked(response.Services, responseFrame.MessageNumber))
                        {
                            changed = true;
                        }
                    }

                    if (changed)
                    {
                        this.discoveredServices = null;
                    }
                }

                if (isNewServer)
                {
                    this.RaiseEvent(this.ServerDiscovered, new DiscoveredServerEventArgs(discoveredServer.ConnectionInfo));
                }

                this.UpdateDiscoveredServices(discoveredServer.ConnectionInfo, discoveredServer.Services, oldServices);

                if (changed)
                {
                    this.RaiseEvent(this.ServicesChanged, EventArgs.Empty);
                }
            }
        }
Example #29
0
        public void CreateStaging(DiscoveredServer liveServer)
        {
            _stagingDatabase = liveServer.ExpectDatabase(GetDatabaseName(null, LoadBubble.Staging));

            if (!_stagingDatabase.Exists())
            {
                _stagingDatabase.Create();
            }

            //get rid of any old data from previous load
            foreach (var t in _stagingDatabase.DiscoverTables(false))
            {
                t.Truncate();
            }
        }
        public void EqualityTest_DiscoveredTable_AreEqual(string table1, string schema1, string table2, string schema2)
        {
            var s = new DiscoveredServer("Server=fish", DatabaseType.MicrosoftSQLServer);

            var db  = s.ExpectDatabase("MyDb");
            var db2 = s.ExpectDatabase("MyDb");

            Assert.IsFalse(ReferenceEquals(db, db2));
            Assert.IsTrue(db.Equals(db2));

            var t1 = db.ExpectTable(table1, schema1);
            var t2 = db2.ExpectTable(table2, schema2);

            Assert.AreEqual(t1, t2);
            Assert.AreEqual(t1.GetHashCode(), t2.GetHashCode());
        }
    public override void OnReceivedBroadcast(string aFromAddress, string aRawData)
    {
        BroadcastData data = new BroadcastData();
        data.FromString(aRawData);

        // DEBUG LOG
        broadcastLogCounter += 1;
        receivedBroadcastLog.Enqueue(broadcastLogTokens[broadcastLogCounter % broadcastLogTokens.Length] + " " + aRawData);
        if (receivedBroadcastLog.Count > maxLogLines) {
            receivedBroadcastLog.Dequeue();
        }

        var server = new DiscoveredServer(data);
        server.rawData = aRawData;
        server.ipAddress = aFromAddress;
        server.timestamp = Time.time;

        bool newData = false;
        if (!discoveredServers.ContainsKey(aFromAddress))
        {
            // New server
            discoveredServers.Add(aFromAddress, server);
            newData = true;
        }
        else
        {
            if (discoveredServers[aFromAddress].rawData != aRawData)
            {
                // Old server with new info
                discoveredServers[aFromAddress] = server;
                newData = true;
            }
            else
            {
                // Just update the timestamp
                discoveredServers[aFromAddress].timestamp = Time.time;
                newData = false;
            }
        }

        networkManager.OnReceivedBroadcast(aFromAddress, aRawData);

        if (newData)
        {
            networkManager.OnDiscoveredServer(server);
        }
    }
 public virtual void OnDiscoveredServer(DiscoveredServer aServer)
 {
     // Override
 }
    public void OnDiscoveredServer(DiscoveredServer aServer)
    {
        if (verboseLogging) {
            Debug.Log("#CaptainsMess# Discovered " + aServer.rawData);
        }

        if (discoveryServer.isOpen) {
            Debug.Log("#CaptainsMess# Already hosting a server, ignoring " + aServer.rawData);
            return;
        }

        SendDiscoveredServerMessage(aServer);

        bool shouldJoin = false;
        bool isMe = (aServer.peerId == peerId);
        if (!isMe)
        {
            if (aServer.isOpen && aServer.numPlayers < maxPlayers)
            {
                if (aServer.privateTeamKey == discoveryServer.privateTeamKey)
                {
                    if (aServer.numPlayers > 0) {
                        shouldJoin = true; // Pick the first server that already has players
                    } else if (BestHostingCandidate() == aServer.peerId) {
                        shouldJoin = true;
                    }
                }
            }
        }

        if (shouldJoin)
        {
            if (verboseLogging) {
                Debug.Log("#CaptainsMess# Should join!");
            }

            // We found something! Cancel hosting...
            CancelInvoke(maybeStartHostingFunction);

            if (client == null)
            {
                if (discoveryClient.autoJoin)
                {
                    JoinServer(aServer.ipAddress, networkPort);
                }
                else
                {
                    if (verboseLogging) {
                        Debug.Log("#CaptainsMess# JOIN CANCELED: Auto join disabled.");
                    }
                }
            }
            else
            {
                if (verboseLogging) {
                    Debug.Log("#CaptainsMess# JOIN CANCELED: Already have client.");
                }
            }
        }
        else
        {
            if (verboseLogging) {
                Debug.Log("#CaptainsMess# Should NOT join.");
            }
        }
    }
 public void SendDiscoveredServerMessage(DiscoveredServer aServer)
 {
     listener.OnDiscoveredServer(aServer);
 }