Skip to content

OnTaskDetails thrown an exception because TaskSetup attempts load data from instance #54

@AmenJlili

Description

@AmenJlili

data = taskProperties.GetValEx($"{taskProperties.AddInName}{taskProperties.TaskName}{typeof(T).Name}");

The line above throws an exception. This needs to be omitted OnTaskDetails

Temp solution

public override LoadData(ref CmdData) {
  if (Container == null)
                throw new Exception("Please set the container property.");



            IEdmTaskProperties taskProperties = cmd.mpoExtra as IEdmTaskProperties;
            IEdmTaskInstance taskInstance = cmd.mpoExtra as IEdmTaskInstance;

            if (taskProperties == null)
                taskInstance = cmd.mpoExtra as IEdmTaskInstance;

            

            this.Vault = cmd.mpoVault as IEdmVault5;

            object data = null;

            if (SaveLoadDataToVariable == false)
            {
                if (taskProperties == null)
                    data = taskInstance.GetValEx($"{taskInstance.InstanceGUID}{taskInstance.TaskName}{typeof(T).Name}");
                else
                    data = taskProperties.GetValEx($"{taskProperties.AddInName}{taskProperties.TaskName}{typeof(T).Name}");
            }
            else
            if (SaveLoadDataToVariable == true)
            {
                var vault = cmd.mpoVault as IEdmVault5;

                if (taskProperties == null)
                    data = taskInstance.GetVar(SaveLoadDataToVariableId);
                  // fix here:
                  else if (poCmd.mlCmdType != EdmCmdType.TaskDetails) 
                   data = taskProperties.GetVar(SaveLoadDataToVariableId);
            }

            if (data != null)
            {
                var dataStr = data.ToString();

                var deserializedViewModel = default(T);

                if (string.IsNullOrWhiteSpace(dataStr))
                    deserializedViewModel = (T)Activator.CreateInstance(typeof(T));
                else
                    try
                    {
                        deserializedViewModel = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(dataStr);
                    }
                    catch (Exception e)
                    {
                        var logger = Container.GetInstance(typeof(ILogger)) as ILogger;
                        logger.LogToOutput(logger.OutputLocation, $"Exception occurred while serializing settings view model. {e.Message}");
                    }

                if (deserializedViewModel != null)
                {
                    this.ViewModel = deserializedViewModel;
                    OnDataLoaded();
                }
            }
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions