Esempio n. 1
0
    public void Init(int id, Vector2 position, int width, int height, GUIStyle nodeStyle, GUIStyle selectedStyle, GUIStyle inPointStyle, GUIStyle outPointStyle, Action <ConnectionPoint> OnClickInPoint, Action <ConnectionPoint> OnClickOutPoint, Action <Node> OnClickRemoveNode)
    {
        this.id       = id;
        title         = "Check Variable Node";
        currentHeight = height;
        rect          = new Rect(position.x, position.y, width, height);
        style         = nodeStyle;
        inPoints.Add(new ConnectionPoint(this, ConnectionPoint.ConnectionPointType.In, inPointStyle, OnClickInPoint, 0, 0));
        outPoints.Add(new ConnectionPoint(this, ConnectionPoint.ConnectionPointType.Out, outPointStyle, OnClickOutPoint, 0, outPointOffset));
        outPoints.Add(new ConnectionPoint(this, ConnectionPoint.ConnectionPointType.Out, outPointStyle, OnClickOutPoint, 1, outPointOffset));
        defaultInPointStyle   = inPointStyle;
        defaultNodeStyle      = nodeStyle;
        selectedNodeStyle     = selectedStyle;
        defaultOnClickInPoint = OnClickInPoint;
        OnRemoveNode          = OnClickRemoveNode;

        // Load all flags from AllFlags asset into bools list
        AllFlags allFlags = (AllFlags)AssetDatabase.LoadAssetAtPath("Assets/Resources/AllFlags.asset", typeof(AllFlags));

        bools = new string[allFlags.flags.Count];
        for (int i = 0; i < bools.Length; i++)
        {
            bools[i] = allFlags.flags[i].description;
        }
    }
Esempio n. 2
0
            public void TestUInt64ToString()
            {
                var flag1NativeToString = Flag1.ToString();
                var flag2NativeToString = Flag2.ToString();

                Flag1.AsString().ShouldBeEquivalentTo(Flag1StringValue);
                Flag2.AsString().ShouldBeEquivalentTo(flag2NativeToString);
                AllFlags.AsString().ShouldBeEquivalentTo(AllFlags.ToString());
                (Flag2 | Flag10).ShouldBeEquivalentTo(Flag2Flag10StringValue);
                AllFlags.AsString().ShouldBeEquivalentTo(FlagsAllStringValue);
            }
Esempio n. 3
0
        internal void UpdateFrom(SolvedConfigurationStatus finalConfigStatus, FinalConfigStartableStatus s, DelayedPropertyNotification notifier)
        {
            AllFlags newOne = new AllFlags(finalConfigStatus, s);

            notifier.Update(this, ref _flags.CanStop, newOne.CanStop, () => CanStop);
            notifier.Update(this, ref _flags.CanStart, newOne.CanStart, () => CanStart);
            notifier.Update(this, ref _flags.CanStartWithFullStart, newOne.CanStartWithFullStart, () => CanStartWithFullStart);
            notifier.Update(this, ref _flags.CanStartWithStartRecommended, newOne.CanStartWithStartRecommended, () => CanStartWithStartRecommended);
            notifier.Update(this, ref _flags.CanStartWithStopOptionalAndRunnable, newOne.CanStartWithStopOptionalAndRunnable, () => CanStartWithStopOptionalAndRunnable);
            notifier.Update(this, ref _flags.CanStartWithFullStop, newOne.CanStartWithFullStop, () => CanStartWithFullStop);
        }
Esempio n. 4
0
 // Singleton
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(this);
     }
     else
     {
         Destroy(this);
     }
 }
Esempio n. 5
0
 private bool FlagsSingle(string flag)
 {
     flag = flag.Trim();
     if (flag == "")
     {
         return(true);
     }
     if (flag[0] == '!')
     {
         return(!AllFlags.Contains(flag.Substring(1)));
     }
     return(AllFlags.Contains(flag));
 }
Esempio n. 6
0
    private static void CreateAllConditionsAsset()
    {
        if (Instance)
        {
            return;
        }

        AllFlags instance = CreateInstance <AllFlags>();

        AssetDatabase.CreateAsset(instance, "Assets/Resources/AllFlags.asset");

        Instance = instance;

        instance.flags = new List <Flag>();
    }
    void OnEnable()
    {
        if (boolIndex == null)
        {
            boolIndex = new List <int>();
        }
        if (boolValueIndex == null)
        {
            boolValueIndex = new List <int>();
        }

        AllFlags allFlags = (AllFlags)AssetDatabase.LoadAssetAtPath("Assets/Resources/AllFlags.asset", typeof(AllFlags));

        bools = new string[allFlags.flags.Count];
        for (int i = 0; i < bools.Length; i++)
        {
            bools[i] = allFlags.flags[i].description;
        }
    }
