SenseNet.ContentRepository.FeedContent.WriteActions C# (CSharp) Method

WriteActions() protected method

protected WriteActions ( XmlWriter writer, string path, IEnumerable actions ) : void
writer System.Xml.XmlWriter
path string
actions IEnumerable
return void
        protected void WriteActions(XmlWriter writer, string path, IEnumerable<ActionBase> actions)
        {
            if (actions == null)
                return;
            if (actions.Count() == 0)
                return;

            writer.WriteStartElement("Actions");
            foreach (var action in actions)
            {
                try
                {
                    if (action.Active)
                    {
                        //if the name does not follow the standard xml element name rules, we must log this and skip it
                        if (!Regex.IsMatch(action.Name, XML_ELEMENTNAME_REGEX))
                        {
                            Logger.WriteWarning("Content actions serialization error: invalid xml element. Path: "+ path + ". Action name: " + action.Name);
                            continue;
                        }

                        if (action.IncludeBackUrl)
                        {
                            writer.WriteElementString(action.Name, action.Uri);
                        }
                        else
                        {
                            var actionUrl = action.Uri;
                            var urlSeparator = (actionUrl != null && actionUrl.Contains("?")) ? "&" : "?";
                            var back = string.Format("{0}{1}={2}", urlSeparator, ActionBase.BackUrlParameterName, action.BackUri);

                            writer.WriteStartElement(action.Name);
                            writer.WriteAttributeString(ActionBase.BackUrlParameterName, back);
                            writer.WriteString(actionUrl);
                            writer.WriteEndElement();
                        }
                    }
                }
                catch (Exception ex)
                {
                    //log exception, but continue writing actions
                    Logger.WriteException(ex);

                    //no point in continuing the process if the writer is closed
                    if (writer.WriteState == WriteState.Error || writer.WriteState == WriteState.Closed)
                        break;
                }
            }

            writer.WriteEndElement();
        }
    }