示例#1
0
        public static void Select(CloudMessage command, CloudMessage results, List <string> messages, out string error)
        {
            var computerId = CloudHelper.GetComputerId(command, out error).Value;

            // Get all user games.
            if (command.UserGames != null)
            {
                UserGame[] userGames;
                error = Select(computerId, command.UserGames, out userGames);
                messages.Add(error);
                results.UserGames = FilterByChecksum(userGames, command.Checksums, out error);
                if (!string.IsNullOrEmpty(error))
                {
                    messages.Add(error);
                }
            }
            // Get all user devices.
            if (command.UserDevices != null)
            {
                UserDevice[] userDevices;
                error = Select(computerId, command.UserDevices, out userDevices);
                messages.Add(error);
                results.UserDevices = FilterByChecksum(userDevices, command.Checksums, out error);
                if (!string.IsNullOrEmpty(error))
                {
                    messages.Add(error);
                }
            }
            // Get all user computers.
            if (command.UserComputers != null)
            {
                UserComputer[] userComputers;
                error = Select(computerId, command.UserComputers, out userComputers);
                messages.Add(error);
                results.UserComputers = FilterByChecksum(userComputers, command.Checksums, out error);
                if (!string.IsNullOrEmpty(error))
                {
                    messages.Add(error);
                }
            }
            // Get all user instances.
            if (command.UserInstances != null)
            {
                UserInstance[] userInstances;
                error = Select(computerId, command.UserInstances, out userInstances);
                messages.Add(error);
                results.UserInstances = FilterByChecksum(userInstances, command.Checksums, out error);
                if (!string.IsNullOrEmpty(error))
                {
                    messages.Add(error);
                }
            }
        }
示例#2
0
        public static Guid?FixComputerId(CloudMessage command, out string error)
        {
            var computerId = CloudHelper.GetComputerId(command, out error);

            if (computerId.HasValue)
            {
                // Fix computer id
                if (command.UserGames != null)
                {
                    foreach (var item in command.UserGames)
                    {
                        item.ComputerId = computerId.Value;
                    }
                }
                if (command.UserDevices != null)
                {
                    foreach (var item in command.UserDevices)
                    {
                        item.ComputerId = computerId.Value;
                    }
                }
            }
            return(computerId);
        }
示例#3
0
        //[System.Web.Services.Protocols.SoapHeader("Authentication")]
        public CloudMessage Execute(CloudMessage command)
        {
            var results  = new CloudMessage();
            var messages = new List <string>();

            try
            {
                JocysCom.WebSites.Engine.Security.Data.User user;
                string error;
                Guid?  computerId;
                switch (command.Action)
                {
                case CloudAction.LogIn:
                    // Action requires valid user.
                    user = CloudHelper.GetUser(command, out error);
                    if (user == null)
                    {
                        messages.Add("Not authorised");
                        results.ErrorCode = 2;
                    }
                    break;

                case CloudAction.GetPublicRsaKey:
                    var rsa = new JocysCom.ClassLibrary.Security.Encryption(CloudKey.Cloud);
                    if (string.IsNullOrEmpty(rsa.RsaPublicKeyValue))
                    {
                        rsa.RsaNewKeysSave(2048);
                    }
                    results.Values = new KeyValueList();
                    results.Values.Add(CloudKey.RsaPublicKey, rsa.RsaPublicKeyValue);
                    break;

                case CloudAction.Delete:
                    // Action requires valid user.
                    computerId = CloudHelper.GetComputerId(command, out error);
                    if (computerId.HasValue)
                    {
                        foreach (var item in command.UserGames)
                        {
                            item.ComputerId = computerId.Value;
                        }
                        foreach (var item in command.UserDevices)
                        {
                            item.ComputerId = computerId.Value;
                        }
                        messages.Add(Delete(command.UserDevices));
                        messages.Add(Delete(command.UserGames));
                    }
                    else
                    {
                        messages.Add(error);
                        results.ErrorCode = 2;
                    }
                    break;

                case CloudAction.Insert:
                case CloudAction.Update:
                    computerId = CloudHelper.GetComputerId(command, out error);
                    if (computerId.HasValue)
                    {
                        // Fix computer id
                        foreach (var item in command.UserGames)
                        {
                            item.ComputerId = computerId.Value;
                        }
                        foreach (var item in command.UserDevices)
                        {
                            item.ComputerId = computerId.Value;
                        }
                        // Games can be inserted by using computer id only.
                        messages.Add(Upsert(command.UserGames));
                        messages.Add(Upsert(command.UserDevices));
                    }
                    else
                    {
                        messages.Add(error);
                        results.ErrorCode = 2;
                    }
                    break;

                default:
                    break;
                }
                results.ErrorMessage = string.Join("\r\n", messages.Where(x => !string.IsNullOrEmpty(x)));
            }
            catch (Exception ex)
            {
                results.ErrorCode    = 1;
                results.ErrorMessage = "Server: " + ex.Message;
            }
            return(results);
        }