Inheritance: MonoBehaviour
Beispiel #1
0
        public async Task <List <CloudEntity> > GetCloudEntities1(
            DatastoreService dataStore, string projectId,
            KindName kindName, Offset offset, ResultsLimit skip, DateTime dateAdded)
        {
            var res = dataStore.Projects.RunQuery(
                getQueryRequest(dateAdded, kindName), projectId);

            var response = await res.ExecuteAsync();

            var entityResults = response.Batch.EntityResults;

            var toReturn = new List <CloudEntity>();

            foreach (var entityResult in response.Batch.EntityResults)
            {
                var entity      = entityResult.Entity;
                var path        = entity.Key.Path.FirstOrDefault();
                var cloudEntity = new CloudEntity()
                {
                    FormName     = path.Kind,
                    Id           = path.Name,
                    EntityId     = entity.Properties["entityid"].StringValue,
                    DataBlob     = entity.Properties["datablob"].StringValue,
                    KindMetaData = entity.Properties["kindmetadata"].StringValue,

                    //EditDay = Convert.ToInt32( entity.Properties["editday"].IntegerValue),
                    //EditDate = Convert.ToInt64(entity.Properties["editdate"].IntegerValue),

                    //{ "editday", new Value() { IntegerValue = now.toYMDInt() } },
                    //{ "editdate", new Value() { IntegerValue = now.ToBinary() } },

                    //DateAdded = Convert.ToDateTime(
                    //    entity.Properties["dateadded"].TimestampValue)
                };

                if (entity.Properties.ContainsKey("editdate"))
                {
                    var editDate = entity.Properties["editdate"].IntegerValue;
                    cloudEntity.EditDate = Convert.ToInt64(editDate);

                    var editDay = entity.Properties["editday"].IntegerValue;
                    cloudEntity.EditDay = Convert.ToInt32(editDay);
                }
                else
                {
                    //use field date added
                    var entityDate = Convert.ToDateTime(
                        entity.Properties["dateadded"].TimestampValue);
                    var editday = entityDate.toYMDInt();
                    cloudEntity.EditDay = editday;

                    var local    = entityDate.ToLocalTime();
                    var editdate = local.ToBinary();
                    cloudEntity.EditDate = editdate;
                }

                toReturn.Add(cloudEntity);
            }
            return(toReturn);
        }
        public Task DeleteMessageAsync(string messageId, string popReceipt)
        {
            Require.NotEmpty(messageId, "messageId");
            Require.NotEmpty(popReceipt, "popReceipt");

            return(CloudEntity.DeleteMessageAsync(messageId, popReceipt));
        }
Beispiel #3
0
 public IBatchOperation PrepareBatchOperation()
 {
     return(new TableBatchOperationAdapter(
                batch => CloudEntity.ExecuteBatchAsync(batch, null, null),
                batch => CloudEntity.ExecuteBatch(batch),
                m_tableEntityConverter));
 }