Esempio n. 8
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build flagstring
                string flags = "{";
                if (Urg)
                {
                    flags += "urg[0x" + System.Convert.ToString(UrgentPointer, 16) + "]|";
                }
                if (Ack)
                {
                    flags += "ack[" + AcknowledgmentNumber + " (0x" + System.Convert.ToString(AcknowledgmentNumber, 16) + ")]|";
                }
                if (Psh)
                {
                    flags += "psh|";
                }
                if (Rst)
                {
                    flags += "rst|";
                }
                if (Syn)
                {
                    flags += "syn[0x" + System.Convert.ToString(SequenceNumber, 16) + "," + SequenceNumber + "]|";
                }
                flags  = flags.TrimEnd('|');
                flags += "}";

                // build the output string
                buffer.AppendFormat("{0}[TCPPacket: SourcePort={2}, DestinationPort={3}, Flags={4}]{1}",
                                    color,
                                    colorEscape,
                                    SourcePort,
                                    DestinationPort,
                                    flags);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("source port", SourcePort.ToString());
                properties.Add("destination port", DestinationPort.ToString());
                properties.Add("sequence number", SequenceNumber.ToString() + " (0x" + SequenceNumber.ToString("x") + ")");
                properties.Add("acknowledgement number", AcknowledgmentNumber.ToString() + " (0x" + AcknowledgmentNumber.ToString("x") + ")");
                // TODO: Implement a HeaderLength property for TCPPacket
                //properties.Add("header length", HeaderLength.ToString());
                properties.Add("flags", "(0x" + AllFlags.ToString("x") + ")");
                string flags = Convert.ToString(AllFlags, 2).PadLeft(8, '0');
                properties.Add("", flags[0] + "... .... = [" + flags[0] + "] congestion window reduced");
                properties.Add(" ", "." + flags[1] + ".. .... = [" + flags[1] + "] ECN - echo");
                properties.Add("  ", ".." + flags[2] + ". .... = [" + flags[2] + "] urgent");
                properties.Add("   ", "..." + flags[3] + " .... = [" + flags[3] + "] acknowledgement");
                properties.Add("    ", ".... " + flags[4] + "... = [" + flags[4] + "] push");
                properties.Add("     ", ".... ." + flags[5] + ".. = [" + flags[5] + "] reset");
                properties.Add("      ", ".... .." + flags[6] + ". = [" + flags[6] + "] syn");
                properties.Add("       ", ".... ..." + flags[7] + " = [" + flags[7] + "] fin");
                properties.Add("window size", WindowSize.ToString());
                properties.Add("checksum", "0x" + Checksum.ToString() + " [" + (ValidChecksum ? "valid" : "invalid") + "]");
                properties.Add("options", "0x" + BitConverter.ToString(Options).Replace("-", "").PadLeft(12, '0'));
                var parsedOptions = OptionsCollection;
                if (parsedOptions != null)
                {
                    for (int i = 0; i < parsedOptions.Count; i++)
                    {
                        properties.Add("option" + (i + 1).ToString(), parsedOptions[i].ToString());
                    }
                }

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("TCP:  ******* TCP - \"Transmission Control Protocol\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("TCP:");
                foreach (var property in properties)
                {
                    if (property.Key.Trim() != "")
                    {
                        buffer.AppendLine("TCP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                    }
                    else
                    {
                        buffer.AppendLine("TCP: " + property.Key.PadLeft(padLength) + "   " + property.Value);
                    }
                }
                buffer.AppendLine("TCP:");
            }

            // append the base class output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 9
0
 internal void UpdateFrom( SolvedConfigurationStatus finalConfigStatus, FinalConfigStartableStatus s, DelayedPropertyNotification notifier )
 {
     AllFlags newOne = new AllFlags( finalConfigStatus, s );
     notifier.Update( this, ref _flags.CanStop, newOne.CanStop, () => CanStop );
     notifier.Update( this, ref _flags.CanStart, newOne.CanStart, () => CanStart );
     notifier.Update( this, ref _flags.CanStartWithFullStart, newOne.CanStartWithFullStart, () => CanStartWithFullStart );
     notifier.Update( this, ref _flags.CanStartWithStartRecommended, newOne.CanStartWithStartRecommended, () => CanStartWithStartRecommended );
     notifier.Update( this, ref _flags.CanStartWithStopOptionalAndRunnable, newOne.CanStartWithStopOptionalAndRunnable, () => CanStartWithStopOptionalAndRunnable );
     notifier.Update( this, ref _flags.CanStartWithFullStop, newOne.CanStartWithFullStop, () => CanStartWithFullStop );
 }
Esempio n. 10
0
 internal LiveRunCapability( SolvedConfigurationStatus finalConfigStatus, FinalConfigStartableStatus s )
 {
     _flags = new AllFlags( finalConfigStatus, s );
 }
Esempio n. 11
0
 public void TestUInt64RemoveFlags()
 {
     AllFlags.RemoveFlags(Flag1, Flag2, Flag4, Flag8).ShouldBeEquivalentTo(Flag10);
 }
Esempio n. 12
0
 public int SameFlags(BlockInfo other)
 {
     return(AllFlags.Intersect(other.AllFlags).Count());
 }
Esempio n. 13
0
        IEnumerable <Action> InternalRun(List <CmdlineArgument> args)
        {
            showCompletion = Environment.GetEnvironmentVariable("SHOW_COMPLETIONS").Eval((e) => e != null && (e == "1" || e == "2"));

            CmdlineParseItem cmdToRun = null;

            var missingCommand = false;
            var missingFlag    = false;

            #region flags
            if (AllFlags.Any())
            {
                foreach (var(arg, argIdx) in args.WithIndex())
                {
                    if (arg.Matched)
                    {
                        continue;
                    }

                    var availFlags = AllFlags.Where(r => !r.Matches);
                    if (!availFlags.Any())
                    {
                        break;                    // all flags consumed
                    }
                    CmdlineParseItem qFlag = null;

                    foreach (var flag in availFlags)
                    {
                        #region short flag
                        if (flag.HasShortName)
                        {
                            if (flag.HasValueName)
                            {
                                if (arg.Argument == flag.ShortFlag)
                                {
                                    if (argIdx < args.Count - 1)
                                    {
                                        var valArg = args[argIdx + 1];
                                        valArg.MatchedItem = flag;
                                        flag.SetValue(valArg);
                                        qFlag = flag;
                                        break;
                                    }
                                }
                                else if (arg.Argument.StartsWith($"{flag.ShortFlag}="))
                                {
                                    flag.SetValue(arg, arg.Argument.Substring($"{flag.ShortFlag}=".Length));
                                    qFlag = flag;
                                    break;
                                }
                                else if (flag.ShortFlag.StartsWith(arg.Argument))
                                {
                                    PrintCompletions(new[] { $"{flag.ShortFlag}=" });
                                }
                            }
                            else
                            {
                                if (arg.Argument == flag.ShortFlag)
                                {
                                    qFlag = flag;
                                    break;
                                }
                                else if (flag.ShortFlag.StartsWith(arg.Argument))
                                {
                                    PrintCompletions(new[] { flag.ShortFlag });
                                }
                            }
                        }
                        #endregion

                        #region long flag
                        if (flag.HasLongName)
                        {
                            if (flag.HasValueName)
                            {
                                if (arg.Argument == flag.LongFlag)
                                {
                                    if (argIdx < args.Count - 1)
                                    {
                                        var valArg = args[argIdx + 1];
                                        valArg.MatchedItem = flag;
                                        flag.SetValue(valArg);
                                        qFlag = flag;
                                        break;
                                    }
                                }
                                else if (arg.Argument.StartsWith($"{flag.LongFlag}="))
                                {
                                    flag.SetValue(arg, arg.Argument.Substring($"{flag.LongFlag}=".Length));
                                    qFlag = flag;
                                    break;
                                }
                                else if (flag.LongFlag.StartsWith(arg.Argument))
                                {
                                    PrintCompletions(new[] { $"{flag.LongFlag}=" });
                                }
                            }
                            else
                            {
                                if (arg.Argument == flag.LongFlag)
                                {
                                    qFlag = flag;
                                    break;
                                }
                                else if (flag.LongFlag.StartsWith(arg.Argument))
                                {
                                    PrintCompletions(new[] { flag.LongFlag });
                                }
                            }
                        }
                        #endregion
                    }

                    if (qFlag != null)
                    {
                        qFlag.Match(this, arg);
                        if (!qFlag.GlobalFlagActionNested && qFlag.GlobalFlagAction != null)
                        {
                            qFlag.GlobalFlagAction(qFlag);
                            qFlag.GlobalFlagActionExecuted = true;
                        }
                    }
                }

                if (!showCompletion)
                {
                    var qMandatoryMissing = Flags.FirstOrDefault(r => r.Mandatory && !r.Matches);
                    if (qMandatoryMissing != null)
                    {
                        ErrorColor();
                        System.Console.WriteLine($"missing mandatory flag [{qMandatoryMissing.ShortLongFlag}]");
                        ResetColors();
                        PrintUsage();
                        missingFlag = true;
                    }
                }
            }
            #endregion

            #region commands
            if (Commands.Any())
            {
                var arg = args.FirstOrDefault(w => !w.Matched);

                if (arg != null)
                {
                    var qcmd = Commands.FirstOrDefault(w => w.ShortName == arg.Argument);
                    // if not found valid command checks global flags
                    if (qcmd == null)
                    {
                        missingCommand = true;

                        if (showCompletion)
                        {
                            PrintCompletions(Commands.Select(w => w.ShortName).Where(r => r.StartsWith(arg.Argument) && r != arg.Argument));
                        }
                    }
                    else
                    {
                        qcmd.Match(this, arg);
                        cmdToRun = qcmd;
                    }
                }
                else
                {
                    missingCommand = true;

                    if (showCompletion)
                    {
                        PrintCompletions(Commands.Select(w => w.ShortName));
                    }
                }
            }
            #endregion

            CmdlineParseItem missingParameter = null;

            #region parameters
            if (ParametersOrArray.Any())
            {
                foreach (var param in Parameters)
                {
                    var arg = args.FirstOrDefault(r => !r.Matched);

                    if (arg == null)
                    {
                        if (showCompletion)
                        {
                            if (param.onCompletion != null && !missingCommand)
                            {
                                PrintCompletions(param.onCompletion(""));
                            }
                        }
                        else
                        {
                            if (param.Mandatory)
                            {
                                missingParameter = param;
                            }
                            break;
                        }
                    }
                    else
                    {
                        var skipCompletion = !showCompletion;

                        if (showCompletion)
                        {
                            if (param.onCompletion != null && !missingCommand)
                            {
                                var completions = param.onCompletion(arg.Argument).Where(r => r != arg.Argument);
                                if (completions.Count() > 0)
                                {
                                    PrintCompletions(completions);
                                }
                                else
                                {
                                    skipCompletion = true;
                                }
                            }
                        }

                        if (skipCompletion)
                        {
                            param.Match(this, arg);
                            param.SetValue(arg);
                        }
                    }
                }

                var parr = ParameterArrays.FirstOrDefault();

                if (parr != null)
                {
                    var parrArgs = new List <CmdlineArgument>();
                    while (true)
                    {
                        var arg = args.FirstOrDefault(r => !r.Matched);
                        if (arg == null)
                        {
                            if (showCompletion)
                            {
                                if (parr.onCompletion != null && !missingCommand)
                                {
                                    PrintCompletions(parr.onCompletion(""));
                                }
                            }
                            else
                            {
                                if (parr.Mandatory && parrArgs.Count == 0)
                                {
                                    missingParameter = parr;
                                }
                            }
                            break;
                        }
                        else
                        {
                            var skipCompletion = !showCompletion || parr.onCompletion == null;

                            if (showCompletion)
                            {
                                if (parr.onCompletion != null && !missingCommand)
                                {
                                    var completions = parr.onCompletion(arg.Argument).Where(r => r != arg.Argument);
                                    if (completions.Count() > 0)
                                    {
                                        PrintCompletions(completions);
                                        break;
                                    }
                                    else
                                    {
                                        skipCompletion = true;
                                    }
                                }
                            }

                            if (skipCompletion)
                            {
                                parr.Match(this, arg);
                                parrArgs.Add(arg);
                            }
                        }
                    }
                    parr.SetValues(parrArgs);
                }
            }
            #endregion

            var qglobal = AllFlags.Where(r => r.IsGlobal && r.GlobalFlagActionNested && r.Matches).ToList();

            if (!showCompletion && qglobal.Count == 0 && missingCommand)
            {
                ErrorColor();
                System.Console.WriteLine($"missing command");
                ResetColors();
                PrintUsage();
                yield break;
            }

            if (!showCompletion && missingParameter != null)
            {
                ErrorColor();
                System.Console.WriteLine($"missing required parameter [{missingParameter.ShortName}]");
                ResetColors();
                PrintUsage();
                yield break;
            }

            if (!showCompletion && onCmdlineMatch != null && qglobal.Count == 0 && !missingFlag)
            {
                yield return(onCmdlineMatch);
            }

            if (cmdToRun != null)
            {
                var qGlobalToremove = new List <CmdlineParseItem>();
                foreach (var x in qglobal)
                {
                    if (!x.GlobalFlagActionNested)
                    {
                        qGlobalToremove.Add(x);
                    }
                    else
                    {
                        x.Unmatch();
                    }
                }
                foreach (var x in qGlobalToremove)
                {
                    qglobal.Remove(x);
                }

                if (!missingFlag)
                {
                    foreach (var x in cmdToRun.Parser.InternalRun(args))
                    {
                        yield return(x);
                    }
                }
                yield break;
            }
            if (cmdToRun == null && qglobal.Count > 0)
            {
                foreach (var x in qglobal.Where(r => !r.GlobalFlagActionExecuted))
                {
                    x.GlobalFlagAction(x);
                }
                yield break;
            }
        }
Esempio n. 14
0
 internal LiveRunCapability(SolvedConfigurationStatus finalConfigStatus, FinalConfigStartableStatus s)
 {
     _flags = new AllFlags(finalConfigStatus, s);
 }