Exemplo n.º 1
0
        public static void ModifyReservation(string urlPrefix, string accountName, bool removeReservation)
        {
            Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTP_SERVICE_CONFIG_URLACL_SET hTTPSERVICECONFIGURLACLSET = new Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTP_SERVICE_CONFIG_URLACL_SET();
            string str = HttpReservation.CreateSddl(accountName);

            hTTPSERVICECONFIGURLACLSET.Key.UrlPrefix = urlPrefix;
            hTTPSERVICECONFIGURLACLSET.Param.Sddl    = str;
            Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTPAPI_VERSION hTTPAPIVERSION = new Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTPAPI_VERSION(1, 0);
            int num = Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HttpInitialize(hTTPAPIVERSION, 2, IntPtr.Zero);

            if (num != 0)
            {
                throw HttpReservation.GetException("HttpInitialize", num);
            }
            try
            {
                if (removeReservation)
                {
                    num = Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HttpDeleteServiceConfigurationAcl(IntPtr.Zero, 2, ref hTTPSERVICECONFIGURLACLSET, Marshal.SizeOf(typeof(Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTP_SERVICE_CONFIG_URLACL_SET)), IntPtr.Zero);
                }
                num = Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HttpSetServiceConfigurationAcl(IntPtr.Zero, 2, ref hTTPSERVICECONFIGURLACLSET, Marshal.SizeOf(typeof(Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTP_SERVICE_CONFIG_URLACL_SET)), IntPtr.Zero);
                if (num != 0)
                {
                    throw HttpReservation.GetException("HttpSetServiceConfigurationAcl", num);
                }
            }
            finally
            {
                Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HttpTerminate(2, IntPtr.Zero);
            }
        }
Exemplo n.º 2
0
        private static Exception GetException(string fcn, int errorCode)
        {
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            object[] objArray = new object[] { fcn, HttpReservation.GetWin32ErrorMessage(errorCode) };
            return(new HttpReservationException(string.Format(invariantCulture, "{0} failed: {1}", objArray)));
        }
Exemplo n.º 3
0
        public static bool ArePortsReserved(string urlPrefix, string accountName)
        {
            Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTP_SERVICE_CONFIG_URLACL_SET hTTPSERVICECONFIGURLACLSET = new Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTP_SERVICE_CONFIG_URLACL_SET();
            bool   flag;
            bool   flag1 = false;
            string str   = HttpReservation.CreateSddl(accountName);

            hTTPSERVICECONFIGURLACLSET.Key.UrlPrefix = urlPrefix;
            hTTPSERVICECONFIGURLACLSET.Param.Sddl    = str;
            Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTPAPI_VERSION hTTPAPIVERSION = new Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTPAPI_VERSION(1, 0);
            int num = Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HttpInitialize(hTTPAPIVERSION, 2, IntPtr.Zero);

            if (num != 0)
            {
                throw HttpReservation.GetException("HttpInitialize", num);
            }
            try
            {
                num = Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HttpDeleteServiceConfigurationAcl(IntPtr.Zero, 2, ref hTTPSERVICECONFIGURLACLSET, Marshal.SizeOf(typeof(Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTP_SERVICE_CONFIG_URLACL_SET)), IntPtr.Zero);
                if (num != 0)
                {
                    flag1 = false;
                }
                else
                {
                    num = Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HttpSetServiceConfigurationAcl(IntPtr.Zero, 2, ref hTTPSERVICECONFIGURLACLSET, Marshal.SizeOf(typeof(Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HTTP_SERVICE_CONFIG_URLACL_SET)), IntPtr.Zero);
                    if (num != 0)
                    {
                        throw HttpReservation.GetException("HttpSetServiceConfigurationAcl", num);
                    }
                    flag1 = true;
                }
                flag = flag1;
            }
            finally
            {
                Microsoft.WindowsAzure.Storage.Emulator.Controller.NativeMethods.HttpTerminate(2, IntPtr.Zero);
            }
            return(flag);
        }
