2011-09-12 5 views
6

私はホストされたサービスでワーカーの役割を持っています。 労働者は、毎日電子メールを送信しています。 しかし、ホステッドサービスでは、2つの環境、ステージングとプロダクションがあります。 私のワーカーの役割は毎日2回電子メールを送信します。 私は、労働者が停滞しているか生産中であるかを検出する方法を知りたいと思います。 ありがとうございます。環境がAzureでホストされているサービスワーカーロールでステージングまたはプロダクションであるかどうかを検出する方法はありますか。

+1

こちらをご覧ください:http://stackoverflow.com/questions/4328462/staging-or-production-instance – Igorek

答えて

1

私の質問hereによれば、速いの方法がないことがわかります。また、実際にあなたが何をしているのかわからない限り、私は強くお勧めしますこれを行わないでください

あなたは私たちはいくつかのtrouble with WCF using it.

はここで(ノートでそれを行う方法について簡単にサンプルがあります持っていなかったが、あなたは本当に素晴らしいライブラリ(Azure Service Management via C#)を使用することができますしたい場合は、あなたが管理証明書を含める必要があなたのコード内のリソースとして&)はアズールに展開:

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's not panic 
       TraceManager.AzureFrameworkTraceSource.TraceData(System.Diagnostics.TraceEventType.Error, "Exception", e); 
       return false; 
      } 
     } 
0

SQL Serverを使用している場合(いずれかのAzure SQLまたはVMでホストされているSQL Serverの)、あなたは仕事をしてからステージングWorkerロールを停止することができプロダクションインスタンスのパブリックIPにデータベースサーバへのアクセスのみを許可します。

関連する問題