Exemplo n.º 1
0
        public async Task SetValue(Uri requestUri, string version, string content, string mediaType)
        {
            var properties = GetProperties();

            if (properties.TryGetValue(requestUri.AbsolutePath, out var value))
            {
                if (value.RequiredVersion != value.ContentVersion)
                {
                    value.ContentVersion = version;
                    value.MediaType      = mediaType;

                    File.WriteAllText(GetFileName(value), content);
                }
                else
                {
                    MicroLogger.LogWarning("Cache same version error");
                }
            }
            else
            {
                value = new PropertiesObject
                {
                    UrlPath         = requestUri.AbsolutePath,
                    MediaType       = mediaType,
                    ContentVersion  = version,
                    RequiredVersion = version,
                    FileName        = Path.GetRandomFileName()
                };
                properties.Add(requestUri.AbsolutePath, value);

                File.WriteAllText(GetFileName(value), content);
            }

            await StoreProperties();
        }
 internal PropertiesModel CastStockData(PropertiesObject blobData)
 {
     try
     {
         PropertiesModel property = new PropertiesModel
         {
             Id        = blobData.Id,
             YearBuilt = blobData.Physical.YearBuilt,
             ListPrice = blobData.Financial != null?string.Format("{0:F2}", blobData.Financial.ListPrice) : "0",
                             MonthlyRent = blobData.Financial != null?string.Format("{0:F2}", blobData.Financial.MonthlyRent) : "0",
                                               GrossYield = string.Format("{0:F2}", (blobData.Financial != null ? Convert.ToDecimal(blobData.Financial.MonthlyRent) : 0 * 12)
                                                                          / (blobData.Financial != null ? Convert.ToDecimal(blobData.Financial.ListPrice) : 1)),
                                               MainImageUrl = blobData.MainImageUrl,
                                               Address1     = blobData.Address.Address1,
                                               Address2     = blobData.Address.Address2,
                                               City         = blobData.Address.City,
                                               Country      = blobData.Address.Country,
                                               County       = blobData.Address.County,
                                               District     = blobData.Address.District,
                                               State        = blobData.Address.State,
                                               ZipCode      = blobData.Address.ZipCode,
                                               ZipPlusFour  = blobData.Address.ZipPlusFour,
                                               Resources    = blobData.Resources,
                                               Bathrooms    = blobData.Physical.Bathrooms,
                                               BedRooms     = blobData.Physical.BedRooms,
                                               squareFeet   = blobData.Physical.squareFeet
         };
         return(property);
     }
     catch (Exception ex)
     {
         _logger.Error($"An error has occured casting the properties {ex.Message}", ex);
         throw;
     }
 }
Exemplo n.º 3
0
        internal static string GetWebRootProperty(KnowledgeBase KB, string GeneratorName)
        {
            KBModel          targetmodel      = KB.DesignModel.Environment.TargetModel;
            GxModel          arg              = targetmodel.GetAs <GxModel>();
            PropertiesObject propertiesObject = null;
            GxEnvironment    environment;

            foreach (GxEnvironment current in arg.Environments)
            {
                if (current.EnvironmentCategory.Name.ToLower().Trim() == GeneratorName.ToLower().Trim())
                {
                    environment      = current;
                    propertiesObject = PropertiesObject.GetFrom(current);
                }
            }
            string salida;

            if (propertiesObject == null)
            {
                salida = "";
            }
            else
            {
                salida = propertiesObject.GetPropertyValueString("WebRoot");
            }
            return(salida);
        }
Exemplo n.º 4
0
        public async Task <PropertiesModel> GetStockDataById(int id)
        {
            //Calling an external layer to get the API info by Id
            PropertiesObject blobData = await _externalApi.GetStockDataById(id);

            //Calling the metod to cast the properties into the object that we'll return
            return(CastStockData(blobData));
        }
Exemplo n.º 5
0
    private void ReadPropertiesObject(JSONObject propsObject, PropertiesObject obj)
    {
        if (propsObject["properties"] != null)
        {
            foreach (JSONNode propNode in propsObject["properties"].AsArray)
            {
                JSONArray propArray   = propNode.AsArray;
                string    name        = propArray[0];
                string    valueString = propArray[1];

                bool     foundProp = false;
                Property prop      = new Property(null, null, null, null, null);
                foreach (Property checkProp in Property.JoinProperties(
                             obj.Properties(), obj.DeprecatedProperties()))
                {
                    if (checkProp.name == name)
                    {
                        prop      = checkProp;
                        foundProp = true;
                        break;
                    }
                }
                if (!foundProp)
                {
                    warnings.Add("Unrecognized property: " + name);
                    continue;
                }

                System.Type propType;
                if (propArray.Count > 2)
                {
                    propType = System.Type.GetType(propArray[2]); // explicit type
                }
                else
                {
                    propType = prop.value.GetType();
                }

                if (propType == typeof(Material))
                {
                    // skip equality check
                    prop.setter(ReadMaterial(propArray[1].AsObject));
                }
                else
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(propType);
                    using (var textReader = new StringReader(valueString))
                    {
                        // skip equality check. important if this is an EntityReference,
                        // since EntityReference.Equals gets the entity which may not exist yet
                        prop.setter(xmlSerializer.Deserialize(textReader));
                    }
                }
            }
        }
    }
Exemplo n.º 6
0
    private void PropertiesObjectGUI(PropertiesObject obj, string suffix = "",
                                     System.Action changedAction         = null)
    {
        string title;

        if (obj == null)
        {
            if (suffix.Length != 0)
            {
                title = "No" + suffix;
            }
            else
            {
                title = "None";
            }
        }
        else
        {
            title = obj.ObjectType().fullName + suffix;
            if (obj.Properties().Count > 0)
            {
                title += ":";
            }
        }
        GUILayout.BeginHorizontal();
        if (obj != null && GUILayout.Button(obj.ObjectType().icon, iconStyle.Value))
        {
            var typeInfo = gameObject.AddComponent <TypeInfoGUI>();
            typeInfo.type = obj.ObjectType();
        }
        GUILayout.Label(title, GUIStyleSet.instance.labelTitle);
        GUILayout.EndHorizontal();

        if (obj == null)
        {
            return;
        }
        var props = obj.Properties();

        foreach (Property prop in props)
        {
            Property wrappedProp = prop;
            wrappedProp.setter = v =>
            {
                prop.setter(v);
                voxelArray.unsavedChanges = true;
                adjustingSlider           = true;
                if (changedAction != null)
                {
                    changedAction();
                }
            };
            prop.gui(wrappedProp);
        }
    }
Exemplo n.º 7
0
 public static object GetProperty(PropertiesObject obj, string key)
 {
     foreach (Property prop in obj.Properties())
     {
         if (prop.id == key)
         {
             return(prop.getter());
         }
     }
     return(null);
 }
