Пример #1
0
        public static SqlDatabase GetSqlDatabase(int itemId)
        {
            // load meta item
            SqlDatabase item = (SqlDatabase)PackageController.GetPackageItem(itemId);

            // load service item
            DatabaseServer sql      = GetDatabaseServer(item.ServiceId);
            SqlDatabase    database = sql.GetDatabase(item.Name);

            if (database == null)
            {
                return(item);
            }

            // add common properties
            database.Id        = item.Id;
            database.PackageId = item.PackageId;
            database.ServiceId = item.ServiceId;
            database.GroupName = item.GroupName;

            StringDictionary settings = ServerController.GetServiceSettings(item.ServiceId);


            if (settings["InternalAddress"] != null)
            {
                database.InternalServerName = settings["InternalAddress"];
            }
            if (settings["ExternalAddress"] != null)
            {
                database.ExternalServerName = settings["ExternalAddress"];
            }

            return(database);
        }
        public int BackupItem(string tempFolder, XmlWriter writer, ServiceProviderItem item, ResourceGroupInfo group)
        {
            if (item is SqlDatabase)
            {
                // backup database
                DatabaseServer sql = GetDatabaseServer(item.ServiceId);

                string backupName       = String.Format("DatabaseBackup_{0}.zip", item.Id);
                string remoteBackupFile = sql.BackupDatabase(item.Name, backupName, true);

                // download remote backup
                string localBackupPath = Path.Combine(tempFolder, backupName);

                byte[]     buffer = null;
                FileStream stream = new FileStream(localBackupPath, FileMode.Create, FileAccess.Write);

                int  offset = 0;
                long length = 0;
                do
                {
                    // read remote content
                    buffer = sql.GetTempFileBinaryChunk(remoteBackupFile, offset, FILE_BUFFER_LENGTH);

                    // write remote content
                    stream.Write(buffer, 0, buffer.Length);

                    length += buffer.Length;
                    offset += FILE_BUFFER_LENGTH;
                }while (buffer.Length == FILE_BUFFER_LENGTH);
                stream.Close();

                // add file pointer

                BackupController.WriteFileElement(writer, "DatabaseBackup", backupName, length);

                // store meta item
                SqlDatabase   database   = sql.GetDatabase(item.Name);
                XmlSerializer serializer = new XmlSerializer(typeof(SqlDatabase));
                serializer.Serialize(writer, database);
            }
            else if (item is SqlUser)
            {
                // backup user
                DatabaseServer sql = GetDatabaseServer(item.ServiceId);

                SqlUser userItem = item as SqlUser;

                // store user info
                SqlUser user = sql.GetUser(item.Name, GetSqlDatabasesArray(item.PackageId, item.GroupName));
                user.Password = userItem.Password;

                XmlSerializer serializer = new XmlSerializer(typeof(SqlUser));
                serializer.Serialize(writer, user);
            }

            return(0);
        }
        public static SqlDatabase GetSqlDatabase(int itemId)
        {
            // load meta item
            SqlDatabase item = (SqlDatabase)PackageController.GetPackageItem(itemId);

            // load service item
            DatabaseServer sql      = GetDatabaseServer(item.ServiceId);
            SqlDatabase    database = sql.GetDatabase(item.Name);

            if (database == null)
            {
                return(item);
            }

            // add common properties
            database.Id        = item.Id;
            database.PackageId = item.PackageId;
            database.ServiceId = item.ServiceId;
            database.GroupName = item.GroupName;

            return(database);
        }