コード例 #1
0
        public override Task <SupportedMethods> GetSupportedMethods(Empty request, ServerCallContext context)
        {
            var supportedEndpoints = _endpointDataSource.Endpoints
                                     .Select(x => x.Metadata.FirstOrDefault(m => m is GrpcMethodMetadata))
                                     .OfType <GrpcMethodMetadata>()
                                     .Where(x => x.Method.ServiceName.Contains("client"))
                                     .Select(x => {
                var method = new SupportedMethod {
                    MethodName  = x.Method.Name.ToLower(),
                    ServiceName = x.Method.ServiceName.ToLower(),
                };
                if (x.Method.ServiceName.Contains("PersistentSubscriptions"))
                {
                    method.Features.AddRange(new[] { "stream", "all" });
                }
                else if (x.Method.ServiceName.Contains("Streams") && x.Method.Name.Contains("Read"))
                {
                    method.Features.AddRange(new[] { "position", "events" });
                }
                return(method);
            });

            var versionParts = EventStore.Common.Utils.VersionInfo.Version.Split('.');
            var result       = new SupportedMethods {
                EventStoreServerVersion = string.Join('.', versionParts.Take(3))
            };

            result.Methods.AddRange(supportedEndpoints.Distinct());
            return(Task.FromResult(result));
        }
コード例 #2
0
        public void AddPayment(Domain.Payment.Models.Payment payment)
        {
            //Verify payment type and method are supported.
            if (payment.PaymentType != SupportedType)
            {
                throw new InvalidPaymentException("Payment type not supported by current payment service.");
            }
            if (!SupportedMethods.Contains(((CreditCardPayment)payment).PaymentMethod))
            {
                throw new InvalidPaymentException("Payment method not supported by current payment service.");
            }

            var paymentList =
                _sessionStorage.Get <List <Domain.Payment.Models.Payment> >(SessionKeys.DomainPayments) ??
                new List <Domain.Payment.Models.Payment>();

            //Add Reference Id to generate Payment Id.
            payment.ReferenceId = "123456";

            //Generate random status.
            payment.Status = _random.Next(100) <= 80
                ? PaymentStatus.Approved
                : _random.Next(100) <= 50
                    ? PaymentStatus.Pending
                    : PaymentStatus.Declined;

            paymentList.Add(payment);

            _sessionStorage.Add(SessionKeys.DomainPayments, paymentList);
        }
コード例 #3
0
 private IEnumerable <Path> ParsePaths(JsonObject json)
 {
     return(json.Select(pathKvp => new Path
     {
         Route = pathKvp.Key,
         Operations = JsonObject.Parse(pathKvp.Value).Where(operationKvp => SupportedMethods.Contains(operationKvp.Key))
                      .ToDictionary(
             operationKvp => operationKvp.Key.ToUpperInvariant(),
             operationKvp => ParseOperation(pathKvp.Key, operationKvp.Key, operationKvp.Value))
     })
            .OrderBy(p => p.Route));
 }
コード例 #4
0
        public virtual string Send(string url, object requestData, string accept, HttpMethods method, IDictionary <string, string> headers = null)
        {
            if (!SupportedMethods.Contains(method))
            {
                return(string.Empty);
            }

            var req = BuildWebRequest(url, requestData, accept, method, headers);

            var rsp      = (HttpWebResponse)req.GetResponse();
            var encoding = Encoding.GetEncoding(string.IsNullOrEmpty(rsp.CharacterSet) ? "utf-8" : rsp.CharacterSet);

            return(GetResponseAsString(rsp, encoding));
        }
コード例 #5
0
        protected override HTTPResponse Process(HTTPRequest request)
        {
            if (!SupportedMethods.Contains(request.HTTPMethod))
            {
                Trace.WriteLine(NOT_IMPLEMENTED_STATUS);
                string             err    = NOT_IMPLEMENTED_MESSAGE_PREFIX + NOT_IMPLEMENTED_STATUS + NOT_IMPLEMENTED_MESSAGE_SUFFIX;
                HTTPResponseHeader header = MakeHeader(request.HTTPVersion, MESSAGE_MIME_TYPE, NOT_IMPLEMENTED_STATUS);
                return(new HTTPResponse(header, new MemoryStream(Encoding.ASCII.GetBytes(err))));
            }

            string path = ResolveRootPath(request.Path);

            Trace.WriteLine(path);
            return(GetHTTPResponseForPath(path, request.HTTPVersion));
        }
コード例 #6
0
        internal static byte[] CreateHash(SupportedMethods method, string password, byte[] salt)
        {
            var pwd = Encoding.UTF8.GetBytes((password ?? "").Trim());

            if (salt == null)
            {
                salt = new byte[0];
            }
            switch (method)
            {
            case SupportedMethods.SCRYPT:
                return(HashSha512(pwd, salt));

            case SupportedMethods.SHA512:
                return(HashSCrypt(pwd, salt));
            }
            //shouldn't happen
            throw new NotImplementedException(string.Format("The selected method ({0}) is not enabled for processing.", method.ToString()));
        }
