Пример #1
0
        /// <summary>
        /// Parse a string specification in the server format into an object.
        /// </summary>
        /// <remarks>
        /// The base implementation parses the generic specification tag::value
        /// format into the underlying dictionary
        /// </remarks>
        /// <param name="spec">String specification</param>
        /// <returns>Success/Failure</returns>
        virtual public bool Parse(String spec)
        {
            String currentTag = String.Empty;
            SimpleList <string> currentValueList = null;

            String[] lines = spec.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            for (int idx = 0; idx < lines.Length; idx++)
            {
                if (lines[idx][0] == '#')                 // # comment
                {
                    if (Comments == null)
                    {
                        Comments = lines[idx];
                    }
                    else
                    {
                        Comments += "\r\n";
                        Comments += lines[idx];
                    }
                    continue;
                }
                else if (lines[idx][0] == '\t')                 // tab char so this is part of a value field
                {
                    currentValueList.Add(lines[idx].TrimStart('\t'));
                }
                else
                {
                    //new tag line
                    String line     = lines[idx].Trim();
                    int    colonPos = line.IndexOf(':');
                    if (colonPos <= 0)                     //bad line
                    {
                        continue;
                    }

                    // start of a tag
                    currentValueList = null;

                    currentTag = line.Substring(0, colonPos);
                    if (colonPos < line.Length - 1)
                    {
                        // right of colon is the value
                        this[currentTag]             = line.Substring(colonPos + 1).Trim();
                        IsFieldMultiLine[currentTag] = false;
                    }
                    else
                    {
                        IsFieldMultiLine[currentTag] = true;
                        currentValueList             = new SimpleList <string>();
                        this[currentTag]             = currentValueList;
                    }
                }
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Fill in the fields for the changelist using the tagged output of a "change' command
        /// </summary>
        /// <param name="objectInfo">The tagged output of a "change' command</param>
        /// <param name="GetShelved">Access shelved files or not</param>
        /// <param name="offset">Offset within array</param>
        /// <param name="dst_mismatch">Daylight savings time for conversions</param>
        public void FromChangeCmdTaggedOutput(TaggedObject objectInfo, bool GetShelved, string offset, bool dst_mismatch)
        {
            // need to check for tags starting with upper and lower case, it the 'change' command's
            //  output the tags start with an uppercase character whereas with the 'changes' command
            //  they start with a lower case character, i.e. "Change" vs "change"

            _baseForm = new FormBase();

            _baseForm.SetValues(objectInfo);

            if (objectInfo.ContainsKey("Change"))
            {
                int v = -1;
                if (int.TryParse(objectInfo["Change"], out v))
                {
                    Id = v;
                }
            }
            else if (objectInfo.ContainsKey("change"))
            {
                int v = -1;
                if (int.TryParse(objectInfo["change"], out v))
                {
                    Id = v;
                }
            }

            if (objectInfo.ContainsKey("Date"))
            {
                DateTime v;
                DateTime.TryParse(objectInfo["Date"], out v);
                ModifiedDate = v;
            }
            else if (objectInfo.ContainsKey("time"))
            {
                long v;
                if (long.TryParse(objectInfo["time"], out v))
                {
                    DateTime UTC = FormBase.ConvertUnixTime(v);
                    DateTime GMT = new DateTime(UTC.Year, UTC.Month, UTC.Day, UTC.Hour, UTC.Minute, UTC.Second,
                                                DateTimeKind.Unspecified);
                    ModifiedDate = FormBase.ConvertFromUTC(GMT, offset, dst_mismatch);
                }
            }
            if (objectInfo.ContainsKey("Client"))
            {
                ClientId = objectInfo["Client"];
            }
            else if (objectInfo.ContainsKey("client"))
            {
                ClientId = objectInfo["client"];
            }

            if (objectInfo.ContainsKey("User"))
            {
                OwnerName = objectInfo["User"];
            }
            else if (objectInfo.ContainsKey("user"))
            {
                OwnerName = objectInfo["user"];
            }


            if (objectInfo.ContainsKey("Status"))
            {
                Pending = true;
                String v = objectInfo["Status"];
                if (v == "submitted")
                {
                    Pending = false;
                }
            }
            else if (objectInfo.ContainsKey("status"))
            {
                Pending = true;
                String v = objectInfo["status"];
                if (v == "submitted")
                {
                    Pending = false;
                }
            }

            if (objectInfo.ContainsKey("Description"))
            {
                Description = objectInfo["Description"];
            }
            else if (objectInfo.ContainsKey("desc"))
            {
                Description = objectInfo["desc"];
            }
            char[] array = { '\r', '\n' };
            Description = Description.TrimEnd(array);
            Description = Description.Replace("\r", "");
            Description = Description.Replace("\n", "\r\n");

            if (objectInfo.ContainsKey("Type"))
            {
                _type = objectInfo["Type"];
            }
            else if (objectInfo.ContainsKey("changeType"))
            {
                _type = objectInfo["changeType"];
            }

            if (objectInfo.ContainsKey("shelved"))
            {
                Shelved = true;
            }

            int    idx = 0;
            String key = "Jobs0";

            if (objectInfo.ContainsKey(key))
            {
                idx  = 1;
                Jobs = new Dictionary <string, string>();
                do
                {
                    Jobs.Add(objectInfo[key], null);
                    key = String.Format("Jobs{0}", idx++);
                } while (objectInfo.ContainsKey(key));
            }
            else
            {
                key = "jobs0";
                if (objectInfo.ContainsKey(key))
                {
                    idx  = 1;
                    Jobs = new Dictionary <string, string>();
                    do
                    {
                        Jobs.Add(objectInfo[key], null);
                        key = String.Format("jobs{0}", idx++);
                    } while (objectInfo.ContainsKey(key));
                }
            }

            key = "Files0";
            if (objectInfo.ContainsKey(key))
            {
                idx   = 1;
                Files = new List <FileMetaData>();
                do
                {
                    FileMetaData file = new FileMetaData();
                    file.DepotPath = new DepotPath(PathSpec.UnescapePath(objectInfo[key]));
                    Files.Add(file);
                    key = String.Format("Files{0}", idx++);
                } while (objectInfo.ContainsKey(key));
            }
            else
            {
                key = "files0";
                if (objectInfo.ContainsKey(key))
                {
                    idx = 1;
                    SimpleList <FileMetaData> files = new SimpleList <FileMetaData>();
                    do
                    {
                        FileMetaData file = new FileMetaData();
                        file.DepotPath = new DepotPath(PathSpec.UnescapePath(objectInfo[key]));
                        Files.Add(file);
                        key = String.Format("files{0}", idx++);
                    } while (objectInfo.ContainsKey(key));
                    Files = (List <FileMetaData>)files;
                }
            }
            if (GetShelved)
            {
                key = "depotFile0";
                String actionKey = "action0";
                String typeKey   = "type0";
                String revKey    = "rev0";
                String sizeKey   = "fileSize0";
                String digestKey = "digest0";

                if (objectInfo.ContainsKey(key))
                {
                    SimpleList <ShelvedFile> shelvedFiles = new SimpleList <ShelvedFile>();
                    idx = 1;
                    do
                    {
                        ShelvedFile file = new ShelvedFile();
                        file.Path = new DepotPath(PathSpec.UnescapePath(objectInfo[key]));
                        StringEnum <FileAction> action = objectInfo[actionKey];
                        file.Action = action;
                        file.Type   = new FileType(objectInfo[typeKey]);
                        string revstr = objectInfo[revKey];
                        if (revstr == "none")
                        {
                            revstr = "0";
                        }
                        int rev = Convert.ToInt32(revstr);
                        file.Revision = rev;

                        if (objectInfo.ContainsKey(sizeKey))
                        {
                            long size = -1;
                            long.TryParse(objectInfo[sizeKey], out size);
                            file.Size = size;
                        }

                        if (objectInfo.ContainsKey(digestKey))
                        {
                            file.Digest = objectInfo[digestKey];
                        }

                        shelvedFiles.Add(file);

                        key       = String.Format("depotFile{0}", idx);
                        actionKey = String.Format("action{0}", idx);
                        typeKey   = String.Format("type{0}", idx);
                        revKey    = String.Format("rev{0}", idx);
                        sizeKey   = String.Format("fileSize{0}", idx);
                        digestKey = String.Format("digest{0}", idx++);
                    } while (objectInfo.ContainsKey(key));
                    ShelvedFiles = (List <ShelvedFile>)shelvedFiles;
                }
            }
            else
            {
                key = "depotFile0";
                String actionKey = "action0";
                String typeKey   = "type0";
                String revKey    = "rev0";
                String sizeKey   = "fileSize0";
                String digestKey = "digest0";

                if (objectInfo.ContainsKey(key))
                {
                    idx = 1;
                    SimpleList <FileMetaData> fileList = new SimpleList <FileMetaData>();
                    do
                    {
                        FileMetaData file = new FileMetaData();
                        file.DepotPath = new DepotPath(PathSpec.UnescapePath(objectInfo[key]));
                        StringEnum <FileAction> action = objectInfo[actionKey];
                        file.Action = action;
                        file.Type   = new FileType(objectInfo[typeKey]);
                        string revstr = objectInfo[revKey];
                        int    rev    = Convert.ToInt32(revstr);
                        file.HeadRev = rev;

                        if (objectInfo.ContainsKey(sizeKey))
                        {
                            long size = -1;
                            long.TryParse(objectInfo[sizeKey], out size);
                            file.FileSize = size;
                        }

                        if (objectInfo.ContainsKey(digestKey))
                        {
                            file.Digest = objectInfo[digestKey];
                        }

                        fileList.Add(file);

                        key       = String.Format("depotFile{0}", idx);
                        actionKey = String.Format("action{0}", idx);
                        typeKey   = String.Format("type{0}", idx);
                        revKey    = String.Format("rev{0}", idx);
                        sizeKey   = String.Format("fileSize{0}", idx);
                        digestKey = String.Format("digest{0}", idx++);
                    } while (objectInfo.ContainsKey(key));
                    Files = (List <FileMetaData>)fileList;
                }
            }

            key = "job0";
            String statKey = "jobstat0";

            if (objectInfo.ContainsKey(key))
            {
                idx  = 1;
                Jobs = new Dictionary <string, string>();
                do
                {
                    string jobStatus = string.Empty;
                    string jobId     = objectInfo[key];
                    if (objectInfo.ContainsKey(statKey))
                    {
                        jobStatus = objectInfo[statKey];
                    }
                    Jobs.Add(jobId, jobStatus);
                    key     = String.Format("job{0}", idx);
                    statKey = String.Format("jobstat{0}", idx++);
                } while (objectInfo.ContainsKey(key));
            }
        }