示例#1
0
        public static Snippet CreateAvalonEditSnippet(RunbookModelProxy runbook, string snippetText)
        {
            if (snippetText == null)
            {
                throw new ArgumentNullException("text");
            }

            var replaceableElements = new Dictionary <string, SnippetReplaceableTextElement>(StringComparer.OrdinalIgnoreCase);

            foreach (Match m in pattern.Matches(snippetText))
            {
                string val        = m.Groups[1].Value;
                int    equalsSign = val.IndexOf('=');
                if (equalsSign > 0)
                {
                    string name = val.Substring(0, equalsSign);
                    replaceableElements[name] = new SnippetReplaceableTextElement();
                }
            }

            Snippet snippet = new Snippet();
            int     pos     = 0;

            foreach (Match m in pattern.Matches(snippetText))
            {
                if (pos < m.Index)
                {
                    snippet.Elements.Add(new SnippetTextElement {
                        Text = snippetText.Substring(pos, m.Index - pos)
                    });
                    pos = m.Index;
                }

                snippet.Elements.Add(CreateElementForValue(runbook, replaceableElements, m.Groups[1].Value, m.Index, snippetText));
                pos = m.Index + m.Length;
            }

            if (pos < snippetText.Length)
            {
                snippet.Elements.Add(new SnippetTextElement {
                    Text = snippetText.Substring(pos)
                });
            }

            if (!snippet.Elements.Any(e => e is SnippetCaretElement))
            {
                var obj   = snippet.Elements.FirstOrDefault(e2 => e2 is SnippetSelectionElement);
                int index = snippet.Elements.IndexOf(obj);

                if (index > -1)
                {
                    snippet.Elements.Insert(index + 1, new SnippetCaretElement());
                }
            }

            return(snippet);
        }
        public JobHistoryViewModel(RunbookViewModel runbookViewModel)
        {
            _runbook = (RunbookModelProxy)runbookViewModel.Model;
            Owner    = _runbook.Context.Service;

            Jobs = new ObservableCollection <JobModelProxy>();

            //AsyncExecution.Run(ThreadPriority.Normal, () =>
            Task.Run(() =>
            {
                IList <JobModelProxy> draftJobs     = null;
                IList <JobModelProxy> publishedJobs = null;

                try
                {
                    if (_runbook.DraftRunbookVersionID.HasValue)
                    {
                        draftJobs = Owner.GetJobs(_runbook.DraftRunbookVersionID.Value);
                    }

                    if (_runbook.PublishedRunbookVersionID.HasValue)
                    {
                        publishedJobs = Owner.GetJobs(_runbook.PublishedRunbookVersionID.Value);
                    }
                }
                catch (ApplicationException ex)
                {
                    GlobalExceptionHandler.Show(ex);
                }

                Execute.OnUIThread(() =>
                {
                    if (draftJobs != null)
                    {
                        foreach (var job in draftJobs)
                        {
                            job.BoundRunbookViewModel = runbookViewModel;
                            job.RunbookType           = RunbookType.Draft;
                            Jobs.Add(job);
                        }
                    }

                    if (publishedJobs != null)
                    {
                        foreach (var job in publishedJobs)
                        {
                            job.BoundRunbookViewModel = runbookViewModel;
                            job.RunbookType           = RunbookType.Published;
                            Jobs.Add(job);
                        }
                    }

                    Jobs = Jobs.OrderBy(j => j.StartTime).ToObservableCollection();
                });
            });
        }
示例#3
0
        public async Task <bool> Copy(RunbookModelProxy runbook)
        {
            var newRunbook = default(RunbookModelProxy);

            if (runbook.Context.Equals(this))
            {
                return(false);
            }

            switch (runbook.Context.ContextType)
            {
            case ContextType.SMA:
                newRunbook = new RunbookModelProxy(new SMA.Runbook
                {
                    RunbookName = runbook.RunbookName,
                    Tags        = runbook.Tags != null ? runbook.Tags : string.Empty
                }, this);
                break;

            default:
                newRunbook = new RunbookModelProxy(new Vendor.Azure.Runbook
                {
                    RunbookName = runbook.RunbookName,
                    Tags        = runbook.Tags != null ? runbook.Tags : string.Empty
                }, this);
                break;
            }

            var runbookDraftContent = await runbook.Context.Service.GetContentAsync(runbook.Context.Service.GetBackendUrl(RunbookType.Draft, runbook));

            var runbookPublishedContent = await runbook.Context.Service.GetContentAsync(runbook.Context.Service.GetBackendUrl(RunbookType.Published, runbook));

            if (string.IsNullOrEmpty(runbookPublishedContent))
            {
                // We only have draft content
                await Service.SaveRunbookAsync(newRunbook, runbookDraftContent);
            }
            else
            {
                await Service.SaveRunbookAsync(newRunbook, string.Empty);

                await Service.SaveRunbookContentAsync(newRunbook, runbookPublishedContent, RunbookType.Published);

                await Service.SaveRunbookContentAsync(newRunbook, runbookDraftContent, RunbookType.Draft);
            }

            AddToRunbooks(newRunbook);
            Start();

            return(true);
        }
示例#4
0
        static string GetValue(RunbookModelProxy runbook, string propertyName)
        {
            if (runbook == null)
            {
                return(null);
            }

            var property = runbook.GetType().GetProperty(propertyName);

            if (property != null)
            {
                return(property.GetValue(runbook).ToString());
            }

            return(null);
        }
示例#5
0
        static SnippetElement CreateElementForValue(RunbookModelProxy runbook, Dictionary <string, SnippetReplaceableTextElement> replaceableElements, string val, int offset, string snippetText)
        {
            SnippetReplaceableTextElement srte;
            int equalsSign = val.IndexOf('=');

            if (equalsSign > 0)
            {
                string name = val.Substring(0, equalsSign);
                if (replaceableElements.TryGetValue(name, out srte))
                {
                    if (srte.Text == null)
                    {
                        srte.Text = val.Substring(equalsSign + 1);
                    }
                    return(srte);
                }
            }

            if (replaceableElements.TryGetValue(val, out srte))
            {
                return new SnippetBoundElement {
                           TargetElement = srte
                }
            }
            ;

            string result = GetValue(runbook, val);

            if (result != null)
            {
                return new SnippetTextElement {
                           Text = result
                }
            }
            ;
            else
            {
                return new SnippetReplaceableTextElement {
                           Text = val
                }
            };                                                           // ${unknown} -> replaceable element
        }
示例#6
0
        public void AddToRunbooks(RunbookModelProxy runbook)
        {
            if (_runbookNameCache.Contains(runbook.RunbookName))
            {
                return;
            }

            try
            {
                Execute.OnUIThread(() =>
                {
                    Runbooks.Add(new ResourceContainer(runbook.RunbookName, runbook, IconsDescription.Runbook));

                    if (!_runbookNameCache.Contains(runbook.RunbookName))
                    {
                        _runbookNameCache.Add(runbook.RunbookName);
                    }
                });
            }
            catch (TaskCanceledException) { }
        }
示例#7
0
 public Snippet CreateAvalonEditSnippet(RunbookModelProxy runbook)
 {
     return(CreateAvalonEditSnippet(runbook, this.Text));
 }