コード例 #7
0
        /// <summary>
        /// extract full 'where'
        /// </summary>
        /// <param name="selectQuery"></param>
        /// <param name="index"></param>
        /// <param name="parent"></param>
        private void ExtractInside(string selectQuery, string breakString, char startChar, char breakChar, ref int index, IAddConditionSides parent)
        {
            //find variable with 'var' word
            byte foundVariableStep = 0;

            if (string.IsNullOrEmpty(breakString))
            {
                foundVariableStep = 1;
            }
            bool canSkip = true;
            //variable name that found after 'var'
            string variableName = "";
            string concat       = "";

            //calculate all of char after select query
            for (int i = index; i < selectQuery.Length; i++)
            {
                //current char
                char currentChar      = selectQuery[i];
                bool isWhiteSpaceChar = StringHelper.IsWhiteSpaceCharacter(currentChar);
                if (canSkip)
                {
                    //skip white space chars
                    if (isWhiteSpaceChar || (foundVariableStep == 0 && currentChar == startChar))
                    {
                        continue;
                    }
                    else
                    {
                        canSkip = false;
                    }
                }
                concat += currentChar;
                if (currentChar == breakChar)
                {
                    concat = concat.Trim('}');
                    CheckVariable(currentChar, ref i, ref index);
                    index = i;
                    break;
                }
                if (isWhiteSpaceChar && foundVariableStep == 0 && concat.Trim().Equals("in", StringComparison.OrdinalIgnoreCase))
                {
                    foundVariableStep = 3;
                    concat            = "";
                    canSkip           = true;
                }
                else if (foundVariableStep == 3 && isWhiteSpaceChar)
                {
                    parent.Add(new PropertyInfo()
                    {
                        PropertyPath = concat.Trim(), PublicVariables = parent.PublicVariables
                    });
                    foundVariableStep = 0;
                    concat            = "";
                    canSkip           = true;
                }
                //find a side
                else if (foundVariableStep == 1)
                {
                    if (currentChar == '"')
                    {
                        index             = i;
                        parent            = ExtractString(selectQuery, ref index, parent);
                        i                 = index;
                        foundVariableStep = 2;
                        concat            = "";
                        variableName      = "";
                        canSkip           = true;
                    }
                    else
                    {
                        CheckVariable(currentChar, ref i, ref index);
                    }
                }
                //find operator and parameter
                else if (foundVariableStep == 2)
                {
                    //find next parameter of method
                    if (currentChar == ',')
                    {
                        foundVariableStep = 1;
                        concat            = concat.Trim().Trim(',').Trim();
                        canSkip           = true;
                        continue;
                    }
                    //find operator
                    else
                    {
                        string trim = concat.Trim().ToLower();
                        //now this is a method
                        if (OperatorInfo.SupportedOperators.TryGetValue(trim, out OperatorType currentOperator))
                        {
                            if (OperatorInfo.OperatorStartChars.Contains(selectQuery[i + 1]))
                            {
                                continue;
                            }
                            parent.ChangeOperatorType(currentOperator);
                            //OperatorKey findEmpty = parent.WhereInfo.Operators.FirstOrDefault(x => x.OperatorType == OperatorType.None);
                            foundVariableStep = 1;
                            concat            = "";
                            canSkip           = true;
                        }
                        else if (concat.Equals("var", StringComparison.OrdinalIgnoreCase))
                        {
                            index = i;
                            do
                            {
                                index--;
                            }while (selectQuery[index].ToString().ToLower() != "v");

                            VariableInfo newVariableInfo = new VariableInfo()
                            {
                                WhereInfo = new WhereInfo()
                            };
                            newVariableInfo.Parent                    = parent.Parent;
                            newVariableInfo.WhereInfo.Parent          = newVariableInfo;
                            newVariableInfo.WhereInfo.PublicVariables = newVariableInfo.PublicVariables;
                            parent.Parent.Add(newVariableInfo);
                            ExtractVariables(selectQuery, ref index, newVariableInfo.WhereInfo);
                            i       = index;
                            concat  = "";
                            canSkip = true;
                        }
                        else if (concat.Length > 3)
                        {
                            throw new Exception($"I cannot found operator,I try but found '{concat}' are you sure you don't missed?");
                        }
                    }
                }
                else if (concat.Equals(breakString, StringComparison.OrdinalIgnoreCase))
                {
                    concat            = "";
                    canSkip           = true;
                    foundVariableStep = 1;
                }
            }

            void CheckVariable(char currentChar, ref int i, ref int index2)
            {
                string trim = concat.Trim();

                //step 1 of left side complete
                if (trim.Length > 0)
                {
                    bool isFindingOperator = OperatorInfo.OperatorStartChars.Contains(currentChar);
                    int  findNextP         = CheckFirstCharacterNoWitheSpace(selectQuery, i + 1, '(');
                    if (currentChar == '(' || findNextP >= 0)
                    {
                        if (string.IsNullOrEmpty(variableName))
                        {
                            IAddConditionSides addParent = null;
                            //check if variable name is nuot null so its a method
                            //else its just Parentheses
                            if (!string.IsNullOrEmpty(trim.Trim('(')))
                            {
                                //method name
                                variableName = trim.Trim('(').ToLower();
                                if (!SupportedMethods.TryGetValue(variableName, out IAddConditionSides addConditionSides))
                                {
                                    throw new Exception($"I cannot find method '{variableName}' are you sure you wrote true?");
                                }
                                else
                                {
                                    Tuple <IAddConditionSides, IAddConditionSides> value = addConditionSides.AddDouble(parent);
                                    parent    = value.Item1;
                                    addParent = value.Item2;
                                }
                                variableName = "";
                            }
                            else
                            {
                                addParent = parent.Add();
                            }
                            concat = "";
                            if (findNextP >= 0)
                            {
                                index2 = findNextP + 1;
                            }
                            else
                            {
                                index2 = i + 1;
                            }
                            ExtractInside(selectQuery, null, '(', ')', ref index2, addParent);
                            i = index2;
                            foundVariableStep = 2;
                            canSkip           = true;
                        }
                    }
                    else if (StringHelper.IsWhiteSpaceCharacter(currentChar) || isFindingOperator || currentChar == breakChar)
                    {
                        variableName = trim.Trim().Trim(breakChar).Trim(')').Trim(',').Trim();
                        concat       = "";
                        canSkip      = true;
                        //if there was no space this will fix that
                        //example user.name="ali" there is no space like user.name = "ali"
                        if (isFindingOperator)
                        {
                            variableName = variableName.Trim(OperatorInfo.OperatorStartChars);
                            i--;
                        }
                        if (foundVariableStep == 1)
                        {
                            //calculate left side
                            parent = CalculateSide(variableName, parent);
                            foundVariableStep++;
                            canSkip      = true;
                            variableName = "";
                        }
                    }
                    else if (currentChar == ',')
                    {
                        variableName = trim.Trim().Trim(',').Trim();
                        if (!string.IsNullOrEmpty(variableName))
                        {
                            if (foundVariableStep == 1)
                            {
                                //calculate left side
                                parent = CalculateSide(variableName, parent);
                                foundVariableStep++;
                                canSkip      = true;
                                variableName = "";
                                concat       = "";
                            }
                            index2 = i;
                            ExtractInside(selectQuery, null, ',', ')', ref index2, parent);
                            i = index2 - 1;
                        }
                    }
                    //variable is method
                    //that is method so find method name and data
                    //or is just inside of Parentheses
                }
            }
        }
