Beispiel #1
0
        public void Add(int fileDoId, TagDO tag)
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var tagRepository     = uow.TagRepository;
                var fileTagRepository = uow.FileTagsRepository;
                var fileTag           = new FileTags()
                {
                    FileDoId = fileDoId
                };

                var dbTag = GetByKey(tag.Key);
                if (dbTag == null)
                {
                    tagRepository.Add(tag);
                    uow.SaveChanges();

                    dbTag = tagRepository.GetByKey(tag.Key);
                }

                fileTag.TagId = dbTag.Id;

                fileTagRepository.Add(fileTag);
                uow.SaveChanges();
            }
        }
Beispiel #2
0
            /// <summary>
            /// Creates a FileTags from a file name.
            /// </summary>
            public static FileTags Create(string fileNameWithoutExtension)
            {
                FileTags ret = new FileTags();

                // Go through each tag match, and apply it
                foreach (Match match in _tagRegex.Matches(fileNameWithoutExtension))
                {
                    ret.ApplyTag(match.Groups["tag"].Value, match.Groups["value"].Value, fileNameWithoutExtension);
                }

                // Get the title
                int braceIndex = fileNameWithoutExtension.IndexOf('[');

                if (braceIndex > 0)
                {
                    ret.Title = fileNameWithoutExtension.Substring(0, braceIndex).Trim();
                }
                else
                {
                    ret.Title = fileNameWithoutExtension;
                }

                if (ret.Title.Contains("[") || ret.Title.Contains("]"))
                {
                    throw new Exception("GrhData update failed for filename `" + fileNameWithoutExtension + "` because a [ or ] character was found in the sprite title." +
                                        " Make sure your file name is correctly formed, and each [ has a matching ].");
                }

                return(ret);
            }
 public void ConvertEmptyStringToJson()
 {
     Assert.AreEqual(
         "{\"tags\":\"\"}",
         FileTags.ConvertToJson(new List <string> {
     })
         );
 }
 public void ConvertEmptyStringToSpaceDelimitedString()
 {
     Assert.AreEqual(
         "",
         FileTags.ConvertToSpaceDelimitedString(new List <string> {
     })
         );
 }
Beispiel #5
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="allTagNames">所有标签</param>
 public AddFileDialog(IEnumerable <string> allTagNames)
 {
     InitializeComponent();
     DataContext = this;
     foreach (string tagName in allTagNames)
     {
         FileTags.Add(new SelectableFileTag(tagName));
     }
 }
 public void ConvertTwoTagsToJson()
 {
     Assert.AreEqual(
         "{\"tags\":\"test1 test2\"}",
         FileTags.ConvertToJson(new List <string> {
         "test1", "test2"
     })
         );
 }
 public void ConvertTwoTagsToSpaceDelimitedString()
 {
     Assert.AreEqual(
         "test1 test2",
         FileTags.ConvertToSpaceDelimitedString(new List <string> {
         "test1", "test2"
     })
         );
 }
Beispiel #8
0
 public EditFileDialog(FileInfoForEdit fileInfo, IEnumerable <string> allTagName)
 {
     InitializeComponent();
     FileInfo    = fileInfo;
     DataContext = this;
     //fill FileTag Collection
     foreach (string tagName in allTagName)
     {
         FileTags.Add(new SelectableFileTag(
                          tagName, fileInfo.TagNames.Contains(tagName)));
     }
 }
        public void ConvertSpecialCharactersToJson()
        {
            var outputJson = FileTags.ConvertToJson(new List <string> {
                "}\":{\\{"
            });

            Assert.DoesNotThrow(() => JsonConvert.DeserializeObject(outputJson));

            Assert.AreEqual(
                "{\"tags\":\"}\\\":{\\\\{\"}",
                outputJson
                );
        }
Beispiel #10
0
        public void UpdateAll(int fileDoId, IList <TagDO> tags)
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var tagRepository     = uow.TagRepository;
                var fileTagRepository = uow.FileTagsRepository;
                // update old tags and add new
                foreach (var tag in tags)
                {
                    var dbTag = tagRepository.FindOne(x => x.Key == tag.Key);
                    if (!object.Equals(dbTag, default(TagDO)))
                    {
                        dbTag.Value = tag.Value;
                    }
                    else
                    {
                        tagRepository.Add(tag);
                    }
                }
                uow.SaveChanges();

                // remove all fileTags with fileDoId
                RemoveAll(fileDoId);

                // Add new fileTags to the fileDo
                foreach (var tag in tags)
                {
                    var dbTag = tagRepository.FindOne(x => x.Key == tag.Key);
                    if (!object.Equals(dbTag, default(TagDO)))
                    {
                        var fileTag = new FileTags()
                        {
                            FileDoId = fileDoId,
                            TagId    = dbTag.Id
                        };

                        fileTagRepository.Add(fileTag);
                    }
                }
                uow.SaveChanges();
            }
        }
Beispiel #11
0
        private Dictionary <FileDO, TagDO> CreateFileTagsLink()
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var      fileDo   = CreateFileDo();
                var      tagDo    = CreateTagDo(1, "key1", "value1");
                FileTags fileTags = new FileTags()
                {
                    Id       = 1,
                    FileDoId = fileDo.Id,
                    TagId    = tagDo.Id
                };

                uow.FileTagsRepository.Add(fileTags);
                uow.SaveChanges();

                var dict = new Dictionary <FileDO, TagDO>();
                dict.Add(fileDo, tagDo);

                return(dict);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AutomaticAnimatedGrhData"/> class.
        /// </summary>
        /// <param name="cm">The <see cref="IContentManager"/> used for creating the frames.</param>
        /// <param name="grhIndex">The <see cref="GrhIndex"/>.</param>
        /// <param name="cat">The <see cref="SpriteCategorization"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="grhIndex"/> is equal to GrhIndex.Invalid.</exception>
        internal AutomaticAnimatedGrhData(IContentManager cm, GrhIndex grhIndex, SpriteCategorization cat) : base(grhIndex, cat)
        {
            _cm = cm;

            try
            {
                var framesDir     = GetFramesDirectory();
                var framesDirName = Path.GetFileName(framesDir).Substring(1); // Get dir name only, and skip the _ at the start

                var fileTags = FileTags.Create(framesDirName);
                _speed = 1f / fileTags.AnimationSpeed.Value;

                Debug.Assert(fileTags.Title == cat.Title);

                _frames = CreateFrames(framesDir);
            }
            catch
            {
                _speed  = 1f;
                _frames = new StationaryGrhData[0];
            }
        }
Beispiel #13
0
            /// <summary>
            /// Creates a FileTags from a file name.
            /// </summary>
            public static FileTags Create(string fileNameWithoutExtension)
            {
                FileTags ret = new FileTags();

                // Go through each tag match, and apply it
                foreach (Match match in _tagRegex.Matches(fileNameWithoutExtension))
                {
                    ret.ApplyTag(match.Groups["tag"].Value, match.Groups["value"].Value, fileNameWithoutExtension);
                }

                // Get the title
                int braceIndex = fileNameWithoutExtension.IndexOf('[');
                if (braceIndex > 0)
                    ret.Title = fileNameWithoutExtension.Substring(0, braceIndex).Trim();
                else
                    ret.Title = fileNameWithoutExtension;

                if (ret.Title.Contains("[") || ret.Title.Contains("]"))
                {
                    throw new Exception("GrhData update failed for filename `" + fileNameWithoutExtension + "` because a [ or ] character was found in the sprite title." +
                        " Make sure your file name is correctly formed, and each [ has a matching ].");
                }

                return ret;
            }