public async Task <IActionResult> UploadFile(IFormFile file) { if (file == null || file.Length == 0) { return(RedirectToAction("Index")); } try { var parser = new LicenseParser(file, ';'); var results = parser.ParseStudents(); //TODO: This is probably not performant; better to get a stored procedure to dump the table _context.EligibleStudent.RemoveRange(_context.EligibleStudent.ToList()); foreach (EligibleStudent es in results.ValidList.Values) { _context.EligibleStudent.Add(es); } await _context.SaveChangesAsync(); TempData["InvalidList"] = results.InvalidList; } catch (InvalidDataException e) { TempData["BadFileType"] = e.Message; } catch (Exception e) { Console.WriteLine($"Exception: {e}"); } return(RedirectToAction("Index")); }
public async Task <IActionResult> UploadFile(IFormFile file) { if (file == null || file.Length == 0) { return(RedirectToAction("Index")); } try { var parser = new LicenseParser(file, ';'); var results = parser.ParseProducts(); foreach (KeyValuePair <string, Product> entry in results.ValidList) { Product existingRow = _context.Product.FirstOrDefault(p => p.Name == entry.Value.Name); if (existingRow == null) { _context.Product.Add(entry.Value); } else { results.InvalidList.Add(entry.Key, entry.Value.Name); } } await _context.SaveChangesAsync(); TempData["InvalidList"] = results.InvalidList; } catch (InvalidDataException e) { TempData["BadFileType"] = e.Message; } catch (Exception e) { Console.WriteLine($"Exception: {e}"); } return(RedirectToAction("Index")); }
public static Template Parse(string json) { var jObject = JObject.Parse(json); var result = new Template(); foreach (var item in jObject.Children <JProperty>()) { switch (item.Name.ToLower()) { case "id": result.Id = (int)item.Value; break; case "autolevels": result.AutoLevels = (bool)item.Value; break; case "category": result.Category = Category.Parse(item.Value); break; case "defaultlanguage": result.DefaultLanguage = Language.Parse(item.Value); break; case "description": result.Description = (string)item.Value; break; case "isembeddable": result.IsEmbeddable = (bool)item.Value; break; case "license": result.License = LicenseParser.Parse(item.Value); break; case "localvariables": result.LocalVars = ReadLocalVars(item.Value); break; case "name": result.Name = (string)item.Value; break; case "notifysubscribers": result.NotifySubscribers = (bool)item.Value; break; case "privacy": result.Privacy = PrivacyStatusParser.Parse(item.Value); break; case "publicstatsviewable": result.PublicStatsViewable = (bool)item.Value; break; case "publishtimes": result.PublishTimes = ReadPublishTimes(item.Value); break; case "shouldpublishat": result.ShouldPublishAt = (bool)item.Value; break; case "stabilize": result.Stabilize = (bool)item.Value; break; case "tags": result.Tags = (string)item.Value; break; case "thumbnailpath": result.ThumbnailPath = (string)item.Value; break; case "title": result.Title = (string)item.Value; break; default: break; } } return(result); }
public async Task <IActionResult> UploadFile(IFormFile file) { if (file == null || file.Length == 0) { return(RedirectToAction("Index")); } try { var parser = new LicenseParser(file, ';'); var results = parser.ParseKeys(); foreach (KeyValuePair <string, Tuple <string, string> > pk in results.ValidList) { ProductKey existingRow = _context.ProductKey .Include(p => p.Product) .FirstOrDefault(p => p.Product.Name == pk.Value.Item1 && p.Key == pk.Value.Item2); if (existingRow == null) { var product = _context.Product.FirstOrDefault(pn => pn.Name == pk.Value.Item1); if (product != null) { var nameId = product.Id; ProductKey newKey = new ProductKey() { NameId = nameId, Key = pk.Value.Item2, Status = "New" }; _context.ProductKey.Add(newKey); } else { //Add not-found products to invalid list results.InvalidList.Add(pk.Key, pk.Value.Item1 + ";" + pk.Value.Item2); } } } TempData["InvalidList"] = results.InvalidList; await _context.SaveChangesAsync(); } catch (InvalidDataException e) { TempData["BadFileType"] = e.Message; } catch (Exception e) { Console.WriteLine($"Exception: {e}"); } // Count the key number for each product and store the number into database var products = _context.Product.AsQueryable(); var productkeys = _context.ProductKey.AsQueryable(); foreach (Product product in products) { int keyCount = productkeys.Where(k => k.NameId == product.Id).Count(); int usedKeyCount = productkeys.Where(k => k.NameId == product.Id && k.Status == "Used").Count(); // Save the calculated key count number into database product.KeyCount = keyCount; _context.Entry(product).Property("KeyCount").IsModified = true; product.UsedKeyCount = usedKeyCount; _context.Entry(product).Property("UsedKeyCount").IsModified = true; } await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (_scriptsReloaded) { _scriptsReloaded = false; _initialized = false; Init(property); } if (EditorApplication.isCompiling) { _initialized = false; } else if (!_initialized) { Init(property); } _lineEndings = 0; var layerMask = property.FindPropertyRelative("LayerMask"); var eyeTrackingFilter = property.FindPropertyRelative("EyeTrackingFilter"); var advancedEnabled = property.FindPropertyRelative("AdvancedEnabled"); var licenseProp = property.FindPropertyRelative("LicenseAsset"); position.height = EditorGUIUtility.singleLineHeight; EditorGUI.LabelField(position, "Information", EditorStyles.boldLabel); CarriageReturn(ref position); EditorGUI.LabelField(position, "Change settings used to initialize Tobii XR. For more info click the button below."); CarriageReturn(ref position); var buttonPosition = position; var buttonContent = new GUIContent("Open website"); buttonPosition.width = GUI.skin.button.CalcSize(buttonContent).x; if (GUI.Button(buttonPosition, buttonContent)) { Application.OpenURL("https://vr.tobii.com/sdk/develop/unity/documentation/tobii-settings/"); } CarriageReturn(ref position, 2); EditorGUI.BeginDisabledGroup(Application.isPlaying); EditorGUI.PropertyField(position, layerMask, new GUIContent("G2OM Layer Mask", "Choose in which layers G2OM looks for potential candidates.")); CarriageReturn(ref position); // *************************** // Ocumen // *************************** EditorGUI.LabelField(position, "", GUI.skin.horizontalSlider); CarriageReturn(ref position); EditorGUI.LabelField(position, new GUIContent("Tobii Ocumen", "This section adds settings for Ocumen usages of the XR SDK."), EditorStyles.boldLabel); CarriageReturn(ref position); EditorGUI.LabelField(position, "Ocumen features require a license and will only work with the Tobii Provider."); CarriageReturn(ref position); EditorGUI.LabelField(position, "For more info click the button below."); CarriageReturn(ref position); buttonPosition = position; buttonContent = new GUIContent("Open website"); buttonPosition.width = GUI.skin.button.CalcSize(buttonContent).x; if (GUI.Button(buttonPosition, buttonContent)) { Application.OpenURL("https://vr.tobii.com/sdk/solutions/tobii-ocumen/"); } CarriageReturn(ref position); CarriageReturn(ref position); EditorGUI.PropertyField(position, licenseProp, new GUIContent("License Asset", "Choose license asset to use.")); CarriageReturn(ref position); EditorGUI.indentLevel++; if (licenseProp.objectReferenceValue != null) { var licenseAsset = licenseProp.objectReferenceValue as TextAsset; var lic = new LicenseParser(Encoding.Unicode.GetString(licenseAsset.bytes)); if (lic.LicenseIsParsed) { var style = new GUIStyle(); EditorGUI.LabelField(position, "Licensee:", lic.Licensee); CarriageReturn(ref position); if (lic.ValidTo != null) { var time = (DateTime)lic.ValidTo; EditorGUI.LabelField(position, "Expiry Date:", time.ToString("yyyy-MM-dd"), GetExpiryDateColor(lic.ValidTo, style)); } else { EditorGUI.LabelField(position, "Expiry Date:", "No Expiry Date", GetExpiryDateColor(lic.ValidTo, style)); } // CarriageReturn(ref position); // var signalsFiltersAvailable = lic.FeatureGroup == FeatureGroup.Professional; // EditorGUI.LabelField(position, "Signals & Filters:", GetLicenseAvailablityString(signalsFiltersAvailable), GetLicenseStyle(signalsFiltersAvailable, style)); // CarriageReturn(ref position); // // var configurationAvailable = lic.FeatureGroup >= FeatureGroup.Config; // EditorGUI.LabelField(position, "Configuration:", GetLicenseAvailablityString(configurationAvailable), GetLicenseStyle(configurationAvailable, style)); // CarriageReturn(ref position); // // var eyeImagesAvailable = lic.EyeImages; // EditorGUI.LabelField(position, "Eye Images:", GetLicenseAvailablityString(eyeImagesAvailable), GetLicenseStyle(eyeImagesAvailable, style)); // CarriageReturn(ref position); advancedEnabled.boolValue = lic.FeatureGroup == FeatureGroup.Professional; } else { var style = new GUIStyle { normal = { textColor = _redColor } }; EditorGUI.LabelField(position, "Invalid License", style); advancedEnabled.boolValue = false; } } else { advancedEnabled.boolValue = false; } CarriageReturn(ref position); EditorGUI.indentLevel--; // *************************** // Providers // *************************** EditorGUI.LabelField(position, "", GUI.skin.horizontalSlider); CarriageReturn(ref position); EditorGUI.LabelField(position, new GUIContent("Eye Tracking Providers", "If no provider is initialized successfully TobiiXR will use Nose Direction Provider even if it is removed from this list."), EditorStyles.boldLabel); CarriageReturn(ref position); if (licenseProp.objectReferenceValue != null) // A license was provided { EditorGUI.LabelField(position, "Tobii Provider is the only provider that supports licenses."); CarriageReturn(ref position); EditorGUI.LabelField(position, "The core API can still be used when advanced is enabled."); CarriageReturn(ref position); EditorGUI.LabelField(position, "Clear the license field if you want to use another provider."); CarriageReturn(ref position); CarriageReturn(ref position); } else { var providerList = EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.Android ? _androidProviderList : _standaloneProviderList; providerList.DoList(position); CarriageReturn(ref position); _providerListHeight = providerList.GetHeight(); position.y += _providerListHeight; } // *************************** // Filter // *************************** if (eyeTrackingFilter.objectReferenceValue != null && eyeTrackingFilter.objectReferenceValue is EyeTrackingFilterBase == false) { Debug.LogError("Filter must implement interface EyeTrackingFilterBase."); eyeTrackingFilter.objectReferenceValue = null; } EditorGUI.PropertyField(position, eyeTrackingFilter, new GUIContent("Eye Tracking Filter", "If you want the eye tracking data to be filtered. One example is the Gaze Modifier Filter.")); CarriageReturn(ref position); EditorGUI.EndDisabledGroup(); // *************************** // Player settings // *************************** if (licenseProp.objectReferenceValue == null) // No player settings are currently relevant when using a license { if (EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.Standalone || EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.Android) { CarriageReturn(ref position); CarriageReturn(ref position); EditorGUI.LabelField(position, new GUIContent(EditorUserBuildSettings.selectedBuildTargetGroup.ToString() + " Player Settings*", "Settings specific to a player."), EditorStyles.boldLabel); CarriageReturn(ref position); if (EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.Standalone) { var viveProviderEnabled = EditorGUI.ToggleLeft(position, new GUIContent("Support VIVE Pro Eye (requires SRanipal SDK)", "Please add VIVE SRanipal SDK to your project before enabling VIVE Pro Eye support"), _viveProviderEnabled); if (viveProviderEnabled != _viveProviderEnabled) { var flags = EditorUtils.GetCompilerFlagsForBuildTarget(BuildTargetGroup.Standalone); if (viveProviderEnabled) { flags.Add(ViveProviderCompilerFlagString); } else { flags.RemoveAll(x => x == ViveProviderCompilerFlagString); } EditorUtils.SetCompilerFlagsForBuildTarget(BuildTargetGroup.Standalone, flags); _viveProviderEnabled = viveProviderEnabled; } } else if (EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.Android) { var picoProviderEnabled = EditorGUI.ToggleLeft(position, new GUIContent("Support Pico (requires Pico VR SDK)", "Please add Pico VR SDK to your project before enabling Pico support"), _picoProviderEnabled); if (picoProviderEnabled != _picoProviderEnabled) { var flags = EditorUtils.GetCompilerFlagsForBuildTarget(BuildTargetGroup.Android); if (picoProviderEnabled) { flags.Add(PicoProviderCompilerFlagString); } else { flags.RemoveAll(x => x == PicoProviderCompilerFlagString); } EditorUtils.SetCompilerFlagsForBuildTarget(BuildTargetGroup.Android, flags); _picoProviderEnabled = picoProviderEnabled; } } } CarriageReturn(ref position); CarriageReturn(ref position); EditorGUI.LabelField(position, "*Changing player settings will trigger a recompile."); } }
private Core(CredentialsManager credentialsLoader, LicenseProvider dataProvider, LicenseParser licenseParser) { m_credentialsManager = credentialsLoader; m_dataProvider = dataProvider; m_licenseParser = licenseParser; }