Ejemplo n.º 1
0
 public AddParameterToLinkedParameters(List<ILinkedParameter> linkedParameters, ILinkedParameter linkedParameter, IModuleParameter parameter)
 {
     if ( linkedParameters == null ) throw new ArgumentNullException( "linkedParameters" );
     this.LinkedParameters = linkedParameters;
     this.LinkedParameter = linkedParameter;
     this.Parameter = parameter;
 }
Ejemplo n.º 2
0
        private IModuleParameter GetCorrespondingParameter(IModuleParameter p, IModelSystemStructure mss, IModelSystemStructure newMSS)
        {
            if ( mss == p.BelongsTo )
            {
                foreach ( var param in newMSS.Parameters.Parameters )
                {
                    if ( param.Name == p.Name )
                    {
                        return param;
                    }
                }
                return null;
            }

            var list = mss.Children;
            var newList = newMSS.Children;
            if ( list == null | newList == null )
            {
                return null;
            }
            for ( int i = 0; i < list.Count; i++ )
            {
                var ret = GetCorrespondingParameter( p, list[i], newList[i] );
                if ( ret != null )
                {
                    return ret;
                }
            }
            return null;
        }
Ejemplo n.º 3
0
        private IModuleParameter GetCorrespondingParameter(IModuleParameter p, IModelSystemStructure mss, IModelSystemStructure newMSS)
        {
            if (mss == p.BelongsTo)
            {
                foreach (var param in newMSS.Parameters.Parameters)
                {
                    if (param.Name == p.Name)
                    {
                        return(param);
                    }
                }
                return(null);
            }

            var list    = mss.Children;
            var newList = newMSS.Children;

            if (list == null | newList == null)
            {
                return(null);
            }
            for (int i = 0; i < list.Count; i++)
            {
                var ret = GetCorrespondingParameter(p, list[i], newList[i]);
                if (ret != null)
                {
                    return(ret);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        private void lpContextMenu_SelectFileRequested(IModuleParameter parameter)
        {
            var module         = parameter.BelongsTo;
            var currentRoot    = this.GetRoot(module);
            var inputDirectory = GetInputDirectory(currentRoot);

            if (inputDirectory != null)
            {
                string fileName = this.OpenFile();
                if (fileName == null)
                {
                    return;
                }
                TransformToRelativePath(inputDirectory, ref fileName);
                if (this.AddCommand(new Commands.Editing.ParameterChangeCommand(parameter,
                                                                                fileName, this.GetLinkParameters())))
                {
                    this.ParameterEditor.RefreshParameters();
                    this.QuickParameterControl.RefreshParameters();
                    this.Save();
                }
                else
                {
                    MessageBox.Show("Unable to set file name'" + fileName + "'!", "Unable set file name",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes the specified parameters.
        /// </summary>
        /// <param name="params">The parameters.</param>
        public void Execute(IModuleParameter @params)
        {
            FileInfo fileInfo = new FileInfo(@params.Filename);

            if (fileInfo.Extension == ".jpg" ||
                fileInfo.Extension == ".gif" ||
                fileInfo.Extension == ".png")
            {
                System.Console.Write("Smashing image " + fileInfo.FullName);

                Bitmap img = new Bitmap(fileInfo.FullName);
                img.SetResolution(150, 150);

                switch (fileInfo.Extension)
                {
                case ".jpg":
                    img.Save(fileInfo.FullName, ImageFormat.Jpeg);
                    break;

                case ".gif":
                    img.Save(fileInfo.FullName, ImageFormat.Gif);
                    break;

                case ".png":
                    img.Save(fileInfo.FullName, ImageFormat.Png);
                    break;

                default:
                    break;
                }

                System.Console.WriteLine("Done.");
            }
        }
Ejemplo n.º 6
0
        private static string LookupName(IModuleParameter reference, IModelSystemStructure current)
        {
            var param = current.Parameters;

            if (param != null)
            {
                int index = param.Parameters.IndexOf(reference);
                if (index >= 0)
                {
                    return(current.Parameters.Parameters[index].Name);
                }
            }
            var childrenList = current.Children;

            if (childrenList != null)
            {
                for (int i = 0; i < childrenList.Count; i++)
                {
                    var res = LookupName(reference, childrenList[i]);
                    if (res != null)
                    {
                        // make sure to use an escape character before the . to avoid making the mistake of reading it as another index
                        return(string.Concat(current.IsCollection ? i.ToString()
                            : childrenList[i].ParentFieldName.Replace(".", "\\."), '.', res));
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 7
0
        private static void AssignValueNoTypeCheck <T>(IConfiguration config, IModuleParameter parameter, T t)
        {
            var currentStructure = parameter.BelongsTo;

            if (currentStructure == null)
            {
                throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "The parameter doesn't belong to any module!");
            }
            if (currentStructure.Module == null)
            {
                // If any ancestors of the model system structure were disabled ignore this
                if (BuildModelStructureChain(config, currentStructure)
                    .Any(mss => mss is IModelSystemStructure2 mss2 && mss2.IsDisabled))
                {
                    return;
                }
                throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "The currentstructure.Module was null!");
            }
            parameter.Value = t;
            var type = currentStructure.Module.GetType();

            if (parameter.OnField)
            {
                var field = type.GetField(parameter.VariableName);
                field.SetValue(currentStructure.Module, t);
            }
            else
            {
                var field = type.GetProperty(parameter.VariableName);
                field.SetValue(currentStructure.Module, t, null);
            }
        }
Ejemplo n.º 8
0
 public static void AssignValue <T>(IConfiguration config, IModuleParameter parameter, T t)
 {
     if (parameter.Type != typeof(T))
     {
         throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "The parameter " + parameter.Name + " was not of type " + typeof(T).FullName + "!");
     }
     AssignValueNoTypeCheck(config, parameter, t);
 }
Ejemplo n.º 9
0
 public ParameterChangeCommand(IModuleParameter parameter, string newValue, List<ILinkedParameter> linkedParameters)
 {
     this.Before = parameter.Value.ToString();
     this.AttachedParameter = parameter;
     this.After = newValue;
     this.LinkedParameters = linkedParameters;
     this.ContainedIn = null;
 }
Ejemplo n.º 10
0
 public ParameterChangeCommand(IModuleParameter parameter, string newValue, List <ILinkedParameter> linkedParameters)
 {
     this.Before            = parameter.Value.ToString();
     this.AttachedParameter = parameter;
     this.After             = newValue;
     this.LinkedParameters  = linkedParameters;
     this.ContainedIn       = null;
 }
Ejemplo n.º 11
0
 public ModelParameterProxy(IModuleParameter realParam, List <ILinkedParameter> linkedParameters)
 {
     this.RealParameter = realParam;
     if (realParam.BelongsTo != null)
     {
         this.ModuleName = realParam.BelongsTo.Name;
     }
     else
     {
         this.ModuleName = null;
     }
     this.Name = realParam.Name;
     if (realParam.Value == null)
     {
         FixType(realParam);
     }
     else
     {
         this.Type = realParam.Type;
     }
     this.Description = realParam.Description;
     this.Quick       = this.TempQuick = realParam.QuickParameter;
     this.ToolTipText = this.Name + " : " + this.ModuleName;
     if (this.Type == typeof(DateTime))
     {
         DateTime v = (DateTime)realParam.Value;
         this.Value = v.ToShortTimeString();
     }
     else
     {
         this.Value = realParam.Value.ToString();
     }
     if (linkedParameters != null)
     {
         bool found = false;
         // check to see if it is in a linked parameter
         for (int i = 0; i < linkedParameters.Count; i++)
         {
             if (linkedParameters[i] != null)
             {
                 for (int j = 0; j < linkedParameters[i].Parameters.Count; j++)
                 {
                     if (linkedParameters[i].Parameters[j] == realParam)
                     {
                         this.LinkedParameter = linkedParameters[i].Name;
                         found = true;
                         break;
                     }
                 }
                 if (found)
                 {
                     break;
                 }
             }
         }
     }
     this.TempValue = this.Value;
 }
Ejemplo n.º 12
0
 public ModelParameterProxy(IModuleParameter realParam, List<ILinkedParameter> linkedParameters)
 {
     this.RealParameter = realParam;
     if ( realParam.BelongsTo != null )
     {
         this.ModuleName = realParam.BelongsTo.Name;
     }
     else
     {
         this.ModuleName = null;
     }
     this.Name = realParam.Name;
     if ( realParam.Value == null )
     {
         FixType( realParam );
     }
     else
     {
         this.Type = realParam.Type;
     }
     this.Description = realParam.Description;
     this.Quick = this.TempQuick = realParam.QuickParameter;
     this.ToolTipText = this.Name + " : " + this.ModuleName;
     if ( this.Type == typeof( DateTime ) )
     {
         DateTime v = (DateTime)realParam.Value;
         this.Value = v.ToShortTimeString();
     }
     else
     {
         this.Value = realParam.Value.ToString();
     }
     if ( linkedParameters != null )
     {
         bool found = false;
         // check to see if it is in a linked parameter
         for ( int i = 0; i < linkedParameters.Count; i++ )
         {
             if ( linkedParameters[i] != null )
             {
                 for ( int j = 0; j < linkedParameters[i].Parameters.Count; j++ )
                 {
                     if ( linkedParameters[i].Parameters[j] == realParam )
                     {
                         this.LinkedParameter = linkedParameters[i].Name;
                         found = true;
                         break;
                     }
                 }
                 if ( found )
                 {
                     break;
                 }
             }
         }
     }
     this.TempValue = this.Value;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Remove a parameter from this linked parameter
 /// </summary>
 /// <param name="parameter">The parameter to remove</param>
 /// <returns>If we removed it from this linked parameter.
 /// If it is not contained, it will return false!</returns>
 public bool Remove(IModuleParameter parameter, ref string error)
 {
     if (!this.Parameters.Remove(parameter))
     {
         error = "The parameter '" + parameter.Name + "' was not contained within '" + this.Name + "'!";
         return(false);
     }
     return(true);
 }
Ejemplo n.º 14
0
 public AddParameterToLinkedParameters(List <ILinkedParameter> linkedParameters, ILinkedParameter linkedParameter, IModuleParameter parameter)
 {
     if (linkedParameters == null)
     {
         throw new ArgumentNullException("linkedParameters");
     }
     this.LinkedParameters = linkedParameters;
     this.LinkedParameter  = linkedParameter;
     this.Parameter        = parameter;
 }
Ejemplo n.º 15
0
        private void FixType(IModuleParameter realParam)
        {
            var moduleType = realParam.BelongsTo.Type;

            if (SearchFields(moduleType, realParam.Name))
            {
                return;
            }
            SearchProperties(moduleType, realParam.Name);
        }
Ejemplo n.º 16
0
        internal ParameterModel GetParameterModel(IModuleParameter moduleParameter)
        {
            var owner = GetModelFor(moduleParameter.BelongsTo as ModelSystemStructure);

            if (owner != null)
            {
                return(GetParameterModel(owner, moduleParameter));
            }
            return(null);
        }
Ejemplo n.º 17
0
 public bool RuntimeValidation(ref string error)
 {
     _parameter = Functions.ModelSystemReflection.FindParameter(_config, this, ParameterPath);
     if (_parameter == null)
     {
         error = "In '" + Name + "' we were unable to find a parameter with the path '" + ParameterPath + "'!";
         return(false);
     }
     return(true);
 }
Ejemplo n.º 18
0
        private ParameterModel GetParameterModel(ModelSystemStructureModel owner, IModuleParameter moduleParameter)
        {
            var parameters = owner.Parameters.Parameters;

            if (parameters != null)
            {
                for (int i = 0; i < parameters.Count; i++)
                {
                    if (parameters[i].RealParameter == moduleParameter)
                    {
                        return(parameters[i]);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 19
0
        private static void LoadParameters(IModelSystemStructure modelSystemStructure, XmlNode child, Dictionary <int, Type> lookUp)
        {
            if (child.HasChildNodes)
            {
                foreach (XmlNode paramChild in child.ChildNodes)
                {
                    if (paramChild.Name == "Param")
                    {
                        var paramNameAttribute           = paramChild.Attributes["Name"];
                        var paramTIndexAttribute         = paramChild.Attributes["TIndex"];
                        var paramTypeAttribute           = paramChild.Attributes["Type"];
                        var paramValueAttribute          = paramChild.Attributes["Value"];
                        var paramQuickParameterAttribute = paramChild.Attributes["QuickParameter"];
                        if (paramNameAttribute != null || paramTypeAttribute != null || paramValueAttribute != null)
                        {
                            string name = paramNameAttribute.InnerText;
                            if (modelSystemStructure.Parameters != null)
                            {
                                IModuleParameter selectedParam = null;
                                foreach (var p in modelSystemStructure.Parameters)
                                {
                                    if (p.Name == name)
                                    {
                                        selectedParam = p;
                                        break;
                                    }
                                }

                                // we will just ignore parameters that no longer exist
                                if (selectedParam != null)
                                {
                                    if (paramQuickParameterAttribute != null)
                                    {
                                        bool quick;
                                        if (bool.TryParse(paramQuickParameterAttribute.InnerText, out quick))
                                        {
                                            selectedParam.QuickParameter = quick;
                                        }
                                    }
                                    AssignTypeValue(paramTIndexAttribute, paramTypeAttribute, paramValueAttribute, selectedParam, lookUp);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 20
0
        private void ParameterUpdate(IModuleParameter parameter, string newValue)
        {
            List <ILinkedParameter> linkedParameters = null;

            if (_Project != null)
            {
                if (this._Project.LinkedParameters != null)
                {
                    linkedParameters = this._Project.LinkedParameters[this._Project.ModelSystemStructure.IndexOf(this.Root)];
                }
            }
            else
            {
                linkedParameters = this.ModelSystem.LinkedParameters;
            }
            this.AddCommand(new ParameterChangeCommand(parameter, newValue, linkedParameters));
        }
Ejemplo n.º 21
0
        public static void AssignValue(IConfiguration config, IModuleParameter parameter, string value)
        {
            string error = null;
            object trueValue;

            if (parameter == null)
            {
                throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "The parameter was null!");
            }
            if ((trueValue = ArbitraryParameterParser.ArbitraryParameterParse(parameter.Type, value, ref error)) != null)
            {
                AssignValueNoTypeCheck(config, parameter, trueValue);
            }
            else
            {
                throw new XTMFRuntimeException(parameter.BelongsTo?.Module, "We were unable to assign the value of '" + value + "' to the parameter " + parameter.Name);
            }
        }
Ejemplo n.º 22
0
        public static void AssignValue(IModuleParameter parameter, string value)
        {
            string error = null;
            object trueValue;

            if (parameter == null)
            {
                throw new XTMFRuntimeException("The parameter was null!");
            }
            var currentStructure = parameter.BelongsTo;

            if (currentStructure == null)
            {
                throw new XTMFRuntimeException("The parameter doesn't belong to any module!");
            }
            if (value == null)
            {
                throw new XTMFRuntimeException("The value was null!");
            }
            if (currentStructure.Module == null)
            {
                throw new XTMFRuntimeException("The currentstructure.Module was null!");
            }
            if ((trueValue = ArbitraryParameterParser.ArbitraryParameterParse(parameter.Type, value, ref error)) != null)
            {
                parameter.Value = trueValue;
                var type = currentStructure.Module.GetType();
                if (parameter.OnField)
                {
                    var field = type.GetField(parameter.VariableName);
                    field.SetValue(currentStructure.Module, trueValue);
                }
                else
                {
                    var field = type.GetProperty(parameter.VariableName);
                    field.SetValue(currentStructure.Module, trueValue, null);
                }
            }
            else
            {
                throw new XTMFRuntimeException("We were unable to assign the value of '" + value + "' to the parameter " + parameter.Name);
            }
        }
Ejemplo n.º 23
0
        private void OpenFile(IModuleParameter parameter, bool openWith, bool openDirectory)
        {
            var module         = parameter.BelongsTo;
            var parameterValue = parameter.Value.ToString();
            var currentRoot    = this.GetRoot(module);
            var inputDirectory = GetInputDirectory(currentRoot);

            if (inputDirectory != null)
            {
                var fileName = this.GetRelativePath(inputDirectory, parameterValue);
                if (openDirectory)
                {
                    openWith = false;
                    fileName = System.IO.Path.GetDirectoryName(fileName);
                }
                try
                {
                    Process toRun = new Process();
                    if (openWith)
                    {
                        toRun.StartInfo.FileName  = "Rundll32.exe";
                        toRun.StartInfo.Arguments = "Shell32.dll,OpenAs_RunDLL " + fileName;
                    }
                    else
                    {
                        toRun.StartInfo.FileName = fileName;
                    }
                    toRun.Start();
                }
                catch
                {
                    MessageBox.Show("Unable to load file '" + fileName + "'!", "Unable to open",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Unable to find input directory.", "Unable to open",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 24
0
 public static void AssignValue(IModuleParameter parameter, string value)
 {
     string error = null;
     object trueValue;
     if(parameter == null)
     {
         throw new XTMFRuntimeException("The parameter was null!");
     }
     var currentStructure = parameter.BelongsTo;
     if(currentStructure == null)
     {
         throw new XTMFRuntimeException("The parameter doesn't belong to any module!");
     }
     if(value == null)
     {
         throw new XTMFRuntimeException("The value was null!");
     }
     if(currentStructure.Module == null)
     {
         throw new XTMFRuntimeException("The currentstructure.Module was null!");
     }
     if((trueValue = ArbitraryParameterParser.ArbitraryParameterParse(parameter.Type, value, ref error)) != null)
     {
         parameter.Value = trueValue;
         var type = currentStructure.Module.GetType();
         if(parameter.OnField)
         {
             var field = type.GetField(parameter.VariableName);
             field.SetValue(currentStructure.Module, trueValue);
         }
         else
         {
             var field = type.GetProperty(parameter.VariableName);
             field.SetValue(currentStructure.Module, trueValue, null);
         }
     }
     else
     {
         throw new XTMFRuntimeException("We were unable to assign the value of '" + value + "' to the parameter " + parameter.Name);
     }
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Add a new parameter to this linkedParameter set
 /// </summary>
 /// <param name="parameter">The parameter to add</param>
 /// <returns>If we were able to add the parameter</returns>
 public bool Add(IModuleParameter parameter, ref string error)
 {
     // you can't have the same parameter multiple times!
     if ( parameter == null )
     {
         error = "The parameter does not exist!";
         return false;
     }
     if ( this.Parameters.Contains( parameter ) )
     {
         error = "The parameter '" + parameter.Name + "' already exists within the linked parameter '" + this.Name + "'.";
         return false;
     }
     var value = ArbitraryParameterParser.ArbitraryParameterParse( parameter.Type, this.Value, ref error );
     if ( value == null )
     {
         return false;
     }
     parameter.Value = value;
     this.Parameters.Add( parameter );
     return true;
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Add a new parameter to this linkedParameter set
        /// </summary>
        /// <param name="parameter">The parameter to add</param>
        /// <returns>If we were able to add the parameter</returns>
        public bool Add(IModuleParameter parameter, ref string error)
        {
            // you can't have the same parameter multiple times!
            if (parameter == null)
            {
                error = "The parameter does not exist!";
                return(false);
            }
            if (this.Parameters.Contains(parameter))
            {
                error = "The parameter '" + parameter.Name + "' already exists within the linked parameter '" + this.Name + "'.";
                return(false);
            }
            var value = ArbitraryParameterParser.ArbitraryParameterParse(parameter.Type, this.Value, ref error);

            if (value == null)
            {
                return(false);
            }
            parameter.Value = value;
            this.Parameters.Add(parameter);
            return(true);
        }
 private void lpContextMenu_OpenFileLocationRequested(IModuleParameter parameter)
 {
     OpenFile(parameter, false, true);
 }
 private void lpContextMenu_AddToLinkedParameterRequested(ILinkedParameter linkedParameter, IModuleParameter parameter)
 {
     string error = null;
     if(parameter == null)
     {
         MessageBox.Show("No parameter was selected!", "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning);
         return;
     }
     if(linkedParameter == null)
     {
         MessageBox.Show("No linked parameter parameter was selected!", "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning);
         return;
     }
     if(!this.AddCommand(new AddParameterToLinkedParameters(this.GetLinkParameters(), linkedParameter, parameter), ref error))
     {
         MessageBox.Show(error, "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
     this.ParameterEditor.RefreshParameters();
     // this will actually refresh everything
     this.QuickParameterControl_ParameterChanged();
 }
 private bool LinkedParameterEditor_RemoveLinkedParameterParameter(ILinkedParameter lp, IModuleParameter param)
 {
     if(!this.AddCommand(new RemoveParameterFromLinkedParameter(lp, param)))
     {
         return false;
     }
     this.ParameterEditor.RefreshParameters();
     this.Save();
     return true;
 }
Ejemplo n.º 30
0
 internal ParameterModel GetParameterModel(IModuleParameter moduleParameter)
 {
     var owner = GetModelFor(moduleParameter.BelongsTo as ModelSystemStructure);
     if(owner != null)
     {
         return GetParameterModel(owner, moduleParameter);
     }
     return null;
 }
Ejemplo n.º 31
0
        private List <ILinkedParameter> LoadLinkedParameters(ModelSystemStructure root, Stream stream)
        {
            var    ret   = new List <ILinkedParameter>();
            string error = null;

            using (XmlReader reader = XmlReader.Create(stream))
            {
                bool skipRead = false;
                while (!reader.EOF && (skipRead || reader.Read()))
                {
                    skipRead = false;
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }
                    switch (reader.LocalName)
                    {
                    case "LinkedParameter":
                    {
                        string linkedParameterName = "Unnamed";
                        string valueRepresentation = null;
                        var    startingDepth       = reader.Depth;
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.NodeType == XmlNodeType.Attribute)
                            {
                                if (reader.LocalName == "Name")
                                {
                                    linkedParameterName = reader.ReadContentAsString();
                                }
                                else if (reader.LocalName == "Value")
                                {
                                    valueRepresentation = reader.ReadContentAsString();
                                }
                            }
                        }
                        LinkedParameter lp = new LinkedParameter(linkedParameterName);
                        lp.SetValue(valueRepresentation, ref error);
                        ret.Add(lp);
                        skipRead = true;
                        while (reader.Read())
                        {
                            if (reader.Depth <= startingDepth)
                            {
                                break;
                            }
                            if (reader.NodeType != XmlNodeType.Element)
                            {
                                continue;
                            }
                            if (reader.LocalName == "Reference")
                            {
                                string variableLink = null;
                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.Name == "Name")
                                    {
                                        variableLink = reader.ReadContentAsString();
                                    }
                                }
                                if (variableLink != null)
                                {
                                    IModuleParameter param = GetParameterFromLink(variableLink, root);
                                    if (param != null)
                                    {
                                        // in any case if there is a type error, just throw it out
                                        lp.Add(param, ref error);
                                    }
                                }
                            }
                        }
                    }
                    break;
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 32
0
 private static void AssignTypeValue(XmlAttribute paramTIndex, XmlAttribute paramTypeAttribute, XmlAttribute paramValueAttribute, IModuleParameter selectedParam, Dictionary<int, Type> lookUp)
 {
     string error = null;
     var temp = ArbitraryParameterParser.ArbitraryParameterParse(selectedParam.Type, paramValueAttribute.InnerText, ref error);
     if(temp != null)
     {
         // don't overwrite the default if we are loading something bad
         selectedParam.Value = temp;
     }
 }
 private void OpenFile(IModuleParameter parameter, bool openWith, bool openDirectory)
 {
     var module = parameter.BelongsTo;
     var parameterValue = parameter.Value.ToString();
     var currentRoot = this.GetRoot(module);
     var inputDirectory = GetInputDirectory(currentRoot);
     if(inputDirectory != null)
     {
         var fileName = this.GetRelativePath(inputDirectory, parameterValue);
         if(openDirectory)
         {
             openWith = false;
             fileName = System.IO.Path.GetDirectoryName(fileName);
         }
         try
         {
             Process toRun = new Process();
             if(openWith)
             {
                 toRun.StartInfo.FileName = "Rundll32.exe";
                 toRun.StartInfo.Arguments = "Shell32.dll,OpenAs_RunDLL " + fileName;
             }
             else
             {
                 toRun.StartInfo.FileName = fileName;
             }
             toRun.Start();
         }
         catch
         {
             MessageBox.Show("Unable to load file '" + fileName + "'!", "Unable to open",
                 MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else
     {
         MessageBox.Show("Unable to find input directory.", "Unable to open",
          MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Ejemplo n.º 34
0
 private IModuleParameter GetCorrespondingParameter(IModuleParameter p, IModelSystemStructure newMSS)
 {
     return GetCorrespondingParameter( p, this.ModelSystem.ModelSystemStructure, newMSS );
 }
Ejemplo n.º 35
0
 private IModuleParameter GetCorrespondingParameter(IModuleParameter p, IModelSystemStructure oldMSS)
 {
     return GetCorrespondingParameter( p, oldMSS, this.GeneratedModelSystem.ModelSystemStructure );
 }
Ejemplo n.º 36
0
 private ParameterModel GetParameterModel(ModelSystemStructureModel owner, IModuleParameter moduleParameter)
 {
     var parameters = owner.Parameters.Parameters;
     if(parameters != null)
     {
         for(int i = 0; i < parameters.Count; i++)
         {
             if(parameters[i].RealParameter == moduleParameter)
             {
                 return parameters[i];
             }
         }
     }
     return null;
 }
Ejemplo n.º 37
0
 private void lpContextMenu_OpenFileWithRequested(IModuleParameter parameter)
 {
     OpenFile(parameter, true, false);
 }
Ejemplo n.º 38
0
 private void lpContextMenu_OpenFileLocationRequested(IModuleParameter parameter)
 {
     OpenFile(parameter, false, true);
 }
 public RemoveParameterFromLinkedParameter(ILinkedParameter linkedParameter, IModuleParameter parameter)
 {
     this.LinkedParameter = linkedParameter;
     this.Parameter = parameter;
 }
 private void lpContextMenu_OpenFileWithRequested(IModuleParameter parameter)
 {
     OpenFile(parameter, true, false);
 }
 private void lpContextMenu_SelectFileRequested(IModuleParameter parameter)
 {
     var module = parameter.BelongsTo;
     var currentRoot = this.GetRoot(module);
     var inputDirectory = GetInputDirectory(currentRoot);
     if(inputDirectory != null)
     {
         string fileName = this.OpenFile();
         if(fileName == null)
         {
             return;
         }
         TransformToRelativePath(inputDirectory, ref fileName);
         if(this.AddCommand(new Commands.Editing.ParameterChangeCommand(parameter,
             fileName, this.GetLinkParameters())))
         {
             this.ParameterEditor.RefreshParameters();
             this.QuickParameterControl.RefreshParameters();
             this.Save();
         }
         else
         {
             MessageBox.Show("Unable to set file name'" + fileName + "'!", "Unable set file name",
                MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
Ejemplo n.º 42
0
 private string LookupName(IModuleParameter reference)
 {
     return LookupName(reference, ModelSystemStructure);
 }
 private void ParameterUpdate(IModuleParameter parameter, string newValue)
 {
     List<ILinkedParameter> linkedParameters = null;
     if(_Project != null)
     {
         if(this._Project.LinkedParameters != null)
         {
             linkedParameters = this._Project.LinkedParameters[this._Project.ModelSystemStructure.IndexOf(this.Root)];
         }
     }
     else
     {
         linkedParameters = this.ModelSystem.LinkedParameters;
     }
     this.AddCommand(new ParameterChangeCommand(parameter, newValue, linkedParameters));
 }
Ejemplo n.º 44
0
        private void LoadFromStream(Stream stream, IConfiguration config, ref string error)
        {
            if (_LinkedParameters == null)
            {
                _LinkedParameters = new List <ILinkedParameter>();
            }
            else
            {
                _LinkedParameters.Clear();
            }
            ModelSystemStructure          = XTMF.ModelSystemStructure.Load(stream, config);
            ModelSystemStructure.Required = true;
            // restart to get to the linked parameters
            stream.Seek(0, SeekOrigin.Begin);
            using (XmlReader reader = XmlReader.Create(stream))
            {
                bool skipRead = false;
                while (!reader.EOF && (skipRead || reader.Read()))
                {
                    skipRead = false;
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }
                    switch (reader.LocalName)
                    {
                    case "LinkedParameter":
                    {
                        string linkedParameterName = "Unnamed";
                        string valueRepresentation = null;
                        var    startingDepth       = reader.Depth;
                        while (reader.MoveToNextAttribute())
                        {
                            if (reader.NodeType == XmlNodeType.Attribute)
                            {
                                if (reader.LocalName == "Name")
                                {
                                    linkedParameterName = reader.ReadContentAsString();
                                }
                                else if (reader.LocalName == "Value")
                                {
                                    valueRepresentation = reader.ReadContentAsString();
                                }
                            }
                        }
                        LinkedParameter lp = new LinkedParameter(linkedParameterName);
                        lp.SetValue(valueRepresentation, ref error);
                        _LinkedParameters.Add(lp);
                        skipRead = true;
                        while (reader.Read())
                        {
                            if (reader.Depth <= startingDepth && reader.NodeType != XmlNodeType.Element)
                            {
                                break;
                            }
                            if (reader.NodeType != XmlNodeType.Element)
                            {
                                continue;
                            }
                            if (reader.LocalName == "Reference")
                            {
                                string variableLink = null;
                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.Name == "Name")
                                    {
                                        variableLink = reader.ReadContentAsString();
                                    }
                                }
                                if (variableLink != null)
                                {
                                    IModuleParameter param = GetParameterFromLink(variableLink);
                                    if (param != null)
                                    {
                                        // in any case if there is a type error, just throw it out
                                        lp.Add(param, ref error);
                                    }
                                }
                            }
                        }
                    }
                    break;

                    case "Description":
                    {
                        bool textLast = false;

                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Text)
                            {
                                textLast = true;
                                break;
                            }
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                skipRead = true;
                                break;
                            }
                        }
                        if (textLast)
                        {
                            Description = reader.ReadContentAsString();
                        }
                    }
                    break;
                    }
                }
            }
        }
Ejemplo n.º 45
0
        private static void BackupTypeLoader(XmlAttribute paramTypeAttribute, XmlAttribute paramValueAttribute, IModuleParameter selectedParam)
        {
            switch(paramTypeAttribute.InnerText)
            {
                case "System.String":
                    {
                        selectedParam.Value = paramValueAttribute.InnerText;
                    }
                    break;

                case "System.Int32":
                    {
                        Int32 temp;
                        if(Int32.TryParse(paramValueAttribute.InnerText, out temp))
                        {
                            selectedParam.Value = temp;
                        }
                    }
                    break;

                case "System.Int64":
                    {
                        Int64 temp;
                        if(Int64.TryParse(paramValueAttribute.InnerText, out temp))
                        {
                            selectedParam.Value = temp;
                        }
                    }
                    break;

                case "System.DateTime":
                    {
                        DateTime temp;
                        if(DateTime.TryParse(paramValueAttribute.InnerText, out temp))
                        {
                            selectedParam.Value = temp;
                        }
                    }
                    break;

                case "System.Single":
                    {
                        Single temp;
                        if(Single.TryParse(paramValueAttribute.InnerText, out temp))
                        {
                            selectedParam.Value = temp;
                        }
                    }
                    break;

                case "System.Double":
                    {
                        Double temp;
                        if(Double.TryParse(paramValueAttribute.InnerText, out temp))
                        {
                            selectedParam.Value = temp;
                        }
                    }
                    break;

                case "System.Boolean":
                    {
                        bool temp;
                        if(Boolean.TryParse(paramValueAttribute.InnerText, out temp))
                        {
                            selectedParam.Value = temp;
                        }
                    }
                    break;

                case "System.Char":
                    {
                        char temp;
                        if(Char.TryParse(paramValueAttribute.InnerText, out temp))
                        {
                            selectedParam.Value = temp;
                        }
                    }
                    break;

                default:
                    {
                        //TODO: Unable to load a type we don't know about, should add this to a Log entry or something
                    }
                    break;
            }
        }
Ejemplo n.º 46
0
        private static void AssignTypeValue(XmlAttribute paramTIndex, XmlAttribute paramTypeAttribute, XmlAttribute paramValueAttribute, IModuleParameter selectedParam, Dictionary <int, Type> lookUp)
        {
            string error = null;
            var    temp  = ArbitraryParameterParser.ArbitraryParameterParse(selectedParam.Type, paramValueAttribute.InnerText, ref error);

            if (temp != null)
            {
                // don't overwrite the default if we are loading something bad
                selectedParam.Value = temp;
            }
        }
Ejemplo n.º 47
0
        private void Load(IConfiguration config, string name)
        {
            if (name != null)
            {
                var fileName = Path.Combine(Config.ModelSystemDirectory, name + ".xml");
                if (_LinkedParameters == null)
                {
                    _LinkedParameters = new List <ILinkedParameter>();
                }
                else
                {
                    _LinkedParameters.Clear();
                }
                try
                {
                    ModelSystemStructure = XTMF.ModelSystemStructure.Load(fileName, config);
                    using (XmlReader reader = XmlReader.Create(fileName))
                    {
                        bool skipRead = false;
                        while (!reader.EOF && (skipRead || reader.Read()))
                        {
                            skipRead = false;
                            if (reader.NodeType != XmlNodeType.Element)
                            {
                                continue;
                            }
                            switch (reader.LocalName)
                            {
                            case "LinkedParameter":
                            {
                                string linkedParameterName = "Unnamed";
                                string valueRepresentation = null;
                                var    startingDepth       = reader.Depth;
                                while (reader.MoveToNextAttribute())
                                {
                                    if (reader.NodeType == XmlNodeType.Attribute)
                                    {
                                        if (reader.LocalName == "Name")
                                        {
                                            linkedParameterName = reader.ReadContentAsString();
                                        }
                                        else if (reader.LocalName == "Value")
                                        {
                                            valueRepresentation = reader.ReadContentAsString();
                                        }
                                    }
                                }
                                LinkedParameter lp    = new LinkedParameter(linkedParameterName);
                                string          error = null;
                                lp.SetValue(valueRepresentation, ref error);
                                _LinkedParameters.Add(lp);
                                skipRead = true;
                                while (reader.Read())
                                {
                                    if (reader.Depth <= startingDepth && reader.NodeType != XmlNodeType.Element)
                                    {
                                        break;
                                    }
                                    if (reader.NodeType != XmlNodeType.Element)
                                    {
                                        continue;
                                    }
                                    if (reader.LocalName == "Reference")
                                    {
                                        string variableLink = null;
                                        while (reader.MoveToNextAttribute())
                                        {
                                            if (reader.Name == "Name")
                                            {
                                                variableLink = reader.ReadContentAsString();
                                            }
                                        }
                                        if (variableLink != null)
                                        {
                                            IModuleParameter param = GetParameterFromLink(variableLink);
                                            if (param != null)
                                            {
                                                // in any case if there is a type error, just throw it out
                                                lp.Add(param, ref error);
                                            }
                                        }
                                    }
                                }
                            }
                            break;

                            case "Description":
                            {
                                bool textLast = false;

                                while (reader.Read())
                                {
                                    if (reader.NodeType == XmlNodeType.Text)
                                    {
                                        textLast = true;
                                        break;
                                    }
                                    else if (reader.NodeType == XmlNodeType.Element)
                                    {
                                        skipRead = true;
                                        break;
                                    }
                                }
                                if (textLast)
                                {
                                    Description = reader.ReadContentAsString();
                                }
                            }
                            break;
                            }
                        }
                    }
                }
                catch
                {
                    Description = string.Empty;
                    if (_ModelSystemStructure == null)
                    {
                        _ModelSystemStructure          = new ModelSystemStructure(Config, Name, typeof(IModelSystemTemplate));
                        _ModelSystemStructure.Required = true;
                    }
                    else
                    {
                        _ModelSystemStructure.ParentFieldType = typeof(IModelSystemTemplate);
                        _ModelSystemStructure.Required        = true;
                    }
                }
            }
        }
Ejemplo n.º 48
0
 private string LookupName(IModuleParameter reference)
 {
     return(LookupName(reference, ModelSystemStructure));
 }
Ejemplo n.º 49
0
 private bool LinkedParameterEditor_RemoveLinkedParameterParameter(ILinkedParameter lp, IModuleParameter param)
 {
     if (!this.AddCommand(new RemoveParameterFromLinkedParameter(lp, param)))
     {
         return(false);
     }
     this.ParameterEditor.RefreshParameters();
     this.Save();
     return(true);
 }
Ejemplo n.º 50
0
 private string LookupName(IModuleParameter reference, IModelSystemStructure current)
 {
     var param = current.Parameters;
     if (param != null)
     {
         int index = param.Parameters.IndexOf(reference);
         if (index >= 0)
         {
             return current.Parameters.Parameters[index].Name;
         }
     }
     var childrenList = current.Children;
     if (childrenList != null)
     {
         for (int i = 0; i < childrenList.Count; i++)
         {
             var res = LookupName(reference, childrenList[i]);
             if (res != null)
             {
                 // make sure to use an escape character before the . to avoid making the mistake of reading it as another index
                 return string.Concat(current.IsCollection ? i.ToString()
                     : childrenList[i].ParentFieldName.Replace(".", "\\."), '.', res);
             }
         }
     }
     return null;
 }
Ejemplo n.º 51
0
        private static void BackupTypeLoader(XmlAttribute paramTypeAttribute, XmlAttribute paramValueAttribute, IModuleParameter selectedParam)
        {
            switch (paramTypeAttribute.InnerText)
            {
            case "System.String":
            {
                selectedParam.Value = paramValueAttribute.InnerText;
            }
            break;

            case "System.Int32":
            {
                Int32 temp;
                if (Int32.TryParse(paramValueAttribute.InnerText, out temp))
                {
                    selectedParam.Value = temp;
                }
            }
            break;

            case "System.Int64":
            {
                Int64 temp;
                if (Int64.TryParse(paramValueAttribute.InnerText, out temp))
                {
                    selectedParam.Value = temp;
                }
            }
            break;

            case "System.DateTime":
            {
                DateTime temp;
                if (DateTime.TryParse(paramValueAttribute.InnerText, out temp))
                {
                    selectedParam.Value = temp;
                }
            }
            break;

            case "System.Single":
            {
                Single temp;
                if (Single.TryParse(paramValueAttribute.InnerText, out temp))
                {
                    selectedParam.Value = temp;
                }
            }
            break;

            case "System.Double":
            {
                Double temp;
                if (Double.TryParse(paramValueAttribute.InnerText, out temp))
                {
                    selectedParam.Value = temp;
                }
            }
            break;

            case "System.Boolean":
            {
                bool temp;
                if (Boolean.TryParse(paramValueAttribute.InnerText, out temp))
                {
                    selectedParam.Value = temp;
                }
            }
            break;

            case "System.Char":
            {
                char temp;
                if (Char.TryParse(paramValueAttribute.InnerText, out temp))
                {
                    selectedParam.Value = temp;
                }
            }
            break;

            default:
            {
                //TODO: Unable to load a type we don't know about, should add this to a Log entry or something
            }
            break;
            }
        }
Ejemplo n.º 52
0
        private void lpContextMenu_AddToLinkedParameterRequested(ILinkedParameter linkedParameter, IModuleParameter parameter)
        {
            string error = null;

            if (parameter == null)
            {
                MessageBox.Show("No parameter was selected!", "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (linkedParameter == null)
            {
                MessageBox.Show("No linked parameter parameter was selected!", "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (!this.AddCommand(new AddParameterToLinkedParameters(this.GetLinkParameters(), linkedParameter, parameter), ref error))
            {
                MessageBox.Show(error, "Unable To Add", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            this.ParameterEditor.RefreshParameters();
            // this will actually refresh everything
            this.QuickParameterControl_ParameterChanged();
        }
Ejemplo n.º 53
0
 /// <summary>
 /// Remove a parameter from this linked parameter
 /// </summary>
 /// <param name="parameter">The parameter to remove</param>
 /// <returns>If we removed it from this linked parameter.
 /// If it is not contained, it will return false!</returns>
 public bool Remove(IModuleParameter parameter, ref string error)
 {
     if ( !this.Parameters.Remove( parameter ) )
     {
         error = "The parameter '" + parameter.Name + "' was not contained within '" + this.Name + "'!";
         return false;
     }
     return true;
 }
Ejemplo n.º 54
0
 private void FixType(IModuleParameter realParam)
 {
     var moduleType = realParam.BelongsTo.Type;
     if ( SearchFields( moduleType, realParam.Name ) )
     {
         return;
     }
     SearchProperties( moduleType, realParam.Name );
 }