Показаны сообщения с ярлыком C#. Показать все сообщения
Показаны сообщения с ярлыком C#. Показать все сообщения

пятница, 17 февраля 2012 г.

regex last \ in path replace with file prefix


            private string GenFileName(string SourceFile)
            {
                // last slash(\) replace with slash and file prifix (\TMP_)
                return Regex.Replace(SourceFile, @"\\(?=[^\\]*$)", @"\TMP_");
            }

пятница, 20 января 2012 г.

TFS Service Development: Set ChangedBy field for workitem


Case: You are developing service, that should change some WorkItems in Team Foundation Server.
Service should set field ChangedBy properly.


var collection1 = new TfsTeamProjectCollection(new Uri("http://tfs:8080/tfs/collection"));
collection1.EnsureAuthenticated();

var ims = collection1.GetService<IIdentityManagementService>();
var id = ims.ReadIdentity(IdentitySearchFactor.AccountName, "domain\\username"MembershipQuery.None, ReadIdentityOptions.None);

var collection = new TfsTeamProjectCollection(new Uri("http://tfs:8080/tfs/collection"), id.Descriptor);

-- OR --

WorkItem wi;
...
// Change Work Item
...
// Set ChangedBy Field
wi[CoreField.ChangedBy] = userName;
wi.Save();

среда, 24 августа 2011 г.

How to convert TFS folder to branch programmatically by TFS API (Convert to Branch operation in VS2010))


How to convert TFS folder to branch programmatically by TFS API (Convert to Branch operation in VS2010))

First you need create instance of VersionControlServer object. Then use CreateBranchObject method. serverTrunkPath="C:\myWorkspace\trunk" - target folder you want to make branch.

versionControlServer.CreateBranchObject(new BranchProperties(new ItemIdentifier(serverTrunkPath)));

вторник, 22 марта 2011 г.

Select filename from file path


To get file name from file path by Regex:

string file = Regex.Match(FilePath, @"(?<=([\\/]))([^\\/])*?$").Value;

Example:
FilePath="/UI/Pages/WorkItems/QueryExplorer.aspx"
file="QueryExplorer.aspx"

четверг, 10 февраля 2011 г.

Convert files from Dos to Unix and back.


        private void Unix2Dos(string fileName)
        {
            const byte CR = 0x0D;
            const byte LF = 0x0A;
            byte[] DOS_LINE_ENDING = new byte[] { CR, LF };
            byte[] data = File.ReadAllBytes(fileName);
            using (FileStream fileStream = File.OpenWrite(fileName))
            {
                BinaryWriter bw = new BinaryWriter(fileStream);
                int position = 0;
                int index = 0;
                do
                {
                    index = Array.IndexOf<byte>(data, LF, position);
                    if (index >= 0)
                    {
                        if ( ( index > 0 ) && (data[index - 1] == CR ))
                        {
                            // already dos ending
                            bw.Write(data, position, index - position + 1);
                        }
                        else
                        {
                            bw.Write(data, position, index - position);
                            bw.Write(DOS_LINE_ENDING);
                        }
                        position = index + 1;
                    }
                }
                while (index > 0);
                bw.Write(data, position, data.Length - position);
               fileStream.SetLength(fileStream.Position);
            }
        }

        private void Dos2Unix(string fileName)
        {
            const byte CR = 0x0D;
            const byte LF = 0x0A;
            byte[] data = File.ReadAllBytes(fileName);
            using (FileStream fileStream = File.OpenWrite(fileName))
            {
                BinaryWriter bw = new BinaryWriter(fileStream);
                int position = 0;
                int index = 0;
                do
                {
                    index = Array.IndexOf<byte>(data, CR, position);
                    if ((index >= 0) && (data[index + 1] == LF))
                    {
                        // Write before the CR
                        bw.Write(data, position, index - position);
                        // from LF
                        position = index + 1;
                    }
                }
                while (index > 0);
                bw.Write(data, position, data.Length - position);
                fileStream.SetLength(fileStream.Position);
            }
        }

четверг, 3 февраля 2011 г.

TFS: To make merge from stablility or build Label to trunk

For example, you have code labelled "Stable_1" in development branch and you need to merge the code to trunk.

string SourceLabel = "Stable_1"
GetStatus status = workspace.Merge
    (DevelopmentPath, TrunkPath,
    null, VersionSpec.ParseSingleSpec( "L" + SourceLabel, null ),
    LockLevel.CheckOut, RecursionType.Full, MergeOptions.None);