コード例 #1
0
ファイル: TagWriter.cs プロジェクト: fanzcsoft/bacstack
        /// <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
ファイル: TagReader.cs プロジェクト: fanzcsoft/bacstack
        /// <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
ファイル: TagReader.cs プロジェクト: fanzcsoft/bacstack
        /// <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
ファイル: TagWriter.cs プロジェクト: fanzcsoft/bacstack
 /// <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
ファイル: TagWriter.cs プロジェクト: fanzcsoft/bacstack
 /// <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
ファイル: TagReader.cs プロジェクト: LorenVS/bacstack
        /// <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
ファイル: TagWriter.cs プロジェクト: LorenVS/bacstack
 /// <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
ファイル: TagWriter.cs プロジェクト: LorenVS/bacstack
 /// <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
ファイル: TagWriter.cs プロジェクト: LorenVS/bacstack
        /// <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
ファイル: Utils.cs プロジェクト: LorenVS/bacstack
 public Tag(ApplicationTag applicationTag)
     : this()
 {
     this.ContextTag = 255;
     this.ApplicationTag = applicationTag;
 }
コード例 #17
0
ファイル: TagReader.cs プロジェクト: LorenVS/bacstack
        /// <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();
        }