Esempio n. 1
0
        public async Task ConstructorSqlToTable()
        {
            var c = new ConfigValues()
            {
                StorageAccountConnection = "UseDevelopmentStorage=true;",
                SqlConnection = "Server=localhost;Database=King.BTrak.Data;Trusted_Connection=True;",
                SqlTableName = "TableData",
                StorageTableName = "sqlserverdata",
                Direction = Direction.SqlToTable,
            };

            var id = Guid.NewGuid();
            var data = Guid.NewGuid();
            var statement = string.Format("INSERT INTO [dbo].[TestSqlToTable] ([Id], [Data]) VALUES ('{0}', '{1}');", id, data);
            var executor = new Executor(new SqlConnection(c.SqlConnection));
            await executor.NonQuery(statement);

            var s = new Synchronizer(c);
            await s.Run();

            await executor.NonQuery("TRUNCATE TABLE [dbo].[TestSqlToTable]");

            var table = new TableStorage(c.StorageTableName, c.StorageAccountConnection);
            var e = await table.QueryByPartitionAndRow("[dbo].[TestSqlToTable]", id.ToString());
            Assert.IsNotNull(e);
            Assert.AreEqual(data, e["Data"]);
        }
Esempio n. 2
0
        public async Task ConstructorTableToSql()
        {
            var c = new ConfigValues()
            {
                StorageAccountConnection = "UseDevelopmentStorage=true;",
                SqlConnection = "Server=localhost;Database=King.BTrak.Data;Trusted_Connection=True;",
                SqlTableName = "TableData",
                StorageTableName = "sqlserverdata",
                Direction = Direction.TableToSql,
            };

            var tableName = "testsynctabletosql";
            var table = new TableStorage(tableName, c.StorageAccountConnection);
            await table.CreateIfNotExists();
            var entity = new TableEntity
            {
                PartitionKey = Guid.NewGuid().ToString(),
                RowKey = Guid.NewGuid().ToString(),
            };
            await table.InsertOrReplace(entity);

            var s = new Synchronizer(c);
            await s.Run();

            await table.Delete();

            var statement = string.Format("SELECT 1 AS [Exists] FROM [dbo].[TableData] WHERE TableName='{0}' AND PartitionKey = '{1}' AND RowKey = '{2}';", tableName, entity.PartitionKey, entity.RowKey);
            var executor = new Executor(new SqlConnection(c.SqlConnection));
            var ds = await executor.Query(statement);
            var r = ds.Model<DataRow>();
            Assert.IsNotNull(r);
            Assert.IsTrue(r.Exists);
        }
Esempio n. 3
0
        public AzureStorage()
        {
            var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");

            StorageAccount = CloudStorageAccount.Parse(connectionString);

            Blob = new BlobStorage(StorageAccount);
            Table = new TableStorage(StorageAccount);
        }
        public MappedResultsStorageActions(TableStorage tableStorage, IUuidGenerator generator, OrderedPartCollection<AbstractDocumentCodec> documentCodecs, Reference<SnapshotReader> snapshot, Reference<WriteBatch> writeBatch, IBufferPool bufferPool, IStorageActionsAccessor storageActionsAccessor)
			: base(snapshot, bufferPool)
		{
			this.tableStorage = tableStorage;
			this.generator = generator;
			this.documentCodecs = documentCodecs;
			this.writeBatch = writeBatch;
	        this.storageActionsAccessor = storageActionsAccessor;
		}
        public MappedResultsStorageActions(TableStorage tableStorage, IUuidGenerator generator, OrderedPartCollection<AbstractDocumentCodec> documentCodecs, Reference<SnapshotReader> snapshot, 
			Reference<WriteBatch> writeBatch, IBufferPool bufferPool, IStorageActionsAccessor storageActionsAccessor, ConcurrentDictionary<int, RemainingReductionPerLevel> ScheduledReductionsPerViewAndLevel)
			: base(snapshot, bufferPool)
		{
			this.tableStorage = tableStorage;
			this.generator = generator;
			this.documentCodecs = documentCodecs;
			this.writeBatch = writeBatch;
	        this.storageActionsAccessor = storageActionsAccessor;
	        this.scheduledReductionsPerViewAndLevel = ScheduledReductionsPerViewAndLevel;
		}
Esempio n. 6
0
 public ListsStorageActions(TableStorage tableStorage, 
     IUuidGenerator generator, Reference<SnapshotReader> snapshot, 
     Reference<WriteBatch> writeBatch, 
     IBufferPool bufferPool,
     GeneralStorageActions generalStorageActions)
     : base(snapshot, bufferPool)
 {
     this.tableStorage = tableStorage;
     this.generator = generator;
     this.writeBatch = writeBatch;
     this.generalStorageActions = generalStorageActions;
 }
Esempio n. 7
0
 public DocumentsStorageActions(IUuidGenerator uuidGenerator,
                                OrderedPartCollection <AbstractDocumentCodec> documentCodecs,
                                IDocumentCacher documentCacher,
                                Reference <WriteBatch> writeBatch,
                                Reference <SnapshotReader> snapshot,
                                TableStorage tableStorage,
                                IBufferPool bufferPool,
                                bool skipConsistencyCheck = false)
     : base(snapshot, bufferPool)
 {
     this.uuidGenerator        = uuidGenerator;
     this.documentCodecs       = documentCodecs;
     this.documentCacher       = documentCacher;
     this.writeBatch           = writeBatch;
     this.tableStorage         = tableStorage;
     this.SkipConsistencyCheck = skipConsistencyCheck;
     metadataIndex             = tableStorage.Documents.GetIndex(Tables.Documents.Indices.Metadata);
 }
