public static OffnetAttrInstanceWeb FromString(string attributeInstanceString)
        {
            OffnetAttrInstanceWeb attributeInstance = null;

            if (attributeInstanceString.StartsWith("AttributeInstance: "))
            {
                attributeInstance = new OffnetAttrInstanceWeb();

                // remove (address) from glm id
                int open  = attributeInstanceString.IndexOf("@#(");
                int equal = attributeInstanceString.IndexOf('=');
                if (open > 0 && open < equal)
                {
                    attributeInstance.Name = attributeInstanceString.Substring(19, open - 19);
                    attributeInstance.Type = attributeInstanceString.Substring(open + 3, attributeInstanceString.IndexOf(')', open) - open - 3);
                }
                else
                {
                    attributeInstance.Name = attributeInstanceString.Substring(19, equal - 20);
                }

                string value = "null";

                if (attributeInstanceString.Length > equal + 2)
                {
                    value = attributeInstanceString.Substring(equal + 2);
                }
                if (value.Equals("null"))
                {
                    attributeInstance.Value = null;
                }
                else
                {
                    attributeInstance.Value = AttributeChoiceWeb.FromString(value);
                }
            }

            return(attributeInstance);
        }
Esempio n. 2
0
        public static OffnetServiceKeyWeb FromString(string servKeyString)
        {
            OffnetServiceKeyWeb key = null;
            int index1, index2;

            if (servKeyString.StartsWith("ServKey:"))
            {
                key           = new OffnetServiceKeyWeb();
                index1        = servKeyString.IndexOf("Service ID =");
                key.ServiceID = long.Parse(servKeyString.Substring(index1 + 13, index1 - 13));

                index2   = servKeyString.IndexOf(",Date =", index1);
                index1   = servKeyString.IndexOf(',', index2 + 2);
                key.Date = DateTime.Parse(servKeyString.Substring(index2 + 8, index1 - index2 - 8));

                index1 = servKeyString.IndexOf(",Attributes = [", index1);
                if (index1 > 0)
                {
                    index2 = servKeyString.IndexOf(']', index1);
                    string[] instances = servKeyString.Substring(index1 + 15, index2 - index1 - 16).Split(',');
                    List <OffnetAttrInstanceWeb> instanceList = new List <OffnetAttrInstanceWeb>();
                    foreach (string instance in instances)
                    {
                        instanceList.Add(OffnetAttrInstanceWeb.FromString(instance));
                    }
                    key.Attributes = instanceList.ToArray();
                }

                index1      = servKeyString.IndexOf(",ErrorString = ", index2);
                key.IsValid = bool.Parse(servKeyString.Substring(index2 + 11, index1 - index2 - 11));

                key.ErrorString = servKeyString.Substring(index1 + 15);
            }

            return(key);
        }