Esempio n. 1
0
        public void OpenDatabase(bool readOnly)
        {
            System.Diagnostics.Debug.Assert(dda == null, "The database is already open");

            dda = VistaDBEngine.Connections.OpenDDA();
            db = dda.OpenDatabase(Path.Combine(basePath, "game.vdb3"),
              readOnly ? VistaDBDatabaseOpenMode.NonexclusiveReadOnly : VistaDBDatabaseOpenMode.ExclusiveReadWrite, null);
            packTable = db.OpenTable("Pack", false, readOnly);
            markerTable = db.OpenTable("Marker", false, readOnly);
            cardTable = db.OpenTable("Card", false, readOnly);
            cardModelCache = new Dictionary<Guid, CardModel>();
            setCache = new Dictionary<Guid, Set>();
        }
Esempio n. 2
0
        /// <summary>
        /// Turns off auto record identity generation so the record id from the master database can be used.
        /// </summary>
        /// <param name="tableName">SQL table name</param>
        /// <param name="columnName">the identity column</param>
        /// <param name="enable"></param>
        public void SetIdentityInsert(string tableName, string columnName, bool enable)
        {
            // VistaDB DDA code
            IVistaDBTable tbl = null;

            try
            {
                IVistaDBDDA DDAObj      = VistaDBEngine.Connections.OpenDDA();
                string      vistaDbPath = (string)AppDomain.CurrentDomain.GetData("DataDirectory");
                Debug.WriteLine("FormsSql.SetIdentityInsert VistaDbPath: " + vistaDbPath);
                // IVistaDBDatabase db = DDAObj.OpenDatabase(System.AppDomain.CurrentDomain.BaseDirectory + "App_Data\\forms.vdb5", VistaDB.VistaDBDatabaseOpenMode.NonexclusiveReadWrite, "aj80995");
                IVistaDBDatabase db = DDAObj.OpenDatabase(vistaDbPath + @"\forms.vdb5", VistaDB.VistaDBDatabaseOpenMode.NonexclusiveReadWrite, "P@ssword1");

                tbl = db.OpenTable(tableName, false, false);
            }
            catch (Exception xcptn)
            {
                Debug.WriteLine("FormsSql.SetIdentityInsert Exception: " + xcptn.Message);
                throw xcptn;
            }

            // table1s.AddColumn("ID", VistaDBType.Int);
            // table1s.DefineColumnAttributes("ID", false, false, false, false, null, null);
            // table1s.AddColumn("COLINT", VistaDBType.Int);
            // table1s.DefineColumnAttributes("COLINT", false, false, false, false, null, null);

            if (tbl.EnforceIdentities)
            {
                if (enable)
                {
                    tbl.DropIdentity(columnName);
                }
                else
                {
                    if (tableName == "def_FormResults")
                    {
                        int min  = getMin(columnName, tableName);
                        int next = min - 1;
                        tbl.CreateIdentity(columnName, next.ToString(), "-1");
                    }
                    else
                    {
                        int max  = getMax(columnName, tableName);
                        int next = max + 1;
                        tbl.CreateIdentity(columnName, next.ToString(), "1");
                    }
                }
            }
            else
            {
                if (!enable)
                {
                    if (tableName == "def_FormResults")
                    {
                        int min  = getMin(columnName, tableName);
                        int next = min - 1;
                        tbl.CreateIdentity(columnName, next.ToString(), "-1");
                    }
                    else
                    {
                        int max  = getMax(columnName, tableName);
                        int next = max + 1;
                        tbl.CreateIdentity(columnName, next.ToString(), "1");
                    }
                }
            }
            // tbl.CreateIndex("Primary", "ID", true, true);
            // tbl.CreateIndex("idxDate", "COLDATETIME", false, false);

            tbl.Close();
            tbl.Dispose();
            tbl = null;
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a page of errors from the databse in descending order
        /// of logged time.
        /// </summary>

        public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null);
            }

            if (pageSize < 0)
            {
                throw new ArgumentOutOfRangeException("pageSize", pageSize, null);
            }

            VistaDBConnectionStringBuilder builder = new VistaDBConnectionStringBuilder(_connectionString);


            // Use the VistaDB Direct Data Access objects
            IVistaDBDDA ddaObjects = VistaDBEngine.Connections.OpenDDA();
            // Create a connection object to a VistaDB database
            IVistaDBDatabase vistaDB = ddaObjects.OpenDatabase(_databasePath, builder.OpenMode, builder.Password);
            // Open the table
            IVistaDBTable elmahTable = vistaDB.OpenTable("ELMAH_Error", false, true);

            elmahTable.ActiveIndex = "IX_ELMAH_Error_App_Time_Id";

            if (errorEntryList != null)
            {
                if (!elmahTable.EndOfTable)
                {
                    // move to the correct record
                    elmahTable.First();
                    elmahTable.MoveBy(pageIndex * pageSize);

                    int rowsProcessed = 0;

                    // Traverse the table to get the records we want
                    while (!elmahTable.EndOfTable && rowsProcessed < pageSize)
                    {
                        rowsProcessed++;

                        string id    = Convert.ToString(elmahTable.Get("ErrorId").Value, CultureInfo.InvariantCulture);
                        Error  error = new Error();

                        error.ApplicationName = (string)elmahTable.Get("Application").Value;
                        error.HostName        = (string)elmahTable.Get("Host").Value;
                        error.Type            = (string)elmahTable.Get("Type").Value;
                        error.Source          = (string)elmahTable.Get("Source").Value;
                        error.Message         = (string)elmahTable.Get("Message").Value;
                        error.User            = (string)elmahTable.Get("User").Value;
                        error.StatusCode      = (int)elmahTable.Get("StatusCode").Value;
                        error.Time            = ((DateTime)elmahTable.Get("TimeUtc").Value).ToLocalTime();

                        errorEntryList.Add(new ErrorLogEntry(this, id, error));

                        // move to the next record
                        elmahTable.Next();
                    }
                }
            }

            return(Convert.ToInt32(elmahTable.RowCount));
        }