internal void InsertAction(AddRowsTest.InsertPosition insertPosition, int count)
        {
            var selValues = new SelectedValues();

            selValues.Values = SelectedValue.CreateNew(count);
            switch (insertPosition)
            {
            case AddRowsTest.InsertPosition.First:
                ActionValues.Insert(0, selValues);
                break;

            case AddRowsTest.InsertPosition.Second:
                ActionValues.Insert(1, selValues);
                break;

            case AddRowsTest.InsertPosition.Last:
                ActionValues.Insert(ActionValues.Count - 1, selValues);
                break;

            case AddRowsTest.InsertPosition.AfterLast:
                ActionValues.Add(selValues);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(insertPosition), insertPosition, null);
            }
        }
Пример #2
0
 public static ComponentProperty <ActionValues.ActionValue> Deserialize(
     this IValue <ActionValues.ActionValue> property, string value, List <PropertyParameter> parameters)
 {
     ((ComponentProperty <ActionValues.ActionValue>)property).PropertyParameters = parameters;
     property.Value = ActionValues.ParseValue(value);
     return((ComponentProperty <ActionValues.ActionValue>)property);
 }
        internal void AppendAction(int count)
        {
            var selValues = new SelectedValues();

            selValues.Values = SelectedValue.CreateNew(count);
            ActionValues.Add(selValues);
        }
Пример #4
0
        public List <KeyValuePair <AIAction, double> > GetActionValues(State state)
        {
            var pair = ActionValues.Find(x => x.Key.IsEqual(state));

            if (pair == null)
            {
                return(CrateActionValuesWithInitValue(state));
            }
            return(pair.Value.ConvertAll(x => new KeyValuePair <AIAction, double>(x.Key, x.Value)));
        }
Пример #5
0
        public DiscreteActionValueFunction InitActionValues(State state)
        {
            if (ActionValues.Find(x => x.Key.IsEqual(state)) != null)
            {
                return(this);
            }
            List <Pair <State, List <Pair <AIAction, double> > > > result = new List <Pair <State, List <Pair <AIAction, double> > > >(ActionValues);

            result.Add(new Pair <State, List <Pair <AIAction, double> > >(state, CrateActionValuesWithInitValue(state).ConvertAll(x => new Pair <AIAction, double>(x.Key, x.Value))));
            return(new DiscreteActionValueFunction(environment, result));
        }
Пример #6
0
        public double GetValue(State state, AIAction action)
        {
            if (state is TerminalState)
            {
                return(0);
            }
            var keyValue = ActionValues.Find(x => x.Key.IsEqual(state));

            if (keyValue == null)
            {
                return(0);
            }
            var value = keyValue.Value.Find(x => x.Key == action);

            return(value != null ? value.Value : 0.0f);
        }
Пример #7
0
        /// <summary>
        /// Méthode invoquée lors de l'initialisation du viewModel en mode design
        /// </summary>
        protected override async Task OnInitializeDesigner()
        {
            await base.OnInitializeDesigner();

            var(Categories, ActionTypes, ActionValues) = DesignData.GenerateActionCategories();
            this.Types = new SelectionNullWrapper <ActionCategory, ActionType>(
                (ActionCategory)this.ParentViewModel.CurrentItem,
                c => c.Type,
                ActionTypes,
                new ActionType()
            {
                ShortLabel = "Aucun",
                LongLabel  = "Aucun"
            },
                NullItemPosition.Bottom);
            this.Values = ActionValues.ToArray();
        }
Пример #8
0
    public static Action epsilon_greedy_policy(State state, float epsilon)
    {
        ArrayList    probs = ArrayList.Repeat(epsilon / nA, nA);
        ActionValues actionValues;

        if (Q.ContainsKey(state))
        {
            actionValues = Q [state];
        }
        else
        {
            actionValues = new ActionValues();
            Q.Add(state, actionValues);
        }
        probs [(int)actionValues.bestAction()] = 1.0 - epsilon + epsilon / nA;
        Action action = randomChoice(probs);

        return(action);
    }
        internal void DeleteAction(AddRowsTest.DeletePosition deletePosition)
        {
            switch (deletePosition)
            {
            case AddRowsTest.DeletePosition.First:
                ActionValues.RemoveAt(0);
                break;

            case AddRowsTest.DeletePosition.Second:
                ActionValues.RemoveAt(1);
                break;

            case AddRowsTest.DeletePosition.Last:
                ActionValues.RemoveAt(ActionValues.Count - 1);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(deletePosition), deletePosition, null);
            }
        }
