VSS信息的读取的操作

Posted on 2006-01-20 14:55  A.Z  阅读(2565)  评论(5编辑  收藏  举报
无聊的时候突然想要看看VSS里面都发生了什么,好下面看一下怎么看VSS里面的东东。
本篇没有参考什么,纯属自编,如果有什么不对的地方请提出。
作为延伸,你可以考虑一下怎么把指定的时间点的vss内容取出编译。
提示:代码不太规范,请勿仿照。


  1using System;
  2using System.Diagnostics;
  3using System.Drawing;
  4using System.Collections;
  5using System.ComponentModel;
  6using System.Threading;
  7using System.Windows.Forms;
  8using System.Data;
  9using DevExpress.XtraTreeList;
 10using DevExpress.XtraTreeList.Nodes;
 11using SourceSafeTypeLib;
 12
 13namespace VssInfo
 14{
 15    /// <summary>
 16    /// Summary description for Form1.
 17    /// </summary>

 18    public class Form1 : System.Windows.Forms.Form
 19    {
 20        private DevExpress.XtraTreeList.TreeList treeList1;
 21        private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn1;
 22        private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn2;
 23        private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn3;
 24        private System.Windows.Forms.Panel panel1;
 25        private DevExpress.XtraEditors.ComboBoxEdit comboBoxEdit1;
 26        private DevExpress.XtraEditors.SimpleButton simpleButton1;
 27        private DevExpress.XtraEditors.RadioGroup radioGroup1;
 28        private DevExpress.XtraTreeList.Columns.TreeListColumn treeListColumn4;
 29        /// <summary>
 30        /// Required designer variable.
 31        /// </summary>

 32        private System.ComponentModel.Container components = null;
 33
 34        public Form1()
 35        {
 36            //
 37            // Required for Windows Form Designer support
 38            //
 39            InitializeComponent();
 40
 41            //
 42            // TODO: Add any constructor code after InitializeComponent call
 43            //
 44        }

 45
 46        private void ViewVSS(string srcsafeINI, string username, string password)
 47        {
 48            UIInvoke invoke = new UIInvoke(this);
 49            invoke.DOLockReloadNodes();
 50            invoke.DoClearNodes();
 51            VSSDatabase database = new VSSDatabase();
 52            
 53            database.Open(srcsafeINI, username, password);
 54            IVSSItems items = database.get_VSSItem("$/"false).get_Items(false);
 55            
 56            Loop(items);
 57            invoke.DOUnlockReloadNodes();
 58
 59            System.Runtime.InteropServices.Marshal.ReleaseComObject(database);
 60            database = null;
 61
 62        }

 63
 64        private void Loop(IVSSItems  items )
 65        {
 66            foreach(IVSSItem item in items)
 67            {
 68                if(!item.Deleted)
 69                {
 70                    if(item.Type == (int) VSSItemType.VSSITEM_FILE)
 71                    {
 72
 73                        if(GetOPType == Type.CheckOut )
 74                        {
 75                            if(item.IsCheckedOut == (int) VSSFileStatus.VSSFILE_CHECKEDOUT || item.IsCheckedOut == (int) VSSFileStatus.VSSFILE_CHECKEDOUT_ME)
 76                            {
 77                                UIInvoke invoke = new UIInvoke(this);
 78
 79                                invoke.Spec = item.Spec;
 80
 81                                foreach(IVSSCheckout checkoutClass in item.Checkouts)
 82                                {
 83                                    invoke.Username = checkoutClass.Username;
 84                                    invoke.MachineName = checkoutClass.Machine;
 85                                    invoke.Date = checkoutClass.Date.ToShortDateString();
 86
 87                                }

 88                                invoke.Invoke();
 89                            }

 90                        }

 91                        else
 92                        {
 93                            IVSSVersions versions = item.get_Versions(0);
 94                            IEnumerator enumerator = versions.GetEnumerator();
 95                            while(enumerator.MoveNext())
 96                            {
 97                                IVSSVersion  version =(IVSSVersion) enumerator.Current;
 98
 99
100                                if(version.VersionNumber == item.VersionNumber)
101                                {
102                                    if(version.Date.DayOfYear >= DateTime.Now.DayOfYear -1  && version.Date.DayOfYear <= DateTime.Now.DayOfYear )
103                                    {
104                                        UIInvoke invoke = new UIInvoke(this);
105
106                                        invoke.Spec = item.Spec;
107                                        invoke.Username = version.Username;
108                                        invoke.Date = version.Date.ToShortDateString();
109
110                                        foreach(IVSSCheckout checkoutClass in item.get_Version(item.VersionNumber).Checkouts)
111                                        {
112                                            invoke.MachineName = checkoutClass.Machine;
113                                        }

114                                        invoke.Invoke();
115                                    }

116                                    while(enumerator.MoveNext())
117                                    {
118                                        
119                                    }

120                                
121
122                                }

123
124                            }

125                        }

126                    }

127
128                    else
129                    {
130                        Loop(item.get_Items(false));
131                    }

132                }

133
134
135            }

136
137        }

138
139
140        private class UIInvoke
141        {
142            public string Spec;
143            public string Username;
144            public string MachineName;
145            public string Date;
146            Form1 _form1;
147            
148            delegate void  MyInvoke();
149            public UIInvoke(Form1 form1)
150            {
151                _form1 = form1;
152            }

153            public void Invoke()
154            {
155                _form1.treeList1.Invoke(new MyInvoke(DOInvoke));
156            }

157            public void DOLockReloadNodes()
158            {
159                _form1.treeList1.Invoke(new MyInvoke(BeginUnboundLoad));
160            }

161            public void DOUnlockReloadNodes()
162            {
163                _form1.treeList1.Invoke(new MyInvoke(EndUnboundLoad));
164            }

165            public void DoClearNodes()
166            {
167                _form1.treeList1.Invoke(new MyInvoke(ClearNodes));
168            }

169
170            void BeginUnboundLoad()
171            {
172                _form1.treeList1.LockReloadNodes();
173            }

174            void EndUnboundLoad()
175            {
176                _form1.treeList1.UnlockReloadNodes();
177            }

178            void ClearNodes()
179            {
180                _form1.treeList1.ClearNodes();
181            }

182
183
184
185
186
187
188
189
190            void DOInvoke()
191            {
192                TreeListNode node = this._form1.treeList1.AppendNode(nullnull);
193                node[_form1.treeListColumn2] = Spec;
194                node[_form1.treeListColumn1] = Username;
195                node[_form1.treeListColumn4] = Date;
196                node[_form1.treeListColumn3] = MachineName;
197            }

198
199            
200        }

201
202
203
204        /// <summary>
205        /// Clean up any resources being used.
206        /// </summary>

207        protected override void Dispose( bool disposing )
208        {
209            if( disposing )
210            {
211                if(thread != null && thread.IsAlive)
212                {
213                    try
214                    {
215                        thread.Abort();
216                    }

217                    catch
218                    {
219                    }

220                    finally
221                    {
222                        thread = null;
223                    }

224                }

225                if (components != null
226                {
227
228                    components.Dispose();
229                }

230                
231            }

232            base.Dispose( disposing );
233        }

234
235        Windows Form Designer generated code
379
380        /// <summary>
381        /// The main entry point for the application.
382        /// </summary>

383        [STAThread]
384        static void Main() 
385        {
386            Application.Run(new Form1());
387        }

388        Thread thread = null;
389        private void simpleButton1_Click(object sender, System.EventArgs e)
390        {
391            this.simpleButton1.Enabled = false;
392            thread = new Thread(new ThreadStart(DoOP));
393            thread.Start();
394        }

395        private void DoOP()
396        {
397
398            string v3 = @"xxxxx\srcsafe.ini";
399            string xxx_net = @"xxxx\srcsafe.ini";
400            string v4 = @"xxxxxxx\srcsafe.ini";
401            string username = "xxxx";
402            string password = "";
403
404            switch(this.comboBoxEdit1.SelectedIndex)
405            {
406                case 0:
407                    ViewVSS(v3, username , password);
408                    break;
409                case 1:
410                    ViewVSS(cmp_net, username, password);
411                    break;
412                case 2:
413                    ViewVSS(v4, username, password);
414                    break;
415                default:
416                    break;
417            }

418            this.simpleButton1.Enabled = true;
419        }

420
421        Type GetOPType
422        {
423            get
424            {
425                return radioGroup1.SelectedIndex == 0 ? Type.Now : Type.CheckOut;
426            }

427        }

428
429        private enum Type
430        {
431            Now,
432            CheckOut
433        }

434
435
436        
437
438        
439
440    }

441}

442



放在首页一天,谢谢。