Example #1
0
 public GlobalVariableTypeChangedAction(GlobalVariable variable, GlobalVariableType old, GlobalVariableType newName)
 {
     this.variable = variable;
     this.old      = old;
     this.newName  = newName;
     this.id       = variable.Key;
 }
        private static string GetVariableContent(GlobalVariableType globalVariable)
        {
            string resultValue = string.Empty;

            if (cacheVariablesData.ContainsKey(globalVariable))
            {
                resultValue = cacheVariablesData[globalVariable];
            }
            else
            {
                switch (globalVariable)
                {
                case GlobalVariableType.Timestamp:
                    resultValue = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds().ToString();
                    break;

                case GlobalVariableType.CurrentUserName:
                    resultValue = SystemHelper.GetCurrentUserName();
                    //缓存
                    cacheVariablesData.Add(globalVariable, resultValue);
                    break;
                }
            }

            return(resultValue);
        }
 internal VariableContextualParameter(GlobalVariableType type,
                                      string name, IVariablePickerService picker, IItemFromListProvider itemFromListProvider)
 {
     this.type   = type;
     this.name   = name;
     this.picker = picker;
     this.itemFromListProvider = itemFromListProvider;
 }
Example #4
0
        private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
        {
            GlobalVariableType chosenType = (GlobalVariableType)cmbType.SelectedItem;

            bool defaultValid = chosenType.CanHaveDefaultValue;

            txtDefaultValue.Enabled = defaultValid;
            if (!defaultValid)
            {
                txtDefaultValue.Text = string.Empty;
            }
        }
    public async Task <long?> PickVariable(GlobalVariableType type, SmartScriptBase script, long?currentValue)
    {
        var vm = containerProvider.Resolve <VariablePickerViewModel>((typeof(GlobalVariableType), type),
                                                                     (typeof(SmartScriptBase), script), (typeof(long?), currentValue));

        if (await windowManager.ShowDialog(vm))
        {
            return(vm.SelectedItem?.Id);
        }

        return(null);
    }
Example #6
0
        private void OnTypeChanged(GlobalVariableType oldType)
        {
            if (oldType != Type)
            {
                // When type changed or set for the first time
                // Initialize value
                switch (Type)
                {
                case GlobalVariableType.None:
                case GlobalVariableType.Short:
                case GlobalVariableType.Int:
                case GlobalVariableType.Float:
                    Value = 0;
                    break;

                default:
                    // Unknown type enconutered
                    throw new ArgumentException("Illegal Global Variable type: " + Type);
                }
            }
        }
Example #7
0
        public FNAM(byte[] rawData) : base(rawData)
        {
            var reader = new ByteReader();

            VariableType = (GlobalVariableType)reader.ReadBytes <byte>(Data);
        }
Example #8
0
 private void OnGlobalVariableTypeChanged(GlobalVariable variable, GlobalVariableType old, GlobalVariableType newValue)
 {
     PushAction(new GlobalVariableTypeChangedAction(variable, old, newValue));
 }
Example #9
0
 public GlobalVariable(string name, GlobalVariableType type) : this(new GlobalVariableKey(name), type)
 {
 }
Example #10
0
 public GlobalVariable(GlobalVariableKey key, GlobalVariableType type) : base(key)
 {
     Type = type;
 }
Example #11
0
        public static string ToString(long value, SmartBaseElement context, string name, GlobalVariableType type)
        {
            var script = GetScript(context);

            if (script != null)
            {
                foreach (var c in script.GlobalVariables)
                {
                    if (c.VariableType == type && c.Key == value && c.Name != "")
                    {
                        return(c.Name);
                    }
                }
            }

            return($"{name}\\[{value}\\]");
        }
Example #12
0
 internal VariableContextualParameter(GlobalVariableType type, string name)
 {
     this.type = type;
     this.name = name;
 }
Example #13
0
        private void OnTypeChanged(GlobalVariableType oldType)
        {
            if (oldType != Type)
            {
                // When type changed or set for the first time
                // Initialize value
                switch (Type)
                {
                    case GlobalVariableType.None:
                    case GlobalVariableType.Short:
                    case GlobalVariableType.Int:
                    case GlobalVariableType.Float:
                        Value = 0;
                        break;

                    default:
                        // Unknown type enconutered
                        throw new ArgumentException("Illegal Global Variable type: " + Type);
                }
            }
        }
    public VariablePickerViewModel(GlobalVariableType type, SmartScriptBase script, long?initial)
    {
        this.type   = type;
        this.script = script;
        Items       = new(script.GlobalVariables.Where(gv => gv.VariableType == type)
                          .OrderBy(i => i.Key)
                          .Distinct(Compare.By <GlobalVariable, long>(i => i !.Key))
                          .Select(gv => new VariableItemViewModel(gv)));

        SelectedItem = initial.HasValue ? Items.FirstOrDefault(i => i.Id == initial) : null;

        if (SelectedItem == null && initial != null)
        {
            var phantom = VariableItemViewModel.CreatePhantom(initial.Value);
            Items.Add(phantom);
            SelectedItem = phantom;
        }

        Cancel = new DelegateCommand(() =>
        {
            CloseCancel?.Invoke();
        });
        Accept = new DelegateCommand(() =>
        {
            var dict = Items.Where(i => !i.IsPhantom).SafeToDictionary(i => i.OriginalId ?? i.Id, i => i);
            for (var i = script.GlobalVariables.Count - 1; i >= 0; i--)
            {
                var existing = script.GlobalVariables[i];
                if (existing.VariableType == type)
                {
                    if (dict.TryGetValue(existing.Key, out var item))
                    {
                        existing.Key     = item.Id;
                        existing.Name    = item.Name;
                        existing.Comment = item.Comment;
                        dict.Remove(item.OriginalId ?? item.Id);
                    }
                    else
                    {
                        script.GlobalVariables.RemoveAt(i);
                    }
                }
            }

            foreach (var pair in dict)
            {
                script.GlobalVariables.Add(new GlobalVariable()
                {
                    Key          = pair.Key,
                    Name         = pair.Value.Name,
                    Comment      = pair.Value.Comment,
                    VariableType = type
                });
            }

            CloseOk?.Invoke();
        });

        AddItemCommand = new DelegateCommand(() =>
        {
            var phantom = VariableItemViewModel.CreatePhantom((Items.Count > 0 ? Items.Max(i => i.Id) : 0) + 1);
            Items.Add(phantom);
            SelectedItem = phantom;
        });

        RemoveItemCommand = new DelegateCommand(() =>
        {
            if (SelectedItem != null)
            {
                Items.Remove(SelectedItem);
                SelectedItem = null;
            }
        }, () => SelectedItem != null).ObservesProperty(() => SelectedItem);

        Items.DisposeOnRemove();
        AutoDispose(new ActionDisposable(() => Items.Clear()));
    }
Example #15
0
 public static Types ToType(this GlobalVariableType value)
 {
     return(ConvertByName <Types>(value));
 }