Beispiel #1
0
        private void OnChanged(object sender, FileSystemEventArgs e)
        {
            if (Path.GetExtension(e.FullPath).Equals(""))
            {
                return;
            }

            Variables.fileChanged = e.FullPath;

            Variables.BuildFile bf = Functions.CanBuild();

            if (bf == null)
            {
                return;
            }

            if (Variables.MainThread != null && Variables.MainThread.ThreadState != System.Threading.ThreadState.Suspended && Variables.MainThread.ThreadState != System.Threading.ThreadState.Stopped)
            {
                Variables.MainThread.Suspend();
            }


            ThreadStart ths = new ThreadStart(() =>
            {
                try
                {
                    if (Variables.ProcessThread != null && Variables.ProcessThread.ThreadState != System.Threading.ThreadState.Suspended && Variables.ProcessThread.ThreadState != System.Threading.ThreadState.Stopped)
                    {
                        if (!Variables.buildProcess.HasExited)
                        {
                            Variables.buildProcess.Kill();
                        }
                        Variables.ProcessThread.Suspend();

                        Variables.currentBuildFile = bf;

                        Logging.TransmitLog("\r\n-----------\r\nBuild restarted!\r\n-----------\r\n\r\n", Variables.currentBuildFile.WebsiteName);
                    }
                    else
                    {
                        Variables.currentBuildFile = bf;

                        Logging.TransmitLog("\r\n-----------\r\nBuild started!\r\n-----------\r\n\r\n", Variables.currentBuildFile.WebsiteName);
                    }

                    Functions.TriggerBuild();
                }
                catch (Exception ex)
                {
                    Logging.TransmitLog(ex.Message, Variables.currentBuildFile.WebsiteName);
                }
            });

            Variables.MainThread = new Thread(ths);
            Variables.MainThread.Start();

            Variables.watcher.EnableRaisingEvents = false;
            Thread.Sleep(1000);
            Variables.watcher.EnableRaisingEvents = true;
        }
        public static Variables.BuildFile CanBuild()
        {
            if (Variables.fileChanged.Replace("\\", "/").Contains("/obj/"))
            {
                return(null);
            }
            if (Variables.fileChanged.Replace("\\", "/").Contains("/bin/"))
            {
                return(null);
            }

            Variables.BuildFile bf = Functions.GetBuildFile(Variables.fileChanged);

            if (bf == null)
            {
                //Logging.TransmitLog("No build settings file found.");
                return(null);
            }
            if (Variables.fileChanged.Replace("\\", "/").Contains(bf.BuildDirectory.Replace("\\", "/")))
            {
                //Logging.TransmitLog("Created by build!");
                return(null);
            }
            return(bf);
        }
        public static Variables.BuildFile GetBuildFile(string fileChanged)
        {
            string fileName = Path.GetFileName(fileChanged);
            string path     = Path.GetDirectoryName(fileChanged).Replace("\\", "/");
            string watchDir = Variables.WATCH_DIRECTORY.Replace("\\", "/");

            string file = Directory.GetFiles(path).Where(x => x.EndsWith("settings.ncc")).FirstOrDefault();

            while (file == null)
            {
                path = Path.GetFullPath(Path.Combine(path, @"../")).Replace("\\", "/");

                file = Directory.GetFiles(path).Where(x => x.EndsWith("settings.ncc")).FirstOrDefault();

                if (file == null && (watchDir == path || path == watchDir + "/"))
                {
                    break;
                }
            }

            if (file == null)
            {
                return(null);
            }

            Variables.BuildFile bf = new Variables.BuildFile();

            try
            {
                using (StreamReader sr = new StreamReader(File.OpenRead(file)))
                {
                    bf = Newtonsoft.Json.JsonConvert.DeserializeObject <Variables.BuildFile>(sr.ReadToEnd());
                }
            }
            catch (Exception)
            {
                Logging.TransmitLog("Failed to parse build file!", null);
                return(null);
            }
            if (bf == null)
            {
                Logging.TransmitLog("Failed to parse build file!", null);
                return(null);
            }
            bf.Location = path;

            return(bf);
        }