//////////////////////////////////////////////////////////////////////
        /// <summary>Parses an xml node to create a Package object.</summary>
        /// <param name="node">Package node</param>
        /// <param name="parser">AtomFeedParser to use</param>
        /// <returns>the created Package object</returns>
        //////////////////////////////////////////////////////////////////////
        public static Package ParsePackage(XmlNode node, AtomFeedParser parser)
        {
            Tracing.TraceCall();
            Package package = null;

            Tracing.Assert(node != null, "node should not be null");
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            object localname = node.LocalName;

            // Ensure that the namespace is correct.
            if (String.Compare(node.NamespaceURI,
                               GCodeSearchParserNameTable.CSNamespace, true) == 0)
            {
                if (localname.Equals(GCodeSearchParserNameTable.EVENT_PACKAGE))
                {
                    package = new Package();
                    if (node.Attributes != null)
                    {
                        package.name =
                            node.Attributes[
                                GCodeSearchParserNameTable.ATTRIBUTE_NAME].Value;
                        package.uri =
                            node.Attributes[
                                GCodeSearchParserNameTable.ATTRIBUTE_URI].Value;
                    }
                    else
                    {
                        throw new ArgumentNullException(
                                  BaseNameTable.gBatchNamespace +
                                  ":" + GCodeSearchParserNameTable.EVENT_PACKAGE +
                                  " must contain the attributes " +
                                  GCodeSearchParserNameTable.ATTRIBUTE_NAME + " and " +
                                  GCodeSearchParserNameTable.ATTRIBUTE_URI);
                    }
                }
            }
            return(package);
        }
