Пример #1
0
        private string LookupName(ParameterModel reference, ModelSystemStructureModel current)
        {
            var param = current.Parameters;

            if (param != null && param.Parameters != 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);
        }
Пример #2
0
 internal bool Contains(ParameterModel toCheck)
 {
     lock (_ParameterModelsLock)
     {
         return(_ParameterModels.Contains(toCheck));
     }
 }
Пример #3
0
        /// <summary>
        /// Removes a parameter from this linked parameter
        /// </summary>
        /// <param name="toRemove">The parameter to remove</param>
        /// <param name="error">An error message if this is not possible</param>
        /// <returns>True if the parameter was removed, false if it was not.</returns>
        public bool RemoveParameter(ParameterModel toRemove, ref string error)
        {
            LinkedParameterChange change = new LinkedParameterChange();

            return(_Session.RunCommand(XTMFCommand.CreateCommand(
                                           "Remove Parameter from Linked Parameter",
                                           // do
                                           (ref string e) =>
            {
                // we need this outer lock to make sure that it doesn't change while we are checking to make sure that it is contained
                lock (_ParameterModelsLock)
                {
                    if (!_ParameterModels.Contains(toRemove))
                    {
                        e = "The parameter does not exist inside of the linked parameter!";
                        return false;
                    }
                    change.Index = NoCommandRemove(toRemove);
                }
                return true;
            },
                                           // undo
                                           (ref string e) =>
            {
                return NoCommandAdd(toRemove, change.Index, ref e);
            },
                                           // redo
                                           (ref string e) =>
            {
                NoCommandRemove(toRemove);
                return true;
            }
                                           ), ref error));
        }
Пример #4
0
 private void NoCommandAdd(ParameterModel toAdd, int index)
 {
     lock (ParameterModelsLock)
     {
         string error = null;
         ParameterModels.Insert(index, toAdd);
         RealLinkedParameter.Add(toAdd.RealParameter, ref error);
         toAdd.UpdateValueFromReal();
         toAdd.SignalIsLinkedChanged();
     }
 }
Пример #5
0
 private int NoCommandRemove(ParameterModel toRemove)
 {
     lock (ParameterModelsLock)
     {
         var    index = ParameterModels.IndexOf(toRemove);
         string error = null;
         ParameterModels.RemoveAt(index);
         RealLinkedParameter.Remove(toRemove.RealParameter, ref error);
         toRemove.UpdateValueFromReal();
         toRemove.SignalIsLinkedChanged();
         return(index);
     }
 }
Пример #6
0
        /// <summary>
        /// Add a new parameter to this linked parameter
        /// </summary>
        /// <param name="toAdd">The parameter to add</param>
        /// <param name="error">This contains an error message if this returns false</param>
        /// <returns>True if we added the parameter to the linked parameter, false if it failed.</returns>
        public bool AddParameter(ParameterModel toAdd, ref string error)
        {
            LinkedParameterChange change = new LinkedParameterChange();
            var originalValue            = toAdd.Value;

            return(Session.RunCommand(XTMFCommand.CreateCommand(
                                          // do
                                          (ref string e) =>
            {
                if (ParameterModels.Contains(toAdd))
                {
                    e = "The parameter was already contained in the linked parameter!";
                    return false;
                }
                // remove from the linked parameter it was already in
                if ((change.OriginalContainedIn = ModelSystem.LinkedParameters.LinkedParameters.FirstOrDefault((lp) => lp.Contains(toAdd))) != null)
                {
                    change.OriginalIndex = change.OriginalContainedIn.NoCommandRemove(toAdd);
                }
                NoCommandAdd(toAdd, (change.Index = ParameterModels.Count));
                return true;
            },
                                          // undo
                                          (ref string e) =>
            {
                NoCommandRemove(toAdd);
                if (change.OriginalContainedIn != null)
                {
                    change.OriginalContainedIn.NoCommandAdd(toAdd, change.OriginalIndex);
                }
                else
                {
                    // if it isn't part of another linked parameter just add the value back
                    toAdd.SetValue(originalValue, ref e);
                }
                return true;
            },
                                          // redo
                                          (ref string e) =>
            {
                if (change.OriginalContainedIn != null)
                {
                    change.OriginalContainedIn.NoCommandRemove(toAdd);
                }
                NoCommandAdd(toAdd, change.Index);
                return true;
            }
                                          ), ref error));
        }
Пример #7
0
 private bool NoCommandAdd(ParameterModel toAdd, int index, ref string error)
 {
     lock (ParameterModelsLock)
     {
         ParameterModels.Insert(index, toAdd);
         // Try to add the linked parameter
         if (!RealLinkedParameter.Add(toAdd.RealParameter, ref error))
         {
             //if the add failed return that fact
             ParameterModels.RemoveAt(index);
             return(false);
         }
         toAdd.UpdateValueFromReal();
         toAdd.SignalIsLinkedChanged();
         return(true);
     }
 }
Пример #8
0
        private static ObservableCollection <ParameterModel> CreateInitialParameterModels(ILinkedParameter linkedParameter, ModelSystemModel modelSystem)
        {
            var ret  = new ObservableCollection <ParameterModel>();
            var real = linkedParameter.Parameters;

            if (real != null)
            {
                for (int i = 0; i < real.Count; i++)
                {
                    ParameterModel pm = modelSystem.GetParameterModel(real[i]);
                    if (pm != null)
                    {
                        ret.Add(pm);
                    }
                }
            }
            return(ret);
        }
Пример #9
0
 internal bool AddParameterWithoutCommand(ParameterModel parameterModel, ref string error)
 {
     return(NoCommandAdd(parameterModel, ParameterModels.Count, ref error));
 }
