Log() public method

public Log ( Exception ex ) : void
ex System.Exception
return void
Beispiel #1
0
 void PushFiles(BuildContext ctx, SourceInfo source, SourceTagInfo stag, bool safe)
 {
     try {
         ctx.Status = "Uploading files for project " + source.ProjectName;
         foreach (string file in Directory.GetFiles(stag.GetPackagePath(ctx)))
         {
             ctx.Log(LogSeverity.Info, "Uploading [" + source.ProjectName + "] " + Path.GetFileName(file));
             WebRequest req = HttpWebRequest.Create(ctx.ServerUrl + "/package/upload");
             req.Headers ["applicationId"] = ctx.AppId.ToString();
             req.Headers ["sourceTagId"]   = stag.Id.ToString();
             req.Headers ["fileName"]      = Path.GetFileName(file);
             req.Method = "POST";
             req.GetRequestStream().WriteFile(file);
             using (StreamReader s = new StreamReader(req.GetResponse().GetResponseStream())) {
                 if (s.ReadToEnd() != "OK")
                 {
                     throw new Exception("File upload failed");
                 }
             }
         }
     } catch {
         if (!safe)
         {
             throw;
         }
     }
     finally {
         ctx.Status = "Files uploaded";
     }
 }
Beispiel #2
0
        void ExtractDmg(BuildContext ctx, string filePath, string file)
        {
            ctx.Status = "Extracting DMG";
            string tempPath  = Path.Combine(filePath, "__tmp_release");
            string tempPath2 = Path.Combine(filePath, "__tmp_release2");

            Util.ResetFolder(tempPath);
            try {
                Run7z(file, tempPath);
                string hfs = Directory.GetFiles(tempPath, "*.hfs").FirstOrDefault();
                if (hfs == null)
                {
                    ctx.Log(LogSeverity.Error, "Unknown release archive: " + file);
                    return;
                }
                Run7z(hfs, tempPath2);
                CopyDlls(tempPath2, filePath);
            } finally {
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
                if (Directory.Exists(tempPath2))
                {
                    Directory.Delete(tempPath2, true);
                }
            }
        }
Beispiel #3
0
        bool BuildSource(BuildContext ctx, SourceInfo vcs, SourceTagInfo stag)
        {
            // Fetch the source

            ctx.Status = "Fetching project " + vcs.ProjectName + " (" + stag.Name + ")";

            Util.ResetFolder(stag.GetPackagePath(ctx));

            string logFile = stag.GetLogFile(ctx);

            File.AppendAllText(logFile, "<p><b>Fetching Source</b></p>");
            ctx.Server.SetSourceTagStatus(ctx.AppId, stag.Id, SourceTagStatus.Fetching);
            try {
                FetchSource(ctx, vcs, stag, logFile);
            }
            catch (Exception ex) {
                File.AppendAllText(logFile, HttpUtility.HtmlEncode(ex.Message) + "<br/><br/>");
                PushFiles(ctx, vcs, stag, true);
                ctx.Server.SetSourceTagStatus(ctx.AppId, stag.Id, SourceTagStatus.FetchError);
                ctx.Log(ex);
                return(false);
            }

            // Build the add-in

            ctx.Status = "Building project " + vcs.ProjectName;
            File.AppendAllText(logFile, "<p><b>Building Solution</b></p>");
            ctx.Server.SetSourceTagStatus(ctx.AppId, stag.Id, SourceTagStatus.Building);
            try {
                BuildSource(ctx, vcs, stag, logFile);
            }
            catch (Exception ex) {
                File.AppendAllText(logFile, "<p>" + HttpUtility.HtmlEncode(ex.Message) + "</p>");
                PushFiles(ctx, vcs, stag, true);
                ctx.Server.SetSourceTagStatus(ctx.AppId, stag.Id, SourceTagStatus.BuildError);
                ctx.Log(ex);
                return(false);
            }

            PushFiles(ctx, vcs, stag, false);
            ctx.Server.SetSourceTagBuiltAsync(ctx.AppId, stag.Id);
            return(true);
        }
Beispiel #4
0
 bool HandleError(BuildContext ctx, Exception ex)
 {
     try {
         ctx.Status = "ERROR: " + ex.Message;
         ctx.Log(ex);
         return(true);
     } catch (Exception e) {
         LogService.WriteLine(e);
         ctx.Connected = false;
         return(false);
     }
 }