Beispiel #4
0
 private TableQuerySegment <DynamicTableEntity> ExecuteQuerySync(
     TableQuery <DynamicTableEntity> query,
     TableContinuationToken continuationToken,
     TableRequestOptions requestOptions)
 {
     return(CloudEntity.ExecuteQuerySegmented(query, continuationToken, requestOptions));
 }
        public ICloudBlockBlob CreateBlockBlob(string resourceName)
        {
            Require.NotEmpty(resourceName, "resourceName");

            var blob = CloudEntity.GetBlockBlobReference(resourceName);

            return(new CloudBlockBlobAdapter(blob));
        }
 public Task AddMessageAsync(byte[] content, TimeSpan visibilityTimeout)
 {
     return(CloudEntity.AddMessageAsync(
                message: new CloudQueueMessage(content),
                timeToLive: null,
                initialVisibilityDelay: visibilityTimeout,
                options: null,
                operationContext: null));
 }
        public void Convert()
        {
            var timevalues = new TimeValue[20000];

            for (int i = 0; i < timevalues.Length; i++)
            {
                timevalues[i] = new TimeValue {
                    Time = new DateTime(2001, 1, 1).AddMinutes(i), Value = i
                };
            }

            var serie = new TimeSerie {
                TimeValues = timevalues
            };

            var cloudEntity = new CloudEntity <TimeSerie>
            {
                PartitionKey = "part",
                RowKey       = "key",
                Value        = serie
            };

            var fatEntity    = FatEntity.Convert(cloudEntity, _serializer);
            var cloudEntity2 = FatEntity.Convert <TimeSerie>(fatEntity, _serializer, null);
            var fatEntity2   = FatEntity.Convert(cloudEntity2, _serializer);

            Assert.IsNotNull(cloudEntity2);
            Assert.IsNotNull(fatEntity2);

            Assert.AreEqual(cloudEntity.PartitionKey, fatEntity.PartitionKey);
            Assert.AreEqual(cloudEntity.RowKey, fatEntity.RowKey);


            Assert.AreEqual(cloudEntity.PartitionKey, fatEntity2.PartitionKey);
            Assert.AreEqual(cloudEntity.RowKey, fatEntity2.RowKey);

            Assert.IsNotNull(cloudEntity2.Value);
            Assert.AreEqual(cloudEntity.Value.TimeValues.Length, cloudEntity2.Value.TimeValues.Length);

            for (int i = 0; i < timevalues.Length; i++)
            {
                Assert.AreEqual(cloudEntity.Value.TimeValues[i].Time, cloudEntity2.Value.TimeValues[i].Time);
                Assert.AreEqual(cloudEntity.Value.TimeValues[i].Value, cloudEntity2.Value.TimeValues[i].Value);
            }

            var data1 = fatEntity.GetData();
            var data2 = fatEntity2.GetData();

            Assert.AreEqual(data1.Length, data2.Length);
            for (int i = 0; i < data2.Length; i++)
            {
                Assert.AreEqual(data1[i], data2[i]);
            }
        }
        public Task UpdateMessageAsync(string messageId, string popReceipt, TimeSpan visibilityTimeout)
        {
            Require.NotEmpty(messageId, "messageId");
            Require.NotEmpty(popReceipt, "popReceipt");

            var message = new CloudQueueMessage(messageId, popReceipt);

            return(CloudEntity.UpdateMessageAsync(
                       message,
                       visibilityTimeout,
                       MessageUpdateFields.Visibility));
        }
Beispiel #9
0
        private void MenuSmmaries_Click(object sender, RoutedEventArgs e)
        {
            var addRecordsFromTablet = false;

            if (addRecordsFromTablet)
            {
                //we have records that couldn't be synced from the tablet
                var toSave      = new List <CloudEntity>();
                var txt         = File.ReadAllText("Assets\\unsyncd.txt");
                var outEntities = txt.DecompressFromBase64String();

                var now      = DateTime.Now.AddDays(-8);
                var asBinary = now.ToBinary();

                var processors = new Dictionary <string, List <CloudEntity> >();
                foreach (var outEntity in outEntities)
                {
                    var ppdataset = DbSaveableEntity.fromJson <GeneralEntityDataset>(new KindItem(outEntity.DataBlob));
                    var saveable  = new DbSaveableEntity(ppdataset)
                    {
                        kindName = new KindName(ppdataset.FormName)
                    };
                    if (!processors.ContainsKey(ppdataset.FormName))
                    {
                        processors[ppdataset.FormName] = new List <CloudEntity>();
                    }
                    var cloudEntity = new CloudEntity()
                    {
                        Id       = saveable.Id.Value,
                        EntityId = saveable.EntityId.Value,
                        EditDay  = now.toYMDInt(),
                        EditDate = asBinary,
                        DataBlob = saveable
                                   .getJson()
                                   .Encrypt()
                                   .Value,
                        FormName     = ppdataset.FormName,
                        KindMetaData = saveable.Entity.KindMetaData ?? string.Empty
                    };
                    processors[ppdataset.FormName].Add(cloudEntity);
                }
                foreach (var item in processors)
                {
                    new KindDataProcessor()
                    .addToProcessingQueue(item.Key, item.Value);
                }
                //we save them to local
                AppInstance.Instance.CloudDbInstance.RefreshLocalEntities(setProgressValue);
            }

            MessageBox.Show("Menu item clicked ");
        }
Beispiel #10
0
        public LocalEntity toLocalEntity(CloudEntity entity)
        {
            var decrypted = entity.DataBlob.Decrypt();

            return(new LocalEntity()
            {
                Id = entity.Id,
                EntityId = entity.EntityId,
                DataBlob = decrypted.Value,
                EditDate = entity.EditDate,
                EditDay = entity.EditDay,
                FormName = entity.FormName,
                KindMetaData = entity.KindMetaData
            });
        }
        public async Task <ICloudQueueMessage> GetMessageAsync()
        {
            var message = await CloudEntity.GetMessageAsync();

            if (message == null)
            {
                return(null);
            }

            return(new CloudQueueMessageAdapter(
                       message.Id,
                       message.PopReceipt,
                       message.DequeueCount,
                       message.AsBytes));
        }
        public Task UpdateMessageAsync(string messageId, string popReceipt, byte[] content)
        {
            Require.NotEmpty(messageId, "messageId");
            Require.NotEmpty(popReceipt, "popReceipt");
            Require.NotNull(content, "content");

            var message = new CloudQueueMessage(messageId, popReceipt);

            message.SetMessageContent(content);

            return(CloudEntity.UpdateMessageAsync(
                       message,
                       TimeSpan.Zero,
                       MessageUpdateFields.Content | MessageUpdateFields.Visibility));
        }