Esempio n. 8
0
        public async Task <ResponseModel> SetFeaturedMaps(int days)
        {
            var dates = Enumerable.Range(1, days).Select(i => DateTimeOffset.UtcNow.Date.AddDays(i));

            string previous = string.Empty;

            foreach (var date in dates)
            {
                if (await TableStorage.GetFeaturedMap(date) == default(MapEntity))
                {
                    var map = await TableStorage.SetFeaturedMap(await TableStorage.GetRandomMap(previous), date);

                    previous = map.RowKey;
                }
            }

            return(new ResponseModel("Featured maps set.", true));
        }
        public AuditLogIntegrationTests()
        {
            var readConfig = new ConfigurationBuilder().AddJsonFile("appSettings.json").Build();
            var config     = new ServicePrincipleConfig
            {
                InstanceName   = readConfig.GetValue <string>("InstanceName"),
                TenantId       = readConfig.GetValue <string>("TenantId"),
                SubscriptionId = readConfig.GetValue <string>("SubscriptionId"),
                AppId          = readConfig.GetValue <string>("AppId"),
                AppSecret      = readConfig.GetValue <string>("AppSecret"),
            };

            _tableStorage = new TableStorage(config);
            _tableStorage.CreateTable(_tableStorage.AuditTableName).GetAwaiter().GetResult();
            Thread.Sleep(5000);

            _auditLogger = _tableStorage;
        }
        public async Task <MapModel> GetRandomMap(string previous = "")
        {
            var model = MapModel.FromEntity(await TableStorage.GetRandomMap(previous));

            Analytics.AddEventAsync("api.public.get.random", new
            {
                client_id = this.ClientId,
                request_param_previous = previous,
                map_id            = model.Id,
                map_title         = model.Title,
                map_author        = model.Author,
                map_year          = model.Year,
                map_image_url     = model.ImageAddress,
                map_reference_url = model.ReferenceAddress
            });

            return(model);
        }
Esempio n. 11
0
        /// <summary>
        /// 遍历每一个历元
        /// </summary>
        /// <param name="epochInfo"></param>
        /// <returns></returns>
        public override bool Revise(ref EpochInformation epochInfo)
        {
            //如果没有基准卫星,则不可计算
            if (!epochInfo.TotalPrns.Contains(BasePrn))
            {
                return(false);
            }

            //1.计算所有的滤波值,并存储
            foreach (var sat in epochInfo)
            {
                CaculateOneSat(sat);
            }

            //2.构建星间差分对象
            var baseMwValue = this.LatestEpochSatWmValues[BasePrn];

            foreach (var sat in epochInfo) //只处理本历元具有的卫星
            {
                var val = this.LatestEpochSatWmValues[sat.Prn];
                //计算差分值
                CaculateDifferValue(val, baseMwValue);
            }

            //3.输出
            if (IsOutputDetails)
            {
                TableStorage.NewRow();
                TableStorage.AddItem("Epoch", epochInfo.ReceiverTime.ToShortTimeString());

                foreach (var sat in epochInfo) //只处理本历元具有的卫星
                {
                    var val       = this.LatestEpochSatWmValues[sat.Prn];
                    var prnKey    = val.Prn.ToString();
                    var smoothKey = BuildSmoothKey(prnKey);

                    //表格输出小数部分
                    TableStorage.AddItem(prnKey + "_Raw", val.RawValue);
                    TableStorage.AddItem(smoothKey, val.SmoothValue);
                    TableStorage.AddItem(prnKey + "_MwDiffer", val.DifferValue);
                }
            }
            return(true);
        }
        public async Task <MapModel> GetFeaturedMap()
        {
            MapModel model = MapModel.FromEntity(await TableStorage.GetFeaturedMap(DateTimeOffset.UtcNow));

            // If no featured map is set return a random one and set a short update check.
            if (model == null)
            {
                model = MapModel.FromEntity(await TableStorage.GetRandomMap());

                var nextHour = DateTimeOffset.UtcNow.AddHours(1) - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

                model.NextUpdate = (long)nextHour.TotalSeconds;

                Analytics.AddEventAsync("api.public.get.featured", new
                {
                    client_id         = this.ClientId,
                    map_id            = model.Id,
                    map_title         = model.Title,
                    map_author        = model.Author,
                    map_year          = model.Year,
                    map_image_url     = model.ImageAddress,
                    map_reference_url = model.ReferenceAddress,
                    next_update       = model.NextUpdate
                });

                return(model);
            }

            model.NextUpdate = Utils.NextFeaturedUpdateTime();

            Analytics.AddEventAsync("api.public.get.featured", new
            {
                client_id         = this.ClientId,
                map_id            = model.Id,
                map_title         = model.Title,
                map_author        = model.Author,
                map_year          = model.Year,
                map_image_url     = model.ImageAddress,
                map_reference_url = model.ReferenceAddress,
                next_update       = model.NextUpdate
            });

            return(model);
        }
