void IdeMailBox::onDeleteAllMessages(IEvent *e) { HtmlEvent *htmlEvent = dynamic_cast<HtmlEvent *>(e); if(htmlEvent == nullptr) return; MessageFolder folder = conversions::from_utf16<MessageFolder>(htmlEvent->get(0)); if(folder != messageFolderNone) { switch(folder) { case messageFolderInbox: case messageFolderSentItems: // Sposta tutti i messaggi dalla posta in arrivo al cestino getPortal()->getMessenger()->moveFolderMessages(getPage()->getDatabase(), getSessionAccount(), messageFolderInbox, messageFolderTrash); break; case messageFolderTrash: // Elimina tutti i messaggi nel cestino getPortal()->getMessenger()->deleteFolderMessages(getPage()->getDatabase(), getSessionAccount(), messageFolderTrash); break; default: OS_ASSERTFALSE(); break; } // Effettua il render del folder _renderFolder(folder); } }
IJob::JobStatus PortalsOptimizerJob::run() { shared_ptr<Portal> portal = getPortal(); if(portal == nullptr) return jobComplete; NotificationsManager::instance()->notify(_S("Optimization of '") + portal->getPovName() + _S("' started.")); // Lucene RealtimeStatsScopeTimer rssLucene(_S("Activity"), _S("Lucene optimizer")); portal->getSnapshotManager()->optimizeSearchIndexes(); rssLucene.stop(); shared_ptr<PortalsTransaction> databaseWork = portal->startTransaction(true); shared_ptr<IPortalDatabase> database = databaseWork->getDatabase(); // DB Analysis RealtimeStatsScopeTimer rssAnalysis(_S("Activity"), _S("Database analysis")); database->beginTransaction(); database->getConnection()->analyze(); database->commit(); rssAnalysis.stop(); // End portal->getOptions()->setLastOptimizationDate(DateTime::now()); NotificationsManager::instance()->notify(_S("Optimization of '") + portal->getPovName() + _S("' completed.")); return jobComplete; }
IJob::JobStatus PortalsExporterJob::run() { shared_ptr<Portal> portal = getPortal(); if(portal == nullptr) return jobComplete; NotificationsManager::instance()->notify(_S("Exporting of '") + portal->getName() + _S("' started.")); m_file.reset(); shared_ptr<TemporaryFile> file = Options::instance()->createTemporaryFile(); if(file == nullptr) { OS_LOG_ERROR("Cannot create temporary file for export"); return jobComplete; } m_serializer->setStopped(false); if(m_serializer->exportStream(portal, file, m_format)) { file->close(); m_file = file; } NotificationsManager::instance()->notify(_S("Exporting of '") + portal->getName() + _S("' completed.")); return jobComplete; }
void GameCube::draw() { for (int i = 0; i < NUM_SIDES; i++) { Portal &p = getPortal(i); p.draw(vid); } hilighter.draw(); }
String CommentableObjectViewer::getCreatePostLink(const EntityID "ed_object) { ordered_map<std::wstring, std::wstring> params; params.set(OS_URL_PARAM_ACTION, conversions::to_wstring<uint32>(actCreatePost)); if(quoted_object.empty() == false) params.set(OS_URL_PARAM_QUOTE, quoted_object.toWide()); return getPortal()->getViewObjectLink(getEntityID(), params); }
String CommentableObjectViewer::getEditObjectLink(shared_ptr<ObjectsIRevisionable> object) const { if(object == nullptr) { OS_ASSERTFALSE(); return String::EMPTY; } return portal::Edit::getUrl(getPortal(), object->getEntityID(), portal::Edit::acAddRevision); }
void GameCube::animate(float timeStep) { for (int t = portalTicker.tick(timeStep); t; t--) for (int i = 0; i < NUM_SIDES; i++) { Portal &p = getPortal(i); p.animate(); } hilighter.animate(timeStep); }
String CommentableObjectViewer::localizePost(const EntityID &id) { String href; shared_ptr<EntitiesEntity> entity = getPortal()->getEntity(getDatabase(), id); if(entity != nullptr) { shared_ptr<ObjectsPost> post = objects_post_cast(entity->getCurrent()); if(post != nullptr) { shared_ptr<EntitiesEntity> parent_entity = getPortal()->getEntity(getDatabase(), post->getParent()); if(parent_entity != nullptr) { shared_ptr<DbSqlSelect> select; // Ottiene la select per l'estrazione dei posts parent_entity->getChildsStatement(getDatabase(), portalObjectTypePost, RangeUint32::EMPTY, true, false, false, select); // Aggiunge come limite la data del post specificato per localizzarne l'indice select->where.add(DbSqlField(DBTABLES::SNAPSHOT_OBJECTS::SUBMIT_DATE, DBTABLES::SNAPSHOT_OBJECTS_TABLE), Convert::toSQL(entity->getEntitySubmitDate()), DbSqlCondition::cfMinor | DbSqlCondition::cfEqual | DbSqlCondition::cfAnd); ordered_map<std::wstring, std::wstring> params; // Calcola il numero di posts fino a quello specificato uint32 count = parent_entity->getChildsCount(getDatabase(), portalObjectTypePost, select); if(count > 0) { // Ottiene il numero uint32 pager_items = getSkin()->getPagerItems(); // Calcola l'offset per la visualizzazione del post uint32 offset = static_cast<uint32>(count/pager_items)*pager_items; if(offset > 0) params.set(OS_URL_PARAM_OFFSET, conversions::to_wstring(offset)); } // Genera un link al padre con ancora l'id del post href = HttpParser::createAnchor(parent_entity->getViewLink(getPortal(), params), entity->getEntityID().getString()); } } } return href; }
shared_ptr<Portal> PortalsSystem::ensurePortal(shared_ptr<OsirisLink> link, const String &password) { if(link == nullptr) { OS_ASSERTFALSE(); return nullptr; } OS_LOCK(m_cs); shared_ptr<Portal> portal = getPortal(link->getPortal(), link->getPov()); if(portal != nullptr) return portal; shared_ptr<IDbDriver> defaultDriver = DatabasesSystem::instance()->getDefaultDriver(); if(defaultDriver == nullptr) { OS_LOG_ERROR("Invalid database driver"); return nullptr; } PortalID portalID = link->getPortal(); PovID povID = link->getPov(); String portalName = link->getName(); if(portalName.empty()) portalName = portalID.toUTF16(); //String portalDescription = link->getDescription(); shared_ptr<PortalOptions> portalOptions(OS_NEW PortalOptions()); portalOptions->setName(portalName); //portalOptions->setDescription(portalDescription); portalOptions->setPortalID(portalID); portalOptions->setPovID(povID); portalOptions->setPassword(password); portalOptions->setDatabaseDriver(defaultDriver->getName()); portalOptions->setDatabaseOptions(defaultDriver->createOptions()); // VERYURGENT: le varie createPortal/subscribePortal dovrebbero restituire il riferimento al portale portal = subscribePortal(portalOptions); if(portal == nullptr) { OS_LOG_ERROR("Cannot create portal"); return nullptr; } //portal = getPortal(portalID, povID); //OS_ASSERT(portal != nullptr); return portal; }
void IdeMailBox::onReadAllMessages(IEvent *e) { HtmlEvent *htmlEvent = dynamic_cast<HtmlEvent *>(e); if(htmlEvent == nullptr) return; MessageFolder folder = conversions::from_utf16<MessageFolder>(htmlEvent->get(0)); if(folder != messageFolderNone) { // Marca tutti i messaggi del folder specificato come letti getPortal()->getMessenger()->changeMessagesStatus(getPage()->getDatabase(), getSessionAccount(), folder, messageStatusRead); // Effettua il render del folder _renderFolder(folder); } }
void IdeMailBox::onRestoreMessage(IEvent *e) { HtmlEvent *htmlEvent = dynamic_cast<HtmlEvent *>(e); if(htmlEvent == nullptr) return; ObjectID id = htmlEvent->get(0).to_ascii(); if(id.empty() == false) { // Elimina il messaggio getPortal()->getMessenger()->moveMessageToInbox(getPage()->getDatabase(), getSessionAccount(), id); // Mostra la posta in arrivo _renderFolder(messageFolderInbox); } }
void IdeMailBox::onDeleteMessage(IEvent *e) { HtmlEvent *htmlEvent = dynamic_cast<HtmlEvent *>(e); if(htmlEvent == nullptr) return; ObjectID id = htmlEvent->get(0).to_ascii(); if(id.empty() == false) { // Elimina il messaggio getPortal()->getMessenger()->moveMessageToTrash(getPage()->getDatabase(), getSessionAccount(), id); // Mostra la directory di riferimento _renderFolder(m_folder); } }
shared_ptr<IBackgroundJob::Details> PortalsOptimizerJob::getDetails() const { String jobName(Engine::instance()->getText("job.optimizer")); shared_ptr<Portal> portal = getPortal(); if(portal != nullptr) { jobName.append(" - "); jobName.append(portal->getPovName()); } shared_ptr<Details> details(OS_NEW Details(jobName.to_wide())); return details; }
String DocumentationViewer::getPageHref(uint32 offset) const { String href; shared_ptr<EntitiesEntity> entity = m_entity; if(entity != nullptr) { ordered_map<std::wstring, std::wstring> params; if(offset != 0) params.set(OS_URL_PARAM_OFFSET, conversions::to_wstring(offset)); href = entity->getViewLink(getPortal(), params); } return href; }
bool TeSQLite::getIndexesFromTable(const string& tableName, std::vector<TeDatabaseIndex>& vecIndexes) { TeDatabasePortal* portal = getPortal(); std::string sqlIndexes = "PRAGMA index_list(" + tableName + ");"; if(portal->query(sqlIndexes) == false) { delete portal; return false; } while(portal->fetchRow()) { TeDatabaseIndex dbIndex; dbIndex.setIndexName(portal->getData("name")); vecIndexes.push_back(dbIndex); } portal->freeResult(); for(unsigned int i = 0; i < vecIndexes.size(); ++i) { std::string sqlIndex = "PRAGMA index_info(" + vecIndexes[i].getIndexName() + ");"; if(portal->query(sqlIndex) == false) { delete portal; return false; } std::vector<std::string> vecColumns; while(portal->fetchRow()) { vecColumns.push_back(portal->getData("name")); } portal->freeResult(); vecIndexes[i].setColumns(vecColumns); } delete portal; return true; }
bool TeSQLite::tableExist(const string& table) { std::string sql = "SELECT tbl_name FROM sqlite_master"; sql += " WHERE upper(tbl_name) = upper('" + table + "')"; sql += " AND type = 'table'"; bool exists = false; TeDatabasePortal* portal = getPortal(); if(portal->query(sql) && portal->fetchRow()) { exists = true; } delete portal; return exists; }
PORTAL *dispPortalAdd( PORTAL_JUSTIFY just, // How to justify the text int ulRow, // upper left row where portal starts int ulCol, // upper left column where portal starts int width, // width of portal in columns int height, // height of portal in rows PORTAL_TYPE type, // TEXT or GRAPHIC const void *data, // text string or bitmap data. not 0 terminated FONT *font, // null for graphic data size_t length, // length of data int scroll, // boolean 1/0 = scroll/no scroll int scrollDelay) // delay in ms between column shifts { PORTAL *tmp = getPortal(); if(tmp == 0) { setError (EDISP_RANGE, "Out of portals in portalAdd()"); return 0; } tmp->just = just; tmp->type = type; tmp->upperLeftRow = ulRow; tmp->upperLeftCol = ulCol; tmp->width = width; tmp->height = height; tmp->scroll = scroll; tmp->scrollDelay = scrollDelay; tmp->content.text.font = font; if (type == PORTAL_TEXT) copyText (tmp, data, length); else if (type == PORTAL_GRAPHIC) copyGraphic (tmp, data, length); else { setError (EDISP_INVAL, "Invalid parameter passed to portalAdd()"); portals[tmp->id] = 0; return 0; } return tmp; }
void ObjectDetail::onLoad() { PageBase::onLoad(); // Ottiene l'id dell'utente richiesto EntityID id = getUrlID().to_ascii(); shared_ptr<XMLDocument> document(OS_NEW XMLDocument()); shared_ptr<XMLNode> nodeRoot = document->create(_S("object")); shared_ptr<EntitiesEntity> entity = getPortal()->getEntity(getDatabase(), id); if(entity != nullptr) { shared_ptr<XMLPortalExporter> exporter(OS_NEW XMLPortalExporter(nodeRoot, get_this_ptr<IPortalPage>(), XMLPortalExporter::emFull, true)); entity->exportXML(exporter); } String path = getSkin()->getTemplatePath(_S("object_detail.xsl")); shared_ptr<HtmlXSLControl> pageTemplate(OS_NEW HtmlXSLControl(loadStylesheet(path), document)); // Carica il template di riferimento getControls()->add(pageTemplate); }
shared_ptr<IBackgroundJob::Details> PortalsExporterJob::getDetails() const { String jobName(Engine::instance()->getText("job.exporter")); shared_ptr<Portal> portal = getPortal(); if(portal != nullptr) { jobName.append(" - "); jobName.append(portal->getName()); } shared_ptr<Details> details(OS_NEW Details(jobName.to_wide())); details->setPercentage(m_serializer->getProgressPercentage()); if(m_file != nullptr && m_downloadDirectory != nullptr) { // TOTRANSLATE String msg = _S("[center][a class=\"os_button\" href=\"{@url}\"]Click here for download[/a][/center]"); msg.replace_all(_S("{@url}"), m_downloadDirectory->getPath().getUrl()); details->setResult(msg); //details->setUrl(m_downloadDirectory->getPath().getUrl().to_ascii()); } return details; }
void CommentableObjectViewer::onCreatePost() { String quoted_text; shared_ptr<EntitiesEntity> quoted_entity; EntityID quoted_id = static_cast<String>(getRequest()->getUrlParam(OS_URL_PARAM_QUOTE)).to_ascii(); if(quoted_id.empty() == false) { quoted_entity = getPortal()->getEntity(getDatabase(), quoted_id); if(quoted_entity != nullptr) { shared_ptr<ObjectsIObject> quoted_object = quoted_entity->getCurrent(); if(quoted_object != nullptr) { quoted_text = OMLQuote::quoteObject(quoted_entity->getEntityID(), quoted_object->getContent()); quoted_text += _S("\r\n"); } } } shared_ptr<ObjectsIRevisionable> object = getObject(); shared_ptr<edit::PostEditor> post_editor(OS_NEW edit::PostEditor(nullptr, getEntity())); post_editor->setID(_S("postEditor")); post_editor->setTitle(_S("re: ") + object->getTitle()); post_editor->setContent(quoted_text); if(quoted_entity != nullptr) post_editor->setReference(quoted_entity->getEntityID()); post_editor->setRedirectionType(edit::IObjectEditor::rtViewParent); post_editor->setRedirectionParam(OS_URL_PARAM_OFFSET, conversions::to_wstring(IIdePageable::OFFSET_LAST)); getControls()->add(post_editor); _createLastPosts(); }
// Based on: http://digestingduck.blogspot.com/2010/03/simple-stupid-funnel-algorithm.html static void funnelPath( const BNavmesh *navmesh, const BVector *start, const BVector *end, const BAStarOutput *aStarOutput, BPath *outPath ) { const int numTriangles = aStarOutput->numTriangles; const BTriangle **triangles = aStarOutput->triangles; if ( numTriangles < 1 ) { outPath->numVertices = 0; outPath->vertices = NULL; return; } if ( numTriangles == 1 ) { outPath->numVertices = 2; outPath->vertices = malloc( 2 * sizeof( BVector ) ); outPath->vertices[0] = *start; outPath->vertices[1] = *end; return; } assert( isPointInsideNavmeshTriangle( navmesh, start, triangles[0] ) ); assert( isPointInsideNavmeshTriangle( navmesh, end, triangles[numTriangles - 1] ) ); const int numPortals = numTriangles; BEdge *portals = malloc( numPortals * sizeof( BEdge ) ); const int maxVertices = numTriangles + 1; outPath->vertices = malloc( sizeof( BVector ) * maxVertices ); outPath->vertices[0] = *start; outPath->numVertices = 1; for ( int triangleIndex = 0; triangleIndex < numTriangles - 1; triangleIndex++ ) { assert( triangleIndex < numTriangles ); assert( triangleIndex < numPortals - 1 ); assert( triangleIndex + 1 < numTriangles ); getPortal( navmesh, triangles[triangleIndex], triangles[triangleIndex + 1], &portals[triangleIndex] ); } portals[numPortals - 1].start = *end; portals[numPortals - 1].end = *end; BVector portalApex, portalLeft, portalRight; portalApex = *start; portalLeft = *start; portalRight = *start; int apexIndex, leftIndex, rightIndex; apexIndex = 0; leftIndex = 0; rightIndex = 0; for ( int portalIndex = 0; portalIndex < numPortals; portalIndex++ ) { const BVector *right = &portals[portalIndex].start; const BVector *left = &portals[portalIndex].end; if ( triangleArea2( &portalApex, &portalRight, right ) <= 0 ) { if ( vectorEquals( &portalApex, &portalRight ) || triangleArea2( &portalApex, &portalLeft, right ) > 0 ) { // Tighten portalRight = *right; rightIndex = portalIndex; } else { // Right over left, insert left to path and restart scan from portal left point assert( outPath->numVertices < maxVertices ); if ( !vectorEquals( &portalLeft, &outPath->vertices[outPath->numVertices - 1] ) ) { outPath->vertices[outPath->numVertices] = portalLeft; outPath->numVertices++; } // Make current left the new apex portalApex = portalLeft; apexIndex = leftIndex; // Reset portal portalLeft = portalApex; portalRight = portalApex; leftIndex = apexIndex; rightIndex = apexIndex; // Restart scan portalIndex = apexIndex; continue; } } if ( triangleArea2( &portalApex, &portalLeft, left ) >= 0 ) { if ( vectorEquals( &portalApex, &portalLeft ) || triangleArea2( &portalApex, &portalRight, left ) < 0 ) { // Tighten portalLeft = *left; leftIndex = portalIndex; } else { // Left over right, insert right to path and restart scan from portal right point assert( outPath->numVertices < maxVertices ); if ( !vectorEquals( &portalRight, &outPath->vertices[outPath->numVertices - 1] ) ) { outPath->vertices[outPath->numVertices] = portalRight; outPath->numVertices++; } // Make current right the new apex portalApex = portalRight; apexIndex = rightIndex; // Reset portal portalLeft = portalApex; portalRight = portalApex; leftIndex = apexIndex; rightIndex = apexIndex; // Restart scan portalIndex = apexIndex; continue; } } } assert( vectorEquals( &outPath->vertices[0], start ) ); if ( !vectorEquals( &outPath->vertices[outPath->numVertices - 1], end ) ) { assert( outPath->numVertices < maxVertices ); outPath->vertices[outPath->numVertices - 1] = *end; outPath->numVertices++; } free( portals ); }
void IdeMailBox::renderMessage(const ObjectID &id, shared_ptr<XMLNode> node) { shared_ptr<ObjectsMessage> message; shared_ptr<DataLocalMessage> local_message = getPortal()->getMessenger()->getMessage(getPage()->getDatabase(), getSessionAccount(), id, true); if(local_message != nullptr) { // Decodifica il messaggio message = local_message->decode(getSessionAccount()->getPrivateKey()); } if(message == nullptr) return; shared_ptr<OMLContext> messageContext = getPage()->parseOmlEx(message->body, false, true, getSecure(), false, omlRenderModeOsiris, String::EMPTY, String::EMPTY); if(messageContext == nullptr) return; shared_ptr<XMLPortalExporter> messageExporter(OS_NEW XMLPortalExporter(node, getPage(), XMLPortalExporter::emFull)); local_message->exportXML(messageExporter, message->subject, messageContext->getOutput(), messageContext->getSecureCheck()); shared_ptr<XMLNode> node_actions = node->addChild(_S("actions")); shared_ptr<ObjectsUser> author = objects_user_cast(getPage()->getObject(local_message->author)); if(author != nullptr) { shared_ptr<XMLNode> action_reply = node_actions->addChild(_S("action")); action_reply->setAttributeString(_S("name"), _S("reply")); ordered_map<std::wstring, std::wstring> params; params.set(OS_URL_PARAM_QUOTE, (_W("re: ") + message->subject).to_wide()); action_reply->setAttributeString(_S("href"), getPortal()->getSendMessageLink(author->id, params)); } if(local_message->folder == static_cast<uint32>(messageFolderTrash)) { shared_ptr<XMLNode> action_delete = node_actions->addChild(_S("action")); action_delete->setAttributeString(_S("name"), _S("restore")); action_delete->setAttributeString(_S("href"), getEventCommand(EVENT_ONRESTOREMESSAGE, id.toUTF16())); } else { shared_ptr<XMLNode> action_delete = node_actions->addChild(_S("action")); action_delete->setAttributeString(_S("name"), _S("delete")); action_delete->setAttributeString(_S("href"), getEventCommand(EVENT_ONDELETEMESSAGE, id.toUTF16())); } if(getSecure()) { bool unsafe = messageContext->getSecureCheck() == false; if(unsafe == false) { shared_ptr<ObjectsUser> messageAuthor = objects_user_cast(getPage()->getObject(local_message->author)); if(messageAuthor != nullptr) { shared_ptr<OMLContext> markContext = getPage()->parseOmlEx(messageAuthor->mark, false, true, getSecure(), false, omlRenderModeOsiris, String::EMPTY, String::EMPTY); if(markContext != nullptr) unsafe = markContext->getSecureCheck() == false; } } if(unsafe) { shared_ptr<XMLNode> action_delete = node_actions->addChild(_S("action")); action_delete->setAttributeString(_S("name"), _S("show")); action_delete->setAttributeString(_S("href"), getPortal()->getPrivateMessageLink(id, false)); } } }
void IdeMailBox::renderFolder(MessageFolder folder, shared_ptr<XMLNode> node) { getPortal()->getMessenger()->markNewMessagesAsUnread(getPage()->getDatabase(), getSessionAccount()); node->setAttributeString(_S("name"), DataLocalMessage::toString(folder)); // Calcola il numero totale di messaggi nel folder uint32 total_messages = getPortal()->getMessenger()->getMessagesCount(getPage()->getDatabase(), getSessionAccount(), folder); // Calcola il numero di messaggi da mostrare uint32 messages_to_show = getSkin()->getPagerItems(); // Crea il pager dei messaggi se necessario createPager(getSkin(), node, total_messages, messages_to_show, getOffset()); shared_ptr<XMLNode> node_messages; DataLocalMessage::DataLocalMessageList messages; RangeUint32 range(m_offset, messages_to_show); // Estrae i messaggi nel folder corrente if(getPortal()->getMessenger()->getMessages(getPage()->getDatabase(), getSessionAccount(), messages, folder, range)) { for(DataLocalMessage::DataLocalMessageList::const_iterator i = messages.begin(); i != messages.end(); ++i) { shared_ptr<DataLocalMessage> local_message = *i; shared_ptr<ObjectsMessage> message = local_message->decode(getSessionAccount()->getPrivateKey()); if(message != nullptr) { if(node_messages == nullptr) node_messages = node->addChild(_S("messages")); shared_ptr<XMLPortalExporter> messageExporter(OS_NEW XMLPortalExporter(node_messages->addChild(_S("message")), getPage(), XMLPortalExporter::emLite)); local_message->exportXML(messageExporter, message->subject, String::EMPTY, false); } } } shared_ptr<XMLNode> node_actions = node->addChild(_S("actions")); switch(folder) { case messageFolderInbox: { shared_ptr<XMLNode> actionReadAll = node_actions->addChild(_S("action")); actionReadAll->setAttributeString(_S("name"), _S("readAllMessages")); actionReadAll->setAttributeString(_S("href"), getEventCommand(EVENT_ONREADALLMESSAGES, conversions::to_utf16(folder))); } break; case messageFolderTrash: { shared_ptr<XMLNode> actionDeleteAll = node_actions->addChild(_S("action")); actionDeleteAll->setAttributeString(_S("name"), _S("deleteAllMessages")); actionDeleteAll->setAttributeString(_S("href"), getEventCommand(EVENT_ONDELETEALLMESSAGES, conversions::to_utf16(folder))); } break; case messageFolderSentItems: break; default: OS_ASSERTFALSE(); break; } }
bool TeSQLite::insertRasterBlock(const string& table, const string& blockId, const TeCoord2D& ll, const TeCoord2D& ur, unsigned char *buf, unsigned long size, int band, unsigned int res, unsigned int subband) { errorMessage_ = ""; if (blockId.empty()) // no block identifier provided { errorMessage_ = "bloco sem identificador"; return false; } TeDatabasePortal* portal = getPortal(); bool insert = true; std::string sql = "SELECT block_id FROM " + table + " WHERE block_id='" + blockId + "'"; if(!portal->query(sql)) { delete portal; errorMessage_ = portal->errorMessage(); return false; } if(portal->fetchRow()) { insert = false; } delete portal; if(insert) { sql = "INSERT INTO " + table + " (lower_x, lower_y, upper_x, upper_y, band_id, resolution_factor, subband, block_size, spatial_data, block_id) "; sql += " VALUES (?,?,?,?,?,?,?,?,?,?)"; } else { sql = "UPDATE " + table + " SET lower_x=?, lower_y=?, upper_x=?, upper_y=?, band_id=?,"; sql += "resolution_factor=?, subband=?, block_size=?, spatial_data=? WHERE block_id=? "; } sqlite3_stmt* recordSet = 0; int retValue = sqlite3_prepare_v2(_conn, sql.c_str(), -1, &recordSet, 0); if(retValue != SQLITE_OK) { errorMessage_ = errorMessage(); return false; } sqlite3_bind_double(recordSet, 1, ll.x()); sqlite3_bind_double(recordSet, 2, ll.y()); sqlite3_bind_double(recordSet, 3, ur.x()); sqlite3_bind_double(recordSet, 4, ur.y()); sqlite3_bind_int(recordSet, 5, band); sqlite3_bind_int(recordSet, 6, (int)res); sqlite3_bind_int(recordSet, 7, (int)subband); sqlite3_bind_int(recordSet, 8, (int)size); sqlite3_bind_blob(recordSet, 9, buf, size, SQLITE_TRANSIENT); sqlite3_bind_text(recordSet, 10, blockId.c_str(), blockId.size(), SQLITE_TRANSIENT); retValue = sqlite3_step(recordSet); if(retValue != SQLITE_DONE) { return false; } sqlite3_finalize(recordSet); return true; }
/* shared_ptr<Portal> PortalsSystem::createPortal(shared_ptr<PortalOptions> options) // TOCLEAN { options->setPortalID(PortalID::generate()); Buffer public_key; Buffer private_key; // Genera la coppia di chiavi dell'amministratore if(CryptManager::instance()->rsaGenerateKeys(rsaType2048, private_key, public_key) == false) return false; //PortalAccess access = options->getPassword().empty() ? portalAccessPublic : portalAccessPrivate; //options->setPortalID(PortalID::generateAnarchic(access)); if(options->getPortalID().empty()) options->setPortalID(PortalID::generateAnarchic(access)); if(options->getUserID().empty()) { // Create account shared_ptr<IdeAccount> account = IdeAccountsManager::instance()->createAccount(OS_DEFAULT_ADMIN_USERNAME, OS_DEFAULT_ADMIN_PASSWORD, true); if(account == nullptr) { OS_LOG_ERROR("Cannot create account"); return false; } Buffer publicKey; account->getAccount()->decodePublicKey(OS_DEFAULT_ADMIN_PASSWORD, publicKey); options->setUserID(DataAccount::getReferenceUser(publicKey)); } shared_ptr<Portal> portal = subscribePortal(options); if(portal == nullptr) { OS_LOG_ERROR("Cannot create portal"); return nullptr; } return portal; } */ shared_ptr<Portal> PortalsSystem::subscribePortal(shared_ptr<PortalOptions> options) { OS_LOCK(m_cs); if(options == nullptr) { OS_ASSERTFALSE(); return nullptr; } PortalID id = options->getPortalID(); if(id.empty()) { id = PortalID::generate(); options->setPortalID(id); } PovID pov = options->getPovID(); if(pov.empty()) return nullptr; //if(id.getType() != ID::idPortal || id.validate(false) == false) // return nullptr; String fullPov = Portal::generatePovID(id, pov); if(getPortal(id, pov) != nullptr) return nullptr; if(options->getDatabaseName().empty()) options->setDatabaseName(fullPov); if(options->validate() == false) return nullptr; String folder = utils::standardisePath(getPath() + fullPov); if(FileSystem::instance()->exists(folder)) { OS_LOG_ERROR(String::format(_S("Folder '%S' already exists").c_str(), folder.c_str())); return nullptr; } // Assicura che la root dei portali esista FileSystem::instance()->createDirectory(getPath()); // Crea la root del portale if(FileSystem::instance()->createDirectory(folder) == false) { OS_LOG_ERROR(String::format(_S("Cannot create folder '%S'").c_str(), folder.c_str())); return nullptr; } // Crea il portale if(_setupPortal(options, folder) == false) { FileSystem::instance()->removeDirectory(folder); return nullptr; } return _loadPortal(folder, false, true); }