Ejemplo n.º 1
0
 /**
  * Write a specific session
  * 
  * @param int $id Session Id
  * @param string $serializedData Serialized PHP object
  * @throws Exception
  */
 public function write($id, $serializedData)
 {
     // Encode data
     $serializedData = base64_encode(serialize($serializedData));
     if (strlen($serializedData) >= self::MAX_TS_PROPERTY_SIZE && $this->_storageType == self::STORAGE_TYPE_TABLE) {
         throw new Microsoft_WindowsAzure_Exception('Session data exceeds the maximum allowed size of ' . self::MAX_TS_PROPERTY_SIZE . ' bytes that can be stored using table storage. Consider switching to a blob storage back-end or try reducing session data size.');
     }
     // Store data
     if ($this->_storageType == self::STORAGE_TYPE_TABLE) {
         // In table storage
         $sessionRecord = new Microsoft_WindowsAzure_Storage_DynamicTableEntity($this->_sessionContainerPartition, $id);
         $sessionRecord->sessionExpires = time();
         $sessionRecord->serializedData = $serializedData;
         $sessionRecord->setAzurePropertyType('sessionExpires', 'Edm.Int32');
         try {
             $this->_storage->updateEntity($this->_sessionContainer, $sessionRecord);
         } catch (Microsoft_WindowsAzure_Exception $unknownRecord) {
             $this->_storage->insertEntity($this->_sessionContainer, $sessionRecord);
         }
     } else {
         if ($this->_storageType == self::STORAGE_TYPE_BLOB) {
             // In blob storage
             $this->_storage->putBlobData($this->_sessionContainer, $this->_sessionContainerPartition . '/' . $id, $serializedData, array('sessionexpires' => time()));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Write a specific session
  *
  * @param int $id Session Id
  * @param string $serializedData Serialized PHP object
  */
 public function write($id, $serializedData)
 {
     $sessionRecord = new Microsoft_WindowsAzure_Storage_DynamicTableEntity($this->_sessionTablePartition, $id);
     $sessionRecord->sessionExpires = time();
     $sessionRecord->serializedData = base64_encode($serializedData);
     $sessionRecord->setAzurePropertyType('sessionExpires', 'Edm.Int32');
     try {
         $this->_tableStorage->updateEntity($this->_sessionTable, $sessionRecord);
     } catch (Microsoft_WindowsAzure_Exception $unknownRecord) {
         $this->_tableStorage->insertEntity($this->_sessionTable, $sessionRecord);
     }
 }
}
// Ensure the table exists
$table->createTableIfNotExists(TABLE_GUESTBOOK);
// Ensure the blob container exists
$blob->createcontainerIfNotExists(BLOB_GUESTBOOK);
// Set ACL
$blob->setContainerAcl(BLOB_GUESTBOOK, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER);
// If the user submitted something put it into the table storage
// NOTE: Inputs are not cleaned for example purposes
if (isset($_POST['NameTextBox']) && isset($_POST['MessageTextBox'])) {
    $g = new GuestBookEntry();
    $image = $blob->putBlob(BLOB_GUESTBOOK, $_FILES['Image']['name'], $_FILES['Image']['tmp_name']);
    $g->GuestName = $_POST['NameTextBox'];
    $g->Message = $_POST['MessageTextBox'];
    $g->ImageUrl = $image->Url;
    $table->insertEntity(TABLE_GUESTBOOK, $g);
}
// User wishes to delete something
if (isset($_GET['Delete']) && isset($_GET['key'])) {
    $g = $table->retrieveEntityById(TABLE_GUESTBOOK, $_GET['Delete'], $_GET['key']);
    $table->deleteEntity(TABLE_GUESTBOOK, $g);
    header("Location: index.php");
}
// Get all the guest book entries for display
$entries = $table->retrieveEntities(TABLE_GUESTBOOK);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Windows Azure Guestbook</title>
Ejemplo n.º 4
0
<?php

require_once 'Microsoft/WindowsAzure/Storage/Table.php';
$entity = new SampleEntity('partition1', 'row1');
$entity->FullName = "Mario";
$entity->Age = 35;
$entity->Visible = true;
$storageClient = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net', 'myaccount', 'myauthkey');
$result = $storageClient->insertEntity('testtable', $entity);
echo 'Timestamp: ' . $result->getTimestamp() . "\n";
echo 'Etag: ' . $result->getEtag() . "\n";