Beispiel #13
0
		public void Convert()
		{
			var timevalues = new TimeValue[20000];
			for(int i = 0; i < timevalues.Length; i++)
			{
				timevalues[i] = new TimeValue {Time = new DateTime(2001, 1, 1).AddMinutes(i), Value = i};
			}

			var serie = new TimeSerie {TimeValues = timevalues};

			var cloudEntity = new CloudEntity<TimeSerie>
				{
					PartitionKey = "part",
					RowKey = "key",
					Value = serie
				};

			var fatEntity = FatEntity.Convert(cloudEntity, _serializer);
			var cloudEntity2 = FatEntity.Convert<TimeSerie>(fatEntity, _serializer, null);
			var fatEntity2 = FatEntity.Convert(cloudEntity2, _serializer);

			Assert.IsNotNull(cloudEntity2);
			Assert.IsNotNull(fatEntity2);

			Assert.AreEqual(cloudEntity.PartitionKey, fatEntity.PartitionKey);
			Assert.AreEqual(cloudEntity.RowKey, fatEntity.RowKey);
			

			Assert.AreEqual(cloudEntity.PartitionKey, fatEntity2.PartitionKey);
			Assert.AreEqual(cloudEntity.RowKey, fatEntity2.RowKey);

			Assert.IsNotNull(cloudEntity2.Value);
			Assert.AreEqual(cloudEntity.Value.TimeValues.Length, cloudEntity2.Value.TimeValues.Length);

			for(int i = 0; i < timevalues.Length; i++)
			{
				Assert.AreEqual(cloudEntity.Value.TimeValues[i].Time, cloudEntity2.Value.TimeValues[i].Time);
				Assert.AreEqual(cloudEntity.Value.TimeValues[i].Value, cloudEntity2.Value.TimeValues[i].Value);
			}

			var data1 = fatEntity.GetData();
			var data2 = fatEntity2.GetData();
			Assert.AreEqual(data1.Length, data2.Length);
			for(int i = 0; i < data2.Length; i++)
			{
				Assert.AreEqual(data1[i], data2[i]);
			}
		}
        public async Task <IReadOnlyList <ICloudQueueMessage> > GetMessagesAsync(int messageCount)
        {
            var messages = await CloudEntity.GetMessagesAsync(messageCount);

            var result = new List <ICloudQueueMessage>(messageCount);

            result.AddRange(
                messages.Select(message =>
                                new CloudQueueMessageAdapter(
                                    message.Id,
                                    message.PopReceipt,
                                    message.DequeueCount,
                                    message.AsBytes)));

            return(result);
        }
        /// <summary>Converts a <c>CloudEntity</c> toward a <c>FatEntity</c>.</summary>
        public static FatEntity Convert <T>(CloudEntity <T> cloudEntity, IDataSerializer serializer)
        {
            var fatEntity = new FatEntity
            {
                PartitionKey = cloudEntity.PartitionKey,
                RowKey       = cloudEntity.RowKey,
                Timestamp    = cloudEntity.Timestamp
            };

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(cloudEntity.Value, stream, typeof(T));
                fatEntity.SetData(stream.ToArray());
                return(fatEntity);
            }
        }
