示例#1
0
        void Save_Click(object sender, EventArgs e)
        {
            Asset asst = null;

            using (WindchimeEntities wce = new WindchimeEntities())
            {
                if (id != null)
                {
                    asst = (from Asset a in wce.PermissionableEntities.OfType <Asset>()
                            where a.EntityID == id
                            select a).FirstOrDefault();
                }

                if (asst == null)
                {
                    asst = new Asset();
                    wce.AddToPermissionableEntities(asst);
                }

                asst.Headline = Name_box.Text;

                TextVersion tv = new TextVersion();
                tv.Text        = Content_box.Text;
                tv.CreatedDate = DateTime.Now;

                asst.Versions.Add(tv);
                wce.AddToVersionSet(tv);

                wce.SaveChanges();
                wce.Refresh(System.Data.Objects.RefreshMode.StoreWins, asst);
                id = asst.EntityID;
            }
        }
示例#2
0
        public void Setup()
        {
            _textModule = TextModuleFactory.Get();

            _command = new AddVersion
            {
                SiteId               = Guid.NewGuid(),
                ModuleId             = _textModule.ModuleId,
                Id                   = _textModule.Id,
                VersionId            = Guid.NewGuid(),
                Content              = "Content",
                Description          = "Description",
                Status               = TextVersionStatus.Published,
                VersionLocalisations = new List <AddVersion.VersionLocalisation>()
                {
                    new AddVersion.VersionLocalisation
                    {
                        LanguageId = Guid.NewGuid(),
                        Content    = "Localised content"
                    }
                }
            };

            _validatorMock = new Mock <IValidator <AddVersion> >();
            _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());

            _textModule.AddVersion(_command, _validatorMock.Object);

            _newVersion = _textModule.TextVersions.FirstOrDefault(x => x.Id == _command.VersionId);

            _event = _textModule.Events.OfType <VersionAdded>().SingleOrDefault();
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                //                this.ViewState
                return;
            }

            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                id = int.Parse(Request.QueryString["ID"]);

                using (WindchimeEntities wce = new WindchimeEntities())
                {
                    Asset asst = (from Asset a in wce.PermissionableEntities.OfType <Asset>()
                                  where a.EntityID == id
                                  select a).FirstOrDefault();
                    if (asst == null)
                    {
                        throw new ArgumentException("Invalid ID specified as parameter.");
                    }

                    Name_box.Text = asst.Headline;

                    TextVersion version = (from TextVersion tv in asst.Versions
                                           orderby tv.CreatedDate descending
                                           select tv).FirstOrDefault();
                    if (version != null)
                    {
                        Content_box.Text = version.Text;
                    }
                }
            }
        }
        public StringTextSnapshot(string content, int versionNumber)
        {
            Content = content;
            _lines  = new List <ITextSnapshotLine>();

            var start          = 0;
            var delimiterIndex = 0;

            while (delimiterIndex != -1)
            {
                var delimiterLength = 2;
                delimiterIndex = Content.IndexOf("\r\n", start);

                if (delimiterIndex == -1)
                {
                    delimiterLength = 1;
                    delimiterIndex  = Content.IndexOfAny(ParserHelpers.NewLineCharacters, start);
                }

                var nextLineStartIndex = delimiterIndex != -1 ? delimiterIndex + delimiterLength : Content.Length;

                var lineText = Content.Substring(start, nextLineStartIndex - start);
                _lines.Add(new SnapshotLine(lineText, start, this));

                start = nextLineStartIndex;

                Version = new TextVersion(versionNumber);
            }
        }
示例#5
0
        public TextVersion getTextVersion(Asset a)
        {
            TextVersion t = (from TextVersion txt in a.Versions
                             where txt.Assets.EntityID == a.EntityID
                             select txt).FirstOrDefault <TextVersion>();

            return(t);
        }