Esempio n. 2
0
        //////////////////////////////////////////////////////////////////////
        /// <summary>Event chaining. We catch this from the AtomFeedParser
        /// we want to set this to our property, and do not add the entry to the collection
        /// </summary>
        /// <param name="sender"> the object which send the event</param>
        /// <param name="e">FeedParserEventArguments, holds the feed entry</param>
        /// <returns> </returns>
        //////////////////////////////////////////////////////////////////////
        internal void OnParsedNewEntry(object sender, FeedParserEventArgs e)
        {
            // by default, if our event chain is not hooked, add it to the collection
            Tracing.TraceCall("received new item notification");
            Tracing.Assert(e != null, "e should not be null");
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            if (!e.CreatingEntry)
            {
                if (e.Entry != null)
                {
                    // add it to the collection
                    Tracing.TraceMsg("\t new EventEntry found");
                    this.Entry     = e.Entry;
                    e.DiscardEntry = true;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Persistence method for the FileName object
 /// </summary>
 /// <param name="writer">the xmlwriter to write into</param>
 public void Save(XmlWriter writer)
 {
     Tracing.Assert(writer != null, "writer should not be null");
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     if (Utilities.IsPersistable(filename))
     {
         writer.WriteStartElement(XmlPrefix,
                                  XmlName, XmlNameSpace);
         writer.WriteAttributeString(GCodeSearchParserNameTable.ATTRIBUTE_NAME,
                                     filename);
         writer.WriteEndElement();
     }
     else
     {
         throw new ArgumentNullException("Attribute " +
                                         GCodeSearchParserNameTable.ATTRIBUTE_NAME + " is required.");
     }
 }
        //////////////////////////////////////////////////////////////////////
        /// <summary>Parses an xml node to create a Match object.</summary>
        /// <param name="node">Match node</param>
        /// <param name="parser">AtomFeedParser to use</param>
        /// <returns>the created Match object</returns>
        //////////////////////////////////////////////////////////////////////
        public static Match ParseMatch(XmlNode node, AtomFeedParser parser)
        {
            Tracing.TraceCall();
            Match match = null;

            Tracing.Assert(node != null, "node should not be null");
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            object localname = node.LocalName;

            // Ensure that the namespace is correct.
            if (String.Compare(node.NamespaceURI,
                               GCodeSearchParserNameTable.CSNamespace, true) == 0)
            {
                if (localname.Equals(GCodeSearchParserNameTable.EVENT_MATCH))
                {
                    match = new Match();
                    if (node.Attributes != null)
                    {
                        match.linenumber =
                            node.Attributes[
                                GCodeSearchParserNameTable.ATTRIBUTE_LINE_NUMBER].Value;
                    }
                    match.linetext = node.InnerText;
                }
                else
                {
                    throw new ArgumentNullException(
                              BaseNameTable.gBatchNamespace +
                              ":" + GCodeSearchParserNameTable.EVENT_MATCH +
                              " must contain the attribute " +
                              GCodeSearchParserNameTable.ATTRIBUTE_LINE_NUMBER);
                }
            }
            return(match);
        }
Esempio n. 5
0
        /////////////////////////////////////////////////////////////////////////////


        #region FeedLink Parser
        //////////////////////////////////////////////////////////////////////
        /// <summary>Parses an xml node to create an FeedLink object.</summary>
        /// <param name="node">feedLink node</param>
        /// <returns> the created FeedLink object</returns>
        //////////////////////////////////////////////////////////////////////
        public static FeedLink ParseFeedLink(XmlNode node)
        {
            Tracing.TraceCall();
            FeedLink link = null;

            Tracing.Assert(node != null, "node should not be null");
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            object localname = node.LocalName;

            if (localname.Equals(GDataParserNameTable.XmlFeedLinkElement))
            {
                link = new FeedLink();
                if (node.Attributes != null)
                {
                    if (node.Attributes[GDataParserNameTable.XmlAttributeHref] != null)
                    {
                        link.Href = node.Attributes[GDataParserNameTable.XmlAttributeHref].Value;
                    }

                    if (node.Attributes[GDataParserNameTable.XmlAttributeReadOnly] != null)
                    {
                        link.ReadOnly = node.Attributes[GDataParserNameTable.XmlAttributeReadOnly].Value.Equals(Utilities.XSDTrue);
                    }
                    if (node.Attributes[GDataParserNameTable.XmlAttributeRel] != null)
                    {
                        link.Rel = node.Attributes[GDataParserNameTable.XmlAttributeRel].Value;
                    }
                    if (node.Attributes[GDataParserNameTable.XmlAttributeCountHint] != null)
                    {
                        try
                        {
                            link.CountHint = Int32.Parse(node.Attributes[GDataParserNameTable.XmlAttributeCountHint].Value);
                        }
                        catch (FormatException fe)
                        {
                            throw new ArgumentException("Invalid g:feedLink/@countHint.", fe);
                        }
                    }
                }

                if (node.HasChildNodes)
                {
                    XmlNode feedChild = node.FirstChild;
                    while (feedChild != null && feedChild is XmlElement)
                    {
                        if (feedChild.LocalName == AtomParserNameTable.XmlFeedElement &&
                            feedChild.NamespaceURI == BaseNameTable.NSAtom)
                        {
                            if (link.Feed == null)
                            {
                                link.Feed = new AtomFeed(null, new Service());
                                Stream feedStream =
                                    new MemoryStream(ASCIIEncoding.Default.GetBytes(feedChild.OuterXml));

                                link.Feed.Parse(feedStream, AlternativeFormat.Atom);
                            }
                            else
                            {
                                throw new ArgumentException("Only one feed is allowed inside the g:feedLink");
                            }
                        }
                        feedChild = feedChild.NextSibling;
                    }
                }
            }

            return(link);
        }
Esempio n. 6
0
        public void DrawConnection(PointF pointA, PointF pointB, GH_WireDirection directionA, GH_WireDirection directionB, bool selectedA, bool selectedB, GH_WireType type, Color colorinput, GH_Canvas canvas, Graphics graphics)
        {
            if (ConnectionVisible(pointA, pointB, canvas))
            {
                Color color = colorinput;
                if (selectedA || selectedB)
                {
                    color.SolidenColor(Owner.SelectWireSolid);
                }

                GraphicsPath graphicsPath = new GraphicsPath();
                switch (Owner.WireType)
                {
                case 0:
                    graphicsPath = GH_Painter.ConnectionPath(pointA, pointB, directionA, directionB);
                    break;

                case 1:
                    float moveMent = (pointA.X - pointB.X) * (float)Owner.PolywireParam;
                    moveMent = Math.Max(moveMent, 20);
                    PointF C = new PointF(pointA.X - moveMent, pointA.Y);
                    PointF D = new PointF(pointB.X + moveMent, pointB.Y);
                    graphicsPath.AddLine(pointA, C);
                    graphicsPath.AddLine(C, D);
                    graphicsPath.AddLine(D, pointB);
                    graphicsPath.Reverse();
                    break;

                case 2:
                    graphicsPath.AddLine(pointA, pointB);
                    graphicsPath.Reverse();
                    break;

                default:
                    graphicsPath = GH_Painter.ConnectionPath(pointA, pointB, directionA, directionB);
                    break;
                }

                if (graphicsPath == null)
                {
                    graphicsPath = new GraphicsPath();
                    graphicsPath.AddLine(pointA, pointB);
                }

                Pen pen = GenerateWirePen(pointA, pointB, selectedA, selectedB, type, color, canvas);

                if (selectedA || selectedB)
                {
                    pen.Width += (float)Owner.SelectWireThickness;
                }

                if (pen == null)
                {
                    pen = new Pen(Color.Black);
                }
                try
                {
                    graphics.DrawPath(pen, graphicsPath);
                }
                catch (Exception ex)
                {
                    ProjectData.SetProjectError(ex);
                    Exception ex2 = ex;
                    Tracing.Assert(new Guid("{72303320-11AD-484e-BE32-8BDAA7377BE0}"), "Connection could not be drawn:" + Environment.NewLine + ex2.Message + Environment.NewLine + Environment.NewLine + $"A: ({pointA.X}, {pointA.Y})" + Environment.NewLine + $"B: ({pointB.X}, {pointB.Y})" + Environment.NewLine + $"A_Dir: {directionA}" + Environment.NewLine + $"B_Dir: {directionB}" + Environment.NewLine + $"A_Selected: {selectedA}" + Environment.NewLine + $"B_Selected: {selectedB}" + Environment.NewLine + $"Type: {type}");
                    ProjectData.ClearProjectError();
                }
                graphicsPath.Dispose();
                pen.Dispose();
            }
        }
Esempio n. 7
0
        /////////////////////////////////////////////////////////////////////////////


        #region EntryLink Parser
        //////////////////////////////////////////////////////////////////////
        /// <summary>parses an xml node to create an EntryLink object</summary>
        /// <param name="node">entrylink node</param>
        /// <param name="parser">AtomFeedParser to use</param>
        /// <returns> the created EntryLink object</returns>
        //////////////////////////////////////////////////////////////////////
        public static EntryLink ParseEntryLink(XmlNode node, AtomFeedParser parser)
        {
            Tracing.TraceCall();
            EntryLink link = null;

            Tracing.Assert(node != null, "node should not be null");
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }


            object localname = node.LocalName;

            if (localname.Equals(GDataParserNameTable.XmlEntryLinkElement))
            {
                link = new EntryLink();
                if (node.Attributes != null)
                {
                    if (node.Attributes[GDataParserNameTable.XmlAttributeHref] != null)
                    {
                        link.Href = node.Attributes[GDataParserNameTable.XmlAttributeHref].Value;
                    }

                    if (node.Attributes[GDataParserNameTable.XmlAttributeReadOnly] != null)
                    {
                        link.ReadOnly = node.Attributes[GDataParserNameTable.XmlAttributeReadOnly].Value.Equals(Utilities.XSDTrue);
                    }

                    if (node.Attributes[GDataParserNameTable.XmlAttributeRel] != null)
                    {
                        link.Rel = node.Attributes[GDataParserNameTable.XmlAttributeRel].Value;
                    }
                }

                if (node.HasChildNodes)
                {
                    XmlNode entryChild = node.FirstChild;

                    while (entryChild != null && entryChild is XmlElement)
                    {
                        if (entryChild.LocalName == AtomParserNameTable.XmlAtomEntryElement &&
                            entryChild.NamespaceURI == BaseNameTable.NSAtom)
                        {
                            if (link.Entry == null)
                            {
                                XmlReader reader = new XmlNodeReader(entryChild);
                                // move the reader to the first node
                                reader.Read();
                                AtomFeedParser p = new AtomFeedParser();
                                p.NewAtomEntry += new FeedParserEventHandler(link.OnParsedNewEntry);
                                p.ParseEntry(reader);
                            }
                            else
                            {
                                throw new ArgumentException("Only one entry is allowed inside the g:entryLink");
                            }
                        }
                        entryChild = entryChild.NextSibling;
                    }
                }
            }

            return(link);
        }