コード例 #1
0
        /// <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;
        }
コード例 #2
0
        /// <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;
        }
コード例 #3
0
ファイル: Task`1.cs プロジェクト: yuluos/CocoStudio2.0.6
 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));
 }
コード例 #4
0
        private void EmptyStringRaisesArgumentException()
        {
            var emptyString = "";
            var ex          = Assert.Throws <ArgumentException>(() => ArgumentValidator.AssertNotNullOrEmpty(emptyString, nameof(emptyString)));

            Assert.Equal(nameof(emptyString), ex.ParamName);
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        private void NullStringRaisesArgumentNullException()
        {
            string nullString = null;
            var    ex         = Assert.Throws <ArgumentNullException>(() => ArgumentValidator.AssertNotNullOrEmpty(nullString, nameof(nullString)));

            Assert.Equal(nameof(nullString), ex.ParamName);
        }
コード例 #7
0
        /// <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;
            }
        }
コード例 #8
0
ファイル: FileLogger.cs プロジェクト: supermax/TMS
        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);
            }
        }
コード例 #9
0
ファイル: FileLogger.cs プロジェクト: supermax/TMS
        public FileStreamWriter(string filePath, EventHandler <FileLoggerCallbackArgs> callback)
        {
            ArgumentValidator.AssertNotNullOrEmpty(filePath, "filePath");

            FilePath   = filePath;
            FileStream = new FileStream(FilePath, FileMode.Append);
            Callback  += callback;
        }
コード例 #10
0
        /// <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;
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
ファイル: FileLogger.cs プロジェクト: supermax/TMS
        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;
                }
            }
        }
コード例 #14
0
ファイル: EnumHelper.cs プロジェクト: supermax/TMS
        /// <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);
        }
コード例 #15
0
ファイル: FileLogger.cs プロジェクト: supermax/TMS
        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;
                }
            }
        }
コード例 #16
0
ファイル: FileLogger.cs プロジェクト: supermax/TMS
        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);
        }
コード例 #17
0
ファイル: FileLogger.cs プロジェクト: supermax/TMS
        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);
            }
        }
コード例 #18
0
        private void WhiteSpacesDoesNotRaiseException()
        {
            var spaces = "   ";

            ArgumentValidator.AssertNotNullOrEmpty(spaces, nameof(spaces));
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        private void WordDoesNotRaiseException()
        {
            var word = "chickens";

            ArgumentValidator.AssertNotNullOrEmpty(word, nameof(word));
        }
コード例 #21
0
        private void SentenceDoesNotRaiseException()
        {
            var sentence = "I've got a bad feeling about this.";

            ArgumentValidator.AssertNotNullOrEmpty(sentence, nameof(sentence));
        }
コード例 #22
0
ファイル: ObservableDictionary.cs プロジェクト: supermax/TMS
 /// <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));
 }