/// <summary> /// Initializes a new instance of the <see cref="RegionViewMappingPayload" /> class. /// </summary> /// <param name="regionName">Name of the region.</param> /// <param name="viewMappingType">Type of the view mapping.</param> /// <param name="prefabName">Name of the prefab.</param> /// <param name="dataContext">The data context.</param> /// <exception cref="InvalidOperationException">If "viewMappingType" is not /// MapView, UnmapView, ShowView, HideView, LockView, UnlockView, UpdateDataContext</exception> /// <exception cref="ArgumentNullException">If "regionName" is null\empty</exception> /// <exception cref="ArgumentNullException">If "prefabName" is null\empty</exception> public RegionViewMappingPayload(string regionName, RegionViewMappingType viewMappingType, string prefabName, object dataContext = null) : this() { ArgumentValidator.AssertNotNullOrEmpty(regionName, "regionName"); ArgumentValidator.AssertNotNullOrEmpty(prefabName, "prefabName"); if (viewMappingType != RegionViewMappingType.MapView && viewMappingType != RegionViewMappingType.UnmapView && viewMappingType != RegionViewMappingType.ShowView && viewMappingType != RegionViewMappingType.HideView && viewMappingType != RegionViewMappingType.LockView && viewMappingType != RegionViewMappingType.UnlockView && viewMappingType != RegionViewMappingType.UpdateDataContext) { var allowedMappingTypes = string.Format( "This constructor can be used for these operations only: {0}, {1}, {2}, {3}, {4}, {5}, {6}.", RegionViewMappingType.MapView, RegionViewMappingType.UnmapView, RegionViewMappingType.ShowView, RegionViewMappingType.HideView, RegionViewMappingType.LockView, RegionViewMappingType.UnlockView, RegionViewMappingType.UpdateDataContext); ThrowInvalidMappingTypeException(allowedMappingTypes, viewMappingType); } RegionName = regionName; ViewMappingType = viewMappingType; PrefabName = prefabName; DataContext = dataContext; }
/// <summary> /// Initializes a new instance of the <see cref="RegionViewMappingPayload" /> class. /// </summary> /// <param name="regionName">Name of the region.</param> /// <param name="viewMappingType">Type of the view mapping.</param> /// <exception cref="System.ArgumentNullException">If "regionName" is null\empty</exception> /// <exception cref="System.InvalidOperationException">If "viewMappingType" is not one of values: /// UnmapAllViews, HideAllViews, ShowAllViews, LockAllViews, UnlockAllViews, DestroyRegion</exception> public RegionViewMappingPayload(string regionName, RegionViewMappingType viewMappingType) : this() { ArgumentValidator.AssertNotNullOrEmpty(regionName, "regionName"); if (viewMappingType != RegionViewMappingType.UnmapAllViews && viewMappingType != RegionViewMappingType.HideAllViews && viewMappingType != RegionViewMappingType.ShowAllViews && viewMappingType != RegionViewMappingType.LockAllViews && viewMappingType != RegionViewMappingType.UnlockAllViews && viewMappingType != RegionViewMappingType.DestroyRegion) { var allowedMappingTypes = string.Format( "This constructor can be used for these operations only: {0}, {1}, {2}, {3}, {4}, {5}", RegionViewMappingType.UnmapAllViews, RegionViewMappingType.HideAllViews, RegionViewMappingType.ShowAllViews, RegionViewMappingType.LockAllViews, RegionViewMappingType.UnlockAllViews, RegionViewMappingType.DestroyRegion); ThrowInvalidMappingTypeException(allowedMappingTypes, viewMappingType); } RegionName = regionName; ViewMappingType = viewMappingType; }
public Task(Action <TaskEventArgs <T> > execute, string descriptionForUser) { ArgumentValidator.AssertNotNull <Action <TaskEventArgs <T> > >(execute, "execute"); ArgumentValidator.AssertNotNullOrEmpty(descriptionForUser, "descriptionForUser"); this.descriptionForUser = descriptionForUser; this.Execute += (EventHandler <TaskEventArgs <T> >)((o, args) => execute(args)); }
private void EmptyStringRaisesArgumentException() { var emptyString = ""; var ex = Assert.Throws <ArgumentException>(() => ArgumentValidator.AssertNotNullOrEmpty(emptyString, nameof(emptyString))); Assert.Equal(nameof(emptyString), ex.ParamName); }
public void RegisterRegion(IRegion region) { ArgumentValidator.AssertNotNull(region, "region"); ArgumentValidator.AssertNotNullOrEmpty(region.Name, "region.Name"); if (RegisteredRegions.Contains(region.Name)) { return; } RegisteredRegions.Add(region.Name); if (!DelayedRegions.ContainsKey(region.Name)) { return; } var payloads = DelayedRegions[region.Name]; if (payloads.IsNullOrEmpty()) { return; } var ary = payloads.ToArray(); payloads.Clear(); foreach (var payload in ary) { region.ProcessPayload(payload); } }
private void NullStringRaisesArgumentNullException() { string nullString = null; var ex = Assert.Throws <ArgumentNullException>(() => ArgumentValidator.AssertNotNullOrEmpty(nullString, nameof(nullString))); Assert.Equal(nameof(nullString), ex.ParamName); }
/// <summary> /// Initializes a new instance of the <see cref="RegionViewMappingPayload"/> class. /// </summary> /// <param name="regionName">Name of the region.</param> /// <param name="viewMappingType">Type of the view mapping.</param> /// <param name="prefabName">Name of the prefab.</param> /// <param name="index">The index.</param> /// <param name="assignViewName">Name of the assign view.</param> /// <param name="dataContext">The data context.</param> /// <exception cref="System.ArgumentNullException">If "regionName" is null\empty</exception> /// <exception cref="System.ArgumentNullException">If "prefabName" is null\empty</exception> /// <exception cref="System.InvalidOperationException">If "viewMappingType" is not MapView</exception> public RegionViewMappingPayload(string regionName, RegionViewMappingType viewMappingType, string prefabName, int?index = null, string assignViewName = null, object dataContext = null) : this() //: this(regionName, viewMappingType) { ArgumentValidator.AssertNotNullOrEmpty(regionName, "regionName"); ArgumentValidator.AssertNotNullOrEmpty(prefabName, "prefabName"); RegionName = regionName; ViewMappingType = viewMappingType; if (viewMappingType != RegionViewMappingType.MapView) { var allowedMappingTypes = string.Format( "This constructor can be used for this operation: {0}", RegionViewMappingType.MapView); ThrowInvalidMappingTypeException(allowedMappingTypes, viewMappingType); } PrefabName = prefabName; AssignViewName = assignViewName; DataContext = dataContext; if (index.HasValue) { Index = index.Value; } }
private void WriteZipFile(object obj) { var filePath = obj as string; try { ArgumentValidator.AssertNotNullOrEmpty(filePath, "filePath"); if (!File.Exists(filePath)) { throw new FileNotFoundException("Cannot compress file. Cannot locate file.", filePath); } Thread.Sleep(40); // wait 1 frame var dirPath = Path.GetDirectoryName(filePath); var fileName = Path.GetFileName(filePath); var zipFileName = Path.ChangeExtension(fileName, GzipFileExt); GZipHelper.Default.CompressFile(dirPath, fileName, false, zipFileName, null); var zipFilePath = Path.Combine(dirPath, zipFileName); if (File.Exists(zipFilePath)) { //System.Diagnostics.Debug.WriteLine("deleting " + filePath); File.Delete(filePath); //System.Diagnostics.Debug.WriteLine("deleted " + filePath); InvokeFileActionEvent(zipFilePath, FileLoggerAction.Compressed, FileLoggerResult.Success); } } catch (Exception e) { InvokeFileActionEvent(filePath, FileLoggerAction.Compressed, FileLoggerResult.Error, e); } }
public FileStreamWriter(string filePath, EventHandler <FileLoggerCallbackArgs> callback) { ArgumentValidator.AssertNotNullOrEmpty(filePath, "filePath"); FilePath = filePath; FileStream = new FileStream(FilePath, FileMode.Append); Callback += callback; }
/// <summary> /// Registers the region. /// </summary> /// <param name="target">The target.</param> /// <param name="regionName">Name of the region.</param> public void RegisterRegion(GameObject target, string regionName) { ArgumentValidator.AssertNotNull(target, "target"); ArgumentValidator.AssertNotNullOrEmpty(regionName, "regionName"); target.name = regionName; var mapping = target.AddComponent <RegionMapping>(); mapping.name = regionName; }
public void UnregisterRegion(IRegion region) { ArgumentValidator.AssertNotNull(region, "region"); ArgumentValidator.AssertNotNullOrEmpty(region.Name, "region.Name"); if (!RegisteredRegions.Contains(region.Name)) { return; } RegisteredRegions.Remove(region.Name); }
/// <summary> /// Unregisters the region. /// </summary> /// <param name="target">The target.</param> /// <param name="regionName">Name of the region.</param> public void UnregisterRegion(GameObject target, string regionName) { ArgumentValidator.AssertNotNull(target, "target"); ArgumentValidator.AssertNotNullOrEmpty(regionName, "regionName"); var regionMapping = target.GetComponentInChildren <RegionMapping>(); if (regionMapping == null) { return; } Destroy(regionMapping); }
public void LoadFromFile(string filePath, EventHandler <FileLoggerCallbackArgs> callback) { try { if (!Settings.IsEnabled) { const string errMsg = "reading from log file is aborted. Logger is disabled.\r\nTo enable logger set 'Settings.IsEnabled = true'."; #if UNITY_3D || UNITY3D UnityEngine.Debug.LogWarning(errMsg); #else Debug.WriteLine(errMsg); #endif return; } ArgumentValidator.AssertNotNullOrEmpty(filePath, "filePath"); if (!File.Exists(filePath)) { throw new FileNotFoundException(filePath); } if (FileStreams.ContainsKey(filePath)) { throw new OperationCanceledException("File with path '" + filePath + "' is in process."); } var wrapper = new FileStreamReader(filePath, callback) { IsFileCompressionEnabled = Settings.UseGzipCompression }; wrapper.Callback += OnFileStreamAction; FileStreams.Add(filePath, wrapper); wrapper.LoadFromFile(); } catch (Exception e) { FileStreamWrapperBase.InvokeFileActionEvent(callback, null, filePath, null, null, FileLoggerAction.Read, FileLoggerResult.Error, e); if (callback == null) { throw; } } }
/// <summary> /// Converts the specified string value to enum. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value">The value.</param> /// <returns></returns> /// <exception cref="OperationCanceledException"></exception> public static T Convert <T>(string value) { ArgumentValidator.AssertNotNullOrEmpty(value, "value"); var enumType = typeof(T); #if !UNITY_WSA if (!enumType.IsEnum) { throw new OperationCanceledException(string.Format("The \"{0}\" is not \"{1}\"!", enumType, typeof(Enum))); } #else // TODO check if "enumType" is "Enum" #endif var convertedValue = Enum.Parse(enumType, value, true); var method = (T)convertedValue; return(method); }
public virtual void SaveToFile(string text, EventHandler <FileLoggerCallbackArgs> callback) { try { if (!Settings.IsEnabled) { const string errMsg = "Writing to log file is aborted. Logger is disabled.\r\nTo enable logger set 'Settings.IsEnabled = true'."; #if UNITY_3D || UNITY3D UnityEngine.Debug.LogWarning(errMsg); #else Debug.WriteLine(errMsg); #endif return; } ArgumentValidator.AssertNotNullOrEmpty(text, "text"); if (!Directory.Exists(Settings.DirectoryPath)) { Directory.CreateDirectory(Settings.DirectoryPath); } var wrapper = GetFileStream(callback); wrapper.SaveToFile(text); } catch (Exception e) { FileStreamWrapperBase.InvokeFileActionEvent(callback, null, FilePath, null, null, FileLoggerAction.Write, FileLoggerResult.Error, e); if (callback == null) { throw; } } }
public virtual IFileLogger Init(string sid, FileLoggerSettings settings = null) { ArgumentValidator.AssertNotNullOrEmpty(sid, "sid"); if (settings == null) { var dataPath = LocalStorage.Default.LocalDataFolderPath; var dir = Path.Combine(dataPath, "_LOG"); settings = new FileLoggerSettings { IsEnabled = true, IsAutoTimeStampEnabled = true, LogTarget = LogTargetType.File, Severity = LogSeverityType.Normal, TimeStampFormat = "T", DefaultMessageFormat = "{0}", BackupTrigger = FileBackupTriggerType.MaxFileSize, DirectoryPath = dir, FileName = string.Format("{0}_", sid), FileExtension = "log", IsRecordsCacheEnabled = false, MaxFileSize = 2000000, // 2mb MaxRecordsCount = 10000, RecordsCacheSize = 100, RecordWriteTrigger = FileRecordWriteTriggerType.Critical, LineDelimiter = ",", OpeningLine = "[", ClosingLine = "]", UseGzipCompression = false, GzipFileExtension = "bak" }; } Settings = settings; return(this); }
public FileStreamReader(string filePath, EventHandler <FileLoggerCallbackArgs> callback) { try { Callback += callback; ArgumentValidator.AssertNotNullOrEmpty(filePath, "filePath"); if (!File.Exists(filePath)) { throw new FileNotFoundException(filePath); } FilePath = filePath; FileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); if (!FileStream.CanRead) { throw new OperationCanceledException("Cannot read from " + filePath); } } catch (Exception e) { InvokeFileActionEvent(filePath, FileLoggerAction.Init, FileLoggerResult.Error, e); } }
private void WhiteSpacesDoesNotRaiseException() { var spaces = " "; ArgumentValidator.AssertNotNullOrEmpty(spaces, nameof(spaces)); }
private object ReadObjectInstance(Type instType, JsonReader reader) { var tData = _metadataHandler.AddObjectMetadata(instType); var instance = Activator.CreateInstance(instType); while (true) { reader.Read(); if (reader.Token == JsonToken.ObjectEnd) { break; } var property = (string)reader.Value; ArgumentValidator.AssertNotNullOrEmpty(property, "property"); // BUG: reader.Value == NULL in some cases ???!!! if (tData.Properties.ContainsKey(property)) { var propData = tData.Properties[property]; if (propData.IsField) { var fInfo = (FieldInfo)propData.Info; if (!fInfo.IsInitOnly) { var value = ReadValue(propData.Type, reader, propData.Attribute != null ? propData.Attribute.FallbackValue : null); fInfo.SetValue(instance, value); #if DEBUG_JSON Log("ReadValue -> {0}.SetValue({1}, {2});", fInfo, instance, value); #endif } else { ReadValue(propData.Type, reader, propData.Attribute != null ? propData.Attribute.FallbackValue : null); #if DEBUG_JSON Log("ReadValue -> fInfo.CanWrite = FALSE ({0})", fInfo); #endif } } else { var pInfo = (PropertyInfo)propData.Info; if (pInfo.CanWrite) { var value = ReadValue(propData.Type, reader, propData.Attribute != null ? propData.Attribute.FallbackValue : null); pInfo.SetValue(instance, value, null); #if DEBUG_JSON Log("ReadValue -> {0}.SetValue({1}, {2});", pInfo, instance, value); #endif } else { ReadValue(propData.Type, reader, propData.Attribute != null ? propData.Attribute.FallbackValue : null); #if DEBUG_JSON Log("ReadValue -> pInfo.CanWrite = FALSE ({0})", propData); #endif } } } else { if (!tData.IsDictionary) { #if DEBUG_JSON Log("The type {0} doesn't have the property '{1}'", instType, property); #endif ReadValue(typeof(JsonData), reader, null); } else { var res = ReadValue(tData.ElementType, reader, null); try { ((IDictionary)instance).Add(property, res); } catch (Exception exc) // TODO handle exc { #if DEBUG_JSON Log("(({0}) instance - {1}).Add(\"{2}\", {3}); Error: {4}", typeof(IDictionary), instance, property, res, exc); #endif } #if DEBUG_JSON Log("ReadValue -> ((IDictionary) {0}).Add({1}, {2});", instance, property, res); #endif } } } return(instance); }
private void WordDoesNotRaiseException() { var word = "chickens"; ArgumentValidator.AssertNotNullOrEmpty(word, nameof(word)); }
private void SentenceDoesNotRaiseException() { var sentence = "I've got a bad feeling about this."; ArgumentValidator.AssertNotNullOrEmpty(sentence, nameof(sentence)); }
/// <summary> /// Called when [property changed]. /// </summary> /// <param name="propertyName">Name of the property.</param> protected virtual void OnPropertyChanged(string propertyName) { ArgumentValidator.AssertNotNullOrEmpty(propertyName, "propertyName"); PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); }