Пример #1
0
        /// <summary>
        /// Writes a tag header to the stream
        /// </summary>
        /// <param name="tagNumber">The tag number of the header, or 255 for an application tag</param>
        /// <param name="defaultTag">The default application tag if the tag number is 255</param>
        /// <param name="lvt">The 3-bit Length/Value/Type value</param>
        private void _writeHeader(byte tagNumber, ApplicationTag defaultTag, byte lvt)
        {
            bool context = (tagNumber != 255);
            byte tag     = (context ? tagNumber : (byte)defaultTag);

            byte header = 0x00;

            if (tag >= 0x0F)
            {
                header |= 0xF0;
            }
            else
            {
                header |= (byte)(tag << 4);
            }

            if (context)
            {
                header |= 0x08;
            }
            header |= lvt;

            _writer.Write(header);
            if (tag >= 0x0F)
            {
                _writer.Write(tag);
            }
        }
Пример #2
0
        /// <summary>
        /// Ensures that the current tag meets an expected
        /// tag value
        /// </summary>
        /// <param name="tag">The expected tag number, or 255 for an application tag</param>
        /// <param name="defaultTag">The expected application tag if <paramref name="tag"/> is 255</param>
        private void _ensureTag(byte tag, ApplicationTag defaultTag)
        {
            bool context   = (tag != 255);
            byte tagNumber = (tag == 255 ? (byte)defaultTag : tag);

            _nextHeader();
            if (_isContext != context || _tagNumber != tagNumber)
            {
                throw new UnexpectedTagException();
            }
        }
Пример #3
0
        /// <summary>
        /// Checks whether the next tag to be read matches
        /// a certain tag
        /// </summary>
        /// <param name="tag">The tag number to check for, or 255 for an application tag</param>
        /// <param name="defaultTag">The application tag to check for</param>
        /// <returns>True if the next tag matches, false otherwise</returns>
        public bool AtTag(byte tag, ApplicationTag defaultTag)
        {
            bool ret       = false;
            bool hasHeader = _peekHeader();

            if (hasHeader)
            {
                bool context   = (tag != 255);
                byte tagNumber = (context ? tag : (byte)defaultTag);
                return(_isContext == context && _tagNumber == tagNumber);
            }

            return(ret);
        }
Пример #4
0
 /// <summary>
 /// Writes a tag header with a length LVT
 /// </summary>
 /// <param name="tagNumber">The tag number of the header, or 255 for an application tag</param>
 /// <param name="defaultTag">The default application tag if the tag number is 255</param>
 /// <param name="length">The length LVT of the tag</param>
 private void _writeLengthHeader(byte tagNumber, ApplicationTag defaultTag, int length)
 {
     _writeHeader(tagNumber, defaultTag, (byte)(length >= 0x05 ? 0x05 : length));
     if (length >= ushort.MaxValue)
     {
         _writer.Write((byte)0xFF);
         _writer.Write(new Union4((uint)length).ReverseLE().UInt32);
     }
     else if (length >= 254)
     {
         _writer.Write((byte)0xFE);
         _writer.Write(new Union2((ushort)length).ReverseLE().UInt16);
     }
     else if (length >= 5)
     {
         _writer.Write((byte)length);
     }
 }
Пример #5
0
        public async Task <ActionResult> Create(CreateArticleViewModel model)
        {
            CurrentAction.currentAction = "Manage-Article-Create";
            if (ModelState.IsValid)
            {
                var Article = new ApplicationArticle
                {
                    Title          = model.Title,
                    ArticleContent = model.ArticleContent,
                    UserId         = User.Identity.GetUserId()
                };

                string[] tags = model.Tags == null ? new string[0] : model.Tags.Split(',');
                foreach (var item in tags)
                {
                    string sitem = item.Trim();
                    var    t     = db.ApplicationTags.Where(x => x.Tag == sitem).FirstOrDefault();
                    // not this tag in database
                    if (t == null)
                    {
                        var tag = new ApplicationTag
                        {
                            Tag = sitem
                        };
                        db.ApplicationTags.Add(tag);
                        Article.Tags.Add(tag);
                    }
                    else
                    {
                        Article.Tags.Add(t);
                    }
                }

                db.ApplicationArticles.Add(Article);
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "Article", new { id = Article.Id }));
            }
            //ViewBag.CategoryId = new SelectList(db.ApplicationCategories, "Id", "Category", model.CategoryId);
            return(View(model));
        }
