Example #1
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public void OnEnable()
        {
            _energyIncrease          = 0.0f;
            _fitnessChange           = 0.0f;
            _newAvatarMode           = OCPhysiologicalModel.AvatarMode.ACTIVE;
            _changeFactors           = new Dictionary <string, float>();
            _changeFactors["hunger"] = 0.5f;
            _changeFactors["thirst"] = 0.5f;
            //_changeFactors["energy"] = 0.5f;
            //_changeFactors["fitness"] = 0.5f;
            _changeFactors["pee_urgency"] = 0.5f;
            _changeFactors["poo_urgency"] = 0.5f;
            _resetFactors = new List <string>();
            config        = Utility.Config.GetInstance();
        }
Example #2
0
        public void CustomizeCodeDom(CodeCompileUnit codeUnit, IServiceProvider services)
        {
            config = Utility.Config.LoadSettings();

            var actionsToRemove = new List <CodeTypeDeclaration>();
            var types           = codeUnit.Namespaces[0].Types;
            var namespaceName   = codeUnit.Namespaces[0].Name;

            foreach (CodeTypeDeclaration type in types)
            {
                var _type = type.BaseTypes.Count > 0 ? type.BaseTypes[0].BaseType : null;
                if (Skip(type.Name, _type))
                {
                    actionsToRemove.Add(type);
                }
            }

            foreach (var actionToRemove in actionsToRemove)
            {
                types.Remove(actionToRemove);
            }
        }
Example #3
0
        public void CustomizeCodeDom(CodeCompileUnit codeUnit, IServiceProvider services)
        {
            config = Utility.Config.LoadSettings();

            var types         = codeUnit.Namespaces[0].Types;
            var namespaceName = codeUnit.Namespaces[0].Name;

            foreach (CodeTypeDeclaration type in types)
            {
                if (!type.IsClass || type.IsContextType())
                {
                    continue;
                }
                var logicalName = type.GetFieldInitalizedValue("EntityLogicalName");
                if (logicalName == null)
                {
                    return;
                }

                var propertiesToEdit = new List <Tuple <CodeMemberProperty, string> >();
                foreach (var member in type.Members)
                {
                    var property = member as CodeMemberProperty;
                    if (SkipProperty(property, type))
                    {
                        continue;
                    }

                    if (!IsOptionSetProperty(property))
                    {
                        continue;
                    }

                    if (property == null || property.Name == null)
                    {
                        continue;
                    }

                    if (!config.GlobalOptionSetsDepedencies.Where(x => x.Item1 == $"{logicalName}_{property.Name.ToLower()}").Any())
                    {
                        continue;
                    }

                    propertiesToEdit.Add(new Tuple <CodeMemberProperty, string>(property,
                                                                                config.GlobalOptionSetsDepedencies.Where(x => x.Item1 == $"{logicalName}_{property.Name.ToLower()}").First().Item2));
                }

                foreach (var enumProp in propertiesToEdit.Where(p => p != null && p.Item1 != null))
                {
                    type.Members.Remove(enumProp.Item1);


                    enumProp.Item1.SetStatements.Clear();
                    enumProp.Item1.GetStatements.Clear();


                    enumProp.Item1.Type = new CodeTypeReference($"System.Nullable<{namespaceName}.{enumProp.Item2.ToLower()}>");

                    var codeGetAssigment = new CodeSnippetExpression(
                        $"Microsoft.Xrm.Sdk.OptionSetValue optionSet = this.GetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>(\"{enumProp.Item1.Name.ToLower()}\");" + Environment.NewLine +
                        $"                if ((optionSet != null))" + Environment.NewLine +
                        "                {" + Environment.NewLine +
                        $"                    return (({namespaceName}.{enumProp.Item2.ToLower()})(System.Enum.ToObject(typeof({namespaceName}.{enumProp.Item2.ToLower()}), optionSet.Value)));" + Environment.NewLine +
                        "                }" + Environment.NewLine +
                        "                else" + Environment.NewLine +
                        "                {" + Environment.NewLine +
                        "                    return null;" + Environment.NewLine +
                        "                }");

                    var codeSetAssigment = new CodeSnippetExpression(
                        $"this.OnPropertyChanging(\"{enumProp.Item1.Name}\");" + Environment.NewLine +
                        $"                if ((value == null))" + Environment.NewLine +
                        "                {" + Environment.NewLine +
                        $"                    this.SetAttributeValue(\"{enumProp.Item1.Name.ToLower()}\", null);" + Environment.NewLine +
                        "                }" + Environment.NewLine +
                        "                else" + Environment.NewLine +
                        "                {" + Environment.NewLine +
                        $"                    this.SetAttributeValue(\"{enumProp.Item1.Name.ToLower()}\", new Microsoft.Xrm.Sdk.OptionSetValue(((int)(value))));;" + Environment.NewLine +
                        "                }" + Environment.NewLine +
                        $"                this.OnPropertyChanged(\"{enumProp.Item1.Name}\");"
                        );


                    enumProp.Item1.GetStatements.Add(codeGetAssigment);
                    enumProp.Item1.SetStatements.Add(codeSetAssigment);
                    type.Members.Add(enumProp.Item1);
                }
            }
        }
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Public Member Functions

	//---------------------------------------------------------------------------

	public void OnEnable()
	{
			_energyIncrease = 0.0f;
			_fitnessChange = 0.0f;
			_newAvatarMode = OCPhysiologicalModel.AvatarMode.ACTIVE;
			_changeFactors = new Dictionary<string,float>();
			_changeFactors["hunger"] = 0.5f;
			_changeFactors["thirst"] = 0.5f;
			//_changeFactors["energy"] = 0.5f;
			//_changeFactors["fitness"] = 0.5f;
			_changeFactors["pee_urgency"]	= 0.5f;
			_changeFactors["poo_urgency"]	= 0.5f;
			_resetFactors = new List<string>();
			config = Utility.Config.GetInstance();
	}