public Resource(JObject json)
        {
            Annotations = new Dictionary <string, string>();
            RawJson     = json;
            FullId      = json.SelectToken("id").ToString();

            // Parse FullID into Account, Kind and Id
            string[] parts = FullId.Split(":", 3);
            Account = parts[0];
            // Convert kind string into enum
            Kind = (ResourceKind)Enum.Parse(typeof(ResourceKind), parts[1]);
            Id   = parts[2];

            // Parse Annotations into Dictionary
            JArray annotations = RawJson.SelectToken("annotations").ToObject <JArray>();

            foreach (JObject a in annotations)
            {
                IList <string> keys = a.Properties().Select(p => p.Name).ToList();
                foreach (string key in keys)
                {
                    string value = a.GetValue(key).ToString();
                    Annotations.Add(key, value);
                }
            }
        }
Example #2
0
        private void BindValues()
        {
            string[] parts = FullId.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);

            string path = "Navigation/Tabs";

            if (parts.Length > 0)
            {
                path += String.Format(CultureInfo.InvariantCulture, "/Tab[@id='{0}']", parts[0]);
            }

            for (int i = 1; i < parts.Length; i++)
            {
                path += String.Format(CultureInfo.InvariantCulture, "/Link[@id='{0}']", parts[i]);
            }

            string profileString   = ProfileId.HasValue ? ProfileId.Value.ToString() : String.Empty;
            string principalString = PrincipalId.HasValue ? PrincipalId.Value.ToString() : String.Empty;

            if (PrincipalId.HasValue)
            {
                profileString = ProfileManager.GetProfileIdByUser(PrincipalId.Value).ToString();
            }

            Mediachase.Ibn.XmlTools.Selector selector = new Mediachase.Ibn.XmlTools.Selector(string.Empty, string.Empty, string.Empty, profileString, principalString);
            IXPathNavigable navigable = Mediachase.Ibn.XmlTools.XmlBuilder.GetCustomizationXml(null, Mediachase.Ibn.XmlTools.StructureType.Navigation, selector);
            XPathNavigator  node      = navigable.CreateNavigator().SelectSingleNode(path);

            if (node != null)
            {
                ctrlTitleText.Text = node.GetAttribute("text", string.Empty);

                ItemOrder.Text = node.GetAttribute("order", string.Empty);

                SavedText  = ctrlTitleText.Text;
                SavedOrder = int.Parse(ItemOrder.Text);
            }
        }
Example #3
0
        /// <summary>
        ///     Creates an update for this paragraph in the provided dictionary.
        /// </summary>
        /// <param name="dictionary">The dictionary to put the updated paragraph in</param>
        /// <returns>The updated paragraph</returns>
        public Paragraph CreateParagraphUpdate(Dictionary dictionary)
        {
            Paragraph retVal = (Paragraph)acceptor.getFactory().createParagraph();

            retVal.FullId = FullId;
            retVal.Text   = Text;
            retVal.setUpdates(Guid);

            Specification specUpdate = FindEnclosingSpecification().FindOrCreateSpecificationUpdate(dictionary);

            // If the enclosing is a paragraph, find or create the enclosing paragraph update
            // If it is a chapter, find or create the chapter update
            if (EnclosingParagraph != null)
            {
                string    parentId = FullId.Substring(0, FullId.LastIndexOf('.'));
                Paragraph parent   = specUpdate.FindParagraphByNumber(parentId);
                if (parent == null)
                {
                    parent = EnclosingParagraph.CreateParagraphUpdate(dictionary);
                }
                parent.appendParagraphs(retVal);
                parent.SubParagraphs.Sort();
            }
            else if (EnclosingChapter != null)
            {
                Chapter parent = EnclosingChapter.FindChapterUpdate(dictionary);
                if (parent == null)
                {
                    parent = EnclosingChapter.CreateChapterUpdate(specUpdate);
                }
                parent.appendParagraphs(retVal);
                parent.Paragraphs.Sort();
            }

            UpdatedBy.Add(retVal);

            return(retVal);
        }
Example #4
0
        /// <summary>
        /// This procedure generates XML elements for all the fields of the class,
        /// and also can provide some extra elements, which are calculated automatically.
        /// </summary>
        internal virtual void AddAttributes(XElement controlElement)
        {
            controlElement.Add(new XAttribute("Id", FullId));

            if (this is IInitializable)
            {
                controlElement.Add(new XAttribute("Command", FullId + "Command"));
                controlElement.Add(new XAttribute("QueryCommand", FullId + "QueryCommand"));
            }

            if (FullId.EndsWith("Menu.MainSection." + this.Id))
            {
                controlElement.Add(
                    new XAttribute("MenuItemId", FullId),
                    new XAttribute("CommandValueId", FullId + "Command")
                    );
            }
            else
            {
                if (this.TemplateAlias != null)
                {
                    controlElement.Add(new XAttribute("TemplateAlias", this.TemplateAlias));
                }
                else
                if (this.ParentGroup == null)
                {
                    throw new ValidationException(
                              String.Format("Control {0}{1}: you need to set TemplateAlias property manually for detached from group control.",
                                            this.GetType().Name,
                                            this.Id != null ? " (Id='" + this.Id + "')" : String.Empty)
                              );
                }
                else
                {
                    controlElement.Add(new XAttribute("TemplateAlias", this.ParentGroup.Template.SectionIds.First()));
                }
            }
        }