void DisplayTopic(TopicInformation topic, Dictionary <string, TreeNode> nodes)
        {
            System.Diagnostics.Debug.WriteLine("Add " + topic.TopicString);

            TreeNode parentNode = null;

            if (!string.IsNullOrEmpty(topic.ParentTopicString) && nodes.ContainsKey(topic.ParentTopicString))
            {
                parentNode = nodes[topic.ParentTopicString];
            }

            string displayName = string.Empty;

            string[] topicSegments = topic.TopicString.Split('/');
            displayName = topicSegments[topicSegments.Length - 1];

            TreeNode node = new TreeNode(displayName);

            node.Tag = topic;

            node.ImageKey         = topic.IsTopic ? (topic.IsProperty ? "PropertyEvent" : "Topic"): "TopicsNamespace";
            node.SelectedImageKey = node.ImageKey;

            if (parentNode == null)
            {
                tvTopics.Nodes.Add(node);
            }
            else
            {
                parentNode.Nodes.Add(node);
            }
            nodes.Add(topic.TopicString, node);
        }
示例#2
0
        public void DeleteData_ValidOrInvalidData_Successful()
        {
            const string Message = "Data doesnt exsist in the topicinformation db.";
            //Arrange
            ManageData       manageDataTest   = new ManageData();
            TopicInformation topicinformation = new TopicInformation
            {
                WeekNumber    = 13,
                LastUpdatedBy = "*****@*****.**",
                Topic         = "Revision"
            };
            //Act
            bool isDataDeleted = manageDataTest.DeleData(topicinformation);

            //Assert
            try
            {
                //Returns true if the data passed as parameter to DeteData( data ) function exsists in the database
                Assert.IsTrue(isDataDeleted, "Data exsists to be editted.");
            }
            catch
            {
                ////Returns false if the data passed as parameter to DeteData( data ) function exsist in the database
                Assert.IsFalse(isDataDeleted, Message);
            }
        }
示例#3
0
        public string RenderToHtml(TopicInformation topic, string imageRootUrl = "", ISettingsProvider settings = null)
        {
            var sb = new StringBuilder();

            sb.Append($"<h1>{topic.OriginalName}</h1>");
            sb.Append($"<p><img src=\"{topic.OriginalContent}\" /></p>");
            return(sb.ToString());
        }
示例#4
0
 public string RenderToHtml(TopicInformation topic, string imageRootUrl = "", ISettingsProvider settings = null)
 {
     if (string.IsNullOrEmpty(topic.OriginalContent))
     {
         return(string.Empty);
     }
     return(MarkdownToHtml(topic, imageRootUrl, settings));
 }
    //Published to the broker on a specified topic
    public void Publish(TopicInformation topic, string msg)
    {
        string topicString = $"{TargetTeamID}/{topic.laneType}/{topic.groupID}/{topic.componentType}/{topic.componentID}".ToLower();

        client.Publish(
            topicString, Encoding.UTF8.GetBytes(msg),
            qoSLevel, false);
        Debug.Log($"Published message on topic '{topicString}': '{msg}'");
    }
 private void copyTopicStringToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (tvTopics.SelectedNode != null)
     {
         TopicInformation topic = tvTopics.SelectedNode.Tag as TopicInformation;
         if (topic != null)
         {
             string topicString = topic.TopicString;
             Clipboard.SetDataObject(topicString);
         }
     }
 }
        public string RenderToHtml(TopicInformation topic, string imageRootUrl = "", ISettingsProvider settings = null)
        {
            // TODO: Patch up the root URL of images that have a relative path
            var html = topic.OriginalContent;

            if (string.IsNullOrEmpty(html))
            {
                return(string.Empty);
            }

            return(topic.OriginalContent);
        }
        // GET: DataTable/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TopicInformation topicInformation = manageData.FindDataRowById((int)id);

            if (topicInformation == null)
            {
                return(HttpNotFound());
            }
            return(View(topicInformation));
        }
        private void cmsTopics_Opening(object sender, CancelEventArgs e)
        {
            bool showMenu = false;

            if (tvTopics.SelectedNode != null)
            {
                TopicInformation topic = tvTopics.SelectedNode.Tag as TopicInformation;
                if (topic != null)
                {
                    showMenu = true;
                }
            }
            e.Cancel = !showMenu;
        }
示例#10
0
        public ActionResult DeleteConfirmed(int id)
        {
            TopicInformation topicInformation = manageData.FindDataRowById((int)id);
            bool             dataDelete       = manageData.DeleData(topicInformation);

            if (dataDelete)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.Error = "Rule Cannot be deleted !";
                return(View(topicInformation));
            }
        }
示例#11
0
        private void copyNamespacesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tvTopics.SelectedNode != null)
            {
                TopicInformation topic = tvTopics.SelectedNode.Tag as TopicInformation;
                if (topic != null)
                {
                    string namespaces = string.Empty;
                    foreach (NamespaceDescription descr in topic.Namespaces)
                    {
                        namespaces += string.Format("{0}=\"{1}\"", descr.Prefix, descr.Namespace);
                    }

                    Clipboard.SetDataObject(namespaces);
                }
            }
        }
示例#12
0
        public string GetTemplateName(TopicInformation topic, string suggestedTemplateName, ISettingsProvider settings = null)
        {
            if (TopicTypeHelper.IsMatch(topic.Type, TopicBodyFormats.VstsWorkItem))
            {
                return("Vsts/WorkItem");
            }
            if (TopicTypeHelper.IsMatch(topic.Type, TopicBodyFormats.VstsWorkItemQuery))
            {
                return("Vsts/WorkItemQueryResult");
            }
            if (TopicTypeHelper.IsMatch(topic.Type, TopicBodyFormats.VstsWorkItemQueries))
            {
                return("Vsts/WorkItemQueries");
            }

            return(suggestedTemplateName); // This is probably not good, but so be it
        }
示例#13
0
        public ActionResult Edit([Bind(Include = "WeekNumber,Topic")] TopicInformation topicInformation)
        {
            if (!ModelState.IsValid)
            {
                return(View(topicInformation));
            }
            bool dataEdit = manageData.EditData(topicInformation, User.Identity.Name);

            if (dataEdit)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.Error = "Error occured while editing !";
                return(View(topicInformation));
            }
        }
示例#14
0
        /// <summary>
        /// Domain logic of deleting datatable entry
        /// </summary>
        /// <param name="topicInformation">The refernce to access topic information for deletting it.</param>
        /// <returns></returns>
        public bool DeleData(TopicInformation topicInformation)
        {
            using (var context = new UTSDatabaseEntities())
            {
                var key = context.TopicInfo.Where(m => m.WeekNumber == topicInformation.WeekNumber).FirstOrDefault();

                if (key != null)
                {
                    db.TopicInfo.Remove(topicInformation);
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
示例#15
0
        /// <summary>
        /// Domain logic of Editting datatable entry
        /// </summary>
        /// <param name="topicInformation">The refernce to access topic information for editting it</param>
        /// <param name="loggedinUser">The session of user that is logged in.</param>
        /// <returns></returns>
        public bool EditData(TopicInformation topicInformation, string loggedinUser)
        {
            using (var context = new UTSDatabaseEntities())
            {
                var key = context.TopicInfo.Where(m => m.WeekNumber == topicInformation.WeekNumber).FirstOrDefault();

                if (key != null)
                {
                    topicInformation.LastUpdatedBy   = loggedinUser;
                    db.Entry(topicInformation).State = EntityState.Modified;
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
示例#16
0
        public ActionResult Create([Bind(Include = "WeekNumber,Topic")] TopicInformation topicInformation)
        {
            if (!ModelState.IsValid)
            {
                return(View(topicInformation));
            }

            bool dataSaved = manageData.SaveData(topicInformation, User.Identity.Name);

            if (dataSaved)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.Error = "Duplicate Primary Key - Week Number";
                return(View(topicInformation));
            }
        }
        public static ITopicRenderer GetTopicRenderer(TopicInformation topic)
        {
            // If we recognize the topic type, we use it to determine the renderer
            var renderer = GetRegisteredTopicRenderer(topic.Type);

            if (renderer != null)
            {
                return(renderer);
            }

            // Since we couldn't use type information, we try to inspect the name (URL pattern) to see if we can do anything with it
            var normalizedName = topic.OriginalNameNormalized;

            if (normalizedName.EndsWith(".html") || normalizedName.EndsWith(".htm"))
            {
                return(GetRegisteredTopicRenderer("html"));
            }

            // For anything else, we assume markdown
            return(GetRegisteredTopicRenderer("markdown"));
        }
示例#18
0
        private void tcMessageConstricting_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool enableSend = false;

            if (tvTopics.SelectedNode != null)
            {
                TopicInformation topic = tvTopics.SelectedNode.Tag as TopicInformation;

                if (topic != null && topic.IsTopic)
                {
                    if (tcMessageConstricting.SelectedTab == tpMessageBuilder)
                    {
                        enableSend = _allParametersSupported;
                    }
                    else
                    {
                        enableSend = true;
                    }
                }
            }
            btnSend.Enabled = enableSend;
        }
示例#19
0
        private string MarkdownToHtml(TopicInformation topic, string imageRootUrl, ISettingsProvider settings)
        {
            // TODO: This uses all images as external links. We may need to handle that differently

            var markdown = topic.OriginalContent;

            markdown = markdown.Replace("![](", "![](" + imageRootUrl);
            markdown = markdown.Replace("background: url('", "background: url('" + imageRootUrl);
            markdown = markdown.Replace("src=\"", "src=\"" + imageRootUrl);

            var builder = new MarkdownPipelineBuilder();

            BuildPipeline(builder, settings, markdown);
            var pipeline = builder.Build();
            var html     = Markdig.Markdown.ToHtml(markdown, pipeline);

            if (settings.GetSetting <bool>(SettingsEnum.UseFontAwesomeInMarkdown))
            {
                html = ParseFontAwesomeIcons(html);
            }

            return(html);
        }
示例#20
0
        private void tvTopics_AfterSelect(object sender, TreeViewEventArgs e)
        {
            bool enableSend = false;

            tbMessage.Clear();

            List <string> usedParameters = new List <string>();

            if (tvTopics.SelectedNode != null)
            {
                TopicInformation topic = tvTopics.SelectedNode.Tag as TopicInformation;

                if (topic != null && topic.IsTopic)
                {
                    enableSend = !topic.IsProperty;

                    List <int> starts = new List <int>();
                    List <int> counts = new List <int>();

                    StringBuilder messageSample = new StringBuilder();
                    messageSample.AppendLine("<Message UtcTime=\"%NOW%\">");
                    starts.Add(18);
                    counts.Add(5);
                    messageSample.AppendLine("   <Source>");
                    foreach (SimpleItemDescription item in topic.SourceItems)
                    {
                        messageSample.AppendFormat("      <SimpleItem Name=\"{0}\" Value=\"", item.Name);
                        starts.Add(messageSample.Length - 2);
                        string line = string.Format("value of {0}:{1} data type", item.Type.Namespace, item.Type.Name);
                        counts.Add(line.Length);
                        messageSample.Append(line);
                        messageSample.AppendLine("\" />");

                        usedParameters.Add(item.Name);
                    }
                    messageSample.AppendLine("   </Source>");
                    messageSample.AppendLine("   <Data>");
                    int offset = 5;
                    foreach (SimpleItemDescription item in topic.DataItems)
                    {
                        messageSample.AppendFormat("      <SimpleItem Name=\"{0}\" Value=\"", item.Name);
                        starts.Add(messageSample.Length - offset);
                        offset++;
                        string line = string.Format("value of {0}:{1} data type", item.Type.Namespace, item.Type.Name);
                        counts.Add(line.Length);
                        messageSample.Append(line);
                        messageSample.AppendLine("\" />");

                        usedParameters.Add(item.Name);
                    }
                    messageSample.AppendLine("   </Data>");
                    messageSample.AppendLine("</Message>");
                    tbMessage.Text = messageSample.ToString();

                    for (int i = 0; i < starts.Count; i++)
                    {
                        int begin = starts[i];
                        int count = counts[i];

                        tbMessage.Select(begin, count);
                        tbMessage.SelectionColor = System.Drawing.Color.Red;
                    }
                }
            }

            _allParametersSupported = true;
            foreach (string parameter in usedParameters)
            {
                if (!_inputs.ContainsKey(parameter))
                {
                    _allParametersSupported = false;
                    break;
                }
            }

            if (_allParametersSupported)
            {
                foreach (ParameterInput ctrl in _parameterControls)
                {
                    ctrl.Visible = (usedParameters.Contains(ctrl.ParameterName));
                }
            }
            else
            {
                flpParameters.Enabled = true;
                foreach (ParameterInput ctrl in _parameterControls)
                {
                    ctrl.Visible = false;
                }
            }

            if (!_allParametersSupported)
            {
                enableSend = enableSend && (tcMessageConstricting.SelectedTab == tpRawMessage);
            }
            btnSend.Enabled = enableSend;
        }
示例#21
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            if (tvTopics.SelectedNode != null)
            {
                TopicInformation topic = tvTopics.SelectedNode.Tag as TopicInformation;
                if (topic != null)
                {
                    List <SimpleItem> sourceItems       = new List <SimpleItem>();
                    List <SimpleItem> dataItems         = new List <SimpleItem>();
                    DateTime          messageTime       = DateTime.MinValue;
                    string            propertyOperation = null;

                    if (tcMessageConstricting.SelectedTab == tpRawMessage)
                    {
                        XmlDocument doc = new XmlDocument();
                        try
                        {
                            doc.LoadXml(tbMessage.Text);

                            XmlElement messageElement = doc.DocumentElement;
                            if (messageElement.HasAttribute("PropertyOperation"))
                            {
                                propertyOperation = messageElement.Attributes["PropertyOperation"].Value;
                            }
                            XmlNodeList sourceSimpleItems = messageElement.SelectNodes("Source/SimpleItem");
                            foreach (XmlNode node in sourceSimpleItems)
                            {
                                XmlElement element = node as XmlElement;
                                if (element != null)
                                {
                                    sourceItems.Add(new SimpleItem()
                                    {
                                        Name  = element.Attributes["Name"].Value,
                                        Value = element.Attributes["Value"].Value
                                    });
                                }
                            }
                            XmlNodeList dataSimpleItems = messageElement.SelectNodes("Data/SimpleItem");
                            foreach (XmlNode node in dataSimpleItems)
                            {
                                XmlElement element = node as XmlElement;
                                if (element != null)
                                {
                                    dataItems.Add(new SimpleItem()
                                    {
                                        Name  = element.Attributes["Name"].Value,
                                        Value = element.Attributes["Value"].Value
                                    });
                                }
                            }

                            string dateTimeValue = messageElement.Attributes["UtcTime"].Value;
                            if (dateTimeValue != "%NOW%")
                            {
                                messageTime = DateTime.Parse(dateTimeValue);
                            }
                        }
                        catch (Exception exc)
                        {
                            MessageBox.Show("Message format is not correct");
                            return;
                        }
                    }
                    else
                    {
                        foreach (SimpleItemDescription item in topic.SourceItems)
                        {
                            SimpleItem messageItem = new SimpleItem();
                            messageItem.Name  = item.Name;
                            messageItem.Value = _inputs[item.Name].GetText();
                            sourceItems.Add(messageItem);
                        }
                        foreach (SimpleItemDescription item in topic.DataItems)
                        {
                            SimpleItem messageItem = new SimpleItem();
                            messageItem.Name  = item.Name;
                            messageItem.Value = _inputs[item.Name].GetText();
                            dataItems.Add(messageItem);
                        }
                    }
                    try
                    {
                        EventControlClient.FireEvent(topic, messageTime, propertyOperation, sourceItems.ToArray(), dataItems.ToArray());
                    }
                    catch (Exception exc)
                    {
                        ShowError(exc);
                    }
                }
            }
        }
 public string RenderToJson(TopicInformation topic, string imageRootUrl = "", ISettingsProvider settings = null) => string.Empty;
 public string GetTemplateName(TopicInformation topic, string suggestedTemplateName, ISettingsProvider settings = null) => suggestedTemplateName;
示例#24
0
        private async Task GetHtmlContent()
        {
            var rawTopic = new TopicInformation {
                OriginalName = SelectedTopic.Title, Type = SelectedTopic.Type
            };

            ImageRootUrl = string.Empty;

            var normalizedLink = SelectedTopic.LinkPure.ToLowerInvariant();

            if (normalizedLink.StartsWith("https://") || normalizedLink.StartsWith("http://"))
            {
                // This is an absolute link, so we can just try to load it
                rawTopic.OriginalContent = await WebClientEx.GetStringAsync(SelectedTopic.Link);

                ImageRootUrl = StringHelper.JustPath(SelectedTopic.Link) + "/";
            }
            else if (!string.IsNullOrEmpty(normalizedLink))
            {
                var repositoryType = RepositoryTypeHelper.GetTypeFromTypeName(GetSetting <string>(SettingsEnum.RepositoryType));

                // Even if the overall repository type is something else, we will switch to different repository access for specific node types,
                // as they may point to other repositories or require different APIs even within the same repository
                if (TopicTypeHelper.IsVstsWorkItemType(rawTopic?.Type))
                {
                    repositoryType = RepositoryTypes.VstsWorkItemTracking;
                }

                switch (repositoryType)
                {
                case RepositoryTypes.GitHubRaw:
                    var fullGitHubRawUrl = GitHubMasterUrlRaw + SelectedTopic.Link;
                    if (string.IsNullOrEmpty(rawTopic.Type))
                    {
                        rawTopic.Type = TopicTypeHelper.GetTopicTypeFromLink(fullGitHubRawUrl);
                    }
                    if (TopicTypeHelper.IsMatch(rawTopic.Type, TopicBodyFormats.Markdown) || TopicTypeHelper.IsMatch(rawTopic.Type, TopicBodyFormats.Html))
                    {
                        rawTopic.OriginalContent = await WebClientEx.GetStringAsync(fullGitHubRawUrl);
                    }
                    else if (TopicTypeHelper.IsMatch(rawTopic.Type, TopicBodyFormats.ImageUrl))
                    {
                        rawTopic.OriginalContent = fullGitHubRawUrl;
                    }
                    ImageRootUrl = StringHelper.JustPath(fullGitHubRawUrl);
                    if (!string.IsNullOrEmpty(ImageRootUrl) && !ImageRootUrl.EndsWith("/"))
                    {
                        ImageRootUrl += "/";
                    }
                    break;

                case RepositoryTypes.GitHubApi:
                    if (TopicTypeHelper.IsMatch(rawTopic.Type, TopicBodyFormats.Markdown) || TopicTypeHelper.IsMatch(rawTopic.Type, TopicBodyFormats.Html))
                    {
                        var gitHubClient  = new GithubRepositoryParser(GitHubOwner, GitHubRepository, GitHubPat);
                        var gitHubContent = await gitHubClient.GetItemContent(SelectedTopic.Link);

                        rawTopic.OriginalContent = gitHubContent.Text;
                    }
                    // TODO: else if (TopicTypeHelper.IsMatch(rawTopic.Type, TopicBodyFormats.ImageUrl))
                    //    rawTopic.OriginalContent = fullGitHubRawUrl;
                    //ImageRootUrl = StringHelper.JustPath(fullGitHubRawUrl);
                    //if (!string.IsNullOrEmpty(ImageRootUrl) && !ImageRootUrl.EndsWith("/")) ImageRootUrl += "/";
                    break;

                case RepositoryTypes.VstsGit:
                    if (!string.IsNullOrEmpty(SelectedTopic.LinkPure))
                    {
                        rawTopic.OriginalContent = await VstsHelper.GetFileContents(SelectedTopic.LinkPure, GetSetting <string>(SettingsEnum.VstsInstance), GetSetting <string>(SettingsEnum.VstsProjectName), GetSetting <string>(SettingsEnum.VstsDocsFolder), GetSetting <string>(SettingsEnum.VstsPat), GetSetting <string>(SettingsEnum.VstsApiVersion));
                    }
                    ImageRootUrl = "/___FileProxy___?mode=" + RepositoryTypeNames.VstsGit + "&path=";
                    if (SelectedTopic.LinkPure.Contains("/"))
                    {
                        ImageRootUrl += StringHelper.JustPath(SelectedTopic.LinkPure) + "/";
                    }
                    break;

                case RepositoryTypes.VstsWorkItemTracking:
                    if ((TopicTypeHelper.IsMatch(rawTopic?.Type, TopicBodyFormats.VstsWorkItemQuery) || TopicTypeHelper.IsMatch(rawTopic?.Type, TopicBodyFormats.VstsWorkItemQueries)) && HttpContext.Request.Query.ContainsKey("workitemnumber"))
                    {
                        // The current node is a work item query, but we use it as a context to get the actual work item
                        var itemNumber = int.Parse(HttpContext.Request.Query["workitemnumber"]);
                        rawTopic.OriginalContent = await VstsHelper.GetWorkItemJson(itemNumber, GetSetting <string>(SettingsEnum.VstsInstance), GetSetting <string>(SettingsEnum.VstsPat), GetSetting <string>(SettingsEnum.VstsApiVersion));

                        rawTopic.Type = TopicBodyFormats.VstsWorkItem;
                    }
                    else if (TopicTypeHelper.IsMatch(rawTopic?.Type, TopicBodyFormats.VstsWorkItemQueries) && HttpContext.Request.Query.ContainsKey("queryid"))
                    {
                        // The current node is a list of work item queries, but we use it as a context to run the actual query
                        var queryId       = HttpContext.Request.Query["queryid"];
                        var queryInfoJson = await VstsHelper.GetWorkItemQueriesJson(queryId, GetSetting <string>(SettingsEnum.VstsInstance), GetSetting <string>(SettingsEnum.VstsProjectName), GetSetting <string>(SettingsEnum.VstsPat), GetSetting <string>(SettingsEnum.VstsApiVersion));

                        dynamic queryInfo = JObject.Parse(queryInfoJson);
                        if (queryInfo != null)
                        {
                            Title = "Query: " + queryInfo.name;
                        }
                        rawTopic.OriginalContent = await VstsHelper.RunWorkItemQueryJson(queryId, GetSetting <string>(SettingsEnum.VstsInstance), GetSetting <string>(SettingsEnum.VstsProjectName), GetSetting <string>(SettingsEnum.VstsPat), GetSetting <string>(SettingsEnum.VstsApiVersion));

                        if (rawTopic.OriginalContent.StartsWith("{"))
                        {
                            rawTopic.Type = TopicBodyFormats.VstsWorkItemQuery;
                        }
                        else
                        {
                            rawTopic.Type = TopicBodyFormats.Markdown;     // Something went wrong, but one way or another, we didn't end up with JSON
                        }
                    }
                    else if (TopicTypeHelper.IsMatch(rawTopic?.Type, TopicBodyFormats.VstsWorkItem))
                    {
                        // Plain work item node
                        var itemNumber = int.Parse(SelectedTopic.Link);
                        rawTopic.OriginalContent = await VstsHelper.GetWorkItemJson(itemNumber, GetSetting <string>(SettingsEnum.VstsInstance), GetSetting <string>(SettingsEnum.VstsPat), GetSetting <string>(SettingsEnum.VstsApiVersion));
                    }
                    else if (TopicTypeHelper.IsMatch(rawTopic?.Type, TopicBodyFormats.VstsWorkItemQueries))
                    {
                        // Plain work item queries
                        rawTopic.OriginalContent = await VstsHelper.GetWorkItemQueriesJson(SelectedTopic.Link, GetSetting <string>(SettingsEnum.VstsInstance), GetSetting <string>(SettingsEnum.VstsProjectName), GetSetting <string>(SettingsEnum.VstsPat), GetSetting <string>(SettingsEnum.VstsApiVersion));

                        Title = SelectedTopic.Title;
                    }
                    else if (TopicTypeHelper.IsMatch(rawTopic?.Type, TopicBodyFormats.VstsWorkItemQuery))
                    {
                        // Plain work item query
                        rawTopic.OriginalContent = await VstsHelper.RunWorkItemQueryJson(SelectedTopic.Link, GetSetting <string>(SettingsEnum.VstsInstance), GetSetting <string>(SettingsEnum.VstsProjectName), GetSetting <string>(SettingsEnum.VstsPat), GetSetting <string>(SettingsEnum.VstsApiVersion));

                        Title = SelectedTopic.Title;
                    }

                    Vsts.ImageLink = "/___FileProxy___?mode=" + RepositoryTypeNames.VstsWorkItemTracking + "&topic=" + CurrentSlug + "&path=";
                    break;
                }
            }

            var renderer = TopicRendererFactory.GetTopicRenderer(rawTopic);

            var intermediateHtml = renderer.RenderToHtml(rawTopic, ImageRootUrl, this);

            if (!string.IsNullOrEmpty(intermediateHtml))
            {
                intermediateHtml = await ProcessKavaTopic(intermediateHtml);

                intermediateHtml = AutoGenerateTitle(intermediateHtml);
                intermediateHtml = ProcessBrokenImageLinks(intermediateHtml, ImageRootUrl);
            }

            Html = intermediateHtml;

            Json         = renderer.RenderToJson(rawTopic, ImageRootUrl, this);
            TemplateName = renderer.GetTemplateName(rawTopic, TemplateName, this);

            if (string.IsNullOrEmpty(Html) && SelectedTopic != null)
            {
                var sb = new StringBuilder();
                sb.Append("<h1>" + SelectedTopic.Title + "</h1>");

                if (SelectedTopic.Topics.Count > 0)
                {
                    sb.Append("<ul>");
                    foreach (var topic in SelectedTopic.Topics)
                    {
                        sb.Append("<li class=\"kava-auto-link\">");
                        sb.Append("<a href=\"" + TopicHelper.GetNormalizedName(topic.Title) + "\">");
                        sb.Append(topic.Title);
                        sb.Append("</a>");
                        sb.Append("</li>");
                    }
                    sb.Append("</ul>");
                }

                Html = sb.ToString();
            }
        }
示例#25
0
    //Handles MQTT messages when they are received
    public void HandleMessage(string topic, string message)
    {
        //Parse and store topic information
        TopicInformation info = ParseTopic(topic);

        switch (info.componentType)
        {
        case ComponentTypes.traffic_light:
            //Handle traffic lights
            //Try setting new traffic light state
            try
            {
                TrafficLightState newState = (TrafficLightState)System.Enum.Parse(typeof(TrafficLightState), message);
                SetTrafficLightState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid traffic light state: '{message}' for traffic light with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.warning_light:
            //Handle warning lights
            //Try setting new warning light state
            try
            {
                WarningLightState newState = (WarningLightState)System.Enum.Parse(typeof(WarningLightState), message);
                SetWarningLightState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid warning light state: '{message}' for warning light with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.boat_light:
            //Handle boat lights
            //Try setting new boat light state
            try
            {
                BoatAndTrainLightState newState = (BoatAndTrainLightState)System.Enum.Parse(typeof(BoatAndTrainLightState), message);
                SetBoatLightState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid boat light state: '{message}' for boat light with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.sensor:     //Don't have to handle sensor data
            break;

        case ComponentTypes.barrier:
            //Handle barriers
            //Try setting new barrier state
            try
            {
                BarrierState newState = (BarrierState)System.Enum.Parse(typeof(BarrierState), message);
                SetBarrierState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid barrier state: '{message}' for barrier with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.deck:
            //Handle deck(bridge)
            //Try setting new deck(bridge) state
            try
            {
                DeckState newState = (DeckState)System.Enum.Parse(typeof(DeckState), message);
                SetDeckState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid deck(bridge) state: '{message}' for deck with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.train_light:
            //Handle train_light
            //Try setting new train_light state
            try
            {
                BoatAndTrainLightState newState = (BoatAndTrainLightState)System.Enum.Parse(typeof(BoatAndTrainLightState), message);
                SetTrainLightState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid train_light state: '{message}' for train_light with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;
        }
    }
示例#26
0
 //Invokes 'publish to controller' event (received by M2QTTController script)
 private void PublishToController(TopicInformation topic, string message)
 {
     OnPublishToController.Invoke(topic, message);
 }
示例#27
0
    //Event listener to sensor trigger
    private void OnSensorTriggered(LaneTypes laneType, int groupId, int componentId, bool isTriggered)
    {
        TopicInformation info = new TopicInformation(laneType, groupId, ComponentTypes.sensor, componentId);

        PublishToController(info, (isTriggered ? 1 : 0).ToString());
    }
示例#28
0
 // We simply use the original JSON and pass it on as the content, which will then be picked up by a template
 public string RenderToJson(TopicInformation topic, string imageRootUrl = "", ISettingsProvider settings = null) => topic.OriginalContent;