Пример #10
0
        private void ParseHtmlActionLists(string input)
        {
            var actions = Regex.Split(input, "<p><em><strong>");

            foreach (var action in actions)
            {
                if (!string.IsNullOrEmpty(action))
                {
                    try
                    {
                        var kvp = Regex.Split(action, @"</strong></em>");
                        ActionNames.Add(StripHtmlTags(kvp[0]));
                        ActionValues.Add(StripHtmlTags(kvp[1]));
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        ///     Call this the method when u want the representation in string of the
        ///     Components properties classes
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        public static string StringRepresentation <T>(this ComponentProperty <T> property)
        {
            var strBuilder = new StringBuilder(property.Name);

            foreach (var proParam in property.PropertyParameters)
            {
                strBuilder.Append(";");
                strBuilder.Append(proParam.Name + "=" + proParam.Value);
            }

            strBuilder.Append(":");

            if (property is IValue <string> )
            {
                strBuilder.Append(((IValue <string>)property).Value);
            }
            else if (property is IValue <IList <string> > )
            {
                var flag = false;
                foreach (var cat in ((IValue <IList <string> >)property).Value)
                {
                    if (flag)
                    {
                        strBuilder.Append(',');
                    }
                    strBuilder.Append(cat);
                    flag = true;
                }
            }
            else if (property is IValue <ClassificationValues.ClassificationValue> )
            {
                strBuilder.Append(
                    ClassificationValues.ToString(((IValue <ClassificationValues.ClassificationValue>)property).Value));
            }
            else if (property is IValue <int> )
            {
                strBuilder.Append(((IValue <int>)property).Value);
            }
            else if (property is IValue <StatusValues.Values> )
            {
                strBuilder.Append(StatusValues.ToString(((IValue <StatusValues.Values>)property).Value));
            }
            else if (property is IValue <TransparencyValues.TransparencyValue> )
            {
                strBuilder.Append(
                    TransparencyValues.ToString(((IValue <TransparencyValues.TransparencyValue>)property).Value));
            }
            else if (property is IValue <DateTime> )
            {
                var propValue = ((IValue <DateTime>)property).Value;
                if (
                    property.PropertyParameters.Count(
                        propertyParameter => propertyParameter.Name == "VALUE" && propertyParameter.Value == "DATE") ==
                    1)
                {
                    strBuilder.Append(propValue.ToString("yyyyMMdd"));
                }
                else
                {
                    strBuilder.Append(propValue.ToString("yyyyMMddTHHmmss") +
                                      (propValue.Kind == DateTimeKind.Utc ? "Z" : ""));
                }
            }
            else if (property is IValue <ActionValues.ActionValue> )
            {
                strBuilder.Append(ActionValues.ToString(((IValue <ActionValues.ActionValue>)property).Value));
            }
            else if (property is IValue <DurationType> )
            {
                strBuilder.Append(((IValue <DurationType>)property).Value);
            }
            else if (property is IValue <Period> )
            {
                strBuilder.Append(((IValue <Period>)property).Value);
            }
            else if (property is IValue <TimeSpan> )
            {
                strBuilder.Append(((IValue <TimeSpan>)property).Value.ToStringOffset());
            }
            else if (property is IValue <Recur> )
            {
                strBuilder.Append(((IValue <Recur>)property).Value);
            }
            else if (property is IValue <IList <DateTime> > )
            {
                var values = ((IValue <IList <DateTime> >)property).Value;
                var flag   = false;
                var isDate =
                    property.PropertyParameters.Count(
                        propertyParameter => propertyParameter.Name == "VALUE" && propertyParameter.Value == "DATE") ==
                    1;
                foreach (var value in values)
                {
                    if (flag)
                    {
                        strBuilder.Append(',');
                    }
                    if (isDate)
                    {
                        strBuilder.Append(value.ToString("yyyyMMdd"));
                    }
                    else
                    {
                        strBuilder.Append(value.ToString("yyyyMMddTHHmmss") +
                                          (value.Kind == DateTimeKind.Utc ? "Z" : ""));
                    }
                    flag = true;
                }
            }

            return(strBuilder.SplitLines().ToString());
        }
        /// <summary>
        /// Create  SMB_COM_SESSION_SETUP_ANDX Server response packet 
        /// </summary>
        /// <param name="connection">the connection identified the client</param>
        /// <param name = "uid">
        /// the valid session id, must be response by server of the session setup request. 
        /// </param>
        /// <param name = "action">A 16-bit field. The two lowest order bits have been defined </param>
        /// <returns>The SmbSessionSetupAndXResponsePacket </returns>
        /// <exception cref="ArgumentNullException">connection must not be null</exception>
        public virtual SmbSessionSetupAndxResponsePacket CreateSmbComSessionSetupResponse(
            SmbServerConnection connection,
            ushort uid,
            ActionValues action
            )
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            SmbSessionSetupAndxResponsePacket packet = new SmbSessionSetupAndxResponsePacket();

            // create smb packet header
            SmbHeader smbHeader = CifsMessageUtils.CreateSmbHeader(
                SmbCommand.SMB_COM_SESSION_SETUP_ANDX, connection.ProcessId, connection.MessageId, uid, 0,
                (SmbFlags)connection.Capability.Flag, (SmbFlags2)connection.Capability.Flags2);

            // update smb parameters
            SMB_COM_SESSION_SETUP_ANDX_Response_SMB_Parameters smbParameters = packet.SmbParameters;

            smbParameters.AndXCommand = SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            smbParameters.Action = action;

            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_SESSION_SETUP_ANDX_Response_SMB_Parameters>(
                smbParameters) / SmbCapability.NUM_BYTES_OF_WORD);

            #region Generate security blob according to client request.

            byte[] securityBlob = null;

            SmbSessionSetupAndxRequestPacket request =
                connection.GetRequestPacket(connection.MessageId) as SmbSessionSetupAndxRequestPacket;

            if (request != null)
            {
                connection.GssApi.Accept(request.SmbData.SecurityBlob);

                securityBlob = connection.GssApi.Token;

                if (connection.GssApi.NeedContinueProcessing)
                {
                    unchecked
                    {
                        smbHeader.Status = (uint)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED;
                    }
                }
            }

            #endregion

            smbParameters.SecurityBlobLength = (ushort)securityBlob.Length;

            // update smb data
            SMB_COM_SESSION_SETUP_ANDX_Response_SMB_Data smbData = packet.SmbData;

            smbData.SecurityBlob = securityBlob;
            if (connection.Capability.IsUnicode
                && (smbParameters.SecurityBlobLength % SmbCapability.TWO_BYTES_ALIGN) == 0)
            {
                smbData.Pad = new byte[1];
            }
            else
            {
                smbData.Pad = new byte[0];
            }
            smbData.NativeOS = CifsMessageUtils.ToSmbStringBytes(
                Environment.OSVersion.VersionString, connection.Capability.IsUnicode);
            smbData.NativeLanMan = CifsMessageUtils.ToSmbStringBytes(
                Environment.OSVersion.VersionString, connection.Capability.IsUnicode);
            smbData.PrimaryDomain = CifsMessageUtils.ToSmbStringBytes(
                Environment.UserDomainName, connection.Capability.IsUnicode);

            // update smbData.ByteCount
            smbData.ByteCount = 0;
            smbData.ByteCount += (ushort)smbData.SecurityBlob.Length;
            smbData.ByteCount += (ushort)smbData.Pad.Length;
            smbData.ByteCount += (ushort)smbData.NativeOS.Length;
            smbData.ByteCount += (ushort)smbData.NativeLanMan.Length;
            smbData.ByteCount += (ushort)smbData.PrimaryDomain.Length;

            // store the parameters and data to packet.
            packet.SmbHeader = smbHeader;
            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            return packet;
        }
        /// <summary>
        /// Create  SMB_COM_SESSION_SETUP_ANDX Server response packet 
        /// </summary>
        /// <param name="connection">the connection identified the client</param>
        /// <param name = "uid">
        /// the valid session id, must be response by server of the session setup request. 
        /// </param>
        /// <param name = "action">A 16-bit field. The two lowest order bits have been defined </param>
        /// <returns>The SmbSessionSetupAndXResponsePacket </returns>
        /// <exception cref="ArgumentNullException">connection must not be null</exception>
        public virtual SmbSessionSetupImplicitNtlmAndxResponsePacket CreateSmbComSessionSetupImplicitNtlmResponse(
            SmbServerConnection connection,
            ushort uid,
            ActionValues action
            )
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            Cifs.SmbSessionSetupAndxResponsePacket packet = new Cifs.SmbSessionSetupAndxResponsePacket();

            // create smb packet header
            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(
                SmbCommand.SMB_COM_SESSION_SETUP_ANDX, connection.ProcessId, connection.MessageId, uid, 0,
                (SmbFlags)connection.Capability.Flag, (SmbFlags2)connection.Capability.Flags2);

            // update smb parameters
            Cifs.SMB_COM_SESSION_SETUP_ANDX_Response_SMB_Parameters smbParameters = packet.SmbParameters;

            smbParameters.AndXCommand = SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            smbParameters.Action = action;

            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<Cifs.SMB_COM_SESSION_SETUP_ANDX_Response_SMB_Parameters>(
                smbParameters) / SmbCapability.NUM_BYTES_OF_WORD);

            // update smb data
            Cifs.SMB_COM_SESSION_SETUP_ANDX_Response_SMB_Data smbData = packet.SmbData;

            if (connection.Capability.IsUnicode)
            {
                smbData.Pad = new byte[1];
            }
            else
            {
                smbData.Pad = new byte[0];
            }
            smbData.NativeOS = CifsMessageUtils.ToSmbStringBytes(
                Environment.OSVersion.VersionString, connection.Capability.IsUnicode);
            smbData.NativeLanMan = CifsMessageUtils.ToSmbStringBytes(
                Environment.OSVersion.VersionString, connection.Capability.IsUnicode);
            smbData.PrimaryDomain = CifsMessageUtils.ToSmbStringBytes(
                Environment.UserDomainName, connection.Capability.IsUnicode);

            // update smbData.ByteCount
            smbData.ByteCount = 0;
            smbData.ByteCount += (ushort)smbData.Pad.Length;
            smbData.ByteCount += (ushort)smbData.NativeOS.Length;
            smbData.ByteCount += (ushort)smbData.NativeLanMan.Length;
            smbData.ByteCount += (ushort)smbData.PrimaryDomain.Length;

            // store the parameters and data to packet.
            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            return new SmbSessionSetupImplicitNtlmAndxResponsePacket(packet);
        }