Esempio n. 13
0
		public static void SaveWhereStats(FeedRegistry fr, Calinfo calinfo)
		{
			var id = calinfo.id;
			GenUtils.LogMsg("status", "SaveWhereStats: " + id, null);
			NonIcalStats estats = GetNonIcalStats(NonIcalType.eventful, id, calinfo, settings);
			NonIcalStats ustats = GetNonIcalStats(NonIcalType.upcoming, id, calinfo, settings);
			NonIcalStats ebstats = GetNonIcalStats(NonIcalType.eventbrite, id, calinfo, settings);
			NonIcalStats fbstats = GetNonIcalStats(NonIcalType.facebook, id, calinfo, settings);
			Dictionary<string, IcalStats> istats = GetIcalStats(id);

			var where = calinfo.where;
			string[] response = Utils.FindCityOrTownAndStateAbbrev(where);
			var city_or_town = response[0];
			var state_abbrev = response[1];
			int pop = Utils.FindPop(id, city_or_town, state_abbrev);
			var futurecount = 0;
			futurecount += estats.eventcount;
			futurecount += ustats.eventcount;
			futurecount += ebstats.eventcount;

			var sb_report = new StringBuilder();
			sb_report.Append(MakeTableHeader());

			var options = new ParallelOptions();

			Parallel.ForEach(source: fr.feeds.Keys, parallelOptions: options, body: (feedurl) =>
			//		foreach (var feedurl in fr.feeds.Keys)
			{
				StatsRow(id, istats, sb_report, ref futurecount, feedurl);
			}
			);

			sb_report.Append("</table>\n");

			var events_per_person = Convert.ToInt32(futurecount) / (float)pop;
			var report = Utils.EmbedHtmlSnippetInDefaultPageWrapper(calinfo, sb_report.ToString());
			bs.PutBlob(id, id + ".stats.html", new Hashtable(), Encoding.UTF8.GetBytes(report), "text/html");

			var dict = new Dictionary<string, object>();
			dict.Add("events", futurecount.ToString());
			dict.Add("events_per_person", string.Format("{0:f}", events_per_person));
			TableStorage.UpmergeDictToTableStore(dict, "metadata", id, id);
		}
Esempio n. 14
0
        public void CreateAndGetTable()
        {
            var originalCount = TableStorage.GetTables().Count();

            //Single thread.
            for (int i = 0; i <= 5; i++)
            {
                TableStorage.CreateTable("table" + i.ToString());
            }

            Assert.AreEqual(6, TableStorage.GetTables().Count() - originalCount, "#A01");

            //Remove tables.
            Assert.False(TableStorage.DeleteTable("Table_that_does_not_exist"), "#A02");
            var isSuccess = TableStorage.DeleteTable("table" + 4.ToString());

            Assert.IsTrue(isSuccess, "#A03");
            Assert.AreEqual(5, TableStorage.GetTables().Count() - originalCount, "#A04");
        }
Esempio n. 15
0
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "api/{wallId}/IsGeolocated")] HttpRequestMessage request, TraceWriter log, string wallId)
        {
            if (IsAuthenticated)
            {
                auth = request.GetAuthInfoAsync(log).Result;
            }

            log.Info("Is Authenticated: " + IsAuthenticated);

            bool   isAdmin    = false;
            string realWallId = wallId;

            //if admin ignore geo location
            if (IsAuthenticated)
            {
                var nameId = auth.GetClaim(ClaimTypes.NameIdentifier).Value;
                var result = TableStorage.GetEntity <Tracked>(Constants.TableNames.Tracked, nameId, wallId);
                isAdmin = result != null;

                log.Info("isAdmin: " + isAdmin);
            }

            var tempTable = TableStorage.GetEntity <TemporaryUrl>(Constants.TableNames.TemporaryUrl, wallId, wallId);

            if (tempTable == null && !isAdmin)
            {
                return(request.CreateResponse(HttpStatusCode.NotFound, "There's no wall here"));
            }

            if (!isAdmin)
            {
                realWallId = tempTable.RealUrl;
            }

            var location = TableStorage.GetEntity <Walls>(Constants.TableNames.Walls, realWallId, realWallId);

            if (location == null)
            {
                return(request.CreateResponse(HttpStatusCode.OK, new { IsGeolocated = false }));
            }

            return(request.CreateResponse(HttpStatusCode.OK, new { IsGeolocated = true }));
        }
        public async Task <ActionResult> Delete(string row, MapEntity model)
        {
            MapEntity entity = await TableStorage.Get(MapEntity.MainKey, row);

            try
            {
                await TableStorage.Delete(entity);
            }
            catch (StorageException error)
            {
                Task.Run(() => RavenClient.CaptureException(error));

                return(this.AzureStorageErrorResponse(row, MapEntity.MainKey, error));
            }

            this.TempData["Alerts"] = AlertModel.CreateSingle(AlertType.Info, string.Format("{0} by {1} was deleted.", entity.Title, entity.Author));

            return(this.RedirectToAction("Index"));
        }
Esempio n. 17
0
    public static void BuildSourceImagesForHub(string id)
    {
        var ts = TableStorage.MakeDefaultTableStorage();
        var source_image_results = new ConcurrentDictionary <string, List <Dictionary <string, string> > >();
        var feeds   = new List <Dictionary <string, object> >();
        var sources = new List <string>();
        var query   = string.Format("$filter=PartitionKey eq '{0}' and feedurl ne ''", id);

        feeds   = ts.QueryAllEntitiesAsListDict("metadata", query, 5000).list_dict_obj;
        feeds   = feeds.FindAll(x => x["feedurl"].ToString().Contains("eventful.com") == false);
        feeds   = feeds.OrderBy(x => x["source"].ToString()).ToList();
        sources = feeds.Select(x => x["source"].ToString()).ToList();
        sources = sources.Select(x => x.Replace("\n", "")).ToList();
        sources.Sort();
        var source_images      = GetSourceImages(id);
        var current_selections = GetCurrentImageSelections(id, source_images, sources, "source");

        SaveCategoryOrSourceImages("source", id, current_selections);
    }