Exemplo n.º 8
0
 public static bool SetProperty(PropertiesObject obj, string key, object value)
 {
     foreach (Property prop in obj.Properties())
     {
         if (prop.id == key)
         {
             prop.setter(value);
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 9
0
    // assumes both objects are the same type and have the same order of properties
    public static void CopyProperties(PropertiesObject source, PropertiesObject dest,
                                      Entity findEntity = null, Entity replaceEntity = null)
    {
        var sourceEnumerator = source.Properties().GetEnumerator();
        var destEnumerator   = dest.Properties().GetEnumerator();

        while (sourceEnumerator.MoveNext())
        {
            destEnumerator.MoveNext();
            var value = sourceEnumerator.Current.value;
            // change "Self" references...
            value = PropertyValueReplaceEntity(value, findEntity, replaceEntity);
            destEnumerator.Current.setter(value);
        }
    }
Exemplo n.º 10
0
    public override IEnumerable <Property> Properties()
    {
        return(new Property[]
        {
            new Property("tar", "Target",
                         () => target,
                         v => {
                var prop = (BehaviorTargetProperty)v;

                // selfEntity will be null if multiple entities are selected
                Entity selfEntity = EntityReferencePropertyManager.CurrentEntity();
                var oldTargetEntity = target.GetEntity(selfEntity);
                var newTargetEntity = prop.GetEntity(selfEntity);

                if (oldTargetEntity != null)
                {
                    // replace all property values referencing the old target with the new target
                    // the new target could be null
                    foreach (Property _selfProp in this.Properties())
                    {
                        var selfProp = _selfProp;
                        selfProp.value = PropertiesObject.PropertyValueReplaceEntity(
                            selfProp.value, oldTargetEntity, newTargetEntity);
                    }
                }

                target = prop;
            },
                         PropertyGUIs.BehaviorTarget),
            new Property("con", "Condition",
                         () => condition,
                         v => condition = (Condition)v,
                         (Property property) => {
                if (target.targetEntityIsActivator)
                {
                    PropertyGUIs.ActivatorBehaviorCondition(property);
                }
                else
                {
                    PropertyGUIs.BehaviorCondition(property);
                }
            })
        });
    }
Exemplo n.º 11
0
    public virtual Entity Clone()
    {
        var newEntity = (Entity)(ObjectType().Create());

        PropertiesObject.CopyProperties(this, newEntity, this, newEntity);
        if (sensor != null)
        {
            newEntity.sensor = (Sensor)(sensor.ObjectType().Create());
            PropertiesObject.CopyProperties(sensor, newEntity.sensor, this, newEntity);
        }
        else
        {
            newEntity.sensor = null; // in case the Object Type had a default sensor
        }
        newEntity.behaviors.Clear(); // in case the Object Type had default behaviors
        foreach (var behavior in behaviors)
        {
            var newBehavior = (EntityBehavior)(behavior.ObjectType().Create());
            PropertiesObject.CopyProperties(behavior, newBehavior, this, newEntity);
            newEntity.behaviors.Add(newBehavior);
        }
        return(newEntity);
    }
Exemplo n.º 12
0
    private JSONObject WritePropertiesObject(PropertiesObject obj, bool includeName)
    {
        JSONObject propsObject = new JSONObject();

        if (includeName)
        {
            propsObject["name"] = obj.ObjectType().fullName;
        }

        JSONArray propertiesArray = new JSONArray();

        foreach (Property prop in obj.Properties())
        {
            object value = prop.value;
            if (value == null)
            {
                Debug.Log(prop.name + " is null!");
                continue;
            }
            JSONArray propArray = new JSONArray();
            propArray[0] = prop.name;
            var valueType = value.GetType();

            if (valueType == typeof(Material))
            {
                propArray[1] = WriteMaterial((Material)value);
            }
            else // not a Material
            {
                XmlSerializer xmlSerializer;
                try
                {
                    xmlSerializer = new XmlSerializer(valueType);
                }
                catch (System.InvalidOperationException)
                {
                    Debug.Log(prop.name + " can't be serialized!");
                    continue;
                }
                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                ns.Add("", ""); // skip xsi/xsd namespaces: https://stackoverflow.com/a/935749
                string valueString;
                // https://stackoverflow.com/a/2434558
                // https://stackoverflow.com/a/5414665
                using (var textWriter = new StringWriter())
                    using (var xmlWriter = XmlWriter.Create(textWriter,
                                                            new XmlWriterSettings {
                        Indent = false, OmitXmlDeclaration = true
                    }))
                    {
                        xmlSerializer.Serialize(xmlWriter, value, ns);
                        valueString = textWriter.ToString();
                    }
                propArray[1] = valueString;
            }

            if (prop.explicitType)
            {
                propArray[2] = value.GetType().FullName;
            }
            propertiesArray[-1] = propArray;
        }
        propsObject["properties"] = propertiesArray;

        return(propsObject);
    }
        public async Task <PropertiesModel> GetStockDataById(int id)
        {
            PropertiesObject blobData = await _externalApi.GetStockDataById(id);

            return(CastStockData(blobData));
        }
Exemplo n.º 14
0
 private string GetFileName(PropertiesObject property) => Path.Combine(Xamarin.Essentials.FileSystem.CacheDirectory, property.FileName);
Exemplo n.º 15
0
    private static MessagePackObjectDictionary WritePropertiesObject(PropertiesObject obj, bool includeName)
    {
        var propsDict = new MessagePackObjectDictionary();

        if (includeName)
        {
            propsDict[FileKeys.PROPOBJ_NAME] = obj.ObjectType().fullName;
        }

        var propertiesList = new List <MessagePackObject>();

        foreach (Property prop in obj.Properties())
        {
            object value = prop.value;
            if (value == null)
            {
                Debug.Log(prop.name + " is null!");
                continue;
            }
            var propList = new List <MessagePackObject>();
            propList.Add(prop.id);
            var valueType = value.GetType();

            if (valueType == typeof(Material))
            {
                propList.Add(new MessagePackObject(WriteMaterial((Material)value, true)));
            }
            else if (valueType == typeof(EmbeddedData))
            {
                var embeddedData = (EmbeddedData)value;
                var dataList     = new List <MessagePackObject>();
                dataList.Add(embeddedData.name);
                dataList.Add(embeddedData.type.ToString());
                dataList.Add(embeddedData.bytes);
                propList.Add(new MessagePackObject(dataList));
            }
            else // not a special type
            {
                XmlSerializer xmlSerializer;
                try
                {
                    xmlSerializer = new XmlSerializer(valueType);
                }
                catch (System.InvalidOperationException)
                {
                    Debug.Log(prop.name + " can't be serialized!");
                    continue;
                }
                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                ns.Add("", ""); // skip xsi/xsd namespaces: https://stackoverflow.com/a/935749
                string valueString;
                // https://stackoverflow.com/a/2434558
                // https://stackoverflow.com/a/5414665
                using (var textWriter = new StringWriter())
                    using (var xmlWriter = XmlWriter.Create(textWriter,
                                                            new XmlWriterSettings {
                        Indent = false, OmitXmlDeclaration = true
                    }))
                    {
                        xmlSerializer.Serialize(xmlWriter, value, ns);
                        valueString = textWriter.ToString();
                    }
                propList.Add(valueString);
            }

            if (prop.explicitType)
            {
                propList.Add(value.GetType().FullName);
            }
            propertiesList.Add(new MessagePackObject(propList));
        }
        propsDict[FileKeys.PROPOBJ_PROPERTIES] = new MessagePackObject(propertiesList);

        return(propsDict);
    }
Exemplo n.º 16
0
    private void ReadPropertiesObject(MessagePackObjectDictionary propsDict, PropertiesObject obj)
    {
        if (propsDict.ContainsKey(FileKeys.PROPOBJ_PROPERTIES))
        {
            foreach (var propObj in propsDict[FileKeys.PROPOBJ_PROPERTIES].AsList())
            {
                var    propList = propObj.AsList();
                string id       = propList[0].AsString();

                bool     foundProp = false;
                Property prop      = new Property(null, null, null, null, null);
                foreach (Property checkProp in obj.Properties())
                {
                    if (checkProp.id == id)
                    {
                        prop      = checkProp;
                        foundProp = true;
                        break;
                    }
                }
                if (!foundProp)
                {
                    warnings.Add("Unrecognized property: " + id);
                    continue;
                }

                System.Type propType;
                if (propList.Count > 2)
                {
                    propType = System.Type.GetType(propList[2].AsString()); // explicit type
                }
                else
                {
                    propType = prop.value.GetType();
                }

                if (propType == typeof(Material))
                {
                    // skip equality check
                    prop.setter(ReadMaterial(propList[1].AsDictionary(), true));
                }
                else if (propType == typeof(EmbeddedData))
                {
                    var dataList = propList[1].AsList();
                    var name     = dataList[0].AsString();
                    var type     = (EmbeddedDataType)System.Enum.Parse(typeof(EmbeddedDataType), dataList[1].AsString());
                    var bytes    = dataList[2].AsBinary();
                    prop.setter(new EmbeddedData(name, bytes, type));
                }
                else // not a special type
                {
                    string        valueString   = propList[1].AsString();
                    XmlSerializer xmlSerializer = new XmlSerializer(propType);
                    using (var textReader = new StringReader(valueString))
                    {
                        // skip equality check. important if this is an EntityReference,
                        // since EntityReference.Equals gets the entity which may not exist yet
                        prop.setter(xmlSerializer.Deserialize(textReader));
                    }
                }
            }
        }
    }
Exemplo n.º 17
0
    private void UpdateEditEntity()
    {
        editBehaviors.Clear();
        mismatchedSelectedBehaviorCounts = false;
        if (selectedEntities.Count == 0)
        {
            editEntity = null;
            editSensor = null;
        }
        else if (selectedEntities.Count == 1)
        {
            Entity e = selectedEntities[0];
            editEntity = new StoredPropertiesObject(e);
            if (e.sensor != null)
            {
                editSensor = new StoredPropertiesObject(e.sensor);
            }
            else
            {
                editSensor = null;
            }
            foreach (EntityBehavior behavior in e.behaviors)
            {
                editBehaviors.Add(new StoredEntityBehavior(behavior));
            }
        }
        else
        {
            // types don't match so we need to make a new array
            PropertiesObject[] selectedPropertiesObjects = new PropertiesObject[selectedEntities.Count];
            for (int i = 0; i < selectedEntities.Count; i++)
            {
                selectedPropertiesObjects[i] = selectedEntities[i];
            }
            editEntity = new StoredPropertiesObject(selectedPropertiesObjects);
            PropertiesObject[] selectedSensors = new PropertiesObject[selectedEntities.Count];
            for (int i = 0; i < selectedEntities.Count; i++)
            {
                selectedSensors[i] = selectedEntities[i].sensor;
            }
            editSensor = new StoredPropertiesObject(selectedSensors);
            if (editSensor.ObjectType() == null)
            {
                editSensor = null;
            }

            int numBehaviors = selectedEntities[0].behaviors.Count; // minimum number of behaviors
            foreach (Entity entity in selectedEntities)
            {
                int entityBehaviorCount = entity.behaviors.Count;
                if (entityBehaviorCount != numBehaviors)
                {
                    mismatchedSelectedBehaviorCounts = true;
                }
                if (entityBehaviorCount < numBehaviors)
                {
                    numBehaviors = entityBehaviorCount;
                }
            }

            for (int behaviorI = 0; behaviorI < numBehaviors; behaviorI++)
            {
                EntityBehavior[] selectedBehaviors = new EntityBehavior[selectedEntities.Count];
                for (int entityI = 0; entityI < selectedEntities.Count; entityI++)
                {
                    selectedBehaviors[entityI] = selectedEntities[entityI].behaviors[behaviorI];
                }
                StoredEntityBehavior editBehavior = new StoredEntityBehavior(selectedBehaviors);
                editBehaviors.Add(editBehavior);
            }
        }
    }
Exemplo n.º 18
0
 public StoredPropertiesObject(PropertiesObject store)
 {
     type       = store.ObjectType();
     properties = store.Properties();
 }
Exemplo n.º 19
0
        public static bool SupportsLink(PropertiesObject obj)
        {
            if (obj != null)
            {
                object controlTypeObjValue = obj.GetPropertyValue(Properties.ATT.ControlType);
                if (controlTypeObjValue != null && controlTypeObjValue is Int32)
                {
                    int controlType = (int)controlTypeObjValue;
                    return (controlType == Properties.ATT.ControlType_Values.Edit);
                }
            }

            return false;
        }