Beispiel #16
0
        //private async Task<List<CloudEntity>> fetchCloudData1()
        //{
        //    var toReturn = new List<CloudEntity>();
        //    var repeatDownload = true;
        //    while (repeatDownload)
        //    {

        //        var response = await res.ExecuteAsync();
        //        var entityResults = response.Batch.EntityResults;
        //        //Debug.
        //        if (entityResults == null)
        //        {
        //            repeatDownload = false;
        //            break;
        //        }

        //        query.Query.StartCursor = response.Batch.EndCursor;
        //        foreach (var entityResult in response.Batch.EntityResults)
        //        {
        //            var entity = entityResult.Entity;
        //            var path = entity.Key.Path.FirstOrDefault();
        //            var cloudEntity = new CloudEntity()
        //            {
        //                FormName = path.Kind,
        //                Id = path.Name,
        //                EntityId = entity.Properties["entityid"].StringValue,
        //                DataBlob = entity.Properties["datablob"].StringValue,
        //                KindMetaData = entity.Properties["kindmetadata"].StringValue,
        //                //EditDate = Convert.ToInt64(
        //                //    entity.Properties["editdate"].IntegerValue),
        //                //EditDay = Convert.ToInt32(
        //                //    entity.Properties["editday"].IntegerValue)
        //            };
        //            if (entity.Properties.ContainsKey("editdate"))
        //            {
        //                var editDate = entity.Properties["editdate"].IntegerValue;
        //                cloudEntity.EditDate = Convert.ToInt64(editDate);

        //                var editDay = entity.Properties["editday"].IntegerValue;
        //                cloudEntity.EditDay = Convert.ToInt32(editDay);
        //            }
        //            else
        //            {
        //                //use field date added
        //                var entityDate = Convert.ToDateTime(
        //                    entity.Properties["dateadded"].TimestampValue);
        //                var editday = entityDate.toYMDInt();
        //                cloudEntity.EditDay = editday;
        //                var editdate = entityDate.ToBinary();
        //                cloudEntity.EditDate = editdate;
        //            }
        //            toReturn.Add(cloudEntity);
        //        }

        //        //moreResultsAfterLimit
        //        if (response.Batch.MoreResults == "NO_MORE_RESULTS")
        //        {
        //            repeatDownload = false;
        //            break;
        //        }
        //        else
        //        {
        //            repeatDownload = true;
        //        }
        //    }
        //    return toReturn;
        //}

        private static List <CloudEntity> toCloudEntity(IList <EntityResult> results)
        {
            var toReturn = new List <CloudEntity>();

            foreach (var entityResult in results)
            {
                var entity      = entityResult.Entity;
                var path        = entity.Key.Path.FirstOrDefault();
                var cloudEntity = new CloudEntity()
                {
                    FormName     = path.Kind,
                    Id           = path.Name,
                    EntityId     = entity.Properties["entityid"].StringValue,
                    DataBlob     = entity.Properties["datablob"].StringValue,
                    KindMetaData = entity.Properties["kindmetadata"].StringValue,
                    //EditDate = Convert.ToInt64(
                    //    entity.Properties["editdate"].IntegerValue),
                    //EditDay = Convert.ToInt32(
                    //    entity.Properties["editday"].IntegerValue)
                };
                if (entity.Properties.ContainsKey("editdate"))
                {
                    var editDate = entity.Properties["editdate"].IntegerValue;
                    cloudEntity.EditDate = Convert.ToInt64(editDate);

                    var editDay = entity.Properties["editday"].IntegerValue;
                    cloudEntity.EditDay = Convert.ToInt32(editDay);
                }
                else
                {
                    //use field date added
                    var entityDate = Convert.ToDateTime(
                        entity.Properties["dateadded"].TimestampValue);

                    var editday = entityDate.toYMDInt();
                    cloudEntity.EditDay = editday;

                    var local    = entityDate.ToLocalTime();
                    var editdate = local.ToBinary();
                    cloudEntity.EditDate = editdate;
                }
                toReturn.Add(cloudEntity);
            }
            return(toReturn);
        }
        public async Task <IReadOnlyList <ICloudQueueMessage> > GetMessagesAsync(int messageCount, TimeSpan visibilityTimeout)
        {
            var messages = await CloudEntity.GetMessagesAsync(
                messageCount,
                visibilityTimeout,
                null,
                null);

            var result = new List <ICloudQueueMessage>(CloudQueueMessage.MaxNumberOfMessagesToPeek);

            result.AddRange(
                messages.Select(message =>
                                new CloudQueueMessageAdapter(
                                    message.Id,
                                    message.PopReceipt,
                                    message.DequeueCount,
                                    message.AsBytes)));

            return(result);
        }
Beispiel #18
0
 public void Insert <T>(string tableName, CloudEntity <T> entity)
 {
     InsertInternal(tableName, new[] { entity });
 }
Beispiel #19
0
        private static void SaveAnalysis(Analysis analysis, string partKey = PartitionKey)
        {
            var rowkey = ShortGuid.NewGuid().Value;
            var cloudObject = new CloudEntity<Analysis>
            {
                PartitionKey = partKey,
                RowKey = rowkey,
                Value = analysis
            };

            var entities = new CloudTable<Analysis>(Providers.TableStorage, TableName);
            entities.Insert(cloudObject);
        }
 static System.Tuple <string, string> ToId <T>(CloudEntity <T> entity)
 {
     return(System.Tuple.Create(entity.PartitionKey, entity.RowKey));
 }
