How to determine if the environment is a production or a production as a laureate of service personnel?

I have a working role in my hosted service. An employee sends daily email databases. But there are 2 environments in the hosted service, production and production. Therefore, my work role sends an email 2 times a day. I would like to know how to determine if a worker works in stagnation or production. Thanks in advance.

+6
source share
2 answers

According to my question here you will see that this is not happening. In addition, if you really do not know what you are doing, I highly recommend that you do not .

However, if you want, you can use a really nice library ( Azure Service Management through C # ), although we do have some problems using WCF.

Here is a brief description of how to do this (note: you need to include the management certificate as a resource in your code and deploy it to Azure):

private static bool IsStaging() { try { if (!CloudEnvironment.IsAvailable) return false; const string certName = "AzureManagement.pfx"; const string password = "Pa$$w0rd"; // load certificate var manifestResourceStream = typeof(ProjectContext).Assembly.GetManifestResourceStream(certName); if (manifestResourceStream == null) { // should we panic? return true; } var bytes = new byte[manifestResourceStream.Length]; manifestResourceStream.Read(bytes, 0, bytes.Length); var cert = new X509Certificate2(bytes, password); var serviceManagementChannel = Microsoft.Toolkit.WindowsAzure.ServiceManagement.ServiceManagementHelper. CreateServiceManagementChannel("WindowsAzureServiceManagement", cert); using (new OperationContextScope((IContextChannel)serviceManagementChannel)) { var hostedServices = serviceManagementChannel.ListHostedServices(WellKnownConfiguration.General.SubscriptionId); // because we don't know the name of the hosted service, we'll do something really wasteful // and iterate foreach (var hostedService in hostedServices) { var ad = serviceManagementChannel.GetHostedServiceWithDetails( WellKnownConfiguration.General.SubscriptionId, hostedService.ServiceName, true); var deployment = ad.Deployments.Where( x => x.PrivateID == Zebra.Framework.Azure.CloudEnvironment.CurrentRoleInstanceId). FirstOrDefault (); if (deployment != null) { return deployment.DeploymentSlot.ToLower().Equals("staging"); } } } return false; } catch (Exception e) { // if something went wrong, let not panic TraceManager.AzureFrameworkTraceSource.TraceData(System.Diagnostics.TraceEventType.Error, "Exception", e); return false; } } 
+1
source

If you are using an SQL server (either Azure SQL or SQL Server hosted in a virtual machine), you can stop the intermediate worker role from doing the work by allowing the public IP of the Production instance to access the database server.

0
source

Source: https://habr.com/ru/post/897166/


All Articles