Beispiel #1
0
        /// <summary>
        /// Checks out an item</summary>
        /// <param name="uri">URI representing the path to item</param>
        public override void CheckOut(Uri uri)
        {
            CheckUri(uri);

            FileInfo info = GetInfo(uri);
            if (info.IsLocked)
            {
                var lockUser = string.IsNullOrEmpty(info.OtherLock) ? m_connectionManager.UserName : info.OtherLock;

                // There's no guarantee that the caller is in a transaction, and so throwing an
                //  InvalidTransactionException here could crash the app. Let's just output the message.
                Outputs.WriteLine(OutputMessageType.Warning, "The document is locked by another user: "******"edit", uri.Path())
                     && AllowMultipleCheckout
                     || RunCommand("lock", uri.Path()));
        }
Beispiel #2
0
        /// <summary>
        /// Exports a file of the specified revision to a designated location</summary>
        /// <param name="sourceUri">Source file URI</param>
        /// <param name="destUri">Designated location URI</param>
        /// <param name="revision">Source control revision of file</param>
        public override void Export(Uri sourceUri, Uri destUri, SourceControlRevision revision)
        {
            if (!(Enabled && m_connectionManager.InitializeConnection()))
                return;
            
            string toPath = destUri.Path();
            string fromPath = sourceUri.Path();

            switch (revision.Kind)
            {
                case SourceControlRevisionKind.Number:
                    fromPath += "#" + revision.Number;
                    break;
                case SourceControlRevisionKind.Unspecified:
                    throw new NotSupportedException("Can't export revision of none ");
                //fromPath += "#none";
                //break;
                case SourceControlRevisionKind.Base:
                    fromPath += "#have";
                    break;
                case SourceControlRevisionKind.Head:
                    fromPath += "#head";
                    break;
                case SourceControlRevisionKind.Working:
                    //just file copy 
                    System.IO.File.Copy(fromPath, toPath, true);
                    return;
                case SourceControlRevisionKind.Date:
                    fromPath += "@" + revision.Date;
                    break;
                case SourceControlRevisionKind.ChangeList:
                    fromPath += "@" + revision.ChangeListNumber;
                    break;
            }

            RunP4Command("print", "-q", "-o", toPath, fromPath);

        }
Beispiel #3
0
        /// <summary>
        /// Get the revision logs for an item</summary>
        /// <param name="uri">URI representing the path to item</param>
        /// <returns>Returns revision history logs in a table, where each row is a revision record</returns>
        public override DataTable GetRevisionLog(Uri uri)
        {
            CheckUri(uri);

            DataTable p4DataTable = new DataTable("Perforce Revisions");

            if (Enabled && m_connectionManager.InitializeConnection())
            {
                var path = uri.Path();

                var p4RecordSet =
                    RunP4Command("changes", "-s", "submitted", "-l", "-m", "100", path);

                if (p4RecordSet.TaggedOutput.Count == 0)
                    return p4DataTable;

                p4DataTable.Columns.Add(
                    new DataColumn
                    {
                        DataType = Type.GetType("System.Int32"),
                        ColumnName = "revision",
                        ReadOnly = true,
                        Unique = true
                    });

                p4DataTable.Columns.Add(
                    new DataColumn
                    {
                        DataType = Type.GetType("System.String"),
                        ColumnName = "user"
                    });

                p4DataTable.Columns.Add(
                    new DataColumn
                    {
                        DataType = Type.GetType("System.String"),
                        ColumnName = "description"
                    });

                p4DataTable.Columns.Add(
                    new DataColumn
                    {
                        DataType = Type.GetType("System.String"),
                        ColumnName = "status"
                    });

                p4DataTable.Columns.Add(
                    new DataColumn
                    {
                        DataType = Type.GetType("System.String"),
                        ColumnName = "client"
                    });

                p4DataTable.Columns.Add(
                    new DataColumn
                    {
                        DataType = Type.GetType("System.DateTime"),
                        ColumnName = "time"
                    });

                // Valid keys on each record in this particular record set:
                // "user", "change", "desc", "status", "client", "time"
                foreach (var record in p4RecordSet.TaggedOutput)
                {
                    string change = record["change"];
                    string user = record["user"];
                    string desc = record["desc"];
                    string status = record["status"];
                    string client = record["client"];
                    string time = record["time"];

                    DateTime date;
                    {
                        double dTime = double.Parse(time);
                        date =
                            (new DateTime(1970, 1, 1, 0, 0, 0)
                            .AddSeconds(dTime)
                            .ToLocalTime());
                    }

                    DataRow row = p4DataTable.NewRow();
                    row["revision"] = Int32.Parse(change);
                    row["user"] = user;
                    row["description"] = desc;
                    row["status"] = status;
                    row["client"] = client;
                    row["time"] = date;

                    p4DataTable.Rows.Add(row);
                }

            }
            return p4DataTable;
        }