Beispiel #21
0
        public void InsertAndUpdateFailures()
        {
            var partitionKey = Guid.NewGuid().ToString();
            var rowKey       = Guid.NewGuid().ToString();

            var entity = new CloudEntity <string>
            {
                PartitionKey = partitionKey,
                RowKey       = rowKey,
                Timestamp    = DateTime.UtcNow,
                Value        = "value1"
            };

            // Insert entity.
            TableStorage.Insert(TableName, new[] { entity });

            // Insert Retry should fail.
            try
            {
                TableStorage.Insert(TableName, new[] { entity });
                Assert.Fail("#A01");
            }
            catch (InvalidOperationException)
            {
            }

            // Update entity twice should fail
            try
            {
                entity.Value = "value2";
                TableStorage.Update(TableName, new[] { entity, entity });
                Assert.Fail("#A02");
            }
            catch (InvalidOperationException)
            {
            }

            // Delete entity.
            TableStorage.Delete <string>(TableName, partitionKey, new[] { rowKey });

            // Update deleted entity should fail
            try
            {
                entity.Value = "value2";
                TableStorage.Update(TableName, new[] { entity });
                Assert.Fail("#A03");
            }
            catch (InvalidOperationException)
            {
            }

            // Insert entity twice should fail
            try
            {
                TableStorage.Insert(TableName, new[] { entity, entity });
                Assert.Fail("#A04");
            }
            catch (InvalidOperationException)
            {
            }
        }
Beispiel #22
0
 public void Upsert(CloudEntity <T> entity)
 {
     _provider.Upsert(_tableName, new[] { entity });
 }
Beispiel #23
0
 public void Update(CloudEntity <T> entity)
 {
     _provider.Update(_tableName, new[] { entity }, false);
 }
 public Task AddMessageAsync(byte[] content)
 {
     return(CloudEntity.AddMessageAsync(new CloudQueueMessage(content)));
 }
        public void InsertAndUpdateFailures()
        {
            var partitionKey = Guid.NewGuid().ToString();
            var rowKey = Guid.NewGuid().ToString();

            var entity = new CloudEntity<string>
                {
                    PartitionKey = partitionKey,
                    RowKey = rowKey,
                    Timestamp = DateTime.UtcNow,
                    Value = "value1"
                };

            // Insert entity.
            TableStorage.Insert(TableName, new[] { entity });

            // Insert Retry should fail.
            try
            {
                TableStorage.Insert(TableName, new[] { entity });
                Assert.Fail("#A01");
            }
            catch (InvalidOperationException)
            {
            }

            // Update entity twice should fail
            try
            {
                entity.Value = "value2";
                TableStorage.Update(TableName, new[] { entity, entity });
                Assert.Fail("#A02");
            }
            catch (InvalidOperationException)
            {
            }

            // Delete entity.
            TableStorage.Delete<string>(TableName, partitionKey, new[] { rowKey });

            // Update deleted entity should fail
            try
            {
                entity.Value = "value2";
                TableStorage.Update(TableName, new[] { entity });
                Assert.Fail("#A03");
            }
            catch (InvalidOperationException)
            {
            }

            // Insert entity twice should fail
            try
            {
                TableStorage.Insert(TableName, new[] { entity, entity });
                Assert.Fail("#A04");
            }
            catch (InvalidOperationException)
            {
            }
        }
Beispiel #26
0
 private Task <TableQuerySegment <DynamicTableEntity> > ExecuteQueryAsync(
     TableQuery <DynamicTableEntity> query,
     TableContinuationToken continuationToken)
 {
     return(CloudEntity.ExecuteQuerySegmentedAsync(query, continuationToken));
 }
Beispiel #27
0
 public ActionResult Edit(AnalysisView updatedAnalysis)
 {
     try
     {
         var analysis = Mapper.Map<Analysis>(updatedAnalysis);
         var cloudObject = new CloudEntity<Analysis>()
         {
             PartitionKey = updatedAnalysis.AnalysisPartKey,
             RowKey = updatedAnalysis.AnalysisRowKey,
             Value = analysis
         };
         var entities = new CloudTable<Analysis>(Providers.TableStorage, TableName);
         entities.Update(cloudObject);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }