/** * Given array of MIME parts in raw string, this function converts them into MIME * representation. * * @param array $bodyPartContents The MIME body parts. * * @return array Returns array with two elements 'headers' and 'body' which * represents the MIME message. */ public function encodeMimeMultipart($bodyPartContents) { $count = count($bodyPartContents); $mimeType = Resources::MULTIPART_MIXED_TYPE; $batchGuid = Utilities::getGuid(); $batchId = sprintf('batch_%s', $batchGuid); $contentType1 = array('content_type' => "{$mimeType}"); $changeSetGuid = Utilities::getGuid(); $changeSetId = sprintf('changeset_%s', $changeSetGuid); $contentType2 = array('content_type' => "{$mimeType}; boundary={$changeSetId}"); $options = array('encoding' => 'binary', 'content_type' => Resources::HTTP_TYPE); // Create changeset MIME part $changeSet = new \Mail_mimePart(); for ($i = 0; $i < $count; $i++) { $changeSet->addSubpart($bodyPartContents[$i], $options); } // Encode the changeset MIME part $changeSetEncoded = $changeSet->encode($changeSetId); // Create the batch MIME part $batch = new \Mail_mimePart(Resources::EMPTY_STRING, $contentType1); // Add changeset encoded to batch MIME part $batch->addSubpart($changeSetEncoded['body'], $contentType2); // Encode batch MIME part $batchEncoded = $batch->encode($batchId); return $batchEncoded; }
/** * Create contentKey * * @return none */ public function __construct() { $this->_id = 'nb:kid:UUID:' . Utilities::getGuid(); }
/** * @covers WindowsAzure\Common\Internal\Utilities::getGuid */ public function testGetGuid() { // Test $actual1 = Utilities::getGuid(); $actual2 = Utilities::getGuid(); // Assert $this->assertNotNull($actual1); $this->assertNotNull($actual2); $this->assertInternalType('string', $actual1); $this->assertInternalType('string', $actual2); $this->assertNotEquals($actual1, $actual2); }
/** * Encode contexts * * @return none */ public function encode() { $mimeType = Resources::MULTIPART_MIXED_TYPE; $batchGuid = Utilities::getGuid(); $batchId = sprintf('batch_%s', $batchGuid); $contentType1 = array('content_type' => "{$mimeType}"); $changeSetGuid = Utilities::getGuid(); $changeSetId = sprintf('changeset_%s', $changeSetGuid); $contentType2 = array('content_type' => "{$mimeType}; boundary={$changeSetId}"); $options = array('encoding' => 'binary', 'content_type' => Resources::HTTP_TYPE); // Create changeset MIME part $changeSet = new \Mail_mimePart(); $i = 1; foreach ($this->_contexts as $context) { $context->addHeader(Resources::CONTENT_ID, $i); $changeSet->addSubpart((string) $context, $options); $i++; } // Encode the changeset MIME part $changeSetEncoded = $changeSet->encode($changeSetId); // Create the batch MIME part $batch = new \Mail_mimePart(Resources::EMPTY_STRING, $contentType1); // Add changeset encoded to batch MIME part $batch->addSubpart($changeSetEncoded['body'], $contentType2); // Encode batch MIME part $batchEncoded = $batch->encode($batchId); $this->_headers = $batchEncoded['headers']; $this->_body = $batchEncoded['body']; }
/** * Create task. * * @param int $numberOfInputAssets Number of input Assets the TaskTemplate * must process. * @param int $numberOfOutputAssets Number of output Assets the TaskTemplate * must process. */ public function __construct($numberOfInputAssets, $numberOfOutputAssets) { $this->_id = 'nb:ttid:UUID:' . Utilities::getGuid(); $this->_numberofInputAssets = $numberOfInputAssets; $this->_numberofOutputAssets = $numberOfOutputAssets; }
private static function mutateEntityChangeValues($ent) { foreach ($ent->getProperties() as $propName => $initialProp) { // Don't mess with the keys. if ($propName == 'PartitionKey' || $propName == 'RowKey' || $propName == 'Timestamp') { continue; } $ptype = $initialProp->getEdmType(); if (is_null($ptype)) { $eff = $initialProp->getValue(); $initialProp->setValue($eff . 'AndMore'); } else { if ($ptype == EdmType::DATETIME) { $value = $initialProp->getValue(); if (is_null($value)) { $value = new \DateTime("1/26/1692"); } $value->modify('+1 day'); $initialProp->setValue($value); } else { if ($ptype == EdmType::BINARY) { $eff = $initialProp->getValue(); $initialProp->setValue($eff . 'x'); } else { if ($ptype == EdmType::BOOLEAN) { $eff = $initialProp->getValue(); $initialProp->setValue(!$eff); } else { if ($ptype == EdmType::DOUBLE) { $eff = $initialProp->getValue(); $initialProp->setValue($eff + 1); } else { if ($ptype == EdmType::GUID) { $initialProp->setValue(Utilities::getGuid()); } else { if ($ptype == EdmType::INT32) { $eff = $initialProp->getValue(); $eff = $eff > 10 ? 0 : $eff + 1; $initialProp->setValue($eff); } else { if ($ptype == EdmType::INT64) { $eff = $initialProp->getValue(); $eff = $eff > 10 ? 0 : $eff + 1; $initialProp->setValue(strval($eff)); } else { if ($ptype == EdmType::STRING) { $eff = $initialProp->getValue(); $initialProp->setValue($eff . 'AndMore'); } } } } } } } } } } }
/** * @covers WindowsAzure\Table\TableRestProxy::insertEntity * @covers WindowsAzure\Table\TableRestProxy::queryEntities */ public function testQueryEntitiesWithFilterWorks() { // Arrange $table = self::$testTable5; $numberOfEntries = 5; $entities = array(); for ($i = 0; $i < $numberOfEntries; $i++) { $entity = new Entity(); $entity->setPartitionKey('001'); $entity->setRowKey('queryEntitiesWithFilterWorks-' . $i); $entity->addProperty('test', EdmType::BOOLEAN, $i % 2 == 0); $entity->addProperty('test2', EdmType::STRING, '\'value" ' . $i); $entity->addProperty('test3', EdmType::INT32, $i); $entity->addProperty('test4', EdmType::INT64, strval('12345678901' + $i)); $entity->addProperty('test5', EdmType::DATETIME, new \DateTime('2012-01-0' . $i)); $entity->addProperty('test6', EdmType::BINARY, chr($i)); $entity->addProperty('test7', EdmType::GUID, Utilities::getGuid()); $entities[$i] = $entity; $this->restProxy->insertEntity($table, $entity); } // Act $f = Filter::applyEq(Filter::applyPropertyName('RowKey'), Filter::applyConstant('queryEntitiesWithFilterWorks-3', EdmType::STRING)); $q = new Query(); $q->setFilter($f); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $q->setFilter(Filter::applyQueryString('RowKey eq \'queryEntitiesWithFilterWorks-3\'')); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test'), Filter::applyConstant(true, EdmType::BOOLEAN))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(3, count($result->getEntities()), 'count($result->getEntities())'); // Act $q = new Query(); $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test2'), Filter::applyConstant('\'value" 3', EdmType::STRING))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test4'), Filter::applyConstant(12345678903, EdmType::INT64))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-2', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test5'), Filter::applyConstant(new \DateTime('2012-01-03'), EdmType::DATETIME))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $ent3 = $entities[3]; $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test6'), Filter::applyConstant(chr(3), EdmType::BINARY))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); // Act $q = new Query(); $ent3 = $entities[3]; $q->setFilter(Filter::applyEq(Filter::applyPropertyName('test7'), Filter::applyConstant($ent3->getPropertyValue('test7'), EdmType::GUID))); $qeo = new QueryEntitiesOptions(); $qeo->setQuery($q); $result = $this->restProxy->queryEntities($table, $qeo); // Assert $this->assertNotNull($result, '$result'); $this->assertEquals(1, count($result->getEntities()), 'count($result->getEntities())'); $resEnts = $result->getEntities(); $this->assertEquals('queryEntitiesWithFilterWorks-3', $resEnts[0]->getRowKey(), '$resEnts[0]->getRowKey()'); }