Example #1
0
    bool GetRsaEncryptDecryptParameters()
    {
        bool ok = true;

        if (Parms.Keys.Contains(__data))
        {
            Data = Parms[__data];
            Parms.Remove(__data);
        }
        else
        {
            Message += "  * Data not specified.\r\n";
            ok       = false;
        }

        if (!Parms.Keys.Contains(__keycontainername) && !Parms.Keys.Contains(__keyfile))
        {
            Message += "  * Specify either key container name or key file";
            ok       = false;
        }
        if (Parms.Keys.Contains(__keycontainername))
        {
            KeyContainerName = Parms[__keycontainername];

            Parms.Remove(__keycontainername);
        }
        if (Parms.Keys.Contains(__keyfile))
        {
            if (!System.IO.File.Exists(Parms[__keyfile]))
            {
                Message += "  * Unable to resolve Key File as path.\r\n";
                ok       = false;
            }
            else
            {
                KeyFile = Parms[__keyfile];
            }

            Parms.Remove(__keyfile);
        }
        if (Parms.Keys.Contains(__flags))
        {
            if (Enum.TryParse <CspProviderFlags>(Parms[__flags], true, out CspProviderFlags f))
            {
                Flags = f;
            }
            else
            {
                Message += "  * Unknown CspProviderFlags.\r\n";
                ok       = false;
            }
            Parms.Remove(__flags);
        }
        else
        {
            Flags = CspProviderFlags.NoFlags;
        }

        return(ok);
    }
    bool GetRegexMatchParameters()
    {
        bool ok = true;

        // file, pattern, [regexoptions]
        if (Parms.Keys.Contains(__file))
        {
            if (System.IO.File.Exists(Parms[__file]))
            {
                File     = System.IO.File.ReadAllText(Parms[__file]);
                FilePath = Parms[__file];
            }
            else
            {
                Message += "  * Unable to resolve File as path.\r\n";
                ok       = false;
            }

            Parms.Remove(__file);
        }
        else
        {
            Message += "  * File not specified.\r\n";
            ok       = false;
        }

        if (Parms.Keys.Contains(__pattern))
        {
            Pattern = Parms[__pattern];

            Parms.Remove(__pattern);
        }
        else
        {
            Message += "  * Pattern not specified.\r\n";
            ok       = false;
        }

        if (Parms.Keys.Contains(__options))
        {
            if (Enum.TryParse <RegexOptions>(Parms[__options], true, out RegexOptions o))
            {
                Options = o;
            }
            else
            {
                Message += "  * Unable to parse Options as regexoptions.\r\n";
                ok       = false;
            }

            Parms.Remove(__options);
        }
        else
        {
            Options = RegexOptions.None;
        }

        return(ok);
    }
Example #3
0
        public async Task <object> Get(string Action, string Key, Guid DeviceId, Guid TokenId)
        {
            var pParms = new Parms(Action, Key, DeviceId, TokenId);

            pParms.URL = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
            //return await Task.Run(() => repository.WebGet(pParms));
            return(await Task.Run(() => new { }));
        }
Example #4
0
 private static void UnloadParms(List <Parms> parms, SqlCommand cmd)
 {
     if (parms != null)
     {
         for (int i = 0; i < parms.Count - 1; i++)
         {
             Parms p = parms[i];
             p.value  = cmd.Parameters[i].Value;
             parms[i] = p;
         }
     }
 }
Example #5
0
 public static IEnumerable <Rectangle> DoPosition(Parms parms, Rectangle clientArea, IEnumerable <Rectangle> rectangles)
 {
     return(DoPosition(
                parms.Rows,
                parms.Cols,
                parms.HShape,
                parms.VShape,
                parms.Margin,
                parms.Spacing,
                clientArea,
                rectangles
                ));
 }