Esempio n. 18
0
        public void Initialize()
        {
            bool runInMemory;

            bool.TryParse(settings["Raven/RunInMemory"], out runInMemory);

            var persistenceSource = runInMemory ? StorageEnvironmentOptions.CreateMemoryOnly() :
                                    CreateStorageOptionsFromConfiguration(path, settings);

            tableStorage = new TableStorage(persistenceSource, bufferPool);
            var schemaCreator = new SchemaCreator(configuration, tableStorage, Output, Log);

            schemaCreator.CreateSchema();
            schemaCreator.SetupDatabaseIdAndSchemaVersion();
            schemaCreator.UpdateSchemaIfNecessary();

            SetupDatabaseId();
            idGenerator = new IdGenerator(tableStorage);
        }
Esempio n. 19
0
        public GeoLocationQuery(IConfiguration configuration,
                                ILogger <GeoLocationQuery> logger,
                                IHttpClientFactory httpClientFactory,
                                GeoLocationService geoLocationService)
        {
            logger_             = logger;
            geoLocationService_ = geoLocationService;
            apiKey_             = configuration.GetValue <string>("IPDATA-API-KEY");
            httpClientFactory_  = httpClientFactory;
            newGates_           = configuration.GetValue("NewFeatureGates", false);

            var slot           = configuration.GetDeploymentSlot().ToString().ToLower();
            var slotName       = slot.ToString().ToLower();
            var connection     = configuration.GetValue <string>("SAFeatureGate");
            var storageAccount = CloudStorageAccount.Parse(connection);
            var tableClient    = TableStorageHelpers.CreateClient(storageAccount);

            ipCacheTable_ = new TableStorage(tableClient, $"{slotName}IpCache", true);
        }
Esempio n. 20
0
        public void EventbriteQueryReturnsPageCountOrMinusOne()
        {
            var collector = new Collector(test_calinfo, settings);

            string method = "event_search";
            string args   = collector.MakeEventBriteArgs(2, null);
            int    count  = collector.GetEventBritePageCount(method, args);

            Assert.That(count == -1 || count >= 1);
            if (count >= 1 && settings["eventbrite_quota_reached"] == "True")
            {
                GenUtils.PriorityLogMsg("info", "GetEventBritePageCount", "resetting quota marker");
                var dict = new Dictionary <string, object>()
                {
                    { "value", false }
                };
                TableStorage.UpmergeDictToTableStore(dict, "settings", "settings", "eventbrite_quota_reached");
            }
        }
Esempio n. 21
0
        public static void AssertNotModifiedByAnotherTransaction(TableStorage storage, ITransactionStorageActions transactionStorageActions, string key, Table.ReadResult readResult, TransactionInformation transactionInformation)
        {
            if (readResult == null)
            {
                return;
            }
            var txIdAsBytes = readResult.Key.Value <byte[]>("txId");

            if (txIdAsBytes == null)
            {
                return;
            }

            var txId = new Guid(txIdAsBytes);

            if (transactionInformation != null && transactionInformation.Id == txId)
            {
                return;
            }

            var existingTx = storage.Transactions.Read(new RavenJObject {
                { "txId", txId.ToByteArray() }
            });

            if (existingTx == null)            //probably a bug, ignoring this as not a real tx
            {
                return;
            }

            var timeout = existingTx.Key.Value <DateTime>("timeout");

            if (SystemTime.UtcNow > timeout)
            {
                transactionStorageActions.RollbackTransaction(txId);
                return;
            }

            throw new ConcurrencyException("Document '" + key + "' is locked by transaction: " + txId)
                  {
                      Key = key
                  };
        }
Esempio n. 22
0
        public override void Update(TableStorage tableStorage, Action <string> output)
        {
            Migrate(tableStorage.Environment, Tables.Files.TableName, output, (key, value) =>
            {
                var fileEtag = Guid.Parse(value["etag"].ToString());

                value["etag"] = fileEtag.ToByteArray();
            });

            Migrate(tableStorage.Environment, tableStorage.Files.GetIndexKey(Tables.Files.Indices.ByEtag), output, modifyIndexRecord: (key, reader) =>
            {
                var newKey = Etag.Parse(Guid.Parse(key.ToString()).ToByteArray()).ToString();

                return(new Tuple <Slice, Stream>(newKey, reader.AsStream()));
            });

            Migrate(tableStorage.Environment, Tables.Config.TableName, output, (key, value) =>
            {
                var actualKey = key.ToString();

                if (actualKey.StartsWith(RavenFileNameHelper.SyncNamePrefix, StringComparison.InvariantCultureIgnoreCase))
                {
                    string currentEtag = ((RavenJObject)value["metadata"])["FileETag"].ToString();

                    ((RavenJObject)value["metadata"])["FileETag"] = Etag.Parse(Guid.Parse(currentEtag).ToByteArray()).ToString();
                }
                else if (actualKey.StartsWith(RavenFileNameHelper.SyncResultNamePrefix, StringComparison.InvariantCultureIgnoreCase))
                {
                    string currentEtag = ((RavenJObject)value["metadata"])["FileETag"].ToString();

                    ((RavenJObject)value["metadata"])["FileETag"] = Etag.Parse(Guid.Parse(currentEtag).ToByteArray()).ToString();
                }
                else if (actualKey.StartsWith(SynchronizationConstants.RavenSynchronizationSourcesBasePath, StringComparison.InvariantCultureIgnoreCase))
                {
                    string currentEtag = ((RavenJObject)value["metadata"])["LastSourceFileEtag"].ToString();

                    ((RavenJObject)value["metadata"])["LastSourceFileEtag"] = Etag.Parse(Guid.Parse(currentEtag).ToByteArray()).ToString();
                }
            });

            UpdateSchemaVersion(tableStorage, output);
        }
Esempio n. 23
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "status/{id:int}")] HttpRequestMessage req, int id,
            ILogger log, System.Security.Claims.ClaimsPrincipal claimsPrincipal)
        {
            if (Auth.CheckIdentity(req, log, claimsPrincipal, out HttpResponseMessage err) == false)
            {
                return(err);
            }
            ;

            var icm = TableStorage.ListAllEntity().Where(x => x.RowKey == id.ToString()).ToList();
            HttpResponseMessage response;

            if (icm.Count == 0)
            {
                log.LogInformation("No ICM found, will redirect to /api/status");
                FunctionUtility.AddRunToSALsA(id);
                response = req.CreateResponse(HttpStatusCode.TemporaryRedirect);
                response.Headers.Location = new Uri("/api/status", UriKind.Relative);
            }
            else if (icm.FirstOrDefault().Log == null)
            {
                log.LogInformation("ICM found, but no logs. Will return 404");
                response         = req.CreateResponse(HttpStatusCode.NotFound);
                response.Content = new StringContent(String.Format("<b>SALsA Logs not available.</b><br>Status : <b>{0}</b>",
                                                                   Utility.UrlToHml(icm.FirstOrDefault().SALsAState, icm.FirstOrDefault().SALsALog, 14)), System.Text.Encoding.UTF8, "text/html");
            }
            else
            {
                log.LogInformation("ICM found, logs found. Redirecting to logs");
                response = req.CreateResponse(HttpStatusCode.TemporaryRedirect);
                response.Headers.Location = new Uri(icm.FirstOrDefault().Log, UriKind.Absolute);
            }

            response.Headers.CacheControl = new CacheControlHeaderValue
            {
                NoCache        = true,
                NoStore        = true,
                MustRevalidate = true
            };
            return(response);
        }
        public async static void Run([QueueTrigger("watermarkqueue", Connection = "")] PictureWaterMarkQueque myQueueItem, ILogger log)
        {
            try
            {
                //  AzureStorageConstant.AzureStorageConnectionString = "AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;";
                IBlobStorage blobStorage = new BlobStorage();
                INoSqlStorage <UserPicture> noSqlStorage = new TableStorage <UserPicture>();


                foreach (var item in myQueueItem.Pictures)
                {
                    using var stream = await blobStorage.DownloadAsync(item, EContainerName.pictures);

                    using var memoryStream = AddWaterMark(myQueueItem.WatermarkText, stream);

                    await blobStorage.UploadAsync(memoryStream, item, EContainerName.watermarkpictures);

                    log.LogInformation($"{item} Pictures added for watermark.");
                }

                var userpicture = await noSqlStorage.Get(myQueueItem.UserId, myQueueItem.UserPartitionKey);

                if (userpicture.WatermarkRawPaths != null)
                {
                    myQueueItem.Pictures.AddRange(userpicture.WatermarkPaths);
                }

                userpicture.WatermarkPaths = myQueueItem.Pictures;

                await noSqlStorage.Add(userpicture);

                HttpClient httpClient = new HttpClient();

                var response = await httpClient.GetAsync("https://localhost:44392/api/Notifications/CompleteWatermarkProcess/" + myQueueItem.ConnectionId);

                log.LogInformation($"Client({myQueueItem.ConnectionId}) my process complate.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 25
0
        public async Task <IActionResult> AddGameToSeason(string season, string teamName, string rec)
        {
            if (rec != "jorge")
            {
                return(Unauthorized());
            }

            string bodyAsText;

            using (var bodyReader = new StreamReader(Request.Body))
            {
                bodyAsText = bodyReader.ReadToEnd();
            }

            var input = JsonConvert.DeserializeObject <GameStorageEntity>(bodyAsText);
            //input.Date = DateTime.Now; // Always this date
            await TableStorage.InsertIntoTable(TableName, this.GetPartitionName(season, teamName), Guid.NewGuid().ToString(), input);

            return(Ok());
        }
Esempio n. 26
0
        public void BatchDictionaryThousandsDifferentPartitions()
        {
            var random = new Random();
            var count  = random.Next(2001, 10000);
            var items  = new List <IDictionary <string, object> >();

            for (var i = 0; i < count; i++)
            {
                var dic = new Dictionary <string, object>();
                dic.Add(TableStorage.PartitionKey, Guid.NewGuid().ToString());
                items.Add(dic);
            }

            var name = Guid.NewGuid().ToString();
            var t    = new TableStorage(name, ConnectionString);

            var batches = t.Batch(items);

            Assert.AreEqual(count, batches.Count());
        }
Esempio n. 27
0
        private async Task <bool> InsertUserAsync(User user)
        {
            try
            {
                user.Username = user.Email;
                var entity = new UserEntity(user);
                var table  = await TableStorage.CreateTableAsync(_configuration, UserTableName);

                TableOperation insert = TableOperation.Insert(entity);

                TableResult result = await table.ExecuteAsync(insert);

                return(result.HttpStatusCode == 200 || result.HttpStatusCode == 204);
            }
            catch (StorageException e)
            {
                Log.Logger.Error(e, "Error when register user to storage.");
                throw e;
            }
        }
        public async Task <FileModel> Upload(int projectId, int sectionId)
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            var context = HttpContext.Current.Request;
            var file    = new FileModel();

            if (context.Files.Count > 0)
            {
                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                var          index        = 0;
                BlobStorage  blobStorage  = new BlobStorage();
                TableStorage tableStorage = new TableStorage();
                QueueStorage queueStorage = new QueueStorage();

                foreach (var streamContent in filesReadToProvider.Contents)
                {
                    file.inputStream = await streamContent.ReadAsByteArrayAsync();

                    file.ProjectId = projectId;
                    file.SectionId = sectionId;
                    file.FileName  = context.Files[index].FileName;

                    file.FileSize  = file.inputStream.Length;
                    file.ImagePath = String.Format("{0}_{1}_{2}_{3}", projectId, sectionId, DateTime.Now.Ticks, file.FileName);
                    file.ThumbPath = String.Format("/UploadedFiles/{0}_{1}_th_{2}_{3}", projectId, sectionId, file.FileName, DateTime.Now.Ticks);
                    //var img = Image.FromStream(new System.IO.MemoryStream(fileBytes));
                    blobStorage.Upload(file);
                    file.inputStream = null;
                    // tableStorage.SaveTableStorage(file);
                    queueStorage.PushToQueue(file);

                    // FileModel fileModel= queueStorage.ReadFromQueue();
                    index++;
                }
            }
            return(file);
        }
Esempio n. 29
0
        public override void Update(TableStorage tableStorage, Action <string> output)
        {
            using (var tx = tableStorage.Environment.NewTransaction(TransactionFlags.ReadWrite))
            {
                var lists = tx.ReadTree(Tables.Lists.TableName);

                var iterator = lists.Iterate();

                if (iterator.Seek(Slice.BeforeAllKeys))
                {
                    do
                    {
                        var result = lists.Read(iterator.CurrentKey);

                        using (var stream = result.Reader.AsStream())
                        {
                            var listItem = stream.ToJObject();

                            if (listItem.ContainsKey("createdAt"))
                            {
                                continue;
                            }

                            listItem.Add("createdAt", SystemTime.UtcNow);

                            using (var streamValue = new MemoryStream())
                            {
                                listItem.WriteTo(streamValue);
                                streamValue.Position = 0;

                                lists.Add(iterator.CurrentKey, streamValue);
                            }
                        }
                    } while (iterator.MoveNext());
                }

                tx.Commit();
            }

            UpdateSchemaVersion(tableStorage, output);
        }
Esempio n. 30
0
        public void BatchThousandsDifferentPartitions()
        {
            var random = new Random();
            var count  = random.Next(2001, 10000);
            var items  = new List <ITableEntity>();

            for (var i = 0; i < count; i++)
            {
                items.Add(new TableEntity()
                {
                    PartitionKey = Guid.NewGuid().ToString()
                });
            }

            var name = Guid.NewGuid().ToString();
            var t    = new TableStorage(name, ConnectionString);

            var batches = t.Batch(items);

            Assert.AreEqual(count, batches.Count());
        }
Esempio n. 31
0
        private async Task <bool> InsertUserAsync(User user)
        {
            try
            {
                user.Username = string.Concat(user.Email.Split('@').First(), "@", _configuration.GetValue <string>("AzureAd:Domain"));

                var entity = new UserEntity(user);
                var table  = await TableStorage.CreateTableAsync(_configuration, UserTableName);

                TableOperation insert = TableOperation.Insert(entity);

                TableResult result = await table.ExecuteAsync(insert);

                return(result.HttpStatusCode == 200 || result.HttpStatusCode == 204);
            }
            catch (StorageException e)
            {
                Log.Logger.Error(e, "Error when register user to storage.");
                throw e;
            }
        }
Esempio n. 32
0
        public FeatureGateStore(
            IConfiguration configuration,
            ILogger <FeatureGateStore> logger,
            ServiceOption serviceOption,
            EventualCloudTableClient storage)
        {
            var slot       = configuration.GetDeploymentSlot().ToString().ToLower();
            var slotName   = slot.ToString().ToLower();
            var connection = configuration.GetValue <string>("SAFeatureGate");

            newGates_ = configuration.GetValue("NewFeatureGates", false);
            var storageAccount = CloudStorageAccount.Parse(connection);
            var tableClient    = TableStorageHelpers.CreateClient(storageAccount);

            Storage = storage.GetTableReference($"{slotName}Gates");
            Storage.CreateIfNotExists();
            logger_    = logger;
            rnd_       = new Random();
            GatesTable = new TableStorage(tableClient, $"{slotName}Gates", true);
            Service    = serviceOption.Service;
        }
Esempio n. 33
0
        //public Startup(IConfiguration configuration, ILogger<Startup> logger)
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            //_logger = logger;

            //_logger.LogInformation("Added TodoRepository to services");
            GlobalFunctions.CmdReadEncryptedSettings();

            TS = new TableStorage();
            bool b = TS.EnuserTables().Result;

            TSUserEntity demoUser = TS.FindUser("DemoUser", false, string.Empty).Result;

            if (demoUser is null)
            {
                TSUser newUser = new TSUser()
                {
                    Email      = "*****@*****.**",
                    Password   = "******",
                    FullName   = "Demo User",
                    UserName   = "******",
                    UserID     = TS.GetNewID("AllUsers", "LastUserID", true).Result,
                    CreateDate = DateTime.Now,
                };

                DemoUserID = newUser.UserID;
                b          = TS.AddUser(newUser).Result;
            }
            else
            {
                DemoUserID = demoUser.PartitionKey;
            }

            b = TS.AddActivityLog("AllUser", "Server started", MethodBase.GetCurrentMethod()).Result;


            _timerUserUpdater = new Timer(DoWorkUserUpdater, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10));
            _timerReminder    = new Timer(DoWorkReminder, null, TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(1));
        }
Esempio n. 34
0
        public void Post(SystemEvent @event)
        {
            var table = TableStorage.CreateCloudTable();

            var entity = new EventEntity(@event.Date)
            {
                Message = @event.Message,
                User    = @event.User
            };

            try
            {
                table.CreateIfNotExists();

                var insertOperation = new TableBatchOperation();
                insertOperation.Insert(entity);
                table.ExecuteBatch(insertOperation);
            }
            catch (Exception)
            {
            }
        }
Esempio n. 35
0
        public void CanOpenAfterCompaction()
        {
            var memoryPersistentSource = new MemoryPersistentSource();
            var tableStorage           = new TableStorage(memoryPersistentSource);

            tableStorage.Initialize();
            tableStorage.BeginTransaction();
            tableStorage.Documents.Put(new RavenJObject
            {
                { "key", "1" },
                { "etag", Guid.NewGuid().ToByteArray() },
                { "modified", SystemTime.UtcNow },
                { "id", 1 },
                { "entityName", "test" }
            }, new byte[512]);

            tableStorage.Documents.Put(new RavenJObject
            {
                { "key", "2" },
                { "etag", Guid.NewGuid().ToByteArray() },
                { "modified", SystemTime.UtcNow },
                { "id", 1 },
                { "entityName", "test" }
            }, new byte[512]);
            tableStorage.Commit();

            tableStorage.BeginTransaction();
            tableStorage.Documents.Remove(new RavenJObject {
                { "key", "1" }
            });
            tableStorage.Commit();

            tableStorage.Compact();


            var remoteManagedStorageState = memoryPersistentSource.CreateRemoteAppDomainState();

            new TableStorage(new MemoryPersistentSource(remoteManagedStorageState.Log)).Initialize();
        }
Esempio n. 36
0
        /// <summary>
        /// GSTR3B
        /// </summary>
        /// <param name="attrbute"></param>
        /// <param name="token"></param>
        private void GSTR3B(Attrbute attrbute, string token, Blob blob, TableStorage objTableStorage)
        {
            //upload  payload to blob storage
            var blobStorage = new BlobStorage(blob.Connection, Constants.CotainerPayload, token, new Dictionary <string, string>(), blob.Id);

            var blobPath = blobStorage.UploadBlob(attrbute);

            // prepare message for Event hub
            string jsonReqst = new JavaScriptSerializer()
                               .Serialize(new Request
            {
                RequestType  = RequestType.SaveGSTR3B,
                BlobFile     = token,
                RequestToken = token,
                Blob         = blob.Id,
                Clientid     = _clientid,
                Statecd      = _statecd,
                Username     = _username,
                Txn          = _txn,
                ClientSecret = _clientSecret,
                IpUsr        = _ipUsr,
                AuthToken    = _authToken,
                CreatedOn    = System.DateTime.UtcNow,
                //PartitionKey = Constants.PK_SaveGSTR1,
                RetPeriod = this._ret_period,
                Gstin     = this._gstin,
                ApiAction = attrbute.apiAction
            });

            //Write to Service Bus

            IQueueProcessor masterqueue = new WEP.GSP.EventHub.Queue.ServiceBus();

            masterqueue.WriteAsync(jsonReqst, true);

            //log to table storage  => P1 completed
            Task.Factory.StartNew(() =>
                                  objTableStorage.InsertStageToTableStorage(blob.Keys, (int)WEP.GSP.Document.Stage.Request_WRT_SUCCESS));
        }
        // RoleProvider methods
        public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                name = "TableStorageRoleProvider";
            }

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "Table storage-based role provider");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            bool allowInsecureRemoteEndpoints = Configuration.GetBooleanValue(config, "allowInsecureRemoteEndpoints", false);

            // structure storage-related properties
            ApplicationName = Configuration.GetStringValueWithGlobalDefault(config, "applicationName",
                                                Configuration.DefaultProviderApplicationNameConfigurationString,
                                                Configuration.DefaultProviderApplicationName, false);
            _accountName = Configuration.GetStringValue(config, "accountName", null, true);
            _sharedKey = Configuration.GetStringValue(config, "sharedKey", null, true);
            _tableName = Configuration.GetStringValueWithGlobalDefault(config, "roleTableName",
                                                Configuration.DefaultRoleTableNameConfigurationString,
                                                Configuration.DefaultRoleTableName, false);
            _membershipTableName = Configuration.GetStringValueWithGlobalDefault(config, "membershipTableName",
                                                Configuration.DefaultMembershipTableNameConfigurationString,
                                                Configuration.DefaultMembershipTableName, false);
            _tableServiceBaseUri = Configuration.GetStringValue(config, "tableServiceBaseUri", null, true);

            // remove required attributes
            config.Remove("allowInsecureRemoteEndpoints");
            config.Remove("applicationName");
            config.Remove("accountName");
            config.Remove("sharedKey");
            config.Remove("roleTableName");
            config.Remove("membershipTableName");
            config.Remove("tableServiceBaseUri");

            // Throw an exception if unrecognized attributes remain
            if (config.Count > 0)
            {
                string attr = config.GetKey(0);
                if (!String.IsNullOrEmpty(attr))
                {
                    throw new ProviderException(string.Format(CultureInfo.InstalledUICulture, "Unrecognized attribute: {0}", attr));
                }
            }

            StorageAccountInfo info = null;
            try
            {
                info = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration(true);
                if (_tableServiceBaseUri != null)
                {
                    info.BaseUri = new Uri(_tableServiceBaseUri);
                }
                if (_accountName != null)
                {
                    info.AccountName = _accountName;
                }
                if (_sharedKey != null)
                {
                    info.Base64Key = _sharedKey;
                }
                info.CheckComplete();
                SecUtility.CheckAllowInsecureEndpoints(allowInsecureRemoteEndpoints, info);
                _tableStorage = TableStorage.Create(info);
                _tableStorage.RetryPolicy = _tableRetry;
                _tableStorage.TryCreateTable(_tableName);
            }
            catch (SecurityException)
            {
                throw;
            }
            // catch InvalidOperationException as well as StorageException
            catch (Exception e)
            {
                string exceptionDescription = Configuration.GetInitExceptionDescription(info, "table storage configuration");
                string tableName = (_tableName == null) ? "no role table name specified" : _tableName;
                Log.Write(EventKind.Error, "Could not create or find role table: " + tableName + "!" + Environment.NewLine +
                                            exceptionDescription + Environment.NewLine +
                                            e.Message + Environment.NewLine + e.StackTrace);
                throw new ProviderException("Could not create or find role table. The most probable reason for this is that " +
                            "the storage endpoints are not configured correctly. Please look at the configuration settings " +
                            "in your .cscfg and Web.config files. More information about this error " +
                            "can be found in the logs when running inside the hosting environment or in the output " +
                            "window of Visual Studio.", e);
            }
        }
        public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                name = "TableServiceSessionStateProvider";
            }

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "Session state provider using table storage");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            bool allowInsecureRemoteEndpoints = Configuration.GetBooleanValue(config, "allowInsecureRemoteEndpoints", false);

            // structure storage-related properties
            _applicationName = Configuration.GetStringValueWithGlobalDefault(config, "applicationName",
                                                            Configuration.DefaultProviderApplicationNameConfigurationString,
                                                            Configuration.DefaultProviderApplicationName, false);
            _accountName = Configuration.GetStringValue(config, "accountName", null, true);
            _sharedKey = Configuration.GetStringValue(config, "sharedKey", null, true);
            _tableName = Configuration.GetStringValueWithGlobalDefault(config, "sessionTableName",
                                                Configuration.DefaultSessionTableNameConfigurationString,
                                                Configuration.DefaultSessionTableName, false);
            _tableServiceBaseUri = Configuration.GetStringValue(config, "tableServiceBaseUri", null, true);
            _containerName = Configuration.GetStringValueWithGlobalDefault(config, "containerName",
                                                Configuration.DefaultSessionContainerNameConfigurationString,
                                                Configuration.DefaultSessionContainerName, false);
            if (!SecUtility.IsValidContainerName(_containerName))
            {
                throw new ProviderException("The provider configuration for the TableStorageSessionStateProvider does not contain a valid container name. " +
                                            "Please refer to the documentation for the concrete rules for valid container names." +
                                            "The current container name is: " + _containerName);
            }
            _blobServiceBaseUri = Configuration.GetStringValue(config, "blobServiceBaseUri", null, true);

            config.Remove("allowInsecureRemoteEndpoints");
            config.Remove("accountName");
            config.Remove("sharedKey");
            config.Remove("containerName");
            config.Remove("applicationName");
            config.Remove("blobServiceBaseUri");
            config.Remove("tableServiceBaseUri");
            config.Remove("sessionTableName");

            // Throw an exception if unrecognized attributes remain
            if (config.Count > 0)
            {
                string attr = config.GetKey(0);
                if (!String.IsNullOrEmpty(attr))
                    throw new ProviderException
                    ("Unrecognized attribute: " + attr);
            }

            StorageAccountInfo tableInfo = null;
            StorageAccountInfo blobInfo = null;
            try
            {
                tableInfo = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration(true);
                blobInfo = StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration(true);
                if (_tableServiceBaseUri != null)
                {
                    tableInfo.BaseUri = new Uri(_tableServiceBaseUri);
                }
                if (_blobServiceBaseUri != null)
                {
                    blobInfo.BaseUri = new Uri(_blobServiceBaseUri);
                }
                if (_accountName != null)
                {
                    tableInfo.AccountName = _accountName;
                    blobInfo.AccountName = _accountName;
                }
                if (_sharedKey != null)
                {
                    tableInfo.Base64Key = _sharedKey;
                    blobInfo.Base64Key = _sharedKey;
                }
                tableInfo.CheckComplete();
                SecUtility.CheckAllowInsecureEndpoints(allowInsecureRemoteEndpoints, tableInfo);
                blobInfo.CheckComplete();
                SecUtility.CheckAllowInsecureEndpoints(allowInsecureRemoteEndpoints, blobInfo);
                _tableStorage = TableStorage.Create(tableInfo);
                _tableStorage.RetryPolicy = _tableRetry;
                _tableStorage.TryCreateTable(_tableName);
                _blobProvider = new BlobProvider(blobInfo, _containerName);
            }
            catch (SecurityException)
            {
                throw;
            }
            // catch InvalidOperationException as well as StorageException
            catch (Exception e)
            {
                string exceptionDescription = Configuration.GetInitExceptionDescription(tableInfo, blobInfo);
                string tableName = (_tableName == null) ? "no session table name specified" : _tableName;
                string containerName = (_containerName == null) ? "no container name specified" : _containerName;
                Log.Write(EventKind.Error, "Initialization of data service structures (tables and/or blobs) failed!" +
                                            exceptionDescription + Environment.NewLine +
                                            "Configured blob container: " + containerName + Environment.NewLine +
                                            "Configured table name: " + tableName + Environment.NewLine +
                                            e.Message + Environment.NewLine + e.StackTrace);
                throw new ProviderException("Initialization of data service structures (tables and/or blobs) failed!" +
                                            "The most probable reason for this is that " +
                                            "the storage endpoints are not configured correctly. Please look at the configuration settings " +
                                            "in your .cscfg and Web.config files. More information about this error " +
                                            "can be found in the logs when running inside the hosting environment or in the output " +
                                            "window of Visual Studio.", e);
            }
            Debug.Assert(_blobProvider != null);
        }