public IActionResult Table(string id) { DataAccess data = new DataAccess(configuration); AzureCloud cloud = new AzureCloud(configuration); ViewBag.table = id; if (id.Equals("product")) { TempData["id"] = "product"; List <Product> list = data.GetAllProduct(); foreach (var item in list) { //img = (img + token) item.Img += cloud.GetSAS(); } ViewBag.PList = list; } else if (id.Equals("user")) { TempData["id"] = "user"; List <User> list = data.GetAllUser(); ViewBag.UList = list; } else if (id.Equals("order")) { TempData["id"] = "order"; List <Order> list = data.GetAllOrder(); ViewBag.OList = list; } else { return(RedirectToAction("Index", "Home")); } return(View()); }
public IActionResult Search(UserIndexPage model) { if (model.Search == null) { model.Search = ""; } if (model.Scale == null) { model.Scale = ""; } DataAccess data = new DataAccess(configuration); AzureCloud cloud = new AzureCloud(configuration); List <UserIndexPage> list = data.SearchProductByUser(model.Search, model.Scale); foreach (var item in list) { item.Img += cloud.GetSAS(); } UserIndexPage uIP = new UserIndexPage(); uIP.Search = model.Search; uIP.ListScale = new List <SelectListItem>(); AddToComboBox(uIP, model.Scale); if (list.Count == 0) { ViewBag.PList = null; } else { ViewBag.PList = list; } return(View(uIP)); }
public IActionResult BestSeller(UserIndexPage model) { if (model.Search == null) { model.Search = ""; } if (model.Scale == null) { model.Scale = ""; } UserIndexPage uIP = new UserIndexPage { Search = model.Search, ListScale = new List <SelectListItem>() }; AddToComboBox(uIP, model.Scale); DataAccess data = new DataAccess(configuration); AzureCloud cloud = new AzureCloud(configuration); List <UserIndexPage> list = data.SearchProductBestSale(); foreach (UserIndexPage item in list) { item.Img += cloud.GetSAS(); } ViewBag.PList = list; return(View("Index", uIP)); }
public IActionResult Delete(string id, string model, string img) { DataAccess data = new DataAccess(configuration); AzureCloud cloud = new AzureCloud(configuration); try { if (model.Equals("user")) { data.DeleteUser(id); } else if (model.Equals("product")) { cloud.DeleteBlob(img); data.DeleteProduct(id); } TempData["DeleteS"] = "Delete Success"; return(RedirectToAction("Table", "Home", new { id = "product" })); } catch (Exception) { TempData["DeleteF"] = "Delete Fail"; return(RedirectToAction("Table", "Home", new { id = "product" })); } }
public static string GetForCloud(AzureCloud cloud) { switch (cloud) { case AzureCloud.Unknown: return("cloud:unknown"); case AzureCloud.Public: return("cloud:public"); case AzureCloud.Sovereign: return("cloud:sovereign"); case AzureCloud.China: return("cloud:china"); case AzureCloud.Government: return("cloud:government"); case AzureCloud.German: return("cloud:german"); default: throw new ArgumentOutOfRangeException(nameof(cloud), cloud, null); } }
public IActionResult ViewDetails(string id) { DataAccess data = new DataAccess(configuration); AzureCloud cloud = new AzureCloud(configuration); Product p = data.GetProductDetails(id); p.Img += cloud.GetSAS(); return(View("Product", p)); }
public IActionResult ProductDetail(int id) { DataAccess dataAccess = new DataAccess(configuration); AzureCloud cloud = new AzureCloud(configuration); Product product = dataAccess.SearchByPrimarykey(id); product.Img += cloud.GetSAS(); AddToComboBox(product.Scale); return(View("ProductDetail", product)); }
public IActionResult Insert(List <IFormFile> files, Product product) { long size = files.Count(); bool checkFile = false; var filePath = Path.GetTempFileName(); if (size > 0) { checkFile = files[0].ContentType.Contains("ima"); } var name = _context.Product.FirstOrDefault(t => t.Name.Equals(product.Name)); AddToComboBox(""); if (name != null) { TempData["InsertF"] = "Cannot Create Product!"; ModelState.AddModelError("Name", "This name is existed!"); return(View("CreateProduct")); } if (!ModelState.IsValid) { TempData["InsertF"] = "Cannot Create Product!"; return(View("CreateProduct")); } if (!checkFile) { TempData["InsertF"] = "Cannot Create Product!"; ModelState.AddModelError("Img", "Select Box(1-Img File Only)!"); return(View("CreateProduct")); } var stream = new FileStream(filePath, FileMode.Open); files[0].CopyTo(stream); stream.Position = 0; string extension = Path.GetExtension(files[0].FileName); string fileName = (product.Name + extension); AzureCloud cloud = new AzureCloud(configuration); DataAccess dataAccess = new DataAccess(configuration); try { string uri = cloud.UploadFile(fileName, stream); product.Img = uri; dataAccess.InsertProduct(product); } catch (Exception e) { TempData["InsertF"] = e.Message; return(View("CreateProduct")); } TempData["InsertS"] = "Create Product Success"; return(RedirectToAction("CreateProduct", "Home")); }
public IActionResult Search(string search, string id, string from, string to) { if (search == null) { search = ""; } TempData["id"] = id; DataAccess data = new DataAccess(configuration); AzureCloud cloud = new AzureCloud(configuration); if (id.Equals("product")) { List <Product> list = data.SearchProductByName(search); foreach (var item in list) { //img = (img + token) item.Img += cloud.GetSAS(); } ViewBag.PList = list; } else if (id.Equals("user")) { List <User> list = data.SearchUserByName(search); ViewBag.UList = list; } else { List <Order> list = new List <Order>(); if (from == null && to == null) { list = (from t in _context.Order select t).ToList(); } else if (to == null) { list = (from t in _context.Order where t.DOC > DateTime.Parse(@from) select t).ToList(); } else if (from == null) { list = (from t in _context.Order where DateTime.Parse(to) > t.DOC select t).ToList(); } else { list = (from t in _context.Order where DateTime.Parse(to) > t.DOC && t.DOC > DateTime.Parse(@from) select t).ToList(); } if (list.Count() == 0) { list = null; } ViewBag.OList = list; } return(View("Table")); }
public IActionResult Update(List <IFormFile> files, [Bind("Created,ID,Quantity,Name,Img,Price,Description,Scale,Release")] Product product) { long size = files.Count(); bool checkFile; var filePath = Path.GetTempFileName(); if (size > 0) { checkFile = files[0].ContentType.Contains("ima"); if (!checkFile) { TempData["UpdateF"] = "Cannot Update Product!"; ViewData["ERROR"] = "1-Img File Only"; return(View("ProductDetail")); } } else { product.Img = product.Img.Split("?sv=")[0]; } if (!ModelState.IsValid) { TempData["UpdateF"] = "Cannot Update Product!"; return(View("ProductDetail")); } AzureCloud cloud = new AzureCloud(configuration); DataAccess dataAccess = new DataAccess(configuration); try { if (size > 0) { var stream = new FileStream(filePath, FileMode.Open); files[0].CopyTo(stream); stream.Position = 0; string extension = Path.GetExtension(files[0].FileName); string fileName = (product.Name + extension); cloud.DeleteBlob(product.Img); string uri = cloud.UploadFile(fileName, stream); product.Img = uri; } dataAccess.UpdateProduct(product); TempData["UpdateS"] = "Update Product Success!"; return(RedirectToAction("ProductDetail", "Home", new { id = product.ID })); } catch (Exception e) { TempData["UpdateF"] = "Cannot Update Product!" + e.Message; return(View("ProductDetail")); } }
/// <summary> /// Gets the <see cref="AzureEnvironment"/> representation of the <see cref="AzureCloud"/>. /// </summary> /// <param name="cloud">The enumeration to determine the environment.</param> /// <returns> /// An <see cref="AzureEnvironment"/> instance that the <see cref="AzureCloud"/> represents. /// </returns> /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="cloud"/> is outside the bounds of the enumeration.</exception> public static AzureEnvironment GetAzureEnvironment(this AzureCloud cloud) { switch (cloud) { case AzureCloud.Global: return(AzureEnvironment.AzureGlobalCloud); case AzureCloud.China: return(AzureEnvironment.AzureChinaCloud);; case AzureCloud.USGovernment: return(AzureEnvironment.AzureUSGovernment); case AzureCloud.German: return(AzureEnvironment.AzureGermanCloud); default: throw new ArgumentOutOfRangeException(nameof(cloud), cloud, "Unknown cloud environment"); } }
/// <summary> /// Get Azure environment information /// </summary> /// <param name="azureCloud">Microsoft Azure cloud</param> /// <returns>Azure environment information for specified cloud</returns> public static AzureEnvironment GetAzureEnvironment(this AzureCloud azureCloud) { switch (azureCloud) { case AzureCloud.Global: return AzureEnvironment.AzureGlobalCloud; case AzureCloud.China: return AzureEnvironment.AzureChinaCloud; case AzureCloud.Germany: return AzureEnvironment.AzureGermanCloud; case AzureCloud.UsGov: return AzureEnvironment.AzureUSGovernment; default: throw new ArgumentOutOfRangeException(nameof(azureCloud), "No Azure environment is known for"); } }
public IActionResult Index() { DataAccess data = new DataAccess(configuration); AzureCloud cloud = new AzureCloud(configuration); List <UserIndexPage> list = data.SearchProductNewArrival(); foreach (UserIndexPage item in list) { item.Img += cloud.GetSAS(); } ViewBag.PList = list; UserIndexPage uIP = new UserIndexPage(); //null ref uIP.ListScale = new List <SelectListItem>(); AddToComboBox(uIP, ""); return(View(uIP)); }
private static async Task <LogicManagementClient> AuthenticateLogicAppsManagementAsync( string subscriptionId, string tenantId, string clientId, string clientSecret, AzureCloud cloud) { AzureEnvironment azureEnvironment = cloud.GetAzureEnvironment(); string authority = azureEnvironment.AuthenticationEndpoint + tenantId; var authContext = new AuthenticationContext(authority); var credential = new ClientCredential(clientId, clientSecret); AuthenticationResult token = await authContext.AcquireTokenAsync(azureEnvironment.ManagementEndpoint, credential); LogicManagementClient client = AuthenticateLogicAppsManagement(subscriptionId, token.AccessToken); return(client); }
public static Uri GetAzureAuthorityHost(this AzureCloud azureCloud) { switch (azureCloud) { case AzureCloud.Global: return(AzureAuthorityHosts.AzurePublicCloud); case AzureCloud.China: return(AzureAuthorityHosts.AzureChina); case AzureCloud.Germany: return(AzureAuthorityHosts.AzureGermany); case AzureCloud.UsGov: return(AzureAuthorityHosts.AzureGovernment); default: throw new ArgumentOutOfRangeException(nameof(azureCloud), "No Azure environment is known for"); } }
static void Main(string[] args) { // Create a bus instance. IBus bus = AzureCloud .ConfigureBus() .WithPublishConfiguration((c) => c.WithMessageMetadata((m, configure) => { configure.Add("Message.Activo", ((SampleMessage)m).Activo); })) ////.WithSubscriptionConfiguration((c) => c.WithTopicByMessageNamespace()) .CreateBus(); // Subscribe to messages. var autoSubscriber = new AutoSubscriber(bus, "AzureBus.Sample.Console"); autoSubscriber.Subscribe(Assembly.GetExecutingAssembly()); var activo = true; // Send 100 messages. for (int i = 0; i < 10; i++) { activo = !activo; bus.Publish(new SampleMessage(i.ToString(), activo)); } ////// Create a Queue instance ////IQueue queue = AzureCloud.CreateQueue(); ////// Send 100 messages. ////for (int i = 0; i < 10; i++) ////{ //// queue.Send(new SampleMessage(i.ToString())); ////} ////// Subscribe to queue for messages of type SampleMessage ////queue.Subscribe<SampleMessage>((m) => Console.WriteLine(string.Format("Message received from Queue: Value = {0}", m.Value))); Console.ReadKey(); }
/// <summary> /// Uses the service principal to authenticate with Azure. /// </summary> /// <param name="tenantId">The ID where the resources are located on Azure.</param> /// <param name="subscriptionId">The ID that identifies the subscription on Azure.</param> /// <param name="clientId">The ID of the client or application that has access to the logic apps running on Azure.</param> /// <param name="clientSecretName">The secret of the client or application that has access to the logic apps running on Azure.</param> /// <param name="secretProvider">The provider to get the client secret; using the <paramref name="clientSecretName"/>.</param> /// <param name="cloud">The Azure cloud environment to use during authenticating and interacting with the Azure Logic Apps resources.</param> /// <exception cref="ArgumentException">Thrown when the <paramref name="tenantId"/>, <paramref name="subscriptionId"/>, <paramref name="clientId"/>, or <paramref name="clientSecretName"/> is blank.</exception> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="secretProvider"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="cloud"/> is outside the bounds of the enumeration.</exception> public static LogicAppAuthentication UsingServicePrincipal(string tenantId, string subscriptionId, string clientId, string clientSecretName, ISecretProvider secretProvider, AzureCloud cloud = AzureCloud.Global) { Guard.NotNullOrWhitespace(tenantId, nameof(tenantId), "Requires an tenant ID where the Azure resources are located"); Guard.NotNullOrWhitespace(subscriptionId, nameof(subscriptionId), "Requires an ID that identifies the Azure subscription that has access to the Azure resources"); Guard.NotNullOrWhitespace(clientId, nameof(clientId), "Requires an client or application ID that is authorized to interact with the Logic Apps running on Azure"); Guard.NotNullOrWhitespace(clientSecretName, nameof(clientSecretName), "Requires an client or application secret key that points to the secret of the client or application that is authorized to interact with the Logic Apps running on Azure"); Guard.NotNull(secretProvider, nameof(secretProvider), "Requires an secret provider instance to retrieve the secret of the client or application that is authorized to interact with the Logic Apps running on Azure"); Guard.For(() => !Enum.IsDefined(typeof(AzureCloud), cloud), new ArgumentOutOfRangeException(nameof(cloud), cloud, "Requires the Azure cloud environment to be within the bounds of the enumeration")); return(new LogicAppAuthentication(async() => { string clientSecret = await secretProvider.GetRawSecretAsync(clientSecretName); LogicManagementClient managementClient = await AuthenticateLogicAppsManagementAsync(subscriptionId, tenantId, clientId, clientSecret, cloud); return managementClient; })); }
/// <summary> /// Uses the service principal to authenticate with Azure. /// </summary> /// <param name="tenantId">The ID where the resources are located on Azure.</param> /// <param name="subscriptionId">The ID that identifies the subscription on Azure.</param> /// <param name="clientId">The ID of the client or application that has access to the logic apps running on Azure.</param> /// <param name="clientSecret">The authentication key of the client or application that has access to the logic apps running on Azure.</param> /// <param name="cloud">The Azure cloud environment to use during authenticating and interacting with the Azure Logic Apps resources.</param> /// <exception cref="ArgumentException">Thrown when the <paramref name="tenantId"/>, <paramref name="subscriptionId"/>, <paramref name="clientId"/>, or <paramref name="clientSecret"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="cloud"/> is outside the bounds of the enumeration.</exception> public static LogicAppAuthentication UsingServicePrincipal(string tenantId, string subscriptionId, string clientId, string clientSecret, AzureCloud cloud = AzureCloud.Global) { Guard.NotNullOrWhitespace(tenantId, nameof(tenantId), "Requires an tenant ID where the Azure resources are located"); Guard.NotNullOrWhitespace(subscriptionId, nameof(subscriptionId), "Requires an ID that identifies the Azure subscription that has access to the Azure resources"); Guard.NotNullOrWhitespace(clientId, nameof(clientId), "Requires an client or application ID that is authorized to interact with the Logic Apps running on Azure"); Guard.NotNullOrWhitespace(clientSecret, nameof(clientSecret), "Requires an client or application secret that is authorized to interact with the Logic Apps running on Azure"); Guard.For(() => !Enum.IsDefined(typeof(AzureCloud), cloud), new ArgumentOutOfRangeException(nameof(cloud), cloud, "Requires the Azure cloud environment to be within the bounds of the enumeration")); return(new LogicAppAuthentication( () => AuthenticateLogicAppsManagementAsync(subscriptionId, tenantId, clientId, clientSecret, cloud))); }
public void GetAzureEnvironment_WithOutOfBoundsEnum_Throws(AzureCloud cloud) { Assert.ThrowsAny <ArgumentException>(() => cloud.GetAzureEnvironment()); }
public static Cloud GetCloud(DataActionEventArgs e, Database Database) { CloudType type = !e.Values.ContainsKey("type") ? CloudType.Function : (CloudType)Enum.Parse(typeof(CloudType), (string)e.Values["type"]); string accessKeyId = !e.Values.ContainsKey("AccessKeyId") ? null : (string)e.Values["AccessKeyId"]; string awsRegion = !e.Values.ContainsKey("AwsRegion") ? null : (string)e.Values["AwsRegion"]; CloudVendor cloudVendor = !e.Values.ContainsKey("CloudVendor") ? CloudVendor.AWS : (CloudVendor)Enum.Parse(typeof(CloudVendor), (string)e.Values["CloudVendor"]); string encryptedSecretAccessKey = !e.Values.ContainsKey("EncryptedSecretAccessKey") ? null : (string)e.Values["EncryptedSecretAccessKey"]; string name = !e.Values.ContainsKey("Name") ? null : (string)e.Values["Name"]; switch (cloudVendor) { case CloudVendor.Azure: { string encryptedPassword = !e.Values.ContainsKey("password") ? null : (string)e.Values["password"]; string tenant = !e.Values.ContainsKey("tenant") ? null : (string)e.Values["tenant"]; string appId = !e.Values.ContainsKey("appId") ? null : (string)e.Values["appId"]; string subscriptionId = !e.Values.ContainsKey("subscriptionId") ? null : (string)e.Values["subscriptionId"]; string connectionString = !e.Values.ContainsKey("ConnectionString") ? null : (string)e.Values["ConnectionString"]; Cloud cloud = new AzureCloud(Database) { AppId = appId, SubscriptionId = subscriptionId, EncryptedPassword = encryptedPassword, tenant = tenant, CloudVendor = cloudVendor, Name = name, ConnectionString = connectionString, Type = type }; return(cloud); } case CloudVendor.GCP: { string projectName = !e.Values.ContainsKey("ProjectName") ? null : (string)e.Values["ProjectName"]; string clientEmail = !e.Values.ContainsKey("ClientEmail") ? null : (string)e.Values["ClientEmail"]; string encryptedPrivateKey = !e.Values.ContainsKey("EncryptedPrivateKey") ? null : (string)e.Values["EncryptedPrivateKey"]; Cloud cloud = new GoogleCloud(Database) { EncryptedPrivateKey = encryptedPrivateKey, ClientEmail = clientEmail, ProjectName = projectName, CloudVendor = cloudVendor, Name = name, Type = type }; return(cloud); } case CloudVendor.FnProject: { string connectionString = !e.Values.ContainsKey("ConnectionString") ? null : (string)e.Values["ConnectionString"]; string gateway = !e.Values.ContainsKey("Gateway") ? null : (string)e.Values["Gateway"]; Cloud cloud = new FnProjectCloud(Database) { gateway = gateway, connectionString = connectionString, CloudVendor = cloudVendor, Name = name, Type = type }; return(cloud); } case CloudVendor.OpenFaas: { string projectName = !e.Values.ContainsKey("ProjectName") ? null : (string)e.Values["ProjectName"]; string connectionString = !e.Values.ContainsKey("ConnectionString") ? null : (string)e.Values["ConnectionString"]; string gateway = !e.Values.ContainsKey("Gateway") ? null : (string)e.Values["Gateway"]; Cloud cloud = new OpenFaasCloud(Database) { projectName = projectName, gateway = gateway, connectionString = connectionString, CloudVendor = cloudVendor, Name = name, Type = type }; return(cloud); } default: return(new Cloud(Database) { AccessKeyId = accessKeyId, Region = awsRegion, CloudVendor = cloudVendor, EncryptedSecretAccessKey = encryptedSecretAccessKey, Name = name, Type = type }); } //throw new NotImplementedException(); }
public static Durados.Cloud GetCloud(System.Data.DataRowView row, int id, Database Database) { CloudType type = row.Row.IsNull("type") ? CloudType.Function : (CloudType)Enum.Parse(typeof(CloudType), (string)row["type"]); string accessKeyId = row.Row.IsNull("AccessKeyId") ? null : (string)row["AccessKeyId"]; string awsRegion = row.Row.IsNull("AwsRegion") ? null : (string)row["AwsRegion"]; CloudVendor cloudVendor = row.Row.IsNull("CloudVendor") ? CloudVendor.AWS : (CloudVendor)Enum.Parse(typeof(CloudVendor), (string)row["CloudVendor"]); string encryptedSecretAccessKey = row.Row.IsNull("EncryptedSecretAccessKey") ? null : (string)row["EncryptedSecretAccessKey"]; string name = row.Row.IsNull("Name") ? null : (string)row["Name"]; switch (cloudVendor) { case CloudVendor.Azure: { string encryptedPassword = row.Row.IsNull("Password") ? null : (string)row["Password"]; string tenant = row.Row.IsNull("tenant") ? null : (string)row["tenant"]; string appId = row.Row.IsNull("appId") ? null : (string)row["appId"]; string subscriptionId = row.Row.IsNull("subscriptionId") ? null : (string)row["subscriptionId"]; string connectionString = row.Row.IsNull("ConnectionString") ? null : (string)row["ConnectionString"]; Cloud cloud = new AzureCloud(Database) { Id = id, AppId = appId, SubscriptionId = subscriptionId, EncryptedPassword = encryptedPassword, tenant = tenant, CloudVendor = cloudVendor, Name = name, ConnectionString = connectionString, Type = type }; return(cloud); } case CloudVendor.GCP: { string projectName = row.Row.IsNull("ProjectName") ? null : (string)row["ProjectName"]; string clientEmail = row.Row.IsNull("ClientEmail") ? null : (string)row["ClientEmail"]; string encryptedPrivateKey = row.Row.IsNull("EncryptedPrivateKey") ? null : (string)row["EncryptedPrivateKey"]; Cloud cloud = new GoogleCloud(Database) { Id = id, EncryptedPrivateKey = encryptedPrivateKey, ClientEmail = clientEmail, ProjectName = projectName, CloudVendor = cloudVendor, Name = name, Type = type }; return(cloud); } case CloudVendor.FnProject: { string connectionString = row.Row.IsNull("ConnectionString") ? null : (string)row["ConnectionString"]; string gateway = row.Row.IsNull("Gateway") ? null : (string)row["Gateway"]; Cloud cloud = new FnProjectCloud(Database) { Id = id, gateway = gateway, connectionString = connectionString, CloudVendor = cloudVendor, Name = name, Type = type }; return(cloud); } case CloudVendor.OpenFaas: { string projectName = row.Row.IsNull("ProjectName") ? null : (string)row["ProjectName"]; string connectionString = row.Row.IsNull("ConnectionString") ? null : (string)row["ConnectionString"]; string gateway = row.Row.IsNull("Gateway") ? null : (string)row["Gateway"]; Cloud cloud = new OpenFaasCloud(Database) { Id = id, projectName = projectName, gateway = gateway, connectionString = connectionString, CloudVendor = cloudVendor, Name = name, Type = type }; return(cloud); } default: return(new Cloud(Database) { Id = id, AccessKeyId = accessKeyId, Region = awsRegion, CloudVendor = cloudVendor, EncryptedSecretAccessKey = encryptedSecretAccessKey, Name = name, Type = type }); } }