Exemplo n.º 4
0
        internal void PerformEmulatorInitialization()
        {
            StorageEmulatorUpdatableConfiguration storageEmulatorUpdatableConfiguration;
            IStorageContext context = null;

            try
            {
                using (EventWaitHandle eventWaitHandle = EventWaitHandle.OpenExisting("DevelopmentStorage-7580AFBB-2BEC-4269-B083-46C1361A69B0"))
                {
                    this.LogErrorAndThrowException(EmulatorErrorCode.StopRequired, null);
                }
            }
            catch (WaitHandleCannotBeOpenedException waitHandleCannotBeOpenedException)
            {
            }
            if (this.reservePorts || this.unreservePorts)
            {
                try
                {
                    foreach (string value in this.endpoints.Values)
                    {
                        if (!this.unreservePorts)
                        {
                            HttpReservation.ModifyReservation(value, this.username, true);
                            string   addedReservation = Resource.AddedReservation;
                            object[] objArray         = new object[] { value, this.username };
                            this.LogMessage(addedReservation, objArray);
                        }
                        else
                        {
                            if (!HttpReservation.TryDeleteReservation(value, this.username))
                            {
                                continue;
                            }
                            string   removedReservation = Resource.RemovedReservation;
                            object[] objArray1          = new object[] { value, this.username };
                            this.LogMessage(removedReservation, objArray1);
                        }
                    }
                }
                catch (HttpReservationException httpReservationException)
                {
                    string str = string.Format(Resource.ReservationFailed, httpReservationException.Message);
                    this.LogErrorAndThrowException(EmulatorErrorCode.ReservationFailed, str);
                }
                catch (IdentityNotMappedException identityNotMappedException1)
                {
                    IdentityNotMappedException identityNotMappedException = identityNotMappedException1;
                    string str1 = string.Format(Resource.ReservationFailedIncorrectUser, this.username, identityNotMappedException.Message);
                    this.LogErrorAndThrowException(EmulatorErrorCode.ReservationFailedIncorrectUser, str1);
                }
                this.LogNewline();
            }
            if (!this.skipCreate)
            {
                context = this.GetContext();
                try
                {
                    this.CreateDatabaseAndGrantAccess(context);
                    if (!StorageEmulatorUpdatableConfiguration.TryGetFromUserProfile(out storageEmulatorUpdatableConfiguration))
                    {
                        storageEmulatorUpdatableConfiguration = new StorageEmulatorUpdatableConfiguration();
                    }
                    storageEmulatorUpdatableConfiguration.SqlInstance = this.server;
                }
                catch (SqlException sqlException1)
                {
                    SqlException sqlException = sqlException1;
                    string       str2         = string.Format(Resource.DatabaseCreationFailed, context.DatabaseName, sqlException.Message);
                    this.LogErrorAndThrowException(EmulatorErrorCode.DatabaseCreationFailed, str2);
                }
                catch (InvalidOperationException invalidOperationException1)
                {
                    InvalidOperationException invalidOperationException = invalidOperationException1;
                    string str3 = string.Format(Resource.DatabaseCreationFailed, context.DatabaseName, invalidOperationException.Message);
                    this.LogErrorAndThrowException(EmulatorErrorCode.DatabaseCreationFailed, str3);
                }
                catch (IOException oException1)
                {
                    IOException oException = oException1;
                    string      str4       = string.Format(Resource.DatabaseCreationFailed, context.DatabaseName, oException.Message);
                    this.LogErrorAndThrowException(EmulatorErrorCode.DatabaseCreationFailed, str4);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    string    str5      = string.Format(Resource.DatabaseCreationFailed, context.DatabaseName, exception.Message);
                    this.LogErrorAndThrowException(EmulatorErrorCode.DatabaseCreationFailed, str5);
                }
                this.LogNewline();
            }
            this.LogMessage(Resource.ActionsSucceeded, new object[0]);
        }
Exemplo n.º 5
0
 private static string GetWin32ErrorMessage(int errorCode)
 {
     return(Marshal.GetExceptionForHR(HttpReservation.HRESULT_FROM_WIN32(errorCode)).Message);
 }