Beispiel #4
0
 private void AddPerforceFileRequest(Uri uri, Func<Uri, bool> doRequest)
 {
     var path = uri.Path();
     FileInfo info;
     lock (m_infoCache)
         if (!m_infoCache.TryGetValue(path, out info))
             m_infoCache[path] = info = new FileInfo(uri);
     lock (m_pendingRequests)
         m_pendingRequests.Enqueue(new PerforceRequest(info, doRequest));
     m_queryRequestedEvent.Set(); // Trigger the worker thread to talk to the Perforce server.
 }
Beispiel #5
0
 private void Uncache(Uri uri)
 {
     lock (m_infoCache)
     {
         FileInfo info;
         if (m_infoCache.TryGetValue(uri.Path(), out info))
             info.ClearRecord();
     }
 }
Beispiel #6
0
 private void AddPerforceFileRequest(Uri uri, Func<Uri, bool> doRequest, Func<Uri, bool> requestComplete)
 {
     var path = uri.Path();
     FileInfo info;
     if (!m_infoCache.TryGetValue(path, out info))
         m_infoCache[path] = info = new FileInfo(uri);
     RequestProcessed = false;
     m_pendingRequests.Enqueue(new PerforceRequest(info, doRequest, requestComplete));
 }
        public FtpClient Open(bool isSource, ref Uri url)
        {
            var queue = Queue[Key(isSource, url)];
            var ftp = queue.DequeueOrBlock();
            try {
                if (ftp == null) {
                    ftp = new Silversite.FtpSync.FtpClient(Sync, url.Host, url.Port, url.Scheme == "ftps" ? FtpSecurityProtocol.Tls1Explicit : FtpSecurityProtocol.None, ++clientIndex, isSource);
                    //ftp.IsLoggingOn = Sync.Verbose;
                    if (Sync.Verbose) {
                        ftp.ClientRequest += new EventHandler<FtpRequestEventArgs>((sender, args) => {
                            lock (Log.Lock) { Log.YellowLabel("FTP" + ftp.Index + "> "); Log.Text(args.Request.Text); }
                        });
                        ftp.ServerResponse += new EventHandler<FtpResponseEventArgs>((sender, args) => {
                            lock (Log.Lock) { Log.Label("FTP" + ftp.Index + ": "); Log.Text(args.Response.Text); }
                        });
                    }
                    if (url.Query()["passive"] != null || url.Query()["active"] == null) ftp.DataTransferMode = TransferMode.Passive;
                    else ftp.DataTransferMode = TransferMode.Active;
                    ftp.AutoChecksumValidation = HashingFunction.None;
                    if (url.Query()["md5"] != null) ftp.AutoChecksumValidation = HashingFunction.Md5;
                    else if (url.Query()["sha"] != null) ftp.AutoChecksumValidation = HashingFunction.Sha1;
                    else if (url.Query()["crc"] != null) ftp.AutoChecksumValidation = HashingFunction.Crc32;
                } else {
                    if (!ftp.IsConnected) ftp.Reopen();
                }
                if (!ftp.IsConnected) {
                    if (!string.IsNullOrEmpty(url.UserInfo)) {
                        if (url.UserInfo.Contains(':')) {
                            var user = url.UserInfo.Split(':');
                            ftp.Open(user[0], user[1]);
                        } else {
                            ftp.Open(url.UserInfo, string.Empty);
                        }
                    } else {
                        ftp.Open("Anonymous", "anonymous");
                    }
                    // enable UTF8
                    ftp.Quote("OPTS UTF8 ON");
                }

                // change path
                var path = url.Path();
                if (!path.StartsWith("/")) path = "/" + path;
                path = ftp.CorrectPath(path);
                if (url.Query()["raw"] != null && ftp.IsCompressionEnabled) ftp.CompressionOff();
                if (url.Query()["zip"] != null && ftp.IsCompressionEnabled) ftp.CompressionOn();
                if (ftp.CurrentDirectory != path) {
                    try {
                        if (url.Query()["old"] != null) ftp.ChangeDirectoryMultiPath(path);
                        else ftp.ChangeDirectory(path);
                    } catch (Exception ex) {
                        ftp.MakeDirectory(path);
                        if (url.Query()["old"] != null) ftp.ChangeDirectoryMultiPath(path);
                        else ftp.ChangeDirectory(path);
                    }
                }
                // get server local time offset
                var offset = TimeOffset(url);
                if (offset.HasValue) ftp.TimeOffset = offset;
                else if (!ftp.TimeOffset.HasValue) {
                    lock (queue) {
                        var offsetclient = queue.FirstOrDefault(client => client != null && client.TimeOffset.HasValue);
                        if (offsetclient != null) ftp.TimeOffset = offsetclient.TimeOffset;
                        ftp.TimeOffset = ftp.ServerTimeOffset;
                    }
                }
            } catch (FtpDataConnectionException ex) {
                if (url.Query()["passive"] == null) {
                    url = new Uri(url.ToString() + (url.Query().Count > 0 ? "&" : "%3F") + "passive");
                    //ftp.Close();
                    ftp.DataTransferMode = TransferMode.Passive;
                    Pass(ftp);
                    return Open(isSource, ref url);
                } else {
                    Log.Exception(ex);
                }
            } catch (Exception e) {
                Log.Exception(e);
            }
            return ftp;
        }