コード例 #8
0
        public async Task<string> makeOperationAsync(SupportedModules module, SupportedMethods method, Cours reqCours = null, string resStr = "", bool forAuth = false)
        {
            if (IsNetworkAvailable() && (forAuth || await isValidAccountAsync(forAuth)))
            {
                PostDataWriter args = new PostDataWriter() { module = module, method = method, cidReq = reqCours, resStr = resStr };

                String strContent = "";
                try
                {

                    strContent = await getResponseAsync(args);
#if DEBUG
                    Debug.WriteLine("Call for :" + module + "/" + method + "\nResponse :" + strContent + "\n");
#endif
                }
                catch (Exception ex)
                {
                    lastException = ex;
                }
                return strContent;
            }
            else
            {
                lastException = new NetworkException("Network Unavailable");
                return null;
            }
        }
コード例 #9
0
        public async Task<string> MakeOperationAsync(SupportedModules module, SupportedMethods method, string syscode = "", string resStr = "", string genMod = "", bool forAuth = false)
        {
            if (IsNetworkAvailable() && (forAuth || await IsValidAccountAsync(forAuth)))
            {
                PostDataWriter args = new PostDataWriter() { module = module, method = method, cidReq = syscode, resStr = resStr, GenMod = genMod };

                String strContent = "";
                try
                {

                    strContent = await GetResponseAsync(args);
#if DEBUG
                    Debug.WriteLine("Call for :" + module + "/" + method + "\nResponse :" + strContent + "\n");
#endif
                    if (args.method != SupportedMethods.GetPage && strContent.StartsWith("<"))
                    {
                        strContent = "";
                    }
                }
                catch (Exception ex)
                {
                    LastException = ex;
                }
                return strContent;
            }
            else
            {
                LastException = new NetworkException("Network Unavailable");
                return null;
            }
        }