Пример #6
0
        public async Task <ActionResult> Edit(EditArticleViewModel model)
        {
            CurrentAction.currentAction = "Manage-Article-Edit";
            if (ModelState.IsValid)
            {
                var Article = db.ApplicationArticles.Find(model.Id);

                Article.Title          = model.Title;
                Article.ArticleContent = model.ArticleContent;
                Article.DateEdited     = DateTime.Now;

                string[] tags = model.Tags == null ? new string[0] : model.Tags.Split(',');
                foreach (var item in tags)
                {
                    string sitem = item.Trim();
                    var    t     = db.ApplicationTags.Where(x => x.Tag == sitem).FirstOrDefault();
                    // not this tag in database
                    if (t == null)
                    {
                        var tag = new ApplicationTag
                        {
                            Tag = sitem
                        };
                        db.ApplicationTags.Add(tag);
                        Article.Tags.Add(tag);
                    }
                    else
                    {
                        if (!Article.Tags.Any(x => x.Tag == sitem))
                        {
                            Article.Tags.Add(t);
                        }
                    }
                }

                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "Article", new { id = model.Id }));
            }
            return(View(model));
        }
Пример #7
0
        public void DialogsTestTest06SaverJSON()
        {
            Event          obj    = CreateObject();
            ApplicationTag apptag = new ApplicationTag();
            Application    app    = new Application();

            app.Name = "APP_EventTest06";
            app.EventContainer.Add(obj);
            apptag.Entity = app;

            SaverJson saver = new SaverJson();

            saver.ExportApplicationTag(@".\Data\", apptag);

            Assert.True(Directory.Exists(@".\Data\APP_EventTest06\Events"));

            var fileCount = (from file in Directory.EnumerateFiles(@".\Data\APP_EventTest06\Events", "*.EasyBpart", SearchOption.AllDirectories)
                             select file).Count();

            Assert.True(fileCount == 1);
        }
Пример #8
0
        public void FieldTypeTest06SaverJSON()
        {
            FieldType      fieldtype = CreateFieldType();
            ApplicationTag apptag    = new ApplicationTag();
            Application    app       = new Application();

            app.Name = "APP_FieldTypeTest06";
            app.FieldTypeContainer.Add(fieldtype);
            apptag.Entity = app;

            SaverJson saver = new SaverJson();

            saver.ExportApplicationTag(@".\Data\", apptag);

            Assert.True(Directory.Exists(@".\Data\APP_FieldTypeTest06\FieldTypes"));

            var fileCount = (from file in Directory.EnumerateFiles(@".\Data\APP_FieldTypeTest06\FieldTypes", "*.EasyBpart", SearchOption.AllDirectories)
                             select file).Count();

            Assert.True(fileCount == 1);
        }
Пример #9
0
        public void WorkflowQueryCommandTest06SaverJSON()
        {
            WorkflowQueryCommand obj    = CreateObject();
            ApplicationTag       apptag = new ApplicationTag();
            Application          app    = new Application();

            app.Name = "APP_WorkflowQueryCommandTest06";
            app.WorkflowQueryCommandContainer.Add(obj);
            apptag.Entity = app;

            SaverJson saver = new SaverJson();

            saver.ExportApplicationTag(@".\Data\", apptag);

            Assert.IsTrue(Directory.Exists(@".\Data\APP_WorkflowQueryCommandTest06\Queries"));

            var fileCount = (from file in Directory.EnumerateFiles(@".\Data\APP_WorkflowQueryCommandTest06\Queries", "*.EasyBpart", SearchOption.AllDirectories)
                             select file).Count();

            Assert.IsTrue(fileCount == 1);
        }
Пример #10
0
 public Tag(ApplicationTag applicationTag) : this()
 {
     this.ContextTag     = 255;
     this.ApplicationTag = applicationTag;
 }
Пример #11
0
 /// <summary>
 /// Writes a tag header with a value LVT
 /// </summary>
 /// <param name="tagNumber">The tag number of the header, or 255 for an application tag</param>
 /// <param name="defaultTag">The default application tag if the tag number is 255</param>
 /// <param name="value">The boolean value LVT</param>
 private void _writeValueHeader(byte tagNumber, ApplicationTag defaultTag, bool value)
 {
     _writeHeader(tagNumber, defaultTag, (byte)(value ? 0x01 : 0x00));
 }
Пример #12
0
        /// <summary>
        /// Checks whether the next tag to be read matches
        /// a certain tag
        /// </summary>
        /// <param name="tag">The tag number to check for, or 255 for an application tag</param>
        /// <param name="defaultTag">The application tag to check for</param>
        /// <returns>True if the next tag matches, false otherwise</returns>
        public bool AtTag(byte tag, ApplicationTag defaultTag)
        {
            bool ret = false;
            bool hasHeader = _peekHeader();

            if(hasHeader)
            {
                bool context = (tag != 255);
                byte tagNumber = (context ? tag : (byte)defaultTag);
                return (_isContext == context && _tagNumber == tagNumber);
            }

            return ret;
        }
Пример #13
0
 /// <summary>
 /// Writes a tag header with a value LVT
 /// </summary>
 /// <param name="tagNumber">The tag number of the header, or 255 for an application tag</param>
 /// <param name="defaultTag">The default application tag if the tag number is 255</param>
 /// <param name="value">The boolean value LVT</param>
 private void _writeValueHeader(byte tagNumber, ApplicationTag defaultTag, bool value)
 {
     _writeHeader(tagNumber, defaultTag, (byte)(value ? 0x01 : 0x00));
 }
Пример #14
0
 /// <summary>
 /// Writes a tag header with a length LVT
 /// </summary>
 /// <param name="tagNumber">The tag number of the header, or 255 for an application tag</param>
 /// <param name="defaultTag">The default application tag if the tag number is 255</param>
 /// <param name="length">The length LVT of the tag</param>
 private void _writeLengthHeader(byte tagNumber, ApplicationTag defaultTag, int length)
 {
     _writeHeader(tagNumber, defaultTag, (byte)(length >= 0x05 ? 0x05 : length));
     if(length >= ushort.MaxValue)
     {
         _writer.Write((byte)0xFF);
         _writer.Write(new Union4((uint)length).ReverseLE().UInt32);
     }
     else if(length >= 254)
     {
         _writer.Write((byte)0xFE);
         _writer.Write(new Union2((ushort)length).ReverseLE().UInt16);
     }
     else if(length >= 5)
     {
         _writer.Write((byte)length);
     }
 }
Пример #15
0
        /// <summary>
        /// Writes a tag header to the stream
        /// </summary>
        /// <param name="tagNumber">The tag number of the header, or 255 for an application tag</param>
        /// <param name="defaultTag">The default application tag if the tag number is 255</param>
        /// <param name="lvt">The 3-bit Length/Value/Type value</param>
        private void _writeHeader(byte tagNumber, ApplicationTag defaultTag, byte lvt)
        {
            bool context = (tagNumber != 255);
            byte tag = (context ? tagNumber : (byte)defaultTag);

            byte header = 0x00;

            if (tag >= 0x0F)
                header |= 0xF0;
            else
                header |= (byte)(tag << 4);

            if (context)
                header |= 0x08;
            header |= lvt;

            _writer.Write(header);
            if (tag >= 0x0F)
                _writer.Write(tag);
        }
Пример #16
0
 public Tag(ApplicationTag applicationTag)
     : this()
 {
     this.ContextTag = 255;
     this.ApplicationTag = applicationTag;
 }
Пример #17
0
        /// <summary>
        /// Ensures that the current tag meets an expected
        /// tag value
        /// </summary>
        /// <param name="tag">The expected tag number, or 255 for an application tag</param>
        /// <param name="defaultTag">The expected application tag if <paramref name="tag"/> is 255</param>
        private void _ensureTag(byte tag, ApplicationTag defaultTag)
        {
            bool context = (tag != 255);
            byte tagNumber = (tag == 255 ? (byte)defaultTag : tag);

            _nextHeader();
            if (_isContext != context || _tagNumber != tagNumber)
                throw new UnexpectedTagException();
        }