Example #1
0
        void encryptFileName()
        {
            FileStream   fp2 = new FileStream("temp_data.txt", FileMode.Create);
            StreamWriter wp  = new StreamWriter(fp2);

            for (int i = 0; i < 32; i++)
            {
                wp.WriteLine(keyArray[i]);
            }
            Regex  reExp = new Regex(@"\\{1}[^\\]+$", RegexOptions.RightToLeft);
            string title = reExp.Match(textBox_input.Text).ToString();

            title = title.Remove(0, 1);
            wp.WriteLine(title.Length);
            while (title != "")
            {
                while (title != "")
                {
                    wp.WriteLine(char.ConvertToUtf32(title, 0));
                    title = title.Remove(0, 1);
                }
            }
            wp.Close();
            fp2.Close();
            ScriptRuntime pyRumTime = Python.CreateRuntime();
            dynamic       obj       = pyRumTime.UseFile("rsa.py");

            obj.ras_pub(textBox_pub.Text, "temp_data.txt", outPath + ".txt");
            File.Delete("temp_data.txt");
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            DateTime temtime = DateTime.Now;

            try
            {
                string        pypathstr = "";
                string        pyfilestr = "";
                ScriptRuntime pyRunTime = Python.CreateRuntime();
                pypathstr = AppContext.BaseDirectory;
                //pypathstr = "E:\\mysoft\\202003test\\ServerMonitor\\ServerMonitor\\pythonfiles\\";
                pyfilestr = "pythonfiles\\digital1.py";
                dynamic obj = pyRunTime.UseFile(pypathstr + pyfilestr);
                //dynamic obj = pyRunTime.UseFile("digital1.py");
                int int1 = 0, int2 = 0;
                int1 = int.Parse(text_data1.Text);
                int2 = int.Parse(text_data2.Text);
                int val = obj.sum(int1, int2);

                label_result1.Text = val.ToString();
                //MessageBox.Show(val + "");
            }
            catch (Exception ex)
            {
                ClassLog.Writelog(temtime.ToString(), "ServerManger.python1", " .button1_Click()  调用python计算 " + ex.ToString());
                Debug.Print(ex.ToString());
            }
        }
Example #3
0
 private void Initilize_Index()
 {
     pyRunTime = Python.CreateRuntime();
     Console.WriteLine();
     obj_Index = pyRunTime.UseFile(@"..//..//PyShell//Global_Index.py");
     //obj_Index = pyRunTime.UseFile(@"..\..\..\PyShell\Global_Index.py");
 }
Example #4
0
 private void button7_Click(object sender, EventArgs e)
 {
     if (textBox3.Text != "" && textBox11.Text != "" && textBox5.Text != "")
     {
         if (isdigit(textBox3) && isdigit(textBox11) && isdigit(textBox5))
         {
             if (textBox4.Text.Length - 1 >= textBox11.Text.Length)
             {
                 ScriptRuntime pyRumTime = Python.CreateRuntime();
                 dynamic       obj       = pyRumTime.UseFile("rsa.py");
                 textBox12.Text = obj.demo_cal(textBox11.Text, textBox5.Text, textBox3.Text);
                 textBox11.Text = "";
             }
             else
             {
                 MessageBox.Show("输入数字过长,请输入" + (textBox4.Text.Length - 1).ToString() + "位及" + (textBox4.Text.Length - 1).ToString() + "位以下长度的数字", "提示", MessageBoxButtons.OK);
             }
         }
         else
         {
             isdigit(textBox11);
             isdigit(textBox5);
             MessageBox.Show("亲,非法输入,文本框只能输入数字", "提示", MessageBoxButtons.OK);
         }
     }
 }
Example #5
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            ScriptRuntime scriptRuntime = ScriptRuntime.CreateFromConfiguration();
            dynamic       calcRate      = scriptRuntime.UseFile("CalcTax.py");

            label6.Content = calcRate.CalcTax(Convert.ToDecimal(label5.Content)).ToString();
        }