Example #6
0
    bool GetRijndaelParameters()
    {
        bool ok = true;

        if (Parms.Keys.Contains(__data))
        {
            Data = Parms[__data];
            Parms.Remove(__data);
        }
        else
        {
            Message += "  * Data not specified.\r\n";
            ok       = false;
        }

        if (Parms.Keys.Contains(__passphrase))
        {
            PassPhrase = Parms[__passphrase];
            Parms.Remove(__passphrase);
        }
        else
        {
            Message += "  * Pass phrase not specified.\r\n";
            ok       = false;
        }

        if (Parms.Keys.Contains(__saltvalue))
        {
            SaltValue = Parms[__saltvalue];
            Parms.Remove(__saltvalue);
        }
        else
        {
            Message += "  * Salt value not specified.\r\n";
            ok       = false;
        }

        if (Parms.Keys.Contains(__initializationvector))
        {
            InitializationVector = Parms[__initializationvector];
            Parms.Remove(__initializationvector);
        }
        else
        {
            Message += "  * Initialization vector not specified.\r\n";
            ok       = false;
        }

        return(ok);
    }
    bool GetXslTransformParameters()
    {
        bool ok = true;

        // file, xslt
        if (Parms.Keys.Contains(__file))
        {
            if (System.IO.File.Exists(Parms[__file]))
            {
                File     = System.IO.File.ReadAllText(Parms[__file]);
                FilePath = Parms[__file];
            }
            else
            {
                Message += "  * Unable to resolve File as path.\r\n";
                ok       = false;
            }

            Parms.Remove(__file);
        }
        else
        {
            Message += "  * File not specified.\r\n";
            ok       = false;
        }

        if (Parms.Keys.Contains(__xslt))
        {
            if (System.IO.File.Exists(Parms[__xslt]))
            {
                Xslt     = System.IO.File.ReadAllText(Parms[__xslt]);
                XsltPath = Parms[__xslt];
            }
            else
            {
                Message += "  * Unable to resolve Xslt as path.\r\n";
                ok       = false;
            }

            Parms.Remove(__file);
        }
        else
        {
            Message += "  * Xslt not specified.\r\n";
            ok       = false;
        }

        return(ok);
    }
    bool GetConvertParameters()
    {
        bool ok = true;

        // file, outputformat
        if (Parms.Keys.Contains(__file))
        {
            if (System.IO.File.Exists(Parms[__file]))
            {
                File     = System.IO.File.ReadAllText(Parms[__file]);
                FilePath = Parms[__file];
            }
            else
            {
                Message += "  * Unable to resolve File as path.\r\n";
                ok       = false;
            }

            Parms.Remove(__file);
        }
        else
        {
            Message += "  * File not specified.\r\n";
            ok       = false;
        }

        if (Parms.Keys.Contains(__outputformat))
        {
            if (Enum.TryParse <FormatType>(Parms[__outputformat], true, out FormatType outputFormat))
            {
                OutputFormat = outputFormat;
            }
            else
            {
                Message += "  * Unknown OutputFormat.\r\n";
                ok       = false;
            }

            Parms.Remove(__outputformat);
        }
        else
        {
            Message += "  * OutputFormat not specified.\r\n";
            ok       = false;
        }

        return(ok);
    }
Example #9
0
        /// <summary>
        /// 创建过滤规则参数数组
        /// </summary>
        /// <param name="value"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private string CreateFilterParam(object value, string type)
        {
            var paramName = "p" + ++_paramCounter;
            var val       = value;

            ////原版在这里要验证类型
            //if (type.Equals("int", StringComparison.OrdinalIgnoreCase) || type.Equals("digits", StringComparison.OrdinalIgnoreCase))
            //    val = val.ObjToInt ();
            //if (type.Equals("float", StringComparison.OrdinalIgnoreCase) || type.Equals("number", StringComparison.OrdinalIgnoreCase))
            //    val = type.ObjToDecimal();

            var param = new FilterParameter(paramName, val);

            Parms.Add(param);
            return(paramName);
        }
Example #10
0
    bool GetBase64Parameters()
    {
        bool ok = true;

        if (Parms.Keys.Contains(__data))
        {
            Data = Parms[__data];
            Parms.Remove(__data);
        }
        else
        {
            Message += "  * Data not specified.\r\n";
            ok       = false;
        }
        return(ok);
    }
Example #11
0
 protected void SetCustomAttributes(MethodBuilder mb)
 {
     GenInterface.SetCustomAttributes(mb, MethodMeta);
     if (Parms != null)
     {
         for (int i = 0; i < Parms.count(); i++)
         {
             IPersistentMap meta = GenInterface.ExtractAttributes(RT.meta(Parms.nth(i)));
             if (meta != null && meta.count() > 0)
             {
                 ParameterBuilder pb = mb.DefineParameter(i + 1, ParameterAttributes.None, ((Symbol)Parms.nth(i)).Name);
                 GenInterface.SetCustomAttributes(pb, meta);
             }
         }
     }
 }
Example #12
0
    bool GetRsaGenKeyParameters()
    {
        bool ok = true;

        if (Parms.Keys.Contains(__keycontainername))
        {
            KeyContainerName = Parms[__keycontainername];
            if (string.IsNullOrWhiteSpace(KeyContainerName))
            {
                Message += "  * Key container name not specified.\r\n";
                ok       = false;
            }
            Parms.Remove(__keycontainername);
        }

        if (Parms.Keys.Contains(__keyfile))
        {
            KeyFile = Parms[__keyfile];
            if (string.IsNullOrWhiteSpace(KeyFile))
            {
                Message += "  * Key File path not specified.\r\n";
                ok       = false;
            }
            Parms.Remove(__keyfile);
        }

        if (Parms.Keys.Contains(__keysize))
        {
            if (int.TryParse(Parms[__keysize], out int value))
            {
                KeySize = value;
            }
            else
            {
                // default to 0
                KeySize = 0;
            }
            Parms.Remove(__keysize);
        }
        //else
        //{
        //    Message += "  * Key File path not specified.\r\n";
        //    ok = false;
        //}

        return(ok);
    }
Example #13
0
        public static Mat Detect(Mat input, Parms filters = null)
        {
            Mat gray = new Mat();

            CvInvoke.CvtColor(input, gray, ColorConversion.Bgr2Gray);


            if (filters == null)
            {
                filters = defaultParam;
            }
            Mat filtered = filters.filter(gray);

            var edges = new Mat();

            CvInvoke.Canny(filtered, edges, filters.threadshold1, filters.threadshold2);
            return(edges);
        }
    bool GetJsonSelectParameters()
    {
        bool ok = true;

        // file, expression
        if (Parms.Keys.Contains(__file))
        {
            if (System.IO.File.Exists(Parms[__file]))
            {
                File     = System.IO.File.ReadAllText(Parms[__file]);
                FilePath = Parms[__file];
            }
            else
            {
                Message += "  * Unable to resolve File as path.\r\n";
                ok       = false;
            }

            Parms.Remove(__file);
        }
        else
        {
            Message += "  * File not specified.\r\n";
            ok       = false;
        }

        if (Parms.Keys.Contains(__expression))
        {
            Expression = Parms[__expression];

            Parms.Remove(__expression);
        }
        else
        {
            Message += "  * Expression not specified.\r\n";
            ok       = false;
        }

        return(ok);
    }
Example #15
0
        /// <summary>
        /// 远程调用
        /// </summary>
        /// <param name="url"></param>
        /// <param name="fileName"></param>
        /// <param name="method"></param>
        /// <param name="parms"></param>
        /// <returns></returns>
        public string Post(string url, string fileName, string method, object[] parms)
        {
            string     _Result        = string.Empty;
            HttpClient client         = new HttpClient();
            Parms      contract       = new Parms(fileName, method, parms);
            var        param_json_str = JsonConvert.SerializeObject(contract);

            HttpContent content = new StringContent(param_json_str);

            content.Headers.ContentType = new MediaTypeHeaderValue(FDConst.HTTPContent_Json)
            {
                CharSet = FDConst.Encoding_UTF8
            };
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(FDConst.HTTPContent_Json));
            var res = client.PostAsync(url, content).Result;

            res.EnsureSuccessStatusCode();
            if (res.IsSuccessStatusCode)
            {
                _Result = res.Content.ReadAsStringAsync().Result;
            }
            return(_Result);
        }
Example #16
0
 internal void Clear()
 {
     Text.Clear(); Parms.Clear();
 }
 private string BuildQueryString()
 {
     return(Parms.Count == 0 ? string.Empty : string.Join("&", Parms.Select(p => $"{p.Key}={p.Value}")));
 }
Example #18
0
 /// <summary>
 /// Initialize a Leetcode Soltion Test unit
 /// </summary>
 /// <param name="parameters">
 /// The input parameters of the test method.
 /// </param>
 /// <param name="answer">
 /// The answer to which the method was expected to produce.
 /// </param>
 public LeetTestUnit(Parms parameters, object answer)
 {
     Parameters = parameters;
     Answer     = answer;
 }
Example #19
0
 public async Task <object> Post(Parms pParms)
 {
     pParms.URL = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
     //return await Task.Run(() => repository.WebPost(pParms));
     return(await Task.Run(() => new { }));
 }
Example #20
0
        public static int TestSolution(object solution
                                       , LeetTestUnit unit)
        {
            //Check if solution is a valid leetcode solution with attributes
            Type SolutionType   = solution.GetType();
            bool IsLeetSolution = (SolutionType.GetCustomAttributes(
                                       typeof(LeetSolutionAttribute), false)).Any();

            Console.WriteLine($"The Solution class has Attribute: {IsLeetSolution}");
            if (!IsLeetSolution)
            {
                return(100);
            }
            //Searching for methods with LeetMethodAttribute
            var meths =
                from m in SolutionType.GetMethods()
                where m.GetCustomAttributes <LeetMethodAttribute>().Any()
                select m;
            bool ContainLeetMethod = false;

            ContainLeetMethod = meths.Count() > 0;
            Console.WriteLine($"The Solution class has Leet Method: {ContainLeetMethod}");
            if (!ContainLeetMethod)
            {
                return(101);
            }

            //Prepare is OK, start to check if LeetTestUnit fits the parameters

            ParameterInfo[] parms_this = meths.First().GetParameters();
            Parms           parms_unit = unit.Parameters;
            //Checking if the count match
            int cnt_parms = parms_this.Count();
            int cnt_unit  = parms_unit.Count();

            Console.WriteLine($"there are {cnt_parms} parms in solution, and {cnt_unit} parms in tester");
            if (cnt_parms != cnt_unit)
            {
                return(102);
            }
            //Checking if types match
            for (int i = 0; i < cnt_parms; i++)
            {
                Type t0 = parms_this[i].ParameterType;
                Type t1 = parms_unit[i].ParmType;

                Console.WriteLine($"Judging Parameter Types: {t0} = {t1} at index={i}");
                if (parms_this[i].ParameterType != parms_unit[i].ParmType)
                {
                    return(103);
                }
            }
            //Checking if Answer Type in unit is the return type of solution
            //foreach (MethodInfo m in meths)
            //{
            //    if (m.ReturnType != unit.Answer.GetType()) return 104;
            //}
            //All checks completed, starting testing:
            Console.WriteLine(" ╔═══════════════════════════════════╗");
            Console.WriteLine("   Leetcode Solution Tester Starts");
            Console.WriteLine(" ╚═══════════════════════════════════╝");

            // Invoking Solution and evaluate against the answer
            int       count = 0;
            Stopwatch sw    = new Stopwatch();

            foreach (MethodInfo m in meths)
            {
                Console.WriteLine();
                Console.WriteLine("Test {0} starts...", ++count);

                sw.Restart();
                object output = m.Invoke(solution, parms_unit.GetAllParmValues());
                sw.Stop();
#if DEBUG
                //Judging if the result is an int[]
                if (output is int[])
                {
                    string temp = string.Join(",", (int[])output);
                    output = "[" + temp + "]";
                }
#endif

                Console.WriteLine("Output => {0}", output);
                Console.WriteLine("Answer => {0}", unit.Answer);
                string resultIs = unit.Answer.ToString() == output.ToString() ? "correct" : "wrong";
                Console.WriteLine("The result is " + resultIs + ".");
                Console.WriteLine("Program ran for {0} ms.", sw.ElapsedMilliseconds);
                Console.WriteLine();
            }

            Console.WriteLine(" ╔════════════════════════════════════╗");
            Console.WriteLine("   Leetcode Solution Tester Finishes");
            Console.WriteLine(" ╚════════════════════════════════════╝");


#if xDEBUG
            foreach (MethodInfo m in meths)
            {
                ParameterInfo[] ps = m.GetParameters();
                foreach (ParameterInfo p in ps)
                {
                    Console.WriteLine("The Parameter Name is: " + p.Name);
                    Console.WriteLine("Is it out: " + p.IsOut);
                    Console.WriteLine("Is it in: " + p.IsIn);
                    Console.WriteLine("The Type of the parameter: "
                                      + p.ParameterType.ToString());
                }
            }
#endif
            return(0);
        }
Example #21
0
 public override string ToString() => Parms.Aggregate(Name, (current, expression) => current + "#" + expression.Type.Name);
Example #22
0
 internal void AddParm(ExpressionNode expression)
 {
     Parms.Add(expression);
 }
Example #23
0
 public static Mat Detect(string fname, Parms filter = null)
 {
     return(Detect(CvInvoke.Imread(fname), filter));
 }