예제 #1
0
        public XVar Encrypt(XVar source)
        {
            if (source.ToString().Length == 0)
            {
                return(source);
            }

            byte[] encrypted;
            using (RijndaelManaged rijndael = new RijndaelManaged())
            {
                rijndael.Key = key;
                rijndael.IV  = INITIALISATION_VECTOR;

                ICryptoTransform encryptor = rijndael.CreateEncryptor();
                using (MemoryStream msEncrypt = new MemoryStream())
                {
                    using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                    {
                        using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                        {
                            //Write all data to the stream.
                            swEncrypt.Write(source.ToString());
                        }
                        encrypted = msEncrypt.ToArray();
                    }
                }
            }
            return(MVCFunctions.bin2hex(new XVar(encrypted)));
        }
예제 #2
0
        public static XVar parceCSVLine(XVar line, XVar delimiter, XVar removeBOM = null)
        {
            var linestr = line.ToString();

            if (linestr.Length < 3)
            {
                return(false);
            }
            if (linestr.Substring(0, 3) == "\xEF\xBB\xBF")
            {
                linestr = linestr.Substring(3);
            }

            CsvReader csvRdr = new CsvReader(new StringReader(linestr), false, delimiter.ToString()[0]);

            try
            {
                if (csvRdr.ReadNextRecord())
                {
                    XVar row = XVar.Array();
                    for (int i = 0; i < csvRdr.FieldCount; i++)
                    {
                        row.Add(csvRdr[i]);
                    }
                    return(row);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(false);
        }
예제 #3
0
        /**
         * Decrypt
         * Decrypt string, ecncrypted with AES algorythm
         * @param {string} encrypted value
         * @return {string} decrypted value
         */
        public XVar Decrypt(XVar source)
        {
            if (source.ToString().Length == 0)
            {
                return(source);
            }
            try
            {
                byte[] encrypted = (byte[])MVCFunctions.hex2byte(source).Value;
                using (RijndaelManaged rijndael = new RijndaelManaged())
                {
                    rijndael.Key = key;
                    rijndael.IV  = INITIALISATION_VECTOR;

                    ICryptoTransform decryptor = rijndael.CreateDecryptor();
                    // Create the streams used for decryption.
                    using (MemoryStream msDecrypt = new MemoryStream(encrypted))
                    {
                        using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                        {
                            using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                            {
                                // Read the decrypted bytes from the decrypting stream
                                // and place them in a string.
                                return(srDecrypt.ReadToEnd());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(source);
            }
        }
예제 #4
0
        /**
         * Get the number of rows fetched by an SQL query
         * @param String sql	A part of an SQL query or a full SQL query
         * @param Boolean       The flag indicating if the full SQL query (that can be used as a subquery)
         * or the part of an sql query ( from + where clauses ) is passed as the first param
         */
        public XVar getFetchedRowsNumber(XVar sql)
        {
            string countSql = "select count(*) from (" + sql.ToString() + ") a";

            XVar countdata = query(countSql).fetchNumeric();

            return(countdata[0]);
        }
예제 #5
0
        public static void deleteImportTempFile(XVar filePath)
        {
            var filePathStr = filePath.ToString().Replace('/', '\\');

            if (System.IO.File.Exists(filePathStr))
            {
                System.IO.File.Delete(filePathStr);
            }
        }
예제 #6
0
        public string GetViewPath()
        {
            if (!string.IsNullOrEmpty(view_filename))             // view can be overridden
            {
                return("../" + view_filename.ToString());
            }

            return(null);
            //throw ApplicationException("No view found");
        }
예제 #7
0
        /**
         * An interface stub
         * Execute an SQL query
         * @param String sql
         */
        public QueryResult exec(XVar sql)
        {
            //db_exec
            if (GlobalVars.dDebug)
            {
                MVCFunctions.EchoToOutput(sql.ToString() + "<br />");
            }

            return(query(sql));
        }
예제 #8
0
        /// <summary>
        /// changes php arrays into xml text recursively
        /// </summary>
        /// <param name="arg_arr_array">the array to be changed into XML</param>
        /// <param name="_arg_str_operation_name">the name of the main xml tag</param>
        /// <param name="arg_str_pad">the indentation pad text</param>
        /// <returns>xml text</returns>
        public XVar array_to_xml(XVar arg_arr_array, XVar _arg_str_operation_name = null, XVar arg_str_pad = null)
        {
            if (arg_arr_array as Object == null || !arg_arr_array.IsArray())
            {
                return(false);
            }
            XVar      arg_str_operation_name = _arg_str_operation_name ?? "report";
            XDocument xDoc = new XDocument();

            xDoc.Add(new XElement(arg_str_operation_name.ToString()));
            xDoc.Root.Add(this.prv_array_to_xml(arg_arr_array));
            return(xDoc.ToString());
        }
예제 #9
0
        public static void saveTextInFile(XVar filePath, XVar text)
        {
            var filePathStr = filePath.ToString().Replace('/', '\\');

            var dir = System.IO.Path.GetDirectoryName(filePathStr);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            System.IO.File.WriteAllText(filePathStr, text);
        }
예제 #10
0
        public static XVar getImportFileData(XVar fileName)
        {
            var uploadedFile = HttpContext.Current.Request.Files[fileName.ToString()];

            XVar uploadedFileData = XVar.Array();

            uploadedFileData["name"]     = uploadedFile.FileName;
            uploadedFileData["tmp_name"] = uploadedFile.FileName;
            uploadedFileData["size"]     = uploadedFile.ContentLength;
            uploadedFileData["type"]     = uploadedFile.ContentType;
            uploadedFileData["error"]    = "";
            uploadedFileData["file"]     = uploadedFile;
            return(uploadedFileData);
        }
예제 #11
0
        /// <summary>
        /// Sets padding in xml text.
        /// Helps to make the xmlcode readable but can be disabled by emptying arg_str_pad when we do not need to read the xml code.
        /// </summary>
        /// <param name="arg_int_pad_number">the number of indentation pads in this tag</param>
        /// <param name="arg_str_pad">the single pad size</param>
        /// <returns></returns>
        private XVar pad(XVar arg_int_pad_number = null, XVar arg_str_pad = null)
        {
            if (arg_int_pad_number as Object == null || arg_str_pad as Object == null)
            {
                return(null);
            }

            StringBuilder str_pad = new StringBuilder();

            for (int i = 0; i < arg_int_pad_number.Count(); i++)
            {
                str_pad.Append(arg_str_pad.ToString());
            }
            return(str_pad.Length > 0  ? "\n" + str_pad.ToString() : "");
        }
예제 #12
0
        public XVar call_func(XVar _param_var)
        {
            XVar var_var = _param_var.Clone();

            XVar var_out;

            if (!var_var.IsArray() || !var_var["func"].Length())
            {
                return("");
            }
            MVCFunctions.ob_start();

            XVar res = ((XTempl.xtFuncDelegate)var_var["func"].Value)(new XVar());

            var_out = MVCFunctions.ob_get_contents() + res.ToString();
            MVCFunctions.ob_end_clean();
            return(var_out);
        }
예제 #13
0
        public static XVar getFileNamesFromDir(XVar dirPath)
        {
            XVar names = XVar.Array();

            var dirPathStr = dirPath.ToString().Replace('/', '\\');

            if (!System.IO.Directory.Exists(dirPathStr))
            {
                return(names);
            }

            foreach (var file in System.IO.Directory.EnumerateFiles(dirPathStr))
            {
                names.Add(file);
            }

            return(names);
        }
예제 #14
0
        public static XVar OpenCSVFile(XVar uploadfile, XVar delimeter)
        {
            if (uploadfile.Value is string && MVCFunctions.file_exists(uploadfile))
            {
                FileStream fs = new FileStream(uploadfile.ToString(), FileMode.Open);
                return(new XVar(new StreamReader(fs)));
            }
            if (uploadfile.Value is HttpPostedFile)
            {
                Stream fs = (uploadfile.Value as HttpPostedFile).InputStream;
                fs.Position = 0;
                return(new XVar(new StreamReader(fs)));
            }

            // preview mode - file is in the _FILES list
            for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
            {
                if (HttpContext.Current.Request.Files[i].FileName == uploadfile.Value)
                {
                    return(new XVar(new StreamReader(HttpContext.Current.Request.Files[i].InputStream)));
                }
            }
            throw new ApplicationException("CSV file not found");
        }
예제 #15
0
 public static XVar getImportTableName(XVar tname)
 {
     return(XVar.Pack(HttpContext.Current.Request.Files[tname.ToString()]));
 }
예제 #16
0
        /**
         * An interface stub
         * Send an SQL query
         * @param String sql
         * @return QueryResult
         */
        public QueryResult query(XVar sql)
        {
            //db_query
            //return new QueryResult( this, qHandle );

            if (GlobalVars.dDebug)
            {
                MVCFunctions.EchoToOutput(sql.ToString() + "<br />");
            }

            GlobalVars.strLastSQL = sql;
            DbCommand cmd     = null;
            DbCommand initCmd = null;

            try {
                DbConnection connection = connectionsPool.FreeConnection;
                if (connection.State != System.Data.ConnectionState.Open)
                {
                    connection.Open();
                    if (initializingSQL != null)
                    {
                        initCmd             = GetCommand();
                        initCmd.Connection  = connection;
                        initCmd.CommandText = initializingSQL;
                        initCmd.Prepare();
                        initCmd.ExecuteNonQuery();
                    }
                }
                cmd             = GetCommand();
                cmd.Connection  = connection;
                cmd.CommandText = sql;
                cmd.Prepare();

                string    commandStr      = sql.ToLower().Substring(0, 6);
                string [] stopCommandList = { "insert", "update", "delete", "create", "drop", "rename", "alter" };
                if (stopCommandList.Any(x => commandStr.Substring(0, x.Length) == x))
                {
                    cmd.ExecuteNonQuery();
                    CalculateLastInsertedId(commandStr, cmd);
                    cmd.Connection.Close();
                    return(null);
                }
                else
                {
                    RunnerDBReader rdr = cmd.ExecuteReader();
                    rdr.Connection = cmd.Connection;
                    return(new QueryResult(this, rdr));
                }
            }
            catch (Exception e)
            {
                GlobalVars.LastDBError = e.Message;
                if (cmd != null)
                {
                    cmd.Connection.Close();
                }

                if (!silentMode)
                {
                    if (!MVCFunctions.HandleError())
                    {
                        throw e;
                    }
                }
                return(null);
            }
        }
예제 #17
0
 public static void ExportExcelSave(XVar filename, XVar format, XVar objPHPExcel)
 {
     ((ExcelPackage)objPHPExcel["excelObj"].Value).SaveAs(HttpContext.Current.Response.OutputStream);
     HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
     HttpContext.Current.Response.AddHeader("content-disposition", "attachment;  filename=" + filename.ToString());
     HttpContext.Current.Response.End();
     throw new RunnerInlineOutputException();
 }
예제 #18
0
        public override void db_multipleInsertQuery(XVar qstringArray, XVar table = null, XVar isIdentityOffNeeded = null)
        {
            try
            {
                DbConnection connection = connectionsPool.FreeConnection;
                if (connection.State != System.Data.ConnectionState.Open)
                {
                    connection.Open();
                }

                DbCommand cmd = GetCommand();
                cmd.Connection = connection;

                if (isIdentityOffNeeded)
                {
                    cmd.CommandText = "SET IDENTITY_INSERT " + table.ToString() + " ON";
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }
                foreach (var qstring in qstringArray.GetEnumerator())
                {
                    if (GlobalVars.dDebug)
                    {
                        MVCFunctions.EchoToOutput(qstring.Value.ToString() + "<br />");
                    }

                    GlobalVars.strLastSQL = qstring.Value;

                    cmd.CommandText = qstring.Value.ToString();

                    cmd.ExecuteNonQuery();
                }
                if (isIdentityOffNeeded)
                {
                    cmd.CommandText = "SET IDENTITY_INSERT " + table.ToString() + " OFF";
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    cmd.CommandText = "select @@IDENTITY as indent";
                    cmd.Prepare();
                    RunnerDBReader rdr = cmd.ExecuteReader();
                    rdr.Connection = cmd.Connection;
                    if (rdr.Read())
                    {
                        lastInsertedID = new XVar(rdr["indent"]);
                    }
                }
                connection.Close();
            }
            catch (Exception e)
            {
                if (!silentMode)
                {
                    if (!MVCFunctions.HandleError())
                    {
                        throw e;
                    }
                }
            }
        }
예제 #19
0
        private void WriteToPage(object page, XVar objectToWrite)
        {
            if (objectToWrite.IsArray())
            {
                if (objectToWrite.KeyExists("method"))
                {
                    XVar             parameters    = objectToWrite.KeyExists("params") ? objectToWrite["params"] : new XVar();
                    xtMethodDelegate invokedMethod = (xtMethodDelegate)objectToWrite["method"].Value;

                    MVCFunctions.ob_start();
                    var result    = invokedMethod.Invoke(parameters);
                    var resultStr = result as object == null ? "" : result.ToString();


                    MvcHtmlString textToWrite = MvcHtmlString.Create(MVCFunctions.ob_get_contents() + resultStr);
                    MVCFunctions.ob_end_clean();

                    page.GetType().GetMethod("Write", new Type[] { typeof(MvcHtmlString) }).Invoke(page, new object[] { textToWrite });
                }
            }
            else
            {
                page.GetType().GetMethod("Write", new Type[] { typeof(MvcHtmlString) }).Invoke(page, new object[] { MvcHtmlString.Create(objectToWrite.ToString()) });
            }
        }
예제 #20
0
파일: XSession.cs 프로젝트: kurtrad/ABCVote
 public void Remove(XVar key)
 {
     HttpContext.Current.Session.Remove(key.ToString());
 }
예제 #21
0
 public static XVar getTempImportFileName(XVar fname)
 {
     return(HttpContext.Current.Request.Files[fname.ToString()].FileName);
 }
예제 #22
0
 /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
 /// <summary>
 /// Replaces the ToString()
 /// </summary>
 public override string ToString()
 {
     // just return the variable string
     return("(" + XVar.ToString() + "," + YVar.ToString() + ")");
 }
예제 #23
0
파일: XSession.cs 프로젝트: kurtrad/ABCVote
 public bool KeyExists(XVar key)
 {
     return(HttpContext.Current.Session[key.ToString()] != null);
 }