Пример #10
0
 internal bool Contains(ParameterModel toCheck)
 {
     lock (ParameterModelsLock)
     {
         return ParameterModels.Contains(toCheck);
     }
 }
Пример #11
0
 internal void AddParameterWithoutCommand(ParameterModel parameterModel)
 {
     NoCommandAdd(parameterModel, ParameterModels.Count);
 }
Пример #12
0
 internal void RemoveParameterWithoutCommand(ParameterModel parameterToRemove)
 {
     NoCommandRemove(parameterToRemove);
 }
Пример #13
0
 internal void AddParameterWithoutCommand(ParameterModel parameterModel)
 {
     NoCommandAdd(parameterModel, ParameterModels.Count);
 }
Пример #14
0
 private void NoCommandAdd(ParameterModel toAdd, int index)
 {
     lock (ParameterModelsLock)
     {
         string error = null;
         ParameterModels.Insert(index, toAdd);
         RealLinkedParameter.Add(toAdd.RealParameter, ref error);
         toAdd.UpdateValueFromReal();
         toAdd.SignalIsLinkedChanged();
     }
 }
Пример #15
0
 /// <summary>
 /// Removes a parameter from this linked parameter
 /// </summary>
 /// <param name="toRemove">The parameter to remove</param>
 /// <param name="error">An error message if this is not possible</param>
 /// <returns>True if the parameter was removed, false if it was not.</returns>
 public bool RemoveParameter(ParameterModel toRemove, ref string error)
 {
     LinkedParameterChange change = new LinkedParameterChange();
     return Session.RunCommand(XTMFCommand.CreateCommand(
         // do
         (ref string e) =>
         {
             // we need this outer lock to make sure that it doesn't change while we are checking to make sure that it is contained
             lock (ParameterModelsLock)
             {
                 if(!ParameterModels.Contains(toRemove))
                 {
                     e = "The parameter does not exist inside of the linked parameter!";
                     return false;
                 }
                 change.Index = NoCommandRemove(toRemove);
             }
             return true;
         },
         // undo
         (ref string e) =>
         {
             NoCommandAdd(toRemove, change.Index);
             return true;
         },
         // redo
         (ref string e) =>
         {
             NoCommandRemove(toRemove);
             return true;
         }
         ), ref error);
 }
Пример #16
0
 public LinkedParameterModel GetContained(ParameterModel parameterModel)
 {
     return(LinkedParameters.FirstOrDefault((model) => model.Contains(parameterModel)));
 }
Пример #17
0
 internal void RemoveParameterWithoutCommand(ParameterModel parameterToRemove)
 {
     NoCommandRemove(parameterToRemove);
 }
Пример #18
0
 private int NoCommandRemove(ParameterModel toRemove)
 {
     lock (ParameterModelsLock)
     {
         var index = ParameterModels.IndexOf(toRemove);
         string error = null;
         ParameterModels.RemoveAt(index);
         RealLinkedParameter.Remove(toRemove.RealParameter, ref error);
         toRemove.UpdateValueFromReal();
         toRemove.SignalIsLinkedChanged();
         return index;
     }
 }
Пример #19
0
 internal bool AddParameterWithoutCommand(ParameterModel parameterModel, ref string error) => NoCommandAdd(parameterModel, _ParameterModels.Count, ref error);
Пример #20
0
 public LinkedParameterModel GetContained(ParameterModel parameterModel)
 {
     return this.LinkedParameters.FirstOrDefault((model) => model.Contains(parameterModel));
 }
Пример #21
0
 private string LookupName(ParameterModel reference, ModelSystemStructureModel current)
 {
     var param = current.Parameters;
     if(param != null && param.Parameters != 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;
 }
Пример #22
0
 /// <summary>
 /// Add a new parameter to this linked parameter
 /// </summary>
 /// <param name="toAdd">The parameter to add</param>
 /// <param name="error">This contains an error message if this returns false</param>
 /// <returns>True if we added the parameter to the linked parameter, false if it failed.</returns>
 public bool AddParameter(ParameterModel toAdd, ref string error)
 {
     LinkedParameterChange change = new LinkedParameterChange();
     var originalValue = toAdd.Value;
     return Session.RunCommand(XTMFCommand.CreateCommand(
         // do
         (ref string e) =>
         {
             if(ParameterModels.Contains(toAdd))
             {
                 e = "The parameter was already contained in the linked parameter!";
                 return false;
             }
             // remove from the linked parameter it was already in
             if((change.OriginalContainedIn = ModelSystem.LinkedParameters.LinkedParameters.FirstOrDefault((lp) => lp.Contains(toAdd))) != null)
             {
                 change.OriginalIndex = change.OriginalContainedIn.NoCommandRemove(toAdd);
             }
             NoCommandAdd(toAdd, (change.Index = ParameterModels.Count));
             return true;
         },
         // undo
         (ref string e) =>
         {
             NoCommandRemove(toAdd);
             if(change.OriginalContainedIn != null)
             {
                 change.OriginalContainedIn.NoCommandAdd(toAdd, change.OriginalIndex);
             }
             else
             {
                 // if it isn't part of another linked parameter just add the value back
                 toAdd.SetValue(originalValue, ref e);
             }
             return true;
         },
         // redo
         (ref string e) =>
         {
             if(change.OriginalContainedIn != null)
             {
                 change.OriginalContainedIn.NoCommandRemove(toAdd);
             }
             NoCommandAdd(toAdd, change.Index);
             return true;
         }
         ), ref error);
 }