Пример #14
0
 KeyValuePair <AIAction, double> ActionValueFunction.GetActionValue(State state, AIAction action)
 {
     return(ActionValues.Find(x => x.Key.IsEqual(state)).Value.Find(x => x.Key == action));
 }
        public SmbSessionSetupAndxResponsePacket CreateSessionSetupAndxResponse(
            CifsServerPerConnection connection,
            SmbSessionSetupAndxRequestPacket request,
            ActionValues action,
            SmbPacket andxPacket)
        {
            SmbSessionSetupAndxResponsePacket response = new SmbSessionSetupAndxResponsePacket();
            SmbHeader smbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);
            smbHeader.Uid = connection.GenerateUID();
            response.SmbHeader = smbHeader;

            bool isUnicode = (response.SmbHeader.Flags2 & SmbFlags2.SMB_FLAGS2_UNICODE)
                == SmbFlags2.SMB_FLAGS2_UNICODE;
            byte[] oS = CifsMessageUtils.ToSmbStringBytes(CifsMessageUtils.NATIVE_OS, isUnicode);
            byte[] lanMan = CifsMessageUtils.ToSmbStringBytes(CifsMessageUtils.NATIVE_LANMAN, isUnicode);
            byte[] domain = CifsMessageUtils.ToSmbStringBytes(this.context.DomainName, isUnicode);
            int padOffset = Marshal.SizeOf(response.SmbParameters) + sizeof(ushort);
            SMB_COM_SESSION_SETUP_ANDX_Response_SMB_Data smbData = response.SmbData;
            smbData.Pad = new byte[(padOffset + 3) & ~3];
            smbData.NativeOS = oS;
            smbData.NativeLanMan = lanMan;
            smbData.PrimaryDomain = domain;
            smbData.ByteCount = (ushort)(((padOffset + 3) & ~3) + oS.Length + lanMan.Length + domain.Length);
            response.SmbData = smbData;

            SMB_COM_SESSION_SETUP_ANDX_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.AndXCommand =
                andxPacket != null ? andxPacket.SmbHeader.Command : SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            smbParameters.AndXReserved = 0x00;
            smbParameters.AndXOffset = (ushort)(response.HeaderSize + Marshal.SizeOf(response.SmbParameters)
                    + Marshal.SizeOf(response.SmbData));
            smbParameters.Action = action;
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            response.AndxPacket = andxPacket;
            response.UpdateHeader();

            return response;
        }