예제 #1
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();
     return sr;
 }
예제 #2
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 sumaries 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 setings 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;
        }
예제 #3
0
 public SearchResult SearchSettings(SearchParameter[] args)
 {
     var sr = new SearchResult();
     var db = new x360ceModelContainer();
     // Get all device instances of the user.
     var instances = args.Where(x => x.InstanceGuid != Guid.Empty).Select(x => x.InstanceGuid).Distinct().ToArray();
     if (instances.Length == 0)
     {
         sr.Settings = new Setting[0];
     }
     else
     {
         // Get all settings attached to user's device instances.
         sr.Settings = db.Settings.Where(x => instances.Contains(x.InstanceGuid))
             .OrderBy(x => x.ProductName).ThenBy(x => x.FileName).ThenBy(x => x.FileProductName).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 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();
     }
     db.Dispose();
     db = null;
     return sr;
 }
        Summary GetBestSetting(x360ce.Engine.SearchResult sr)
        {
            var sum = new Summary();

            for (int i = 0; i < sr.Settings.Length; i++)
            {
                // Look inside user settings.
                var s = sr.Settings[sr.Settings.Length - i - 1];
                for (int f = 0; f < _sp.Count; f++)
                {
                    // if instance, file name and file product name is match then...
                    if (s.InstanceGuid.Equals(_di.InstanceGuid) && _sp[f].FileName == s.FileName && _sp[f].FileProductName == s.FileProductName)
                    {
                        sum.DateUpdated        = s.DateUpdated;
                        sum.FileName           = GetTitle(s.FileName, s.FileProductName);
                        sum.PadSettingChecksum = s.PadSettingChecksum;
                        return(sum);
                    }
                }
                for (int f = 0; f < _sp.Count; f++)
                {
                    // if instance and file name match then...
                    if (s.InstanceGuid.Equals(_di.InstanceGuid) && _sp[f].FileName == s.FileName)
                    {
                        sum.DateUpdated        = s.DateUpdated;
                        sum.FileName           = GetTitle(s.FileName, s.FileProductName);
                        sum.PadSettingChecksum = s.PadSettingChecksum;
                        return(sum);
                    }
                }
                for (int f = 0; f < _sp.Count; f++)
                {
                    // if only instance match then...
                    if (s.InstanceGuid.Equals(_di.InstanceGuid))
                    {
                        sum.DateUpdated        = s.DateUpdated;
                        sum.FileName           = GetTitle(s.FileName, s.FileProductName);
                        sum.PadSettingChecksum = s.PadSettingChecksum;
                        return(sum);
                    }
                }
            }
            // Order so non empty names and most popular record will come first.
            var summaries = sr.Summaries.OrderByDescending(x => x.ProductName).ThenByDescending(x => x.FileName).ThenByDescending(x => x.FileProductName).ThenByDescending(x => x.Users).ToArray();

            for (int i = 0; i < summaries.Length; i++)
            {
                var s2 = summaries[i];
                // Look inside global settings.
                for (int f = 0; f < _sp.Count; f++)
                {
                    // if instance, file name and file product name is match then...
                    if (s2.ProductGuid.Equals(_di.ProductGuid) && _sp[f].FileName == s2.FileName && _sp[f].FileProductName == s2.FileProductName)
                    {
                        sum.DateUpdated        = s2.DateUpdated;
                        sum.FileName           = GetTitle(s2.FileName, s2.FileProductName);
                        sum.PadSettingChecksum = s2.PadSettingChecksum;
                        return(sum);
                    }
                }
                for (int f = 0; f < _sp.Count; f++)
                {
                    // if instance and file name match then...
                    if (s2.ProductGuid.Equals(_di.ProductGuid) && _sp[f].FileName == s2.FileName)
                    {
                        sum.DateUpdated        = s2.DateUpdated;
                        sum.FileName           = GetTitle(s2.FileName, s2.FileProductName);
                        sum.PadSettingChecksum = s2.PadSettingChecksum;
                        return(sum);
                    }
                }
                for (int f = 0; f < _sp.Count; f++)
                {
                    // if only instance match then...
                    if (s2.ProductGuid.Equals(_di.ProductGuid))
                    {
                        sum.DateUpdated        = s2.DateUpdated;
                        sum.FileName           = GetTitle(s2.FileName, s2.FileProductName);
                        sum.PadSettingChecksum = s2.PadSettingChecksum;
                        return(sum);
                    }
                }
            }
            return(null);
        }
예제 #5
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;
 }
예제 #6
0
        public SearchResult SearchSettings(SearchParameter[] args)
        {
            var sr = new SearchResult();
            var db = new x360ceModelContainer();
            // All instances of the user.
            var instances = args.Where(x => x.InstanceGuid != Guid.Empty).Select(x => x.InstanceGuid).Distinct().ToArray();
            if (instances.Length == 0)
            {
                sr.Settings = new Setting[0];
            }
            else
            {
                sr.Settings = db.Settings.Where(x => instances.Contains(x.InstanceGuid))
                    .OrderBy(x => x.ProductName).ThenBy(x => x.FileName).ThenBy(x => x.FileProductName).ToArray();
            }
            // Global Configurations.
            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);
                sr.Summaries = db.Summaries.Where(lambda).OrderBy(x => x.ProductName).ThenBy(x => x.FileName).ThenBy(x => x.FileProductName).ThenBy(x => x.Users).ToArray();
            }
            return sr;
        }