Esempio n. 1
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));
        }
Esempio n. 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));
        }
Esempio n. 3
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));
        }
Esempio n. 4
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.");
     }
 }
Esempio n. 5
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));
        }
Esempio n. 6
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));
        }
        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.SaveChanges();
            db.Dispose();
            db = null;
            return(string.Format("{0}s: {1} selected.", items.GetType().GetElementType().Name, items.Length));
        }
Esempio n. 8
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("");
        }
Esempio n. 9
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));
        }
Esempio n. 10
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));
        }
Esempio n. 11
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));
        }
Esempio n. 12
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("");
        }
Esempio n. 13
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));
        }
Esempio n. 14
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));
        }
Esempio n. 15
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("");
        }
Esempio n. 16
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));
     }
 }