Ejemplo n.º 1
0
        /// <inheritdoc/>
        public override async Task <bool> Run()
        {
            // Try executing each behavior in order, most important first
            foreach (AbstractBehavior behavior in _behaviors)
            {
                if (behavior.IsEnabled)
                {
                    Logger.LogTrace(Translations.LOG_BEHAVIOR_ENTERED, behavior.Name);
                    bool handled = await behavior.Run();

                    StatusBar.Clear();  // Clean up residual status messages

                    if (handled)
                    {
                        // Behavior handled the current situation; restart execution from top of behavior list
                        Logger.LogTrace(Translations.LOG_BEHAVIOR_EXITED_HANDLED, behavior.Name);
                        return(HANDLED_EXECUTION);
                    }
                    else
                    {
                        // Behavior didn't mark this situation as handled; execute next behavior
                        Logger.LogTrace(Translations.LOG_BEHAVIOR_EXITED_UNHANDLED, behavior.Name);
                    }
                }
            }

            // Tried every behavior but none would execute
            // Nothing left to do, return execution to parent to eventually stop bot
            Logger.LogTrace(Translations.LOG_BEHAVIOR_LIST_COMPLETE);
            return(PASS_EXECUTION);
        }
Ejemplo n.º 2
0
        private async void AddToProject()
        {
            try
            {
                this.IsBusy = true;
                this.AddToProjectCommand.RaiseCanExecuteChanged();
                StatusBar.DisplayMessage("Downloading icons ...");

                var project    = VS.Project.GetActiveProject();
                var projectDir = VS.Project.GetProjectDirectory(project);

                var selectedTypes = new List <Type>();
                if (this.Mdpi.IsSelected)
                {
                    selectedTypes.Add(this.Mdpi.Item);
                }
                if (this.Hdpi.IsSelected)
                {
                    selectedTypes.Add(this.Hdpi.Item);
                }
                if (this.XHdpi.IsSelected)
                {
                    selectedTypes.Add(this.XHdpi.Item);
                }
                if (this.XXHdpi.IsSelected)
                {
                    selectedTypes.Add(this.XXHdpi.Item);
                }
                if (this.XXXHdpi.IsSelected)
                {
                    selectedTypes.Add(this.XXXHdpi.Item);
                }

                foreach (var type in selectedTypes)
                {
                    var color   = (this.Color.IsKnown) ? this.Color : Pallete.Black;
                    var iconUrl = this.GenerateUrl(this.Icon.Group.Id, this.Icon.Id,
                                                   type.Folder, color.Name, this.Size.Value);

                    byte[] icon;
                    using (var client = new HttpClient())
                        icon = await client.GetByteArrayAsync(iconUrl);

                    if (!this.Color.IsKnown)
                    {
                        icon = ColorUtils.ReplaceColor(icon, this.Color.Color);
                    }

                    var filepath = type.Destination(projectDir, this.Name);
                    FileUtils.WriteAllBytes(icon, filepath);
                    // add to project
                    VS.Project.AddFileToProject(project, filepath, "AndroidResource");
                }

                project.Save();
            }
            catch (System.Exception ex)
            {
                OutputPane.Output(ex.Message);
                OutputPane.Output(ex.StackTrace);
                OutputPane.Activate();
            }
            finally
            {
                StatusBar.Clear();
                this.IsBusy = false;
                this.AddToProjectCommand.RaiseCanExecuteChanged();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            DTE          dte    = Package.GetGlobalService(typeof(DTE)) as DTE;
            Document     doc    = dte.ActiveDocument;
            TextDocument txtDoc = doc.Object() as TextDocument;

            var text = txtDoc.CreateEditPoint(txtDoc.StartPoint).GetText(txtDoc.EndPoint);

            text = text.Replace("\r", "");

            uint cookie = 0;

            StatusBar.Progress(ref cookie, 1, string.Empty, 0, 0);

            if (txtDoc.Language == "HTMLX" || txtDoc.Language == "HTML")
            {
                var html           = text;
                var elementList    = new List <HtmlElement>();
                var parsed         = _parser.ParseHtml(html, elementList, txtDoc, StatusBar, ref cookie);
                var cssFileContent = string.Empty;

                if (elementList.Any())
                {
                    foreach (var item in elementList)
                    {
                        var cssClass = string.Empty;
                        if (string.IsNullOrEmpty(item.Class))
                        {
                            cssClass = string.Format(".{0}", string.IsNullOrEmpty(item.Id) ? CreateUniqueElementKey(item.Name, item.LineNumber) : item.Id);
                        }
                        else
                        {
                            cssClass = string.Format(".{0} .{1}", item.Class, CreateUniqueElementKey(item.Name, item.LineNumber));
                        }

                        var idAttr      = string.IsNullOrEmpty(item.Id) ? string.Empty : string.Format("id=\"{0}\"", item.Id);
                        var replaceText = string.Format("{0} {1} class=\"{2}\"", item.Name, idAttr, cssClass.Replace(".", string.Empty));

                        parsed          = parsed.Replace(item.Guid, replaceText);
                        cssFileContent += string.Format("{0}{{{1}}}\n\n", cssClass, "\n" + item.Style);
                    }

                    //css file beautification
                    cssFileContent = cssFileContent.Replace(";", ";\n");

                    //update html file
                    var txtSelHtml = (TextSelection)doc.Selection;
                    txtSelHtml.SelectAll();
                    txtSelHtml.Delete();
                    txtSelHtml.Insert(parsed);

                    //create css file
                    var docName = doc.Name.Substring(0, doc.Name.IndexOf('.'));
                    docName = string.Format("{0}.css", docName);

                    dte.ItemOperations.NewFile(@"General\Text File", docName, EnvDTE.Constants.vsViewKindTextView);

                    var txtSelCss = (TextSelection)dte.ActiveDocument.Selection;
                    txtSelCss.SelectAll();
                    txtSelCss.Delete();
                    txtSelCss.Insert(cssFileContent);
                }
                else
                {
                    VsShellUtilities.ShowMessageBox(this.ServiceProvider, "Not found inline css.", "That's Cool!",
                                                    OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            }
            else
            {
                VsShellUtilities.ShowMessageBox(this.ServiceProvider, "This is not a html file!", "Oops!",
                                                OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }

            // Clear the progress bar.
            StatusBar.Progress(ref cookie, 0, string.Empty, 0, 0);
            StatusBar.FreezeOutput(0);
            StatusBar.Clear();
        }
Ejemplo n.º 4
0
 /// <inheritdoc/>
 public void OnStop()
 {
     StatusBar.Clear();
     Logger.LogInformation(Translations.LOG_BOTBASE_STOPPED);
     Root = null;
 }