示例#6
0
            private void ValidatePrefixBindingCache(SnapshotSpan prefixLocationSpan)
            {
                if (this.lastCachedVersion != null && this.lastCachedVersion.Equals((object)prefixLocationSpan.Snapshot.Version))
                {
                    return;
                }
                this.cachedPrefixBindings.Clear();
                this.cachedDefaultNamespaceUri = (string)null;
                ITextSnapshot snapshot       = prefixLocationSpan.Snapshot;
                SnapshotSpan  spanToTokenize = this.GetSpanToTokenize(new SnapshotPoint(snapshot, 0));

                foreach (ClassificationPosition classificationPosition in this.ScanForward(new ClassificationPosition()
                {
                    CurrentLine = spanToTokenize,
                    CurrentSpanList = this.GetClassificationSpans(spanToTokenize),
                    CurrentSpanIndex = 0
                }))
                {
                    ClassificationSpan         currentSpan     = classificationPosition.CurrentSpan;
                    IList <ClassificationSpan> currentSpanList = classificationPosition.CurrentSpanList;
                    int currentSpanIndex = classificationPosition.CurrentSpanIndex;
                    if (currentSpan.ClassificationType != XamlAnalyzer.ClassEndTag)
                    {
                        if (currentSpan.ClassificationType == XamlAnalyzer.ClassAttrNameIdentifier && currentSpan.Span.GetText() == "xmlns")
                        {
                            XamlNameDecomposition nameDecomposition = new XamlNameDecomposition(currentSpanList, currentSpanIndex);
                            if (nameDecomposition.PrefixText == "xmlns" && (!nameDecomposition.NameSpan.IsEmpty && currentSpanList.Count > currentSpanIndex + 4 && currentSpanList[currentSpanIndex + 4].ClassificationType == XamlAnalyzer.ClassAttrValue))
                            {
                                string text = currentSpanList[currentSpanIndex + 4].Span.GetText();
                                this.cachedPrefixBindings[nameDecomposition.NameText] = text.Substring(1, text.Length - 2);
                            }
                            else if (nameDecomposition.PrefixSpan.IsEmpty && nameDecomposition.NameText == "xmlns" && (currentSpanList.Count > currentSpanIndex + 2 && currentSpanList[currentSpanIndex + 2].ClassificationType == XamlAnalyzer.ClassAttrValue))
                            {
                                string text = currentSpanList[currentSpanIndex + 2].Span.GetText();
                                this.cachedDefaultNamespaceUri = text.Substring(1, text.Length - 2);
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                this.lastCachedVersion = snapshot.Version;
            }
        public StringTextSnapshot(string content, int versionNumber)
        {
            Content = content;
            _lines  = new List <ITextSnapshotLine>();

            var start          = 0;
            var delimiterIndex = 0;

            while (delimiterIndex != -1)
            {
                var delimiterLength = 2;
                delimiterIndex = Content.IndexOf("\r\n", start, StringComparison.Ordinal);

                if (delimiterIndex == -1)
                {
                    delimiterLength = 1;
                    for (var i = start; i < Content.Length; i++)
                    {
                        if (ParserHelpers.IsNewLine(content[i]))
                        {
                            delimiterIndex = i;
                            break;
                        }
                    }
                }

                var nextLineStartIndex = delimiterIndex != -1 ? delimiterIndex + delimiterLength : Content.Length;

                var lineText = Content.Substring(start, nextLineStartIndex - start);
                _lines.Add(new SnapshotLine(lineText, start, this));

                start = nextLineStartIndex;

                Version = new TextVersion(versionNumber);
            }
        }
 /// <summary>
 /// Create a new TextVersion object.
 /// </summary>
 /// <param name="versionID">Initial value of VersionID.</param>
 /// <param name="createdDate">Initial value of CreatedDate.</param>
 /// <param name="log">Initial value of Log.</param>
 /// <param name="text">Initial value of Text.</param>
 public static TextVersion CreateTextVersion(int versionID, global::System.DateTime createdDate, string log, string text)
 {
     TextVersion textVersion = new TextVersion();
     textVersion.VersionID = versionID;
     textVersion.CreatedDate = createdDate;
     textVersion.Log = log;
     textVersion.Text = text;
     return textVersion;
 }
示例#9
0
        protected void LoadTestDataButton_Click(object sender, EventArgs e)
        {
            WindchimeEntities wce = new WindchimeEntities();

            Creator c = new Creator();

            c.FirstName = "EIC";
            c.LastName  = "EIC";
            User u1 = SecurityManager.CreateUser(c, "EIC", "windchime*", true, true);

            c.FirstName = "Regular";
            c.LastName  = "Staff";
            User u2 = SecurityManager.CreateUser(c, "Staff1", "windchime*", true, true);

            c.FirstName = "Regular";
            c.LastName  = "User";
            User u3 = SecurityManager.CreateUser(c, "Regular1", "windchime*", false, true);

            Group g = new Group();

            g.Name      = "Staff";
            g.IsSpecial = false;
            wce.Attach(u1);
            wce.Attach(u2);
            u1.Groups.Load();
            u2.Groups.Load();
            g.Children.Add(u1.Groups.First());
            g.Children.Add(u2.Groups.First());
            wce.AddToGroups(g);

            Asset       a1 = new Asset(), a2 = new Asset(), a3 = new Asset(), a4 = new Asset();
            AssetType   at1 = new AssetType();
            TextVersion tv1 = new TextVersion(), tv2 = new TextVersion(), tv3 = new TextVersion(), tv4 = new TextVersion(), tv5 = new TextVersion();

            at1.Name         = "Text";
            a1.Approved      = true;
            a2.Approved      = false;
            a3.Approved      = false;
            a4.Approved      = true;
            a1.CompletedDate = DateTime.Now;
            a2.CompletedDate = DateTime.Now;
            a3.CompletedDate = DateTime.Now;
            a4.CompletedDate = DateTime.Now;
            a1.Creator       = u1;
            a2.Creator       = u1;
            a3.Creator       = u2;
            a4.Creator       = u2;
            a1.Headline      = "Asset1!";
            a2.Headline      = "Asset2!";
            a3.Headline      = "Asset3!";
            a4.Headline      = "Asset4!";
            a1.Summary       = "An asset";
            a2.Summary       = "An asset";
            a3.Summary       = "An asset";
            a4.Summary       = "An asset";
            a1.AssetType     = at1;
            a2.AssetType     = at1;
            a3.AssetType     = at1;
            a4.AssetType     = at1;

            tv1.Text        = "Asset1 v1";
            tv1.CreatedDate = DateTime.Now;
            tv1.Log         = "";
            tv2.Text        = "Asset1 v2";
            tv2.CreatedDate = DateTime.Now;
            tv2.Log         = "";
            tv3.Text        = "Asset2 v1";
            tv3.CreatedDate = DateTime.Now;
            tv3.Log         = "";
            tv4.Text        = "Asset3 v1";
            tv4.CreatedDate = DateTime.Now;
            tv4.Log         = "";
            tv5.Text        = "Asset4 v1";
            tv5.CreatedDate = DateTime.Now;
            tv5.Log         = "";

            a1.Versions.Add(tv1);
            a1.Versions.Add(tv2);
            a2.Versions.Add(tv3);
            a3.Versions.Add(tv4);
            a4.Versions.Add(tv5);

            wce.AddToPermissionableEntities(a1);
            wce.AddToPermissionableEntities(a2);
            wce.AddToPermissionableEntities(a3);
            wce.AddToPermissionableEntities(a4);
            wce.AddToVersionSet(tv1);
            wce.AddToVersionSet(tv2);
            wce.AddToVersionSet(tv3);
            wce.AddToVersionSet(tv4);
            wce.AddToVersionSet(tv5);

            Collection col1 = new Collection(), col2 = new Collection(), col3 = new Collection(), col4 = new Collection();

            col1.Name = "Text stuff1";
            col1.Assets.Add(a1);
            col2.Name = "Text stuff2";
            col2.Assets.Add(a2);
            col3.Name = "Text stuff3";
            col3.Assets.Add(a3);
            col4.Name = "Text stuff4";
            col4.Assets.Add(a4);

            col1.Children.Add(col2);
            col1.Children.Add(col3);
            col4.Children.Add(col3);

            wce.SaveChanges();


            g = (from Group gr in wce.Groups where gr.IsSpecial && gr.Name.CompareTo("EIC") == 0 select gr).First();
            g.PolicyEntries.Load();
            foreach (Policy p in Enum.GetValues(typeof(Policy)))
            {
                PolicyEntry pe = new PolicyEntry();
                pe.Policy  = p;
                pe.GroupID = g.GroupID;
                g.PolicyEntries.Add(pe);
                wce.SaveChanges();
            }

            LoadTestDataButton.Enabled = false;
        }
示例#10
0
        public void listAssets()
        {
            int count = 0;

            foreach (Assignment asgn in publishableAssignments)
            {
                asgn.Assets.Load();
                List <Asset> a = asgn.Assets.ToList <Asset>();
                foreach (Asset asset in a)
                {
                    Label Headline_lbl = new Label();
                    Headline_lbl.Text = asset.Headline + "<br />";
                    getPlaceHolder(count).Controls.Add(Headline_lbl);
                    Label Summary_lbl = new Label();
                    Summary_lbl.Text = asset.Summary + "<br />";
                    // if asset type is 1 - photo, create an image control
                    if (Convert.ToInt32(asset.AssetTypeReference.EntityKey.EntityKeyValues[0].Value) == 1)
                    {
                        BinaryVersion thisPhoto = getBinaryVersion(asset);
                        if (thisPhoto != null)
                        {
                            Image Photo_img = new Image();
                            Photo_img.ImageUrl = thisPhoto.Path;
                            getPlaceHolder(count).Controls.Add(Photo_img);
                            Label Space_lbl = new Label();
                            Space_lbl.Text = "<br />";
                            getPlaceHolder(count).Controls.Add(Space_lbl);
                        }
                        else
                        {
                            addMissingLabel("Photo", count);
                        }
                    }
                    // if asset type is 2 - article, create a label control
                    else if (Convert.ToInt32(asset.AssetTypeReference.EntityKey.EntityKeyValues[0].Value) == 2)
                    {
                        TextVersion thisArticle = getTextVersion(asset);
                        if (thisArticle != null)
                        {
                            Label Article_lbl = new Label();
                            Article_lbl.Text = thisArticle.Text + "<br />";
                            getPlaceHolder(count).Controls.Add(Article_lbl);
                        }
                        else
                        {
                            addMissingLabel("Article", count);
                        }
                    }
                    else
                    {
                        BinaryVersion thisAd = getBinaryVersion(asset);
                        if (thisAd != null)
                        {
                            Image Photo_img = new Image();
                            Photo_img.ImageUrl = thisAd.Path;
                            AssetPrinter_placeholder_ads.Controls.Add(Photo_img);
                            Label Space_lbl = new Label();
                            Space_lbl.Text = "<br />";
                            AssetPrinter_placeholder_ads.Controls.Add(Space_lbl);
                        }
                        else
                        {
                            addMissingLabel("Unable to display ads. Advertisement", count);
                        }
                    }
                }
                count++;
            }
        }