Example #1
0
        /// <summary>
        /// Parse the fields from a depot specification
        /// </summary>
        /// <param name="spec">Text of the depot specification in server format</param>
        /// <returns></returns>
        public bool Parse(String spec)
        {
            _baseForm = new FormBase();

            _baseForm.Parse(spec);             // parse the values into the underlying dictionary

            if (_baseForm.ContainsKey("Depot"))
            {
                Id = _baseForm["Depot"] as string;
            }

            if (_baseForm.ContainsKey("Owner"))
            {
                Owner = _baseForm["Owner"] as string;
            }

            if (_baseForm.ContainsKey("Date"))
            {
                DateTime v = DateTime.MinValue;
                DateTime.TryParse(_baseForm["Date"] as string, out v);
                Modified = v;
            }

            if (_baseForm.ContainsKey("Description"))
            {
                Description = _baseForm["Description"] as string;
            }

            if (_baseForm.ContainsKey("Type"))
            {
                _type = _baseForm["Type"] as string;
            }

            if (_baseForm.ContainsKey("Address"))
            {
                Address = new ServerAddress(_baseForm["Address"] as string);
            }

            if (_baseForm.ContainsKey("Map"))
            {
                Map = _baseForm["Map"] as string;
            }

            if (_baseForm.ContainsKey("StreamDepth"))
            {
                StreamDepth = _baseForm["StreamDepth"] as string;
            }

            if (_baseForm.ContainsKey("Suffix"))
            {
                Suffix = _baseForm["Suffix"] as string;
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Parse the fields from a stream specification
        /// </summary>
        /// <param name="spec">Text of the stream specification in server format</param>
        /// <returns></returns>
        public bool Parse(String spec)
        {
            _baseForm = new FormBase();
            _baseForm.Parse(spec); // parse the values into the underlying dictionary
            GetSpecDefinition(_baseForm);

            Id          = ParseSingleString(_baseForm, "Stream");
            OwnerName   = ParseSingleString(_baseForm, "Owner");
            Name        = ParseSingleString(_baseForm, "Name");
            Description = ParseDescription(_baseForm);
            Ignored     = ParseView(_baseForm, "Ignored");
            Paths       = ParseView(_baseForm, "Paths");
            Remapped    = ParseView(_baseForm, "Remapped");
            View        = ParseView(_baseForm, "View");
            ChangeView  = ParseView(_baseForm, "ChangeView");
            Updated     = ParseDate(_baseForm, "Update");
            Accessed    = ParseDate(_baseForm, "Access");

            if (_baseForm.ContainsKey("Options"))
            {
                _options = _baseForm["Options"] as string;
                specDef.Remove("Options");
            }

            if (_baseForm.ContainsKey("Type"))
            {
                _type = _baseForm["Type"] as string;
                specDef.Remove("Type");
            }

            if (_baseForm.ContainsKey("ParentView"))
            {
                _parentView = (_baseForm["ParentView"].ToString() == "inherit") ? ParentView.Inherit : ParentView.NoInherit;
                //_parentView = _baseForm["ParentView"] as string;
                specDef.Remove("ParentView");
            }

            if (_baseForm.ContainsKey("Parent"))
            {
                string line = _baseForm["Parent"] as string;
                Parent = new DepotPath(line);
                specDef.Remove("Parent");
            }

            SetCustomFields();

            return(true);
        }
Example #3
0
 private void SetCustomFields()
 {
     foreach (KeyValuePair <string, string> kvp in specDef)
     {
         if (_baseForm.ContainsKey(kvp.Key))
         {
             CustomFields.Add(kvp.Key, _baseForm[kvp.Key]);
         }
     }
 }
Example #4
0
        private string ParseSingleString(FormBase _baseForm, string field)
        {
            string result = null;

            if (_baseForm.ContainsKey(field))
            {
                result = _baseForm[field] as string;
                specDef.Remove(field);
            }
            return(result);
        }
Example #5
0
        private void GetSpecDefinition(FormBase _baseForm)
        {
            if (_baseForm.ContainsKey("specdef"))
            {
                string   tmp    = _baseForm["specdef"] as string;
                string[] fields = tmp.Split(new string[] { ";;" }, StringSplitOptions.None);

                foreach (string field in fields)
                {
                    string   value = "word";
                    string[] line  = field.Split(';');
                    foreach (string x in line)
                    {
                        if (x.Contains("type"))
                        {
                            string[] typeTmp = x.Split(':');
                            value = typeTmp[1];
                        }
                    }
                    specDef.Add(line[0], value);
                }
            }
        }
Example #6
0
        private string ParseDescription(FormBase _baseForm)
        {
            string result = string.Empty;
            string key    = "Description";

            if (_baseForm.ContainsKey(key))
            {
                SimpleList <string> _list = (SimpleList <string>)_baseForm[key];
                string[]            list  = _list.ToArray();
                foreach (string line in list)
                {
                    result += line + "\r\n\t";
                }
                result = result.Substring(0, result.Length - 3);
            }

            if (specDef.ContainsKey(key))
            {
                specDef.Remove(key);
            }

            return(result);
        }
Example #7
0
        private ViewMap ParseView(FormBase _baseForm, string field)
        {
            ViewMap view = new ViewMap();

            if (_baseForm.ContainsKey(field))
            {
                SimpleList <string> _list = (SimpleList <string>)_baseForm[field];
                string[]            list  = _list.ToArray();
                foreach (string line in list)
                {
                    view.Add(line);
                }
            }
            else
            {
                view = null;
            }

            if (specDef.ContainsKey(field))
            {
                specDef.Remove(field);
            }
            return(view);
        }
Example #8
0
        /// <summary>
        /// Parse the fields from a branch specification
        /// </summary>
        /// <param name="spec">Text of the branch specification in server format</param>
        /// <returns></returns>
        public bool Parse(String spec)
        {
            _baseForm = new FormBase();

            _baseForm.Parse(spec);             // parse the values into the underlying dictionary

            if (_baseForm.ContainsKey("Branch"))
            {
                Id = _baseForm["Branch"] as string;
            }

            if (_baseForm.ContainsKey("Owner"))
            {
                if (_baseForm["Owner"] is string)
                {
                    Owner = _baseForm["Owner"] as string;
                }
                if (_baseForm["Owner"] is IList <string> )
                {
                    IList <string> strList = _baseForm["Owner"] as IList <string>;
                    Owner = string.Empty;
                    for (int idx = 0; idx < strList.Count; idx++)
                    {
                        if (idx > 0)
                        {
                            Owner += "\r\n";
                        }
                        Owner += strList[idx];
                    }
                }
                if (_baseForm["Owner"] is SimpleList <string> )
                {
                    SimpleList <string> strList = _baseForm["Owner"] as SimpleList <string>;
                    Owner = string.Empty;
                    SimpleListItem <string> current = strList.Head;
                    bool addCRLF = false;
                    while (current != null)
                    {
                        if (addCRLF)
                        {
                            Owner += "\r\n";
                        }
                        else
                        {
                            addCRLF = true;
                        }
                        Owner  += current.Item;
                        current = current.Next;
                    }
                }
            }

            if (_baseForm.ContainsKey("Update"))
            {
                DateTime v = DateTime.MinValue;
                DateTime.TryParse(_baseForm["Update"] as string, out v);
                Updated = v;
            }

            if (_baseForm.ContainsKey("Access"))
            {
                DateTime v = DateTime.MinValue;
                DateTime.TryParse(_baseForm["Access"] as string, out v);
                Accessed = v;
            }

            if (_baseForm.ContainsKey("Description"))
            {
                if (_baseForm["Description"] is string)
                {
                    Description = _baseForm["Description"] as string;
                }
                if (_baseForm["Description"] is IList <string> )
                {
                    IList <string> strList = _baseForm["Description"] as IList <string>;
                    Description = string.Empty;
                    for (int idx = 0; idx < strList.Count; idx++)
                    {
                        if (idx > 0)
                        {
                            Description += "\r\n";
                        }
                        Description += strList[idx];
                    }
                }
                if (_baseForm["Description"] is SimpleList <string> )
                {
                    SimpleList <string> strList = _baseForm["Description"] as SimpleList <string>;
                    Description = string.Empty;
                    SimpleListItem <string> current = strList.Head;
                    bool addCRLF = false;
                    while (current != null)
                    {
                        if (addCRLF)
                        {
                            Description += "\r\n";
                        }
                        else
                        {
                            addCRLF = true;
                        }
                        Description += current.Item;
                        current      = current.Next;
                    }
                }
            }


            if (_baseForm.ContainsKey("Options"))
            {
#pragma warning disable 618
                Options = _baseForm["Options"] as string;
#pragma warning restore 618
            }

            if (_baseForm.ContainsKey("View"))
            {
                if (_baseForm["View"] is IList <string> )
                {
                    IList <string> lines = _baseForm["View"] as IList <string>;
                    ViewMap = new ViewMap(lines.ToArray());
                }
                else if (_baseForm["View"] is SimpleList <string> )
                {
                    SimpleList <string> lines = _baseForm["View"] as SimpleList <string>;
                    ViewMap = new ViewMap(lines.ToArray());
                }
            }
            return(true);
        }
Example #9
0
        /// <summary>
        /// Parse the fields from a changelist specification
        /// </summary>
        /// <param name="spec">Text of the changelist specification in server format</param>
        /// <returns>true if parse successful</returns>
        public bool Parse(String spec)
        {
            _baseForm = new FormBase();
            _baseForm.Parse(spec);             // parse the values into the underlying dictionary

            if (_baseForm.ContainsKey("Change"))
            {
                int v = -1;
                int.TryParse((string)_baseForm["Change"], out v);
                Id = v;
            }
            if (_baseForm.ContainsKey("Date"))
            {
                DateTime v;
                DateTime.TryParse((string)_baseForm["Date"], out v);
                ModifiedDate = v;
            }
            if (_baseForm.ContainsKey("Client"))
            {
                ClientId = (string)_baseForm["Client"];
            }

            if (_baseForm.ContainsKey("User"))
            {
                OwnerName = (string)_baseForm["User"];
            }

            if (_baseForm.ContainsKey("Status"))
            {
                Pending = true;
                String v = (string)_baseForm["Status"];
                if (v == "submitted")
                {
                    Pending = false;
                }
            }

            if (_baseForm.ContainsKey("Type"))
            {
                _type = (string)_baseForm["Type"];
            }

            if (_baseForm.ContainsKey("Description"))
            {
                if (_baseForm["Description"] is string)
                {
                    Description = (string)_baseForm["Description"];
                }
                else if (_baseForm["Description"] is SimpleList <string> )
                {
                    SimpleList <string> strList = _baseForm["Description"] as SimpleList <string>;
                    Description = string.Empty;
                    SimpleListItem <string> current = strList.Head;
                    bool addCRLF = false;
                    while (current != null)
                    {
                        if (addCRLF)
                        {
                            Description += "\r\n";
                        }
                        else
                        {
                            addCRLF = true;
                        }
                        Description += current.Item;
                        current      = current.Next;
                    }
                }
                else if (_baseForm["Description"] is IList <string> )
                {
                    IList <string> strList = _baseForm["Description"] as IList <string>;
                    Description = string.Empty;
                    for (int idx = 0; idx < strList.Count; idx++)
                    {
                        if (idx > 0)
                        {
                            Description += "\r\n";
                        }
                        Description += strList[idx];
                    }
                }
            }
            if (_baseForm.ContainsKey("Jobs"))
            {
                if (_baseForm["Jobs"] is IList <string> )
                {
                    IList <string> strList = _baseForm["Jobs"] as IList <string>;
                    Jobs = new Dictionary <string, string>(strList.Count);
                    foreach (string job in strList)
                    {
                        if (job.Contains('#'))
                        {
                            string[] parts = job.Split('#');
                            Jobs[parts[0].Trim()] = null;
                        }
                        else
                        {
                            Jobs[job] = null;
                        }
                    }
                }
                else if (_baseForm["Jobs"] is SimpleList <string> )
                {
                    SimpleList <string> strList = _baseForm["Jobs"] as SimpleList <string>;
                    Jobs = new Dictionary <string, string>(strList.Count);
                    SimpleListItem <string> current = strList.Head;
                    while (current != null)
                    {
                        string job = current.Item;
                        if (job.Contains('#'))
                        {
                            string[] parts = job.Split('#');
                            Jobs[parts[0].Trim()] = null;
                        }
                        else
                        {
                            Jobs[job] = null;
                        }
                        current = current.Next;
                    }
                }
            }
            if (_baseForm.ContainsKey("Files"))
            {
                if (_baseForm["Files"] is IList <string> )
                {
                    IList <string> files = (IList <string>)_baseForm["Files"];
                    Files = new List <FileMetaData>(files.Count);
                    foreach (string path in files)
                    {
                        FileMetaData file = new FileMetaData();
                        if (path.Contains('#'))
                        {
                            string[] parts = path.Split('#');
                            file.DepotPath = new DepotPath(parts[0].Trim());
                        }
                        else
                        {
                            file.DepotPath = new DepotPath(path);
                        }
                        Files.Add(file);
                    }
                }
                else if (_baseForm["Files"] is SimpleList <string> )
                {
                    SimpleList <string> files = (SimpleList <string>)_baseForm["Files"];
                    Files = new List <FileMetaData>(files.Count);
                    SimpleListItem <string> current = files.Head;
                    while (current != null)
                    {
                        FileMetaData file = new FileMetaData();
                        if (current.Item.Contains('#'))
                        {
                            string[] parts = current.Item.Split('#');
                            file.DepotPath = new DepotPath(parts[0].Trim());
                        }
                        else
                        {
                            file.DepotPath = new DepotPath(current.Item);
                        }
                        Files.Add(file);
                        current = current.Next;
                    }
                }
            }
            return(true);
        }
Example #10
0
        /// <summary>
        /// Parse the fields from a label specification
        /// </summary>
        /// <param name="spec">Text of the label specification in server format</param>
        /// <returns></returns>
        public bool Parse(String spec)
        {
            _baseForm = new FormBase();

            _baseForm.Parse(spec); // parse the values into the underlying dictionary

            if (_baseForm.ContainsKey("Label"))
            {
                Id = _baseForm["Label"] as string;
            }

            if (_baseForm.ContainsKey("Owner"))
            {
                Owner = _baseForm["Owner"] as string;
            }

            if (_baseForm.ContainsKey("Update"))
            {
                DateTime v = DateTime.MinValue;
                DateTime.TryParse(_baseForm["Update"] as string, out v);
                Update = v;
            }

            if (_baseForm.ContainsKey("Access"))
            {
                DateTime v = DateTime.MinValue;
                DateTime.TryParse(_baseForm["Access"] as string, out v);
                Access = v;
            }

            if (_baseForm.ContainsKey("Description"))
            {
                object d = _baseForm["Description"];
                if (d is string)
                {
                    Description = _baseForm["Description"] as string;
                }
                else if (d is string[])
                {
                    string[] a = d as string[];
                    Description = string.Empty;
                    for (int idx = 0; idx < a.Length; idx++)
                    {
                        if (idx > 0)
                        {
                            Description += "\r\n";
                        }
                        Description += a[idx];
                    }
                }
                else if (d is IList <string> )
                {
                    IList <string> l = d as IList <string>;
                    Description = string.Empty;
                    for (int idx = 0; idx < l.Count; idx++)
                    {
                        if (idx > 0)
                        {
                            Description += "\r\n";
                        }
                        Description += l[idx];
                    }
                }
                else if (d is SimpleList <string> )
                {
                    SimpleList <string> l = d as SimpleList <string>;
                    Description = string.Empty;
                    SimpleListItem <string> current = l.Head;
                    bool addCRLF = false;
                    while (current != null)
                    {
                        if (addCRLF)
                        {
                            Description += "\r\n";
                        }
                        else
                        {
                            addCRLF = true;
                        }
                        Description += current.Item;
                        current      = current.Next;
                    }
                }
            }

            if (_baseForm.ContainsKey("Options"))
            {
#pragma warning disable 618
                Options = _baseForm["Options"] as string;
#pragma warning restore 618
            }

            if (_baseForm.ContainsKey("Revision"))
            {
                Revision = _baseForm["Revision"] as string;
            }

            if (_baseForm.ContainsKey("ServerID"))
            {
                Revision = _baseForm["ServerID"] as string;
            }

            if (_baseForm.ContainsKey("View"))
            {
                if (_baseForm["View"] is IList <string> )
                {
                    IList <string> lines = _baseForm["View"] as IList <string>;
                    ViewMap = new ViewMap(lines.ToArray());
                }
                if (_baseForm["View"] is SimpleList <string> )
                {
                    SimpleList <string> lines = _baseForm["View"] as SimpleList <string>;
                    ViewMap = new ViewMap(lines.ToArray());
                }
            }
            return(true);
        }
Example #11
0
        /// <summary>
        /// Parse the fields from a user specification
        /// </summary>
        /// <param name="spec">Text of the user specification in server format</param>
        /// <returns></returns>
        public bool Parse(String spec)
        {
            _baseForm = new FormBase();

            _baseForm.Parse(spec);             // parse the values into the underlying dictionary

            if (_baseForm.ContainsKey("User"))
            {
                Id = _baseForm["User"] as string;
            }

            if (_baseForm.ContainsKey("Email"))
            {
                EmailAddress = _baseForm["Email"] as string;
            }

            if (_baseForm.ContainsKey("Update"))
            {
                DateTime v = DateTime.MinValue;
                DateTime.TryParse(_baseForm["Update"] as string, out v);
                Updated = v;
            }

            if (_baseForm.ContainsKey("Access"))
            {
                DateTime v = DateTime.MinValue;
                DateTime.TryParse(_baseForm["Access"] as string, out v);
                Accessed = v;
            }

            if (_baseForm.ContainsKey("FullName"))
            {
                FullName = _baseForm["FullName"] as string;
            }

            if (_baseForm.ContainsKey("JobView"))
            {
                JobView = _baseForm["JobView"] as string;
            }

            if (_baseForm.ContainsKey("Reviews"))
            {
                if (_baseForm["Reviews"] is IList <string> )
                {
                    Reviews = _baseForm["Reviews"] as IList <string>;
                }
                if (_baseForm["Reviews"] is SimpleList <string> )
                {
                    SimpleList <string> sls = (SimpleList <string>)_baseForm["Reviews"];
                    Reviews = (List <string>)sls;
                }
            }
            if (_baseForm.ContainsKey("Password"))
            {
                Password = _baseForm["Password"] as string;
            }

            if (_baseForm.ContainsKey("Type"))
            {
                _type = _baseForm["Type"] as string;
            }
            else
            {
                Type = UserType.Standard;
            }

            return(true);
        }
Example #12
0
        /// <summary>
        /// Parse the fields from a stream specification
        /// </summary>
        /// <param name="spec">Text of the stream specification in server format</param>
        /// <returns></returns>
        public bool Parse(String spec)
        {
            _baseForm = new FormBase();
            _baseForm.Parse(spec);             // parse the values into the underlying dictionary

            if (_baseForm.ContainsKey("Stream"))
            {
                Id = _baseForm["Stream"] as string;
            }

            if (_baseForm.ContainsKey("Update"))
            {
                DateTime d;
                if (DateTime.TryParse(_baseForm["Update"] as string, out d))
                {
                    Updated = d;
                }
            }

            if (_baseForm.ContainsKey("Access"))
            {
                DateTime d;
                if (DateTime.TryParse(_baseForm["Access"] as string, out d))
                {
                    Accessed = d;
                }
            }

            if (_baseForm.ContainsKey("Owner"))
            {
                OwnerName = _baseForm["Owner"] as string;
            }

            if (_baseForm.ContainsKey("Name"))
            {
                Name = _baseForm["Name"] as string;
            }

            if (_baseForm.ContainsKey("Parent"))
            {
                string line = _baseForm["Parent"] as string;
                Parent = new DepotPath(line);
            }

            if (_baseForm.ContainsKey("Type"))
            {
                _type = _baseForm["Type"] as string;
            }

            if (_baseForm.ContainsKey("Description"))
            {
                Description = _baseForm["Description"] as string;
            }

            if (_baseForm.ContainsKey("Options"))
            {
                _options = _baseForm["Options"] as string;
            }

            return(true);
        }
Example #13
0
        /// <summary>
        /// Parse the fields from a group specification
        /// </summary>
        /// <param name="spec">Text of group user specification in server format</param>
        /// <returns></returns>
        /// <remarks>
        /// # A Perforce Group Specification.
        /// #
        /// #  Group:       The name of the group.
        /// #  MaxResults:  Limits the rows (unless 'unlimited' or 'unset') any one
        /// #               operation can return to the client.
        /// #               See 'p4 help maxresults'.
        /// #  MaxScanRows: Limits the rows (unless 'unlimited' or 'unset') any one
        /// #               operation can scan from any one database table.
        /// #               See 'p4 help maxresults'.
        /// #  MaxLockTime: Limits the time (in milliseconds, unless 'unlimited' or
        /// #               'unset') any one operation can lock any database table when
        /// #               scanning data. See 'p4 help maxresults'.
        /// #  Timeout:     A time (in seconds, unless 'unlimited' or 'unset')
        /// #               which determines how long a 'p4 login'
        /// #               session ticket remains valid (default is 12 hours).
        /// #  PasswordTimeout:
        /// #               A time (in seconds, unless 'unlimited' or 'unset')
        /// #               which determines how long a 'p4 password'
        /// #               password remains valid (default is unset).
        /// #  Subgroups:   Other groups automatically included in this group.
        /// #  Owners:      Users allowed to change this group without requiring super
        /// #               access permission.
        /// #  Users:       The users in the group.  One per line.
        /// </remarks>
        public bool Parse(String spec)
        {
            _baseForm = new FormBase();

            _baseForm.Parse(spec);             // parse the values into the underlying dictionary

            if (_baseForm.ContainsKey("Group"))
            {
                Id = _baseForm["Group"] as string;
            }

            if (_baseForm.ContainsKey("MaxResults"))
            {
                int v = -1;
                int.TryParse(_baseForm["MaxResults"] as string, out v);
                MaxResults = v;
            }

            if (_baseForm.ContainsKey("MaxScanRows"))
            {
                int v = -1;
                int.TryParse(_baseForm["MaxScanRows"] as string, out v);
                MaxScanRows = v;
            }

            if (_baseForm.ContainsKey("MaxLockTime"))
            {
                int v = -1;
                int.TryParse(_baseForm["MaxLockTime"] as string, out v);
                MaxLockTime = v;
            }

            if (_baseForm.ContainsKey("MaxOpenFiles"))
            {
                int v = -1;
                int.TryParse(_baseForm["MaxOpenFiles"] as string, out v);
                MaxOpenFiles = v;
            }

            if (_baseForm.ContainsKey("Timeout"))
            {
                int v = -1;
                int.TryParse(_baseForm["Timeout"] as string, out v);
                TimeOut = v;
            }

            if (_baseForm.ContainsKey("PasswordTimeout"))
            {
                int v = -1;
                int.TryParse(_baseForm["PasswordTimeout"] as string, out v);
                PasswordTimeout = v;
            }
            if (_baseForm.ContainsKey("Users"))
            {
                if (_baseForm["Users"] is IList <string> )
                {
                    UserNames = _baseForm["Users"] as IList <string>;
                }
                else if (_baseForm["Users"] is SimpleList <string> )
                {
                    UserNames = (List <string>)((SimpleList <string>)_baseForm["Users"]);
                }
            }
            if (_baseForm.ContainsKey("Owners"))
            {
                if (_baseForm["Owners"] is IList <string> )
                {
                    OwnerNames = _baseForm["Owners"] as IList <string>;
                }
                else if (_baseForm["Owners"] is SimpleList <string> )
                {
                    OwnerNames = (List <string>)((SimpleList <string>)_baseForm["Owners"]);
                }
            }
            if (_baseForm.ContainsKey("Subgroups"))
            {
                if (_baseForm["Subgroups"] is IList <string> )
                {
                    SubGroups = _baseForm["Subgroups"] as IList <string>;
                }
                else if (_baseForm["Subgroups"] is SimpleList <string> )
                {
                    SubGroups = (List <string>)((SimpleList <string>)_baseForm["Subgroups"]);
                }
            }
            return(true);
        }