Background
Break News
How to add local font to Tailwind Css and NextJS? - Tutorial Design Pattern? - Blockchain Technology, How to create own Bitcoin virtual currency - Zustand mordern management state - Design Pattern - Flyweight Pattern? - Docker Full training Topic

[Tutorial] How to build program auto commit source code to SVN using CSharp

Sunday 28 June 2015
|
Read: Completed in minutes

[Tutorial] How to build program auto commit source code to SVN using CSharp

Apache Subversion?





Apache Subversion (often abbreviated SVN, after the command name svn) is a software versioning and revision control system distributed as free software under the Apache License. 
Developers use Subversion to maintain current and historical versions of files such as source code, web pages, and documentation.

This topic is focus How to build program auto commit source code to SVN using C#. Here is my solution also ideas and the source code provide to you for support you build a program with auto comit source code to SVN every time using C# dotnet


How to build program auto commit source code to SVN using CSharp


Download sharpsvn lib and autocommit code from link below
๐Ÿ‘‰ svn lib link:

๐Ÿ‘‰ Backup link:


๐Ÿ‘‰ You can download full source code from this link:



Source code:

Some key function 

        
    /* ************************************************************************
     * Author: Vแป‹LH - Zidane (huuvi168@gmail.com)
     * Last Modified: 20141215
     * clsCommons.cs 
     * ************************************************************************
     */
    
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.IO;
    using System.Text;
    using System.Windows.Forms;
    
    namespace AutoComitGUI
    {
        public class clsCommons
        {
            public static string AppTitle = "Auto Commit";
    
            // AddFileToSVN
            public static bool AddFileToSVN(string strLogFile, string path, 
                                                 Timer myTimer)
            {
                try
                {
                    using (SharpSvn.SvnClient client = new SharpSvn.SvnClient())
                    {
                        Collection<sharpsvn.svnstatuseventargs> changeFiles = new 
                                        Collection<sharpsvn.svnstatuseventargs>();
                        client.GetStatus(path, out changeFiles);
    
                        foreach (SharpSvn.SvnStatusEventArgs changeFile in 
                                                             changeFiles)
                        {
                            if (changeFile.LocalContentStatus == 
                                               SharpSvn.SvnStatus.Missing)
                            {
                                client.Delete(changeFile.Path);
                                WriteLog(strLogFile, changeFile.Path + " Removed - 
                                         Missing files (that are not in filesystem)");
    
                                myTimer.Enabled = false;
                            }
    
                            if (changeFile.LocalContentStatus == 
                                             SharpSvn.SvnStatus.NotVersioned)
                            {
                                client.Add(changeFile.Path);
                                WriteLog(strLogFile, changeFile.Path + " Added - 
                                           This file is new in filesystem!");
    
                                myTimer.Enabled = false;
                            }
                        }
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    myTimer.Enabled = true;
                    WriteLog(strLogFile, ex);
                    return false;
                }
            }
    
            // CommitToSVN
            public static bool CommitToSVN(string strLogFile, string workingcopy, 
                                                  string message, Timer myTimer)
            {
                using (SharpSvn.SvnClient client = new SharpSvn.SvnClient())
                {
                    SharpSvn.SvnCommitArgs args = new SharpSvn.SvnCommitArgs();
    
                    args.LogMessage = message;
                    args.ThrowOnError = true;
                    args.ThrowOnCancel = true;
    
                    try
                    {
                        myTimer.Enabled = true;
                        return client.Commit(workingcopy, args);
                    }
                    catch (Exception ex)
                    {
                        myTimer.Enabled = true;
                        WriteLog(strLogFile, ex);
                        return false;
                    }
                }
            }
    
            /// <summary>
            /// Write strContent into strPath
            /// \nMode=1: CreateNew (if new will overwrite, if not exist will create) / 2:Append
            /// </summary>
            /// <param name="strPath" /> Path of file
            /// <param name="strContent" /> content of file
            /// <param name="Mode" /> 1: CreateNew  (if new will overwrite, if not exist will create) / 2:Append
            /// <param name="Encoding" /> Unicode/ANSCII
            /// <returns>true -> succeed</returns>
            public static bool WriteFile(string strPath, List<pre> lstContent, 
                                      int iMode, Encoding en)
            {
                bool bFlag = false;
                FileStream fs = null;
    
                try
                {
                    switch (iMode)
                    {
                        case 1:
                            fs = new FileStream(strPath, FileMode.Create);
                            break;
    
                        case 2:
                            fs = new FileStream(strPath, FileMode.Append);
                            break;
    
                        default:
                            fs = new FileStream(strPath, FileMode.Append);
                            break;
                    }
    
                    // Encoding en = Encoding.Unicode!
    
                    using (StreamWriter sw = new StreamWriter(fs, en))
                    {
                        for (int i = 0; i < lstContent.Count; i++)
                            sw.WriteLine(lstContent[i]);
    
                        sw.Close();
                    }
                    fs.Close();
    
                    bFlag = true;
                }
                catch
                {
                    return bFlag;
                }
                return bFlag;
            }
    
            /// <summary>
            /// Write content strContent into strPath
            /// \nMode=1: CreateNew  (if new will overwrite, if not exist will create) / 2:Append
            /// </summary>
            /// <param name="strPath" /> path of file
            /// <param name="strContent" /> content of file
            /// <param name="Mode" /> 1: CreateNew  (if new will overwrite, if not exist will create) / 2:Append
            /// <returns>true -> succeed</returns>
            public static bool WriteFile(string szPath, string szContent, int iMode, 
                                                                       Encoding en)
            {
                bool bFlag = false;
                FileStream fs = null;
    
                try
                {
                    switch (iMode)
                    {
                        case 1:
                            fs = new FileStream(szPath, FileMode.Create);
                            break;
    
                        case 2:
                            fs = new FileStream(szPath, FileMode.Append);
                            break;
    
                        default:
                            fs = new FileStream(szPath, FileMode.Append);
                            break;
                    }
    
                    using (StreamWriter sw = new StreamWriter(fs, en))
                    {
                        sw.WriteLine(szContent);
                        sw.Close();
                    }
                    fs.Close();
    
                    bFlag = true;
                }
                catch
                {
                    return bFlag;
                }
                return bFlag;
            }
    
    
            /// <summary>
            /// Write content strContent into path strPath
            /// \nMode=1: CreateNew  (if new will overwrite, if not exist will create) / 2:Append
            /// </summary>
            /// <param name="strPath" /> Path of file
            /// <param name="strContent" /> Content of file
            /// <param name="Mode" />1: CreateNew  (if new will overwrite, if not exist will create) / 2:Append
            /// <returns>true -> succeed</returns>
            public static bool WriteFile(string strPath, List<code> lstContent, int iMode)
            {
                bool bFlag = false;
                FileStream fs = null;
    
                try
                {
                    switch (iMode)
                    {
                        case 1:
                            fs = new FileStream(strPath, FileMode.Create);
                            break;
    
                        case 2:
                            fs = new FileStream(strPath, FileMode.Append);
                            break;
    
                        default:
                            fs = new FileStream(strPath, FileMode.Append);
                            break;
                    }
    
                    using (StreamWriter sw = new StreamWriter(fs, Encoding.Unicode))
                    {
                        for (int i = 0; i < lstContent.Count; i++)
                            sw.WriteLine(lstContent[i]);
    
                        sw.Close();
                    }
                    fs.Close();
    
                    bFlag = true;
                }
                catch
                {
    
                    return bFlag;
                }
                return bFlag;
            }
    
    
            public static void WriteLog(string strLogFolder, System.Exception ex)
            {
                try
                {
    
                    string strDate = "[" +
                                            DateTime.Today.Year + "-" + 
                                  DateTime.Today.Month + "-" + DateTime.Today.Day + " " +
                                            DateTime.Now.Hour + ":" + 
                                  DateTime.Now.Minute + ":" + DateTime.Now.Second +
                                     "]: ";
    
                    string strLog = " * " + strDate + "Message = " + ex.Message.ToString() + 
                               "; TargetSite = " + ex.TargetSite + 
                               "; StackTrace = " + ex.StackTrace;
    
                    WriteFile(strLogFolder, strLog, 2, Encoding.UTF8);
                }
                catch { }
            }
    
    
            public static void WriteLog(string strLogFolder, string strLog)
            {
                try
                {
                    string strDate = "[" +
                                            DateTime.Today.Year + "-" + 
                                   DateTime.Today.Month + "-" + DateTime.Today.Day + " " +
                                            DateTime.Now.Hour + ":" + 
                                   DateTime.Now.Minute + ":" + DateTime.Now.Second +
                                     "]: ";
    
                    WriteFile(strLogFolder, " * " + strDate + "\t" + strLog, 2, 
                                                                  Encoding.UTF8);
                }
                catch { }
            }
    
          
        }
    }
    


	
    
    /* ************************************************************************
     * Author: Vแป‹LH - Zidane (huuvi168@gmail.com)
     * Last Modified: 20141215 
     * frmMain.cs
     * ************************************************************************
     */
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Text;
    using System.Windows.Forms;
    
    namespace AutoComitGUI
    {
        public partial class frmAutoCommit : Form
        {
            private static string _fileName;
            private static string _path;
            private static string _section;
            private static string _keyLocalPatch;
            private static string _keyHour;
            private static string _keyMinute;
            private static string _keySecond;
            private static string _keyAuthor;
            private static string _keyEmail;
    
            private static clsIniFile _iniFile;
    
            public frmAutoCommit()
            {
                InitializeComponent();
    
                _fileName = "info.ini";
                _path = Application.StartupPath + "\\" + _fileName;
                _iniFile = new clsIniFile(_path);
    
                _section = "AutoCommit";
                _keyLocalPatch = "LocalPatch";
                _keyHour = "Hour";
                _keyMinute = "Minute";
                _keySecond = "Second";
                _keyAuthor = "Author";
                _keyEmail = "Email";
    
    
    
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                myNotifyIcon.ShowBalloonTip(10, clsCommons.AppTitle, 
                                      "Auto commit file on SVN", ToolTipIcon.Info);
    
                // init comboBox
                Init();
    
                // init file
                loadInfo();
            }
    
            private void Init()
            {
                for (int i = 0; i <= 23; i++)
                    cmbHour.Items.Add(i.ToString());
    
                for (int i = 0; i <= 59; i++)
                {
                    cmbMinute.Items.Add(i.ToString());
                    cmbSecond.Items.Add(i.ToString());
                }
            }
    
            private void WriteInfo(clsInfo clsInfo)
            {
    
                clsIniFile iniFile = new clsIniFile(_path);
    
                iniFile.Write(_section, _keyAuthor, clsInfo.Author);
                iniFile.Write(_section, _keyEmail, clsInfo.Email);
                iniFile.Write(_section, _keyLocalPatch, clsInfo.LocalPath);
                iniFile.Write(_section, _keyHour, clsInfo.Hour.ToString());
                iniFile.Write(_section, _keyMinute, clsInfo.Minute.ToString());
                iniFile.Write(_section, _keySecond, clsInfo.Second.ToString());
    
            }
    
            private void loadInfo()
            {
    
    
                if (!File.Exists(_path))  // ko tรฌm thแบฅy
                {
                    // create file
                    clsInfo info = new clsInfo();
                    info.Hour = 8;
                    info.Minute = 10;
                    info.Second = 10;
                    info.LocalPath = @"E:\GitHub\AutoCommitSVN";
    
                    WriteInfo(info);
                }
    
                txtLocalPath.Text = _iniFile.Read(_section, _keyLocalPatch);
                cmbHour.Text = _iniFile.Read(_section, _keyHour);
                cmbMinute.Text = _iniFile.Read(_section, _keyMinute);
                cmbSecond.Text = _iniFile.Read(_section, _keySecond);
            }
    
            private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
            {
    
                if (WindowState == FormWindowState.Normal)
                {
                    myTimer.Enabled = true;
                    this.Hide();
                    myNotifyIcon.Visible = true;
                    WindowState = FormWindowState.Minimized;
                }
                else if (WindowState == FormWindowState.Minimized)
                {
                    myTimer.Enabled = false;
                    this.Show();
                    myNotifyIcon.Visible = false;
                    WindowState = FormWindowState.Normal;
                }
            }
    
            private void Form1_Resize(object sender, EventArgs e)
            {
                if (WindowState == FormWindowState.Minimized)
                {
                    // Do some stuff
                    myNotifyIcon.Visible = true;
    
                    // Chแปn แบฉn
                    this.Hide();
                    this.ShowInTaskbar = false;
    
                    string szLocalPath = _iniFile.Read(_section, _keyLocalPatch);
                    string szHour = _iniFile.Read(_section, _keyHour);
                    string szMinute = _iniFile.Read(_section, _keyMinute);
                    string szSecond = _iniFile.Read(_section, _keySecond);
    
                    string szMessage = "On: " + szHour + ":" + szMinute + " 
                           everyday, auto commit to svn from this repos:\n" + szLocalPath;
                    myNotifyIcon.ShowBalloonTip(10, clsCommons.AppTitle, 
                                                     szMessage, ToolTipIcon.Info);
                    myTimer.Enabled = true;
                }
            }
    
            private void btnUpdate_Click(object sender, EventArgs e)
            {
                clsInfo info = new AutoComitGUI.clsInfo();
    
                info.LocalPath = txtLocalPath.Text;
                info.Hour = cmbHour.SelectedIndex;
                info.Minute = cmbMinute.SelectedIndex;
                info.Second = cmbSecond.SelectedIndex;
    
                WriteInfo(info);
    
                MessageBox.Show("Settings updated!", clsCommons.AppTitle, 
                                     MessageBoxButtons.OK, MessageBoxIcon.Information);
    
    
                myTimer.Enabled = true;
            }
    
            private void btnExit_Click(object sender, EventArgs e)
            {
                myNotifyIcon.Dispose(); // delete icon
                this.Close();
            }
    
            private void frmAutoCommit_FormClosed(object sender, FormClosedEventArgs e)
            {
                clsInfo info = new AutoComitGUI.clsInfo();
    
                loadInfo();
                info.Hour = cmbHour.SelectedIndex;
                info.Minute = cmbMinute.SelectedIndex;
                info.Second = cmbSecond.SelectedIndex;
                info.LocalPath = txtLocalPath.Text;
    
                WriteInfo(info);
            }
    
            private void btnBrowser_Click(object sender, EventArgs e)
            {
                // Show the FolderBrowserDialog.
    
                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
                DialogResult result = folderBrowserDialog.ShowDialog();
                folderBrowserDialog.ShowNewFolderButton = false;
                if (result == DialogResult.OK)
                {
                    txtLocalPath.Text = folderBrowserDialog.SelectedPath;
                }
            }
    
            private void myTimer_Tick(object sender, EventArgs e)
            {
                int hour = DateTime.Now.Hour;
                int minute = DateTime.Now.Minute;
                int second = DateTime.Now.Second;
    
                string szLocalPatch = _iniFile.Read(_section, _keyLocalPatch);
                string szHour = _iniFile.Read(_section, _keyHour);
                string szMinute = _iniFile.Read(_section, _keyMinute);
                string szSecond = _iniFile.Read(_section, _keySecond);
                            
                int Year = DateTime.Now.Year;
                int Month = DateTime.Now.Month;
                int Day = DateTime.Now.Day;
    
                string logFolder = Application.StartupPath + "\\Log";
                string logFile = Application.StartupPath + "\\Log\\" + 
                                          Year + Month + Day + ".txt";
    
                try
                {
    
                    if (hour == Convert.ToInt16(szHour))
                        if (Convert.ToInt16(szMinute) - 1 <= minute && 
                                      minute <= Convert.ToInt16(szMinute) + 1)
                        {
                         
                           
                            if (!Directory.Exists(logFolder))
                                Directory.CreateDirectory(logFolder);
    
                            bool bFlag = clsCommons.AddFileToSVN(logFile, szLocalPatch, myTimer);
    
                            if (bFlag == true)
                            {
                                myNotifyIcon.ShowBalloonTip(5, clsCommons.AppTitle, 
                                       "Add Files To SVN finished!", ToolTipIcon.Info);
                                string szMessage = "<commit autocommit="" by="" tool=""> 
                                       Update Final Version To SVN, Last Update: " 
                                                            + Year + Month + Day;
                                bFlag = clsCommons.CommitToSVN(logFile, szLocalPatch, 
                                                       szMessage, myTimer);
    
                                if (bFlag == true)
                                    myNotifyIcon.ShowBalloonTip(5, clsCommons.AppTitle, 
                                            "Commit Succeed!", ToolTipIcon.Info);
    
                                else 
                                    myNotifyIcon.ShowBalloonTip(5, clsCommons.AppTitle, 
                                            "Commit Fail, Please Check Log File!", 
                                                                     ToolTipIcon.Info);
                            }
    
                            else
                                myNotifyIcon.ShowBalloonTip(5, clsCommons.AppTitle, 
                                    "Add Files Fail, Please Check Log File!", 
                                                                     ToolTipIcon.Info);
    
                        }
                }
                catch (Exception ex)
                {
                    clsCommons.WriteLog(logFile, ex);
                }
            }
        }
    }
    
    
    /* ************************************************************************
     * Author: Vแป‹LH - Zidane (huuvi168@gmail.com)
     * Last Modified: 20141215 
     * clsInfo.cs
     * ************************************************************************/
    
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace AutoComitGUI
    {
        public class clsInfo
        {
            private string _author;
            private string _email;
            private string _localPath;
            private int _hour;
            private int _minute;
            private int _second;
    
            public clsInfo()
            {
                Author = "ViLH";
                Email = "huuvi168@gmail.com";
            }
    
            public string Email
            {
                get { return _email; }
                set { _email = value; }
            }
    
            public string Author
            {
                get { return _author; }
                set { _author = value; }
            }
    
            public int Hour
            {
                get { return _hour; }
                set { _hour = value; }
            }
    
            public int Minute
            {
                get { return _minute; }
                set { _minute = value; }
            }
    
            public int Second
            {
                get { return _second; }
                set { _second = value; }
            }
    
            public string LocalPath
            {
                get { return _localPath; }
                set { _localPath = value; }
            }
        }
    }
    
    /* ************************************************************************
     * Author: Vแป‹LH - Zidane (huuvi168@gmail.com)
     * Last Modified: 20141215 
     * clsIniFile.cs
     * ************************************************************************
     */
    
    using System;
    using System.Collections.Generic;
    using System.Runtime.InteropServices;
    using System.Text;
    
    /* 
     * How to use: clsIniFile
     * 
     * --> Write file 
     * clsIniFile inif = new clsIniFile("D:\\config.ini");
     * inif.Write("Database", "Devs", "sa");
     * 
     * => [Database]
     *    Devs=sa;
     * 
     * --> Read file
     * clsIniFile inif = new clsIniFile("D:\\config.ini");
     * Console.WriteLine("The Value is:" + inif.Read("Database", "Devs"));
     * => sa
     * 
     */
    
    namespace AutoComitGUI
    {
        public class clsIniFile
        {
            private string filePath;
             
            [DllImport("kernel32")]
            private static extern long WritePrivateProfileString(string section,
                                        string key,
                                        string val,
                                        string filePath);
     
            [DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section,
                                        string key,
                                        string def,
                                        StringBuilder retVal,
                                        int size,
                                        string filePath);
    
            public clsIniFile(string filePath)
            {
                this.filePath = filePath;
            }
     
            public void Write(string section, string key, string value)
            {
                WritePrivateProfileString(section, key, value.ToLower(),  
                                                          this.filePath);
            }
     
            public string Read(string section, string key)
            {
                StringBuilder SB = new StringBuilder(255);
                int i = GetPrivateProfileString(section, key, "", SB, 255, 
                                                           this.filePath);
                return SB.ToString();
            }
             
            public string FilePath
            {
                get { return this.filePath; }
                set { this.filePath = value; }
            }
        }
    }   
    


๐Ÿ‘‰ You can download full source code from this link:


View here for more information with ini files from here
https://learn-tech-tips.blogspot.com/2015/06/how-to-read-write-ini-file-in-C-Sharp.html

Any question or any feedback, please leave your comment. We can discuss about it!

Are you interested in topic How to build program auto commit source code to SVN using CSharp from Webzone Tech Tips? If you have any thoughts or questions, please share them in the comment section below. I would love to hear from you and chat about it

Webzone Tech Tips Zidane


๐Ÿ™‡๐Ÿผ Your Feedback Is Valuable and Helpful to Us - Webzone - all things Tech Tips web development Zidane ๐Ÿ™‡๐Ÿผ
Popular Webzone Tech Tips topic maybe you will be like it - by Webzone Tech Tips - Zidane
As a student, I found Blogspot very useful when I joined in 2014. I have been a developer for years . To give back and share what I learned, I started Webzone, a blog with tech tips. You can also search for tech tips zidane on Google and find my helpful posts. Love you all,

I am glad you visited my blog. I hope you find it useful for learning tech tips and webzone tricks. If you have any technical issues, feel free to browse my posts and see if they can help you solve them. You can also leave a comment or contact me if you need more assistance. Here is my blog address: https://learn-tech-tips.blogspot.com.

My blog where I share my passion for web development, webzone design, and tech tips. You will find tutorials on how to build websites from scratch, using hot trends frameworks like nestjs, nextjs, cakephp, devops, docker, and more. You will also learn how to fix common bugs on development, like a mini stackoverflow. Plus, you will discover how to easily learn programming languages such as PHP (CAKEPHP, LARAVEL), C#, C++, Web(HTML, CSS, javascript), and other useful things like Office (Excel, Photoshop). I hope you enjoy my blog and find it helpful for your projects. :)

Thanks and Best Regards!
Follow me on Tiktok @learntechtips and send me a direct message. I will be happy to chat with you.
Webzone - Zidane (huuvi168@gmail.com)
I'm developer, I like code, I like to learn new technology and want to be friend with people for learn each other
I'm a developer who loves coding, learning new technologies, and making friends with people who share the same passion. I have been a full stack developer since 2015, with more than years of experience in web development.
Copyright @2022(November) Version 1.0.0 - By Webzone, all things Tech Tips for Web Development Zidane
https://learn-tech-tips.blogspot.com