Example #6
0
        static void Main(string[] args)
        {
            //<Snippet2>
            // Set the current directory to the IronPython libraries.
            System.IO.Directory.SetCurrentDirectory(
                Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) +
                @"\IronPython 2.6 for .NET 4.0\Lib");

            // Create an instance of the random.py IronPython library.
            Console.WriteLine("Loading random.py");
            ScriptRuntime py     = Python.CreateRuntime();
            dynamic       random = py.UseFile("random.py");

            Console.WriteLine("random.py loaded.");
            //</Snippet2>

            //<Snippet3>
            // Initialize an enumerable set of integers.
            int[] items = Enumerable.Range(1, 7).ToArray();

            // Randomly shuffle the array of integers by using IronPython.
            for (int i = 0; i < 5; i++)
            {
                random.shuffle(items);
                foreach (int item in items)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("-------------------");
            }
            //</Snippet3>
        }
        private void button2_Click(object sender, EventArgs e)
        {
            ScriptRuntime pyRuntime = Python.CreateRuntime();
            dynamic       obj       = pyRuntime.UseFile(@"recommend.py");

            IronPython.Runtime.List mustlst = new IronPython.Runtime.List();
            IronPython.Runtime.List wantlst = new IronPython.Runtime.List();

            foreach (int i in index_must)
            {
                mustlst.Add(i);
            }
            foreach (int i in index_want)
            {
                wantlst.Add(i);
            }

            string result = obj.getPeople(mustlst, wantlst);

            purl  = obj.getUrl(mustlst, wantlst);
            pname = result;
            MessageBox.Show("为你推荐:" + pname);

            People infofr = new People(pname, purl);

            infofr.Show();
        }
Example #8
0
        private void button2_Click(object sender, EventArgs e)
        {
            string        pypathstr = "";
            string        pyfilestr = "";
            ScriptRuntime pyRunTime = Python.CreateRuntime();

            pypathstr = AppContext.BaseDirectory;
            //pypathstr = "E:\\mysoft\\202003test\\ServerMonitor\\ServerMonitor\\pythonfiles\\";
            pyfilestr = "pythonfiles\\digital1.py";
            dynamic      obj      = pyRunTime.UseFile(pypathstr + pyfilestr);
            string       strfind1 = "";
            string       strfind2 = "";
            UTF8Encoding utf8     = new UTF8Encoding();

            strfind1 = textBox1.Text;
            strfind2 = strfind1; // utf8.GetString(encodedBytes);
            strfind2 = StringToUnicode(strfind1);
            Debug.Print(strfind1);
            Debug.Print(strfind2);
            var strArray = obj.regSearch1("e:\\city.txt", strfind2);

            listBox1.Items.Clear();
            foreach (var s in strArray)
            {
                string ss0 = "";
                string ss1 = "";
                ss0 = "\\" + s;
                //Debug.Print(s);
                ss1 = UnicodeToString(ss0);
                listBox1.Items.Add(s);
            }
            int count = listBox1.Items.Count;

            label3.Text = count.ToString();
        }
Example #9
0
        public PythonHelper()
        {
            engine = Python.CreateEngine();
            ScriptRuntime pyRunTime = Python.CreateRuntime();

            scope = pyRunTime.UseFile("hello.py");
        }
Example #10
0
        public double risk(double lng, double lat, AirCondition airCondition)
        {
            CoorTransferer coorTransferer = new CoorTransferer(20);

            double[] coor = coorTransferer.Nautica2xy(lng, lat);

            PollutedPoint pollutedPoint = new PollutedPoint((int)coor[0], (int)coor[1]);

            foreach (PollutionSource pollutionSource in this.PollutionSources)
            {
                double sourceLng = pollutionSource.X;
                double sourceLat = pollutionSource.Y;

                double[] source = coorTransferer.Nautica2xy(sourceLng, sourceLat);

                pollutionSource.X = source[0];
                pollutionSource.Y = source[1];

                // 加载外部 python 脚本文件.
                ScriptRuntime pyRumTime = Python.CreateRuntime();
                dynamic       obj       = pyRumTime.UseFile("t.py");
                obj.GetArbitraryC(pollutedPoint, airCondition, pollutionSource);    // python脚本计算污染点的浓度值,并将计算结果返回给对象的污染物浓度属性

                // 使用后还原
                pollutionSource.X = sourceLng;
                pollutionSource.Y = sourceLat;
            }

            return(pollutedPoint.Concentration);
        }
Example #11
0
        internal void method2()
        {
            ScriptRuntime scriptRuntime = ScriptRuntime.CreateFromConfiguration();
            dynamic       ccalcRate     = scriptRuntime.UseFile("AmountDisc.py");

            ccalcRate.CalcTax("124m");  //直接调用脚本的函数
        }
Example #12
0
        static void Main(string [] args)
        {
            // Set the current directory to the IronPython libraries.
            Directory.SetCurrentDirectory(@"C:\Program Files\IronPython 2.7\Lib");

            // Create an instance of the random.py IronPython Library.
            Console.WriteLine("Loading random.py");
            ScriptRuntime py     = Python.CreateRuntime();
            dynamic       random = py.UseFile("random.py");

            Console.WriteLine("random.py loaded.");

            // Initialize an enumerable set of integers.
            int[] items = Enumerable.Range(1, 7).ToArray();

            // Randomly shuffle the array of integers by using IronPython.
            for (int i = 0; i < 5; i++)
            {
                random.shuffle(items);
                foreach (int item in items)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("--------------------");
            }

            Console.WriteLine("Press any key to EXIT...");
            Console.ReadKey();
        }
        private void UpdateScript(string script)
        {
            LogTo.Debug("A script was changed - {0}", script);

            if (File.Exists(script))
            {
                _runtime.Shutdown();
                _runtime = Python.CreateRuntime();
                try
                {
                    _script = _runtime.UseFile(script);
                    LogTo.Info("Script loaded");
                    ScriptScope scope  = _script;
                    dynamic     parser = scope.GetVariable("ParserScript");
                    name    = parser.Name;
                    version = parser.Version;
                    author  = parser.Author;
                    LogTo.Info("Name: {0}, Version: {1}, Author: {2}", name, version, author);
                }
                catch (SyntaxErrorException e)
                {
                    LogTo.ErrorException("Syntax error", e);
                }
                catch (Exception e)
                {
                    LogTo.WarnException("Script error", e);
                }
            }
            else
            {
                LogTo.Error("Script not loaded (file doesn't exist)");
            }
        }
Example #14
0
        static void Main(string[] args)
        {
            ScriptRuntime python = Python.CreateRuntime();
            dynamic       r      = python.UseFile("hello.py");

            Console.WriteLine(r.yreadlines(@"C:\Users\LSQ\Desktop\Mes讨论内容.txt"));
            Console.Read();
        }
Example #15
0
        public void mock(AirCondition airCondition)
        {
            this.Initialize();
            CoorTransferer coorTransferer = new CoorTransferer(20);

            foreach (PollutionSource pollutionSource in this.PollutionSources)
            {
                double lng = pollutionSource.X;
                double lat = pollutionSource.Y;

                double[] source = coorTransferer.Nautica2xy(lng, lat);

                pollutionSource.X = source[0];
                pollutionSource.Y = source[1];

                int x = (int)source[0];
                int y = (int)source[1];

                int width = 500;
                int step  = 50;

                for (int dx = x - width; dx <= x + width; dx += step)
                {
                    for (int dy = y - width; dy <= y + width; dy += step)
                    {
                        // 加载外部 python 脚本文件.
                        ScriptRuntime pyRumTime = Python.CreateRuntime();
                        dynamic       obj       = pyRumTime.UseFile("t.py");
                        PollutedPoint newPoint;

                        if (PointExist(dx, dy) < 0)
                        {
                            newPoint = new PollutedPoint(dx, dy);
                            obj.GetArbitraryC(newPoint, airCondition, pollutionSource);    // python脚本计算污染点的浓度值,并将计算结果返回给对象的污染物浓度属性
                            pointsXY.Add(newPoint);
                        }
                        else
                        {
                            newPoint = pointsXY[PointExist(dx, dy)];
                            obj.GetArbitraryC(newPoint, airCondition, pollutionSource);    // python脚本计算污染点的浓度值,并将计算结果返回给对象的污染物浓度属性
                        }
                    }
                }

                // 使用后还原
                pollutionSource.X = lng;
                pollutionSource.Y = lat;
            }

            foreach (PollutedPoint point in pointsXY)
            {
                PollutedPointMap newPointMap = new PollutedPointMap(point);
                PollutedPoints.Add(newPointMap);
            }

            this.SaveChanges();
        }
Example #16
0
        private static void PythonScript( )
        {
            Console.WriteLine("Loading script.py...");
            ScriptRuntime python = Python.CreateRuntime( );
            dynamic       script = python.UseFile("script.py");

            Console.WriteLine("script.py loaded!");

            script.doSomething( );
        }
Example #17
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            ScriptRuntime pyRuntime = Python.CreateRuntime(); //创建一下运行环境

            dynamic obj = pyRuntime.UseFile("gid_dic.py");    //调用一个Python文件
            string  res = "finish";
            var     op  = obj.dbscan(ref res, file1, file2);

            textBox2.Text = (string)op;
        }
Example #18
0
        static void Main()
        {
            ScriptRuntime py     = Python.CreateRuntime();
            dynamic       sample = py.UseFile("sample.py");

            // Pythonのクラスのインスタンス生成
            dynamic p = sample.PythonSample();

            Console.WriteLine(p.getMessage("C#"));
        }
Example #19
0
 private void button_decode_Click(object sender, EventArgs e)
 {
     if (textBox_pri.Text != "" && textBox_input.Text != "" && textBox_output.Text != "")
     {
         try
         {
             System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
             sw.Start();
             ScriptRuntime pyRumTime = Python.CreateRuntime();
             dynamic       obj       = pyRumTime.UseFile("rsa.py");
             string        fileName  = textBox_input.Text;
             fileName = fileName.Remove(fileName.Length - 4);
             obj.ras_pri(textBox_pri.Text, fileName + ".txt", "temp_data.txt");
             FileStream   fp       = new FileStream("temp_data.txt", FileMode.Open);
             StreamReader rp       = new StreamReader(fp);
             byte[]       keyArray = new byte[32];
             for (int i = 0; i < 32; i++)
             {
                 keyArray[i] = Convert.ToByte(rp.ReadLine());
             }
             int    fileNameLen = Convert.ToInt32(rp.ReadLine());
             string title       = "";
             for (int i = 0; i < fileNameLen; i++)
             {
                 title += char.ConvertFromUtf32(Convert.ToInt32(rp.ReadLine()));
             }
             rp.Close();
             fp.Close();
             byte[]          toEncryptArray = File.ReadAllBytes(fileName + ".dat");
             RijndaelManaged rDel           = new RijndaelManaged();
             rDel.Key  = keyArray;
             rDel.Mode = CipherMode.ECB;
             ICryptoTransform cTransform  = rDel.CreateDecryptor();
             byte[]           resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
             File.WriteAllBytes(textBox_output.Text + title, resultArray);
             sw.Stop();
             FileInfo fileInfo = new FileInfo(textBox_input.Text);
             label5.Text = "加密时间:" + (sw.ElapsedMilliseconds / 1000.0).ToString() + "s";
             label6.Text = "速度:" + Math.Round(((double)fileInfo.Length / 1024 / 1024 / sw.ElapsedMilliseconds * 1000), 2).ToString() + "MB/s";
             File.Delete("temp_data.txt");
             warning.Text = "亲,解密成功了哦~~";
             GC.Collect();
         }
         catch
         {
             warning.Text = "亲,您的文件不存在,请重新输入^_^";
             return;
         }
     }
     else
     {
         warning.Text = "亲,您的输入有误,请重新输入^_^";
     }
 }
        static void Main(string[] args)
        {
            //第一句代码创建了一个Python的运行环境,第二句则使用.net4.0的语法创建了一个动态的对象, OK,
            //下面就可以用这个dynamic类型的对象去调用刚才在定义的welcome方法了。
            ScriptRuntime pyRuntime = Python.CreateRuntime();
            dynamic       obj       = pyRuntime.UseFile("hello.py");

            Console.WriteLine(obj.welecom("nICK"));
            Console.WriteLine(obj.add(10, 8));
            Console.ReadKey();
        }
Example #21
0
        public static void Test()
        {
            // 加载外部 python 脚本文件.
            ScriptRuntime pyRumTime = Python.CreateRuntime();
            dynamic       obj       = pyRumTime.UseFile("md5.py");


            Console.WriteLine("测试调用 MD5 方法!");

            Console.WriteLine(obj.md5("12345678901234567890123456789012345678901234567890"));
        }
        public void Open(string port, string baudrate)
        {
            ipy    = Python.CreateRuntime();
            script = ipy.UseFile("src/track.py");
            script.open(port, baudrate);

            isContinue          = true;
            thread              = new Thread(Run);
            thread.IsBackground = true;
            thread.Start();
        }
        public static void Test()
        {
            // 加载外部 python 脚本文件.
            ScriptRuntime pyRumTime = Python.CreateRuntime();
            dynamic       obj       = pyRumTime.UseFile("get_sys_path.py");


            Console.WriteLine("测试调用 get_sys_path 方法!");

            Console.WriteLine(obj.get_sys_path());
        }
Example #24
0
        public static void Test()
        {
            // 加载外部 python 脚本文件.
            ScriptRuntime pyRumTime = Python.CreateRuntime();
            dynamic       obj       = pyRumTime.UseFile("umeng.py");


            Console.WriteLine("测试调用友盟推送方法!");

            Console.WriteLine(obj.push_unicast("AppKey", "App Master Secret", ""));
        }
        private void OnCalculateTax(object sender, RoutedEventArgs e)
        {
            ScriptRuntime scriptRuntime = ScriptRuntime.CreateFromConfiguration();
            dynamic       calcRate      = scriptRuntime.UseFile("Scripts/CalcTax.py");
            decimal       discountedAmount;

            if (!decimal.TryParse(textDiscAmount.Text, out discountedAmount))
            {
                discountedAmount = Convert.ToDecimal(totalAmt.Text);
            }
            textTaxAmount.Text = calcRate.CalcTax(discountedAmount).ToString();
        }
 public WallViewHost(int KalutUID, WelcomeScreen parent)
 {
     IronPython       = Python.CreateRuntime();
     IronPythonScript = IronPython.UseFile("conn.py");
     UID         = KalutUID;
     this.parent = parent;
     InitializeComponent();
     waitView = new WaitForPlayersView(this);
     Controls.Add(waitView);
     waitView.Hide();
     ansView      = new WallAnswerView(this);
     ansView.Dock = DockStyle.Fill;
 }
Example #27
0
        public void TestPythonInput001()
        {
            // Arrange
            string        expected = "Howdy World";
            ScriptRuntime python   = Python.CreateRuntime();
            dynamic       script   = python.UseFile(string.Format(@"{0}\{0}.py", "Script"));

            // Act
            dynamic actual = script.Welcome();

            // Assert
            Assert.AreEqual(expected, actual);
        }
Example #28
0
        public void Open(String port, string baudrate)
        {
            s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            const int buffSize = 4 * 1024;

            ip     = new IPEndPoint(IPAddress.Parse("192.168.0.150"), 15000);
            ipy    = Python.CreateRuntime();
            script = ipy.UseFile("track_h.py");
            script.open(port, baudrate);
            isContinue          = true;
            thread              = new Thread(Run);
            thread.IsBackground = true;
            thread.Start();
        }
Example #29
0
        static void Main(string[] args)
        {
            Console.WriteLine("Loading helloworld.py...");

            ScriptRuntime py         = Python.CreateRuntime();
            dynamic       helloworld = py.UseFile("helloworld.py");

            Console.WriteLine("helloworld.py loaded!");

            for (int i = 0; i < 1000; i++)
            {
                Console.WriteLine(helloworld.welcome("Employee #{0}"), i);
            }
            Console.ReadLine();
        }
Example #30
0
        public void TestPythonOutput001()
        {
            // Arrange
            string        expected = "Value from C#: Avi";
            ScriptRuntime python   = Python.CreateRuntime();
            dynamic       script   = python.UseFile(string.Format(@"{0}\{0}.py", "Script"));

            script.SpecialCSharpValue = "Avi";

            // Act
            dynamic actual = script.OutputValue();

            // Assert
            Assert.AreEqual(expected, actual);
        }