예제 #1
0
        public static bool OrderNewVirtualMachine(string sessionId, string virtualMachineName, decimal amount)
        {
            using (var scope = CreateTagScope(ClassHelper.GetCurrentMethodName()))
            {
                var user = GetUserBySession(sessionId);
                scope.Tags[AppTag.UserId]    = user.UserId;
                scope.Tags[AppTag.SessionId] = sessionId;

                Logger.InfoFormat("Redirect user to external payment system. Amount = {0}", amount);

                if (RandomHelper.GenerateBoolean())
                {
                    scope.Tags[AppTag.VirtualMachine] = virtualMachineName;
                    Logger.Info("Creating virtual machine...");
                    ThreadPool.QueueUserWorkItem(_ => DataCenter.CreateNewVirtualMachine(user.UserId, virtualMachineName));
                    return(true);
                }

                var errorId = Guid.NewGuid().ToString("D");
                scope.Tags[AppTag.ErrorId] = errorId;
                Logger.Error("Payment failed. Unique error ID was displayed.");
                return(false);
            }
        }