Beispiel #5
0
        public void UpdateSourceTags(BuildContext ctx, SourceInfo source, bool force)
        {
            if (!force && (DateTime.Now - source.LastFetchTime).TotalMinutes < 5)
            {
                return;
            }
            ctx.Server.SetSourceStatus(ctx.AppId, source.Id, SourceTagStatus.Fetching, "");
            try {
                List <SourceTagInfo> newTags = new List <SourceTagInfo> (source.SourceTags);
                HashSet <string>     newUrls = new HashSet <string> ();

                SourcePuller sp = VersionControl.GetSourcePuller(source.Type);
                foreach (SourceTagInfo st in sp.GetChildUrls(ctx, source))
                {
                    newUrls.Add(st.Url);
                    SourceTagInfo currentTag = source.GetSourceTag(st.Url);
                    if (currentTag == null)
                    {
                        st.Status = SourceTagStatus.Waiting;
                        newTags.Add(st);
                    }
                    else
                    {
                        if (currentTag.LastRevision != st.LastRevision)
                        {
                            source.CleanSources(ctx, currentTag);
                            currentTag.LastRevision = st.LastRevision;
                            currentTag.Status       = SourceTagStatus.Waiting;
                        }
                    }
                }
                foreach (SourceTagInfo st in source.SourceTags)
                {
                    if (!newUrls.Contains(st.Url))
                    {
                        newTags.Remove(st);
                    }
                }
                source.LastFetchTime = DateTime.Now;
                ctx.Server.UpdateSourceTags(ctx.AppId, source.Id, DateTime.Now, newTags.ToArray());
                ctx.Server.SetSourceStatus(ctx.AppId, source.Id, SourceTagStatus.Ready, "");
            }
            catch (Exception ex) {
                ctx.Server.SetSourceStatus(ctx.AppId, source.Id, SourceTagStatus.FetchError, ex.Message);
                ctx.Log(ex);
            }
        }
Beispiel #6
0
 void PushFiles(BuildContext ctx, SourceInfo source, SourceTagInfo stag, bool safe)
 {
     try {
         ctx.Status = "Uploading files for project " + source.ProjectName;
         foreach (string file in Directory.GetFiles (stag.GetPackagePath (ctx))) {
             ctx.Log (LogSeverity.Info, "Uploading [" + source.ProjectName + "] " + Path.GetFileName (file));
             WebRequest req = HttpWebRequest.Create (ctx.ServerUrl + "/package/upload");
             req.Headers ["applicationId"] = ctx.AppId.ToString ();
             req.Headers ["sourceTagId"] = stag.Id.ToString ();
             req.Headers ["fileName"] = Path.GetFileName (file);
             req.Method = "POST";
             req.GetRequestStream ().WriteFile (file);
             using (StreamReader s = new StreamReader (req.GetResponse ().GetResponseStream ())) {
                 if (s.ReadToEnd () != "OK")
                     throw new Exception ("File upload failed");
             }
         }
     } catch {
         if (!safe)
             throw;
     }
     finally {
         ctx.Status = "Files uploaded";
     }
 }
Beispiel #7
0
 bool HandleError(BuildContext ctx, Exception ex)
 {
     try {
         ctx.Status = "ERROR: " + ex.Message;
         ctx.Log (ex);
         return true;
     } catch (Exception e) {
         Console.WriteLine (e);
         ctx.Connected = false;
         return false;
     }
 }
Beispiel #8
0
        bool BuildSource(BuildContext ctx, SourceInfo vcs, SourceTagInfo stag)
        {
            // Fetch the source

            ctx.Status = "Fetching project " + vcs.ProjectName + " (" + stag.Name + ")";

            Util.ResetFolder (stag.GetPackagePath (ctx));

            string logFile = stag.GetLogFile (ctx);

            File.AppendAllText (logFile, "<p><b>Fetching Source</b></p>");
            ctx.Server.SetSourceTagStatus (ctx.AppId, stag.Id, SourceTagStatus.Fetching);
            try {
                FetchSource (ctx, vcs, stag, logFile);
            }
            catch (Exception ex) {
                File.AppendAllText (logFile, HttpUtility.HtmlEncode (ex.Message) + "<br/><br/>");
                PushFiles (ctx, vcs, stag, true);
                ctx.Server.SetSourceTagStatus (ctx.AppId, stag.Id, SourceTagStatus.FetchError);
                ctx.Log (ex);
                return false;
            }

            // Build the add-in

            ctx.Status = "Building project " + vcs.ProjectName;
            File.AppendAllText (logFile, "<p><b>Building Solution</b></p>");
            ctx.Server.SetSourceTagStatus (ctx.AppId, stag.Id, SourceTagStatus.Building);
            try {
                BuildSource (ctx, vcs, stag, logFile);
            }
            catch (Exception ex) {
                File.AppendAllText (logFile, "<p>" + HttpUtility.HtmlEncode (ex.Message) + "</p>");
                PushFiles (ctx, vcs, stag, true);
                ctx.Server.SetSourceTagStatus (ctx.AppId, stag.Id, SourceTagStatus.BuildError);
                ctx.Log (ex);
                return false;
            }

            PushFiles (ctx, vcs, stag, false);
            ctx.Server.SetSourceTagBuiltAsync (ctx.AppId, stag.Id);
            return true;
        }
Beispiel #9
0
        public void UpdateSourceTags(BuildContext ctx, SourceInfo source, bool force)
        {
            if (!force && (DateTime.Now - source.LastFetchTime).TotalMinutes < 5)
                return;
            ctx.Server.SetSourceStatus (ctx.AppId, source.Id, SourceTagStatus.Fetching, "");
            try {
                List<SourceTagInfo> newTags = new List<SourceTagInfo> (source.SourceTags);
                HashSet<string> newUrls = new HashSet<string> ();

                SourcePuller sp = VersionControl.GetSourcePuller (source.Type);
                foreach (SourceTagInfo st in sp.GetChildUrls (ctx, source)) {
                    newUrls.Add (st.Url);
                    SourceTagInfo currentTag = source.GetSourceTag (st.Url);
                    if (currentTag == null) {
                        st.Status = SourceTagStatus.Waiting;
                        newTags.Add (st);
                    }
                    else {
                        if (currentTag.LastRevision != st.LastRevision) {
                            source.CleanSources (ctx, currentTag);
                            currentTag.LastRevision = st.LastRevision;
                            currentTag.Status = SourceTagStatus.Waiting;
                        }
                    }
                }
                foreach (SourceTagInfo st in source.SourceTags) {
                    if (!newUrls.Contains (st.Url))
                        newTags.Remove (st);
                }
                source.LastFetchTime = DateTime.Now;
                ctx.Server.UpdateSourceTags (ctx.AppId, source.Id, DateTime.Now, newTags.ToArray ());
                ctx.Server.SetSourceStatus (ctx.AppId, source.Id, SourceTagStatus.Ready, "");
            }
            catch (Exception ex) {
                ctx.Server.SetSourceStatus (ctx.AppId, source.Id, SourceTagStatus.FetchError, ex.Message);
                ctx.Log (ex);
            }
        }
Beispiel #10
0
        public void RefreshAppRelease(BuildContext ctx, AppReleaseInfo release)
        {
            string filePath = release.GetAssembliesPath (ctx);
            string file = Path.Combine (filePath, "__release.zip");

            string timestamp = release.LastUpdateTime.ToString ();
            string timestampFile = Path.Combine (filePath, "__timestamp");
            try {
                if (File.Exists (timestampFile)) {
                    string date = File.ReadAllText (timestampFile);
                    if (date == timestamp)
                        return;
                }
            } catch (Exception ex) {
                ctx.Log (ex);
            }

            Util.ResetFolder (filePath);

            ctx.Status = "Downloading assembly package for release " + release.AppVersion;

            WebRequest req = HttpWebRequest.Create (ctx.ServerUrl + release.ZipUrl);
            WebResponse res = req.GetResponse ();
            res.GetResponseStream ().SaveToFile (file);

            ctx.Status = "Extracting assemblies for release " + release.AppVersion;

            using (Stream fs = File.OpenRead (file)) {
                ZipFile zfile = new ZipFile (fs);
                foreach (ZipEntry ze in zfile) {
                    string fname = ze.Name.ToLower ();
                    if (fname.EndsWith (".dll") || fname.EndsWith (".exe")) {
                        using (Stream s = zfile.GetInputStream (ze)) {
                            s.SaveToFile (Path.Combine (filePath, Path.GetFileName (ze.Name)));
                        }
                    }
                }
            }
            File.Delete (file);
            File.WriteAllText (timestampFile, timestamp);
            ctx.Status = "Assembly package for release " + release.AppVersion + " isntalled";
        }
Beispiel #11
0
 void ExtractDmg(BuildContext ctx, string filePath, string file)
 {
     ctx.Status ="Extracting DMG";
     string tempPath = Path.Combine (filePath, "__tmp_release");
     string tempPath2 = Path.Combine (filePath, "__tmp_release2");
     Util.ResetFolder (tempPath);
     try {
         Run7z (file, tempPath);
         string hfs = Directory.GetFiles (tempPath, "*.hfs").FirstOrDefault ();
         if (hfs == null) {
             ctx.Log (LogSeverity.Error, "Unknown release archive: " + file);
             return;
         }
         Run7z (hfs, tempPath2);
         CopyDlls (tempPath2, filePath);
     } finally {
         if (Directory.Exists (tempPath))
             Directory.Delete (tempPath, true);
         if (Directory.Exists (tempPath2))
             Directory.Delete (tempPath2, true);
     }
 }
Beispiel #12
0
        public void RefreshAppRelease(BuildContext ctx, AppReleaseInfo release)
        {
            string filePath = release.GetAssembliesPath (ctx);

            string installPath = Path.Combine (filePath, "__install");
            string timestamp = release.LastUpdateTime.ToString ();
            string timestampFile = Path.Combine (filePath, "__timestamp");
            try {
                if (File.Exists (timestampFile) && Directory.Exists (installPath)) {
                    string date = File.ReadAllText (timestampFile);
                    if (date == timestamp)
                        return;
                }
            } catch (Exception ex) {
                ctx.Log (ex);
            }

            Util.ResetFolder (filePath);

            ctx.Status = "Downloading assembly package for release " + release.AppVersion;

            WebRequest req = HttpWebRequest.Create (ctx.ServerUrl + release.ZipUrl);
            WebResponse res = req.GetResponse ();
            string wfname = res.Headers["Content-Disposition"];
            string ext;
            if (string.IsNullOrEmpty (wfname))
                ext = ".zip";
            else
                ext = Path.GetExtension (wfname);

            string file = Path.Combine (filePath, "__release" + ext);
            res.GetResponseStream ().SaveToFile (file);

            ctx.Status = "Extracting assemblies for release " + release.AppVersion;

            if (ext == ".dmg") {
                ExtractDmg (ctx, filePath, file);
            }
            else {
                try {
                    using (Stream fs = File.OpenRead (file)) {
                        ZipFile zfile = new ZipFile (fs);
                        foreach (ZipEntry ze in zfile) {
                            string fname = ze.Name.ToLower ();
                            if (fname.EndsWith (".dll") || fname.EndsWith (".exe")) {
                                using (Stream s = zfile.GetInputStream (ze)) {
                                    s.SaveToFile (Path.Combine (filePath, Path.GetFileName (ze.Name)));
                                }
                            }
                        }
                    }
                } catch (ZipException) {
                    // Maybe it is a dmg after all
                    ExtractDmg (ctx, filePath, file);
                }
            }

            // Extract the whole app, keeping the directory structure

            Run7z (file, installPath);

            File.Delete (file);
            File.WriteAllText (timestampFile, timestamp);
            ctx.Status = "Assembly package for release " + release.AppVersion + " isntalled";
        }
Beispiel #13
0
        public void RefreshAppRelease(BuildContext ctx, AppReleaseInfo release)
        {
            string filePath = release.GetAssembliesPath(ctx);

            string installPath   = Path.Combine(filePath, "__install");
            string timestamp     = release.LastUpdateTime.ToString();
            string timestampFile = Path.Combine(filePath, "__timestamp");

            try {
                if (File.Exists(timestampFile) && Directory.Exists(installPath))
                {
                    string date = File.ReadAllText(timestampFile);
                    if (date == timestamp)
                    {
                        return;
                    }
                }
            } catch (Exception ex) {
                ctx.Log(ex);
            }

            Util.ResetFolder(filePath);

            ctx.Status = "Downloading assembly package for release " + release.AppVersion;

            WebRequest  req    = HttpWebRequest.Create(ctx.ServerUrl + release.ZipUrl);
            WebResponse res    = req.GetResponse();
            string      wfname = res.Headers["Content-Disposition"];
            string      ext;

            if (string.IsNullOrEmpty(wfname))
            {
                ext = ".zip";
            }
            else
            {
                ext = Path.GetExtension(wfname);
            }

            string file = Path.Combine(filePath, "__release" + ext);

            res.GetResponseStream().SaveToFile(file);

            ctx.Status = "Extracting assemblies for release " + release.AppVersion;

            if (ext == ".dmg")
            {
                ExtractDmg(ctx, filePath, file);
            }
            else
            {
                try {
                    using (Stream fs = File.OpenRead(file)) {
                        ZipFile zfile = new ZipFile(fs);
                        foreach (ZipEntry ze in zfile)
                        {
                            string fname = ze.Name.ToLower();
                            if (fname.EndsWith(".dll") || fname.EndsWith(".exe"))
                            {
                                using (Stream s = zfile.GetInputStream(ze)) {
                                    s.SaveToFile(Path.Combine(filePath, Path.GetFileName(ze.Name)));
                                }
                            }
                        }
                    }
                } catch (ZipException) {
                    // Maybe it is a dmg after all
                    ExtractDmg(ctx, filePath, file);
                }
            }

            // Extract the whole app, keeping the directory structure

            Run7z(file, installPath);

            File.Delete(file);
            File.WriteAllText(timestampFile, timestamp);
            ctx.Status = "Assembly package for release " + release.AppVersion + " isntalled";
        }