예제 #1
0
        private void addSpiderButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var parent = GetSelectedSource();

                var source = new SpiderSource {
                    Name = "New Spider", Path = "unknown", Parent = parent
                };

                if (parent != null)
                {
                    parent.AddChild(source);
                }
                else
                {
                    boundSources.Add(source);
                }
            }
            catch (Exception ex)
            {
                log.Error("SourceView.addSpiderButton_Click", ex);
                MessageBox.Show("There was an error trying to add a spider.\n\n" + ex.Message, "Could Not Add Spider");
            }
        }
예제 #2
0
        private void LoadSpiderStarted(object sender, DoWorkEventArgs args)
        {
            try
            {
                log.Info("LoadSpiderStarted");
                var request = args.Argument as LoadSourceRequest;
                if (request == null)
                {
                    log.Warn("LoadSpiderStarted: request is null");
                    return;
                }

                var source = request.Source;

                if (source != null && !string.IsNullOrEmpty(source.Path))
                {
                    var body = GetResponseBody(source.Path);

                    if (!string.IsNullOrEmpty(source.ChildPattern))
                    {
                        var regex = new Regex(source.ChildPattern);
                        foreach (Match match in regex.Matches(body))
                        {
                            var childName    = match.Groups["NAME"].Value;
                            var childPath    = match.Groups["PATH"].Value;
                            var childSummary = match.Groups["SUMMARY"].Value;

                            if (!string.IsNullOrEmpty(childPath))
                            {
                                //We need to turn relative paths into absolute paths
                                if (childPath.StartsWith("~/"))
                                {
                                    childPath = childPath.Substring(1, childPath.Length - 1);
                                }

                                if (childPath.StartsWith("/"))
                                {
                                    var parentUri = new Uri(source.Path);
                                    childPath = string.Format("{0}://{1}{2}", parentUri.Scheme, parentUri.Host, childPath);
                                }

                                var existingChild = source.Children.Where(x => x.Path == childPath).FirstOrDefault();
                                if (existingChild != null)
                                {
                                    //TODO: Decide whether or not we want to ever update existing items
                                    //if (!string.IsNullOrEmpty(childName) && existingChild.Name != childName)
                                    //{
                                    //Save(existingChild);
                                    //}
                                }
                                else
                                {
                                    var childSpider = new SpiderSource {
                                        Name = childName, Path = childPath, Summary = childSummary, Parent = source
                                    };

                                    log.Info(string.Format("LoadSpiderStarted: Saving new spider child. name={0} path={1}", childName, childPath));
                                    Save(childSpider);
                                    request.Invoke(() => source.AddChild(childSpider));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("LoadSpiderStarted", ex);
            }
        }
예제 #3
0
        private void addSpiderButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var parent = GetSelectedSource();

                var source = new SpiderSource { Name = "New Spider", Path = "unknown", Parent = parent };

                if (parent != null)
                {
                    parent.AddChild(source);
                }
                else
                {
                    boundSources.Add(source);
                }
            }
            catch (Exception ex)
            {
                log.Error("SourceView.addSpiderButton_Click", ex);
                MessageBox.Show("There was an error trying to add a spider.\n\n" + ex.Message, "Could Not Add Spider");
            }
        }