public void ClearForeignNetworkLinks(string ForeignID, Customer.ForeignUserTypes type)
        {
            try
            {
                TableServiceContextV2 clearContext = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);

                string partitionKey = ((int)type).ToString() + "+" + ForeignID;
                partitionKey = partitionKey.ToLower();

                var f = (from e in clearContext.CreateQuery<CustomerForeignNetworkConnectionDb>(TableName) where e.PartitionKey == partitionKey select e).AsTableServiceQuery();

                List<string> custPartitions = new List<string>();

                foreach (CustomerForeignNetworkConnectionDb d in f)
                {
                    custPartitions.Add("Cust" + d.CustomerID.ToString());
                    clearContext.DeleteObject(d);
                }

                clearContext.SaveChangesWithRetries(SaveChangesOptions.Batch);

                foreach (string s in custPartitions)
                {
                    var c = (from e in context.CreateQuery<CustomerForeignNetworkConnectionDb>(TableName) where e.PartitionKey == s && e.RowKey == partitionKey select e).FirstOrDefault();
                    clearContext.DeleteObject(c);
                    clearContext.SaveChangesWithRetries();
                }

                clearContext = null;
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine("FOREIGN NETWORK EXCEPTION: " + e.ToString());
            }
        }
        public void ClearAll(long ChallengeID)
        {
            TableServiceContextV2 clearChalContext = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);
            TableServiceContextV2 clearCustContext = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);

            CloudTableQuery<ChallengeStatusDb> c = (from e in clearChalContext.CreateQuery<ChallengeStatusDb>(TableName) where e.PartitionKey == DbChalKey(ChallengeID) select e).AsTableServiceQuery<ChallengeStatusDb>();

            List<ChallengeStatusDb> custDeletes = new List<ChallengeStatusDb>();

            foreach (ChallengeStatusDb d in c)
            {
                custDeletes.Add(new ChallengeStatusDb { PartitionKey = DbCustKey(d.CustomerID), RowKey = DbChalKey(d.ChallengeID) });
                clearChalContext.DeleteObject(d);
            }
            clearChalContext.SaveChangesWithRetries(SaveChangesOptions.Batch);

            foreach (ChallengeStatusDb d in custDeletes)
            {
                clearCustContext.AttachTo(TableName, d);
                clearCustContext.DeleteObject(d);
            }
            clearCustContext.SaveChangesWithRetries(SaveChangesOptions.Batch);

            clearChalContext = null;
            clearCustContext = null;
        }
 public PushServiceTokenRepository()
 {
     storage = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
     client = storage.CreateCloudTableClient();
     client.CreateTableIfNotExist(TableName);
     context = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);
 }
 public PushServiceTokenRepository()
 {
     storage = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
     client = storage.CreateCloudTableClient();
     client.CreateTableIfNotExist(TableName);
     context = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);
 }
        public CustomerRepoDapper()
        {
            connStr = ConfigurationManager.ConnectionStrings["DMTPrimary"].ConnectionString;

            storage = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
            client = storage.CreateCloudTableClient();
            client.CreateTableIfNotExist(TableName);
            context = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);
        }
        public ChallengeStatusVoteRepository()
        {
            storage = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            client = storage.CreateCloudTableClient();

            client.CreateTableIfNotExist(TableName);

            context = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);
            context.MergeOption = MergeOption.NoTracking;
        }
        public ActivityRepository()
        {
            storage = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
            client = storage.CreateCloudTableClient();

            client.CreateTableIfNotExist(TableName);

            context = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);
            context.IgnoreResourceNotFoundException = true;
        }
        public ChallengeStatusRepository()
        {
            storage = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            client = storage.CreateCloudTableClient();

            client.CreateTableIfNotExist(TableName);

            //context = client.GetDataServiceContext();
            context = new TableServiceContextV2(client.BaseUri.ToString(), client.Credentials);
            context.IgnoreResourceNotFoundException = true;
        }