Example #1
0
 public string SetProgram(Program p)
 {
     if (HttpContext.Current.User.Identity.IsAuthenticated)
     {
         var db = new x360ceModelContainer();
         var o  = db.Programs.FirstOrDefault(x => x.FileName == p.FileName && x.FileProductName == p.FileProductName);
         if (o == null)
         {
             o                 = new Program();
             o.ProgramId       = Guid.NewGuid();
             o.DateCreated     = DateTime.Now;
             o.FileName        = p.FileName;
             o.FileProductName = p.FileProductName;
             db.Programs.AddObject(o);
         }
         else
         {
             o.DateUpdated = DateTime.Now;
         }
         o.HookMask      = p.HookMask;
         o.InstanceCount = p.InstanceCount;
         o.IsEnabled     = p.IsEnabled;
         o.XInputMask    = p.XInputMask;
         db.SaveChanges();
         db.Dispose();
         db = null;
         return("");
     }
     else
     {
         return("User was not authenticated.");
     }
 }
Example #2
0
        string Upsert(List <UserDevice> items)
        {
            var db      = new x360ceModelContainer();
            var created = 0;
            var updated = 0;

            for (int i = 0; i < items.Count; i++)
            {
                var item         = items[i];
                var instanceGuid = item.InstanceGuid;
                var uc           = db.UserDevices.FirstOrDefault(x => x.InstanceGuid == instanceGuid);
                if (uc == null)
                {
                    created++;
                    db.UserDevices.AddObject(item);
                    uc.Id          = Guid.NewGuid();
                    uc.DateCreated = DateTime.Now;
                }
                else
                {
                    updated++;
                    Helper.CopyProperties(item, uc);
                    uc.DateUpdated = DateTime.Now;
                }
            }
            db.SaveChanges();
            db.Dispose();
            db = null;
            return(string.Format("{0} record(s) created, {1} record(s) updated.", created, updated));
        }
Example #3
0
        public List <Program> GetPrograms(EnabledState isEnabled, int minInstanceCount)
        {
            var programs = GetOverridePrograms();

            if (programs == null)
            {
                var db = new x360ceModelContainer();
                IQueryable <Program> list = db.Programs;
                if (isEnabled == EnabledState.Enabled)
                {
                    list = list.Where(x => x.IsEnabled);
                }
                else if (isEnabled == EnabledState.Disabled)
                {
                    list = list.Where(x => !x.IsEnabled);
                }
                if (minInstanceCount > 0)
                {
                    list = list.Where(x => x.InstanceCount == minInstanceCount);
                }
                programs = list.ToList();
                db.Dispose();
                db = null;
            }
            return(programs);
        }
Example #4
0
        public static string Delete <T>(T[] items) where T : EntityObject, IUserRecord
        {
            var db      = new x360ceModelContainer();
            var table   = db.CreateObjectSet <T>();
            var deleted = 0;

            for (int i = 0; i < items.Length; i++)
            {
                var item = items[i];
                // Fix nulls.
                FixData(item);
                var computerId = item.ComputerId;
                var profileId  = item.ProfileId;
                var dbItem     = GetExistingItem(table, item);
                if (dbItem == null)
                {
                    continue;
                }
                table.DeleteObject(dbItem);
                deleted++;
            }
            db.SaveChanges();
            db.Dispose();
            return(string.Format("{0}s: {1} deleted.", items.GetType().GetElementType().Name, deleted));
        }
Example #5
0
        string Upsert(List <UserGame> items)
        {
            var db      = new x360ceModelContainer();
            var created = 0;
            var updated = 0;

            for (int i = 0; i < items.Count; i++)
            {
                var item       = items[i];
                var computerId = item.ComputerId;
                var fileName   = item.FileName;
                var dbItem     = db.UserGames.FirstOrDefault(x => x.ComputerId == computerId && x.FileName == fileName);
                if (dbItem == null)
                {
                    created++;
                    item.GameId      = Guid.NewGuid();
                    item.DateCreated = DateTime.Now;
                    item.DateUpdated = item.DateCreated;
                    db.UserGames.AddObject(item);
                }
                else
                {
                    updated++;
                    // Fix dates.
                    item.DateCreated = dbItem.DateCreated;
                    Helper.CopyDataMembers(item, dbItem, true);
                    dbItem.DateUpdated = DateTime.Now;
                }
            }
            db.SaveChanges();
            db.Dispose();
            db = null;
            return(string.Format("{0}s: {1} created, {2} updated.", items.GetType().GetGenericArguments()[0].Name, created, updated));
        }
Example #6
0
        public static string Upsert(UserInstance[] items)
        {
            var db      = new x360ceModelContainer();
            var created = 0;
            var updated = 0;

            for (int i = 0; i < items.Length; i++)
            {
                var item         = items[i];
                var instanceGuid = item.InstanceGuid;
                var dbItem       = db.UserInstances.FirstOrDefault(x => x.InstanceGuid == instanceGuid);
                if (dbItem == null)
                {
                    created++;
                    item.Id          = Guid.NewGuid();
                    item.DateCreated = DateTime.Now;
                    item.DateUpdated = item.DateCreated;
                    db.UserInstances.AddObject(item);
                }
                else
                {
                    updated++;
                    // Use created date from db.
                    item.DateCreated = dbItem.DateCreated;
                    item.DateUpdated = DateTime.Now;
                    Helper.CopyDataMembers(item, dbItem, true);
                }
            }
            db.SaveChanges();
            db.Dispose();
            return(string.Format("{0}s: {1} created, {2} updated.", items.GetType().GetElementType().Name, created, updated));
        }
Example #7
0
        public static string Upsert <T>(T[] items) where T : EntityObject, IUserRecord
        {
            var db      = new x360ceModelContainer();
            var table   = db.CreateObjectSet <T>();
            var created = 0;
            var updated = 0;

            for (int i = 0; i < items.Length; i++)
            {
                var         item       = items[i];
                var         computerId = item.ComputerId;
                var         profileId  = item.ProfileId;
                IUserRecord dbItem     = GetExistingItem(table, item, true);
                // If database item was not found then...
                if (dbItem == null)
                {
                    // Use supplied item as new item.
                    created++;
                    item.DateCreated = DateTime.Now;
                    item.DateUpdated = item.DateCreated;
                    table.AddObject(item);
                }
                else
                {
                    updated++;
                    // Use created date from db.
                    item.DateCreated = dbItem.DateCreated;
                    item.DateUpdated = DateTime.Now;
                    RuntimeHelper.CopyDataMembers(item, dbItem, true);
                }
            }
            db.SaveChanges();
            db.Dispose();
            return(string.Format("{0}s: {1} created, {2} updated.", items.GetType().GetElementType().Name, created, updated));
        }
Example #8
0
        public static string Select(Guid computerId, UserInstance[] filter, out UserInstance[] items)
        {
            var db = new x360ceModelContainer();

            items = db.UserInstances.Where(x => x.ComputerId == computerId).ToArray();
            db.Dispose();
            return(string.Format("{0}s: {1} selected.", items.GetType().GetElementType().Name, items.Length));
        }
Example #9
0
        public static string Select <T>(Guid computerId, Guid profileId, T[] filter, out T[] items) where T : EntityObject, IUserRecord
        {
            var db    = new x360ceModelContainer();
            var table = db.CreateObjectSet <T>();

            items = table.Where(x => x.ComputerId == computerId && x.ProfileId == profileId).ToArray();
            db.Dispose();
            return(string.Format("{0}s: {1} selected.", items.GetType().GetElementType().Name, items.Length));
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         var db   = new x360ceModelContainer();
         var rows = db.Programs.OrderByDescending(x => x.InstanceCount).Where(x => x.FileProductName.Length > 0).Take(20).ToArray();
         GamesListView.DataSource = rows;
         GamesListView.DataBind();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         var db   = new x360ceModelContainer();
         var rows = db.Products.OrderByDescending(x => x.InstanceCount).Take(20).ToArray();
         ControllersListView.DataSource = rows;
         ControllersListView.DataBind();
     }
 }
Example #12
0
        public SettingsData GetSettingsData()
        {
            var data = new SettingsData();
            var db   = new x360ceModelContainer();

            data.Programs = db.Programs.Where(x => x.IsEnabled && x.InstanceCount > 1).ToList();
            db.Dispose();
            db = null;
            return(data);
        }
Example #13
0
        public SearchResult LoadSetting(Guid[] checksum)
        {
            var sr = new SearchResult();
            var db = new x360ceModelContainer();

            sr.PadSettings = db.PadSettings.Where(x => checksum.Contains(x.PadSettingChecksum)).ToArray();
            db.Dispose();
            db = null;
            return(sr);
        }
Example #14
0
        public SearchResult SearchSettings(SearchParameter[] args)
        {
            // Create default value to reply.
            var sr = new SearchResult();

            sr.Presets     = new Preset[0];
            sr.PadSettings = new PadSetting[0];
            sr.Summaries   = new Summary[0];
            sr.Settings    = new UserSetting[0];

            var hasArgs = args != null && args.Length > 0;

            // Workaround fix.
            args = args.Where(x => !x.IsEmpty()).ToArray();
            // Create database.
            var db = new x360ceModelContainer();
            // Get user instances.
            var p = SearchParameterCollection.GetSqlParameter(args);
            // If user device instances supplied.
            var hasInstances = args.Any(x => x.InstanceGuid != Guid.Empty);
            // If user device products supplied.
            var hasProducts = args.Any(x => x.ProductGuid != Guid.Empty);
            List <PadSetting> padSettings = null;

            // If get My Settings" then...
            if (hasInstances)
            {
                var ds = EngineHelper.GetSettings(args);
                sr.Settings = SqlHelper.ConvertToList <UserSetting>(ds.Tables[0]).ToArray();
                AddToList(ds.Tables[1], ref padSettings);
            }
            // If get "Default Settings for My Controllers" then...
            if (hasProducts)
            {
                var ds = EngineHelper.GetPresets(args);
                sr.Summaries = SqlHelper.ConvertToList <Summary>(ds.Tables[0]).ToArray();
                AddToList(ds.Tables[1], ref padSettings);
            }
            // If get "Default Settings for Most Popular Controllers" then...
            if (!hasInstances && !hasProducts && hasArgs)
            {
                // Get presets.
                var ds = EngineHelper.GetPresets(new SearchParameter[0]);
                sr.Presets = SqlHelper.ConvertToList <Preset>(ds.Tables[0]).ToArray();
                AddToList(ds.Tables[1], ref padSettings);
            }
            if (padSettings != null)
            {
                sr.PadSettings = padSettings.ToArray();
            }
            db.Dispose();
            db = null;
            return(sr);
        }
Example #15
0
        public Program GetProgram(string fileName, string fileProductName)
        {
            var db = new x360ceModelContainer();
            var o  = db.Programs.FirstOrDefault(x => x.FileName == fileName && x.FileProductName == fileProductName);

            if (o != null)
            {
                return(o);
            }
            o = db.Programs.FirstOrDefault(x => x.FileName == fileName);
            db.Dispose();
            db = null;
            return(o);
        }
        public static string Select(Guid computerId, Setting[] filter, out Setting[] items)
        {
            var db = new x360ceModelContainer();

            // Select all instances.
            UserInstance[] userInstances;
            Select(computerId, null, out userInstances);
            var guids = userInstances.Select(x => x.InstanceGuid).ToArray();

            // Select all settings related to user device instances.
            items = db.Settings.Where(x => guids.Contains(x.InstanceGuid)).ToArray();
            db.Dispose();
            return(string.Format("{0}s: {1} selected.", items.GetType().GetElementType().Name, items.Length));
        }
Example #17
0
        public string DeleteSetting(Setting s)
        {
            var db      = new x360ceModelContainer();
            var setting = db.Settings.FirstOrDefault(x => x.InstanceGuid == s.InstanceGuid && x.FileName == s.FileName && x.FileProductName == s.FileProductName);

            if (setting == null)
            {
                return("Setting not found");
            }
            db.Settings.DeleteObject(setting);
            db.SaveChanges();
            db.Dispose();
            db = null;
            return("");
        }
Example #18
0
        public SearchResult GetPresets()
        {
            var sr = new SearchResult();
            var db = new x360ceModelContainer();
            IQueryable <Program> list = db.Programs;

            // Not used.
            sr.Settings = new Setting[0];
            // Contains TOP 20 most popular DirectInput devices.
            var query        = db.Products.OrderByDescending(x => x.InstanceCount).Take(20);
            var products     = query.ToArray();
            var productGuids = products.Select(x => x.ProductGuid).ToArray();
            // Select TOP products
            var query2 =
                // Select most popular devices.
                from row in query
                // Join all summaries for these devices.
                join sum in db.Summaries on row.ProductGuid equals sum.ProductGuid
                // Group in order to identify most popular PAD setting for the device.
                group sum by new { sum.ProductGuid, sum.PadSettingChecksum } into g
            select g.OrderByDescending(x => x.Users).First();

            var padSettingGuids = query2.ToList();

            // Fill summaries.
            sr.Summaries = padSettingGuids.Select(x => new Summary()
            {
                ProductGuid        = x.ProductGuid,
                ProductName        = x.ProductName,
                PadSettingChecksum = x.PadSettingChecksum,
            }).ToArray();
            var settingChecksums = padSettingGuids.Select(x => x.PadSettingChecksum).ToArray();

            //// Join all pad settings related to summaries.
            //join pad in db.PadSettings on sum.PadSettingChecksum equals pad.PadSettingChecksum
            //select new
            //{
            //    Summary = sum,
            //    PadSetting = pad,
            //};
            // Contains most popular PAD Setting for device.
            sr.PadSettings = new PadSetting[0];
            // Code here.
            db.Dispose();
            db = null;
            return(sr);
        }
Example #19
0
        public List <Vendor> GetVendors()
        {
            var db = new x360ceModelContainer();
            var q  = db.Vendors.ToList()
                     .Select(x => new Vendor
            {
                VendorId   = x.VendorId,
                VendorName = x.VendorName,
                ShortName  = x.ShortName,
                WebSite    = x.WebSite
            });
            var vendors = q.ToList();

            db.Dispose();
            db = null;
            return(vendors);
        }
Example #20
0
        public List <Vendor> GetVendors()
        {
            var db = new x360ceModelContainer();
            var q  = from row in db.Vendors
                     select new Vendor
            {
                VendorId   = row.VendorId,
                VendorName = row.VendorName,
                ShortName  = row.ShortName,
                WebSite    = row.WebSite
            };
            var vendors = q.ToList();

            db.Dispose();
            db = null;
            return(vendors);
        }
Example #21
0
        string Upsert(List <UserGame> items)
        {
            var db      = new x360ceModelContainer();
            var created = 0;
            var updated = 0;

            for (int i = 0; i < items.Count; i++)
            {
                var item        = items[i];
                var diskDriveId = item.DiskDriveId;
                var fileName    = item.FileName;
                var game        = db.UserGames.FirstOrDefault(x => x.DiskDriveId == diskDriveId && x.FileName == fileName);
                if (game == null)
                {
                    created++;
                    game        = new UserGame();
                    game.GameId = Guid.NewGuid();
                    db.UserGames.AddObject(game);
                    game.DateCreated = DateTime.Now;
                }
                else
                {
                    updated++;
                    game.DateUpdated = DateTime.Now;
                }
                game.Comment         = item.Comment;
                game.CompanyName     = item.CompanyName;
                game.DInputFile      = item.DInputFile;
                game.DInputMask      = item.DInputMask;
                game.FakePID         = item.FakePID;
                game.FakeVID         = item.FakeVID;
                game.FileName        = item.FileName;
                game.FileProductName = item.FileProductName;
                game.FileVersion     = item.FileVersion;
                game.FullPath        = item.FullPath;
                game.HookMask        = item.HookMask;
                game.IsEnabled       = item.IsEnabled;
                game.Timeout         = item.Timeout;
                game.Weight          = 1;
                game.XInputMask      = item.XInputMask;
            }
            db.SaveChanges();
            db.Dispose();
            db = null;
            return(string.Format("{0} game(s) created, {1} game(s) updated.", created, updated));
        }
Example #22
0
        public SearchResult SearchSettings(SearchParameter[] args)
        {
            // Create default value to reply.
            var sr = new SearchResult();

            sr.Presets     = new Preset[0];
            sr.PadSettings = new PadSetting[0];
            sr.Summaries   = new Summary[0];
            sr.Settings    = new Setting[0];
            // Create database.
            var db = new x360ceModelContainer();
            // Get user instances.
            var p = SearchParameterCollection.GetSqlParameter(args);
            // Get most popular settings for user controllers.
            var products = args.Where(x => x.ProductGuid != Guid.Empty).Select(x => x.ProductGuid).Distinct().ToArray();
            // Get all device instances of the user.
            var hasInstances = args.Any(x => x.InstanceGuid != Guid.Empty);

            if (hasInstances)
            {
                var ds = EngineHelper.GetSettings(args);
                sr.Settings    = SqlHelper.ConvertToList <Setting>(ds.Tables[0]).ToArray();
                sr.PadSettings = SqlHelper.ConvertToList <PadSetting>(ds.Tables[1]).ToArray();
            }
            else if (products.Length > 0)
            {
                // Get presets.
                var ds = EngineHelper.GetPresets(args);
                sr.Summaries   = SqlHelper.ConvertToList <Summary>(ds.Tables[0]).ToArray();
                sr.PadSettings = SqlHelper.ConvertToList <PadSetting>(ds.Tables[1]).ToArray();
            }
            else if (args != null && args.Length > 0)
            {
                // Get presets.
                var ds = EngineHelper.GetPresets(new SearchParameter[0]);
                sr.Presets     = SqlHelper.ConvertToList <Preset>(ds.Tables[0]).ToArray();
                sr.PadSettings = SqlHelper.ConvertToList <PadSetting>(ds.Tables[1]).ToArray();
            }
            db.Dispose();
            db = null;
            return(sr);
        }
Example #23
0
        public static string Delete(UserInstance[] items)
        {
            var db      = new x360ceModelContainer();
            var deleted = 0;

            for (int i = 0; i < items.Length; i++)
            {
                var item         = items[i];
                var instanceGuid = item.InstanceGuid;
                var currentGame  = db.UserInstances.FirstOrDefault(x => x.InstanceGuid == instanceGuid);
                if (currentGame == null)
                {
                    continue;
                }
                db.UserInstances.DeleteObject(currentGame);
                deleted++;
            }
            db.SaveChanges();
            db.Dispose();
            return(string.Format("{0}s: {1} deleted.", items.GetType().GetElementType().Name, deleted));
        }
Example #24
0
        public string SaveSetting(UserSetting s, PadSetting ps)
        {
            var db       = new x360ceModelContainer();
            var checksum = ps.CleanAndGetCheckSum();

            // Update checksum.
            ps.PadSettingChecksum = checksum;
            // Look for existing PadSetting.
            var pDB = db.PadSettings.FirstOrDefault(x => x.PadSettingChecksum == checksum);

            // If PadSetting doesn't exists then...
            if (pDB == null)
            {
                pDB           = ps;
                pDB.EntityKey = null;
                db.PadSettings.AddObject(pDB);
            }
            // Look for existing setting.
            var sDB = db.UserSettings.FirstOrDefault(x => x.InstanceGuid == s.InstanceGuid && x.FileName == s.FileName && x.FileProductName == s.FileProductName);
            var n   = DateTime.Now;

            if (sDB == null)
            {
                sDB           = s;
                sDB.EntityKey = null;
                // Assign brand new ID.
                s.SettingId    = Guid.NewGuid();
                s.DateCreated  = n;
                s.DateUpdated  = n;
                s.DateSelected = n;
                // Link PadSetting with setting.
                s.PadSettingChecksum = pDB.PadSettingChecksum;
                db.UserSettings.AddObject(sDB);
            }
            db.SaveChanges();
            db.Dispose();
            db = null;
            return("");
        }
Example #25
0
        string Delete(List <UserDevice> items)
        {
            var db      = new x360ceModelContainer();
            var deleted = 0;

            for (int i = 0; i < items.Count; i++)
            {
                var item         = items[i];
                var instanceGuid = item.InstanceGuid;
                var currentItem  = db.UserDevices.FirstOrDefault(x => x.InstanceGuid == instanceGuid);
                if (currentItem == null)
                {
                    continue;
                }
                db.UserDevices.DeleteObject(currentItem);
                deleted++;
            }
            db.SaveChanges();
            db.Dispose();
            db = null;
            return(string.Format("{0} record(s) deleted.", deleted));
        }
Example #26
0
        string Delete(List <UserGame> items)
        {
            var db      = new x360ceModelContainer();
            var deleted = 0;

            for (int i = 0; i < items.Count; i++)
            {
                var game        = items[i];
                var diskDriveId = game.DiskDriveId;
                var fileName    = game.FileName;
                var currentGame = db.UserGames.FirstOrDefault(x => x.DiskDriveId == diskDriveId && x.FileName == fileName);
                if (currentGame == null)
                {
                    continue;
                }
                db.UserGames.DeleteObject(currentGame);
                deleted++;
            }
            db.SaveChanges();
            db.Dispose();
            db = null;
            return(string.Format("{0} game(s) deleted.", deleted));
        }
Example #27
0
        string Delete(List <UserGame> items)
        {
            var db      = new x360ceModelContainer();
            var deleted = 0;

            for (int i = 0; i < items.Count; i++)
            {
                var game        = items[i];
                var computerId  = game.ComputerId;
                var fileName    = game.FileName;
                var currentGame = db.UserGames.FirstOrDefault(x => x.ComputerId == computerId && x.FileName == fileName);
                if (currentGame == null)
                {
                    continue;
                }
                db.UserGames.DeleteObject(currentGame);
                deleted++;
            }
            db.SaveChanges();
            db.Dispose();
            db = null;
            return(string.Format("{0}s: {1} deleted.", items.GetType().GetGenericArguments()[0].Name, deleted));
        }
Example #28
0
 public string SetGames(CloudAction action, List <Game> games)
 {
     if (action == CloudAction.Delete)
     {
         var db      = new x360ceModelContainer();
         var deleted = 0;
         for (int i = 0; i < games.Count; i++)
         {
             var game        = games[i];
             var diskDriveId = game.DiskDriveId;
             var fileName    = game.FileName;
             var currentGame = db.Games.FirstOrDefault(x => x.DiskDriveId == diskDriveId && x.FileName == fileName);
             if (currentGame == null)
             {
                 continue;
             }
             db.Games.DeleteObject(currentGame);
             deleted++;
         }
         db.SaveChanges();
         db.Dispose();
         db = null;
         return(string.Format("{0} game(s) deleted.", deleted));
     }
     else
     {
         var db      = new x360ceModelContainer();
         var created = 0;
         var updated = 0;
         for (int i = 0; i < games.Count; i++)
         {
             var game        = games[i];
             var diskDriveId = game.DiskDriveId;
             var fileName    = game.FileName;
             var item        = db.Games.FirstOrDefault(x => x.DiskDriveId == diskDriveId && x.FileName == fileName);
             if (item == null)
             {
                 created++;
                 item        = new Game();
                 item.GameId = Guid.NewGuid();
                 db.Games.AddObject(item);
                 item.DateCreated = DateTime.Now;
             }
             else
             {
                 updated++;
                 item.DateUpdated = DateTime.Now;
             }
             item.Comment         = game.Comment;
             item.CompanyName     = game.CompanyName;
             item.DInputFile      = game.DInputFile;
             item.DInputMask      = game.DInputMask;
             item.FakePID         = game.FakePID;
             item.FakeVID         = game.FakeVID;
             item.FileName        = game.FileName;
             item.FileProductName = game.FileProductName;
             item.FileVersion     = game.FileVersion;
             item.FullPath        = game.FullPath;
             item.HookMask        = game.HookMask;
             item.IsEnabled       = game.IsEnabled;
             item.Timeout         = game.Timeout;
             item.Weight          = 1;
             item.XInputMask      = game.XInputMask;
         }
         db.SaveChanges();
         db.Dispose();
         db = null;
         return(string.Format("{0} game(s) created, {1} game(s) updated.", created, updated));
     }
 }
Example #29
0
        public string SaveSetting(Setting s, PadSetting ps)
        {
            var checksum = ps.GetCheckSum();
            var db       = new x360ceModelContainer();
            var s1       = db.Settings.FirstOrDefault(x => x.InstanceGuid == s.InstanceGuid && x.FileName == s.FileName && x.FileProductName == s.FileProductName);
            var n        = DateTime.Now;

            if (s1 == null)
            {
                s1             = new Setting();
                s1.SettingId   = Guid.NewGuid();
                s1.DateCreated = n;
                db.Settings.AddObject(s1);
            }
            s1.Comment            = s.Comment;
            s1.DateUpdated        = n;
            s1.DateSelected       = n;
            s1.DeviceType         = s.DeviceType;
            s1.FileName           = s.FileName;
            s1.FileProductName    = s.FileProductName;
            s1.InstanceGuid       = s.InstanceGuid;
            s1.InstanceName       = s.InstanceName;
            s1.ProductGuid        = s.ProductGuid;
            s1.ProductName        = s.ProductName;
            s1.IsEnabled          = s.IsEnabled;
            s1.PadSettingChecksum = checksum;
            // Save Pad Settings.
            var p1 = db.PadSettings.FirstOrDefault(x => x.PadSettingChecksum == checksum);

            if (p1 == null)
            {
                p1 = new PadSetting();
                p1.PadSettingChecksum = checksum;
                db.PadSettings.AddObject(p1);
            }
            p1.AxisToDPadDeadZone = ps.AxisToDPadDeadZone;
            p1.AxisToDPadEnabled  = ps.AxisToDPadEnabled;
            p1.AxisToDPadOffset   = ps.AxisToDPadOffset;
            p1.ButtonA            = ps.ButtonA;
            p1.ButtonB            = ps.ButtonB;
            p1.ButtonBig          = string.IsNullOrEmpty(ps.ButtonBig) ? "" : ps.ButtonBig;
            p1.ButtonGuide        = string.IsNullOrEmpty(ps.ButtonGuide) ? "" : ps.ButtonGuide;
            p1.ButtonBack         = ps.ButtonBack;
            p1.ButtonStart        = ps.ButtonStart;
            p1.ButtonX            = ps.ButtonX;
            p1.ButtonY            = ps.ButtonY;
            p1.DPad                    = ps.DPad;
            p1.DPadDown                = ps.DPadDown;
            p1.DPadLeft                = ps.DPadLeft;
            p1.DPadRight               = ps.DPadRight;
            p1.DPadUp                  = ps.DPadUp;
            p1.ForceEnable             = ps.ForceEnable;
            p1.ForceOverall            = ps.ForceOverall;
            p1.ForceSwapMotor          = ps.ForceSwapMotor;
            p1.ForceType               = ps.ForceType;
            p1.GamePadType             = ps.GamePadType;
            p1.LeftMotorPeriod         = ps.LeftMotorPeriod;
            p1.LeftMotorStrength       = string.IsNullOrEmpty(ps.LeftMotorStrength) ? "100" : ps.LeftMotorStrength;
            p1.LeftMotorDirection      = string.IsNullOrEmpty(ps.LeftMotorDirection) ? "0" : ps.LeftMotorDirection;
            p1.LeftShoulder            = ps.LeftShoulder;
            p1.LeftThumbAntiDeadZoneX  = ps.LeftThumbAntiDeadZoneX;
            p1.LeftThumbAntiDeadZoneY  = ps.LeftThumbAntiDeadZoneY;
            p1.LeftThumbAxisX          = ps.LeftThumbAxisX;
            p1.LeftThumbAxisY          = ps.LeftThumbAxisY;
            p1.LeftThumbButton         = ps.LeftThumbButton;
            p1.LeftThumbDeadZoneX      = ps.LeftThumbDeadZoneX;
            p1.LeftThumbDeadZoneY      = ps.LeftThumbDeadZoneY;
            p1.LeftThumbLinearX        = string.IsNullOrEmpty(ps.LeftThumbLinearX) ? "" : ps.LeftThumbLinearX;
            p1.LeftThumbLinearY        = string.IsNullOrEmpty(ps.LeftThumbLinearY) ? "" : ps.LeftThumbLinearY;
            p1.LeftThumbDown           = ps.LeftThumbDown;
            p1.LeftThumbLeft           = ps.LeftThumbLeft;
            p1.LeftThumbRight          = ps.LeftThumbRight;
            p1.LeftThumbUp             = ps.LeftThumbUp;
            p1.LeftTrigger             = ps.LeftTrigger;
            p1.LeftTriggerDeadZone     = ps.LeftTriggerDeadZone;
            p1.PassThrough             = ps.PassThrough;
            p1.RightMotorPeriod        = ps.RightMotorPeriod;
            p1.RightMotorStrength      = string.IsNullOrEmpty(ps.RightMotorStrength) ? "100" : ps.RightMotorStrength;
            p1.RightMotorDirection     = string.IsNullOrEmpty(ps.RightMotorDirection) ? "0" : ps.RightMotorDirection;
            p1.RightShoulder           = ps.RightShoulder;
            p1.RightThumbAntiDeadZoneX = ps.RightThumbAntiDeadZoneX;
            p1.RightThumbAntiDeadZoneY = ps.RightThumbAntiDeadZoneY;
            p1.RightThumbLinearX       = string.IsNullOrEmpty(ps.RightThumbLinearX) ? "" : ps.RightThumbLinearX;
            p1.RightThumbLinearY       = string.IsNullOrEmpty(ps.RightThumbLinearY) ? "" : ps.RightThumbLinearY;
            p1.RightThumbAxisX         = ps.RightThumbAxisX;
            p1.RightThumbAxisY         = ps.RightThumbAxisY;
            p1.RightThumbButton        = ps.RightThumbButton;
            p1.RightThumbDeadZoneX     = ps.RightThumbDeadZoneX;
            p1.RightThumbDeadZoneY     = ps.RightThumbDeadZoneY;
            p1.RightThumbDown          = ps.RightThumbDown;
            p1.RightThumbLeft          = ps.RightThumbLeft;
            p1.RightThumbRight         = ps.RightThumbRight;
            p1.RightThumbUp            = ps.RightThumbUp;
            p1.RightTrigger            = ps.RightTrigger;
            p1.RightTriggerDeadZone    = ps.RightTriggerDeadZone;
            // Axis to button dead-zones.
            p1.ButtonADeadZone          = ps.ButtonADeadZone ?? "";
            p1.ButtonBDeadZone          = ps.ButtonBDeadZone ?? "";
            p1.ButtonBackDeadZone       = ps.ButtonBackDeadZone ?? "";
            p1.ButtonStartDeadZone      = ps.ButtonStartDeadZone ?? "";
            p1.ButtonXDeadZone          = ps.ButtonXDeadZone ?? "";
            p1.ButtonYDeadZone          = ps.ButtonYDeadZone ?? "";
            p1.LeftThumbButtonDeadZone  = ps.LeftThumbButtonDeadZone ?? "";
            p1.RightThumbButtonDeadZone = ps.RightThumbButtonDeadZone ?? "";
            p1.LeftShoulderDeadZone     = ps.LeftShoulderDeadZone ?? "";
            p1.RightShoulderDeadZone    = ps.RightShoulderDeadZone ?? "";
            p1.DPadDownDeadZone         = ps.DPadDownDeadZone ?? "";
            p1.DPadLeftDeadZone         = ps.DPadLeftDeadZone ?? "";
            p1.DPadRightDeadZone        = ps.DPadRightDeadZone ?? "";
            p1.DPadUpDeadZone           = ps.DPadUpDeadZone ?? "";
            db.SaveChanges();
            db.Dispose();
            db = null;
            return("");
        }
Example #30
0
        public SearchResult SearchSettings(SearchParameter[] args)
        {
            var sr = new SearchResult();
            var db = new x360ceModelContainer();
            // Get all device instances of the user.
            var p            = SearchParameterCollection.GetSqlParameter(args);
            var hasInstances = args.Any(x => x.InstanceGuid != Guid.Empty);
            var hasFiles     = args.Any(x => !string.IsNullOrEmpty(x.FileName));
            var hasProducts  = args.Any(x => x.ProductGuid != Guid.Empty);

            if (hasInstances)
            {
                // Get user instances.
                sr.Settings = db.ExecuteStoreQuery <Setting>("exec x360ce_GetUserInstances @args", p).ToArray();
                // Get list of products (unique identifiers).
                var products = args.Where(x => x.ProductGuid != Guid.Empty).Select(x => x.ProductGuid).Distinct().ToArray();
                var files    = args.Where(x => !string.IsNullOrEmpty(x.FileName) || !string.IsNullOrEmpty(x.FileProductName)).ToList();
                if (products.Length == 0)
                {
                    sr.Summaries = new Summary[0];
                }
                else
                {
                    files.Add(new SearchParameter()
                    {
                        FileName = "", FileProductName = ""
                    });
                    Expression body    = null;
                    var        param   = Expression.Parameter(typeof(Summary), "x");
                    var        pgParam = Expression.PropertyOrField(param, "ProductGuid");
                    var        fnParam = Expression.PropertyOrField(param, "FileName");
                    var        fpParam = Expression.PropertyOrField(param, "FileProductName");
                    for (int i = 0; i < products.Length; i++)
                    {
                        var productGuid = products[i];
                        for (int f = 0; f < files.Count; f++)
                        {
                            var fileName        = files[f].FileName;
                            var fileProductName = files[f].FileProductName;
                            var exp1            = Expression.AndAlso(
                                Expression.Equal(pgParam, Expression.Constant(productGuid)),
                                Expression.Equal(fnParam, Expression.Constant(fileName))
                                );
                            exp1 = Expression.AndAlso(exp1, Expression.Equal(fpParam, Expression.Constant(fileProductName)));
                            body = body == null ? exp1 : Expression.OrElse(body, exp1).Reduce();
                        }
                    }
                    var lambda = Expression.Lambda <Func <Summary, bool> >(body, param);
                    // Select only TOP 10 configurations per controller and file.
                    var summaries    = db.Summaries.Where(lambda).ToArray();
                    var topSummaries = new List <Summary>();
                    var productGuids = db.Summaries.Where(lambda).Select(x => x.ProductGuid).Distinct();
                    foreach (var pg in productGuids)
                    {
                        var controllerSummaries = summaries.Where(x => x.ProductGuid == pg);
                        var fileNames           = controllerSummaries.Select(x => x.FileName).Distinct();
                        foreach (var fileName in fileNames)
                        {
                            // Top 10 configurations per file
                            topSummaries.AddRange(controllerSummaries.Where(x => x.FileName == fileName).OrderByDescending(x => x.Users).Take(10));
                        }
                    }
                    sr.Summaries = topSummaries.OrderBy(x => x.ProductName).ThenBy(x => x.FileName).ThenBy(x => x.FileProductName).ThenBy(x => x.Users).ToArray();
                }
            }
            else if (args != null && args.Length > 0)
            {
                // Get presets.
                var item = args.FirstOrDefault();
                var ds   = EngineHelper.GetPresets(new SearchParameter[0]);
                sr.Presets     = SqlHelper.ConvertToList <Preset>(ds.Tables[0]).ToArray();
                sr.PadSettings = SqlHelper.ConvertToList <PadSetting>(ds.Tables[1]).ToArray();
                sr.Summaries   = new Summary[0];
                sr.Settings    = new Setting[0];
            }
            else
            {
                sr.Presets     = new Preset[0];
                sr.PadSettings = new PadSetting[0];
                sr.Summaries   = new Summary[0];
                sr.Settings    = new Setting[0];
            }
            db.Dispose();
            db = null;
            return(sr);
        }