Ejemplo n.º 1
0
 /// <summary>
 /// add a new file to process into the queue
 /// </summary>
 /// <param name="path">object that contains the path and times</param>
 public void AddItem(OrangeJob job)
 {
     // only add to the queue if the file isn't already in the queue
     lock (queue)
     {
         var exists = queue.Where(x => x.Path.ToLower() == job.Path.ToLower()).Count() > 0;
         if (!exists)
             this.queue.Enqueue(job);
     }
 }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------------
        //
        //	Methods
        //
        //--------------------------------------------------------------------------

        #region AddItem
        /// <summary>
        /// add a new file to process into the queue
        /// </summary>
        /// <param name="path">object that contains the path and times</param>
        public void AddItem(OrangeJob job)
        {
            // only add to the queue if the file isn't already in the queue
            lock (queue)
            {
                var exists = queue.Where(x => x.Path.ToLower() == job.Path.ToLower()).Count() > 0;
                if (!exists)
                {
                    this.queue.Enqueue(job);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// process a file, generating the compiled output
        /// </summary>
        /// <param name="item"></param>
        protected void ProcessItem(OrangeJob job)
        {
            var threadedOpenCmd = new Action(() =>
            {
                mainDispatcher.Invoke(new Action(() =>
                {
                    var openCommand = host.HostCommands.OpenFileInEditor;
                    if (openCommand.CanExecute(job.OutputPath))
                    {
                        openCommand.Execute(job.OutputPath);
                    }
                }));
            });

            try
            {
                // do the actual compilation work
                CompileResults results = compiler.Process(job);

                // show the notification bar to notify the user it happened
                if (!String.IsNullOrEmpty(results.Message))
                {
                    host.ShowNotification(results.Message, "Open File", threadedOpenCmd);
                }
                host.Logger.Log(TraceLevel.Info, string.Format("Success:  Compiled {0} to generate {1}", job.Path, job.OutputPath));

                // refresh the tree so the new file (if created) shows up
                if (results.IsNewFile)
                {
                    mainDispatcher.Invoke(new Action(() =>
                    {
                        var refreshCommand = host.HostCommands.GetCommand(CommonCommandIds.GroupId, (int)CommonCommandIds.Ids.Refresh);
                        if (refreshCommand.CanExecute(null))
                        {
                            refreshCommand.Execute(null);
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                host.Logger.Log(TraceLevel.Error, string.Format("Error compiling {0}:  {1}", job.Path, ex.ToString()));
                host.ShowNotification("There was an error processing " + job.Path, "Open File", threadedOpenCmd);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// process a file, generating the compiled output
        /// </summary>
        /// <param name="item"></param>
        protected void ProcessItem(OrangeJob job)
        {
            var threadedOpenCmd = new Action(() =>
            {
                mainDispatcher.Invoke(new Action(() =>
                {
                    var openCommand = host.HostCommands.OpenFileInEditor;
                    if (openCommand.CanExecute(job.OutputPath))
                        openCommand.Execute(job.OutputPath);
                }));
            });

            try
            {
                // do the actual compilation work
                CompileResults results = OrangeCompiler.Process(job);

                // show the notification bar to notify the user it happened
                if (!String.IsNullOrEmpty(results.Message))
                {
                    host.ShowNotification(results.Message, "Open File", threadedOpenCmd);
                }

                // refresh the tree so the new file (if created) shows up
                if (results.IsNewFile)
                {
                    mainDispatcher.Invoke(new Action(() =>
                    {
                        var refreshCommand = host.HostCommands.GetCommand(CommonCommandIds.GroupId, (int)CommonCommandIds.Ids.Refresh);
                        if (refreshCommand.CanExecute(null))
                            refreshCommand.Execute(null);
                    }));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                host.ShowNotification("There was an error processing " + job.Path, "Open File", threadedOpenCmd);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        protected void AddMultiMenu(ContextMenuOpeningEventArgs e, string[] supportedExtensions, OrangeJob.JobType jobType, string title, string multipleTitle)
        {
            var jobs = new List<OrangeJob>();
            foreach (ISiteItem item in e.Items)
            {
                var fsi = item as ISiteFileSystemItem;
                if (fsi != null)
                {
                    if (fsi is ISiteFolder)
                    {
                        // get all of the pngs under the selected path and add a job
                        var dir = new DirectoryInfo((fsi as ISiteFolder).Path);
                        var files = supportedExtensions.SelectMany(x => dir.GetFiles("*" + x, SearchOption.AllDirectories));

                        foreach (var f in files)
                        {
                            if (jobType != OrangeJob.JobType.Minify || (!f.FullName.EndsWith(".min.js") && !f.FullName.EndsWith(".min.css")))
                            {
                                jobs.Add(new OrangeJob()
                                {
                                    Path = f.FullName,
                                    OutputPath = GetOutputPath(f.FullName),
                                    Type = jobType,
                                    Source = OrangeJob.JobSource.Context
                                });
                            }
                        }
                    }
                    else if (supportedExtensions.Contains((new FileInfo(fsi.Path)).Extension.ToLower()))
                    {
                        if (jobType != OrangeJob.JobType.Minify || (!fsi.Path.EndsWith(".min.js") && !fsi.Path.EndsWith(".min.css")))
                        {
                            jobs.Add(new OrangeJob()
                            {
                                Path = fsi.Path,
                                OutputPath = GetOutputPath(fsi.Path),
                                Type = jobType,
                                Source = OrangeJob.JobSource.Context
                            });
                        }
                    }
                }
            }

            if (jobs.Count > 0)
            {
                var menuTitle = jobs.Count > 1 ? multipleTitle : title;
                var menuItem = new ContextMenuItem(menuTitle, null, new DelegateCommand(new Action<object>(AddJob)), jobs);
                e.AddMenuItem(menuItem);
            }
        }