示例#1
0
        private object valueForType(Type typeFrom, Type typeTo, object value)
        {
            try
            {
                if (typeFrom.Equals(typeTo))
                {
                    return(value);
                }

                if (typeTo.Equals(typeof(DateTime)))
                {
                    if (value == null)
                    {
                        return(DateHelper.INIT_DATE);
                    }

                    return((DateTime)value);
                }

                return(value);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
                return(value);
            }
            finally
            {
            }
        }
示例#2
0
        public bool AppendDatatable(DataTable source, ref DataTable target)
        {
            try
            {
                if (source == null)
                {
                    return(false);
                }

                if (target == null)
                {
                    target = new DataTable();
                    target = source.Copy();

                    return(true);
                }

                for (int i = 0; i < source.Rows.Count; i++)
                {
                    target.ImportRow(source.Rows[i]);
                }

                target.AcceptChanges();

                return(true);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
                return(false);
            }
            finally
            {
            }
        }
示例#3
0
        public static object SubFromBase64ByteArray(byte[] ba)
        {
            BinaryFormatter bf = null;
            MemoryStream    ms = null;

            object obj = null;

            try
            {
                bf = new BinaryFormatter();
                ms = new MemoryStream(ba);

                obj = bf.Deserialize(ms);

                if (obj != null)
                {
                    return(obj);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
            }
            finally
            {
            }

            return(null);
        }
示例#4
0
        public static int ExecuteCmdCommand(string command, int timeout, bool verbose)
        {
            ProcessStartInfo processInfo = new ProcessStartInfo("cmd.exe", "/C " + command)
            {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                WorkingDirectory       = "C:\\",
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
            };

            Process process = Process.Start(processInfo);
            string  stdoutx = process.StandardOutput.ReadToEnd();
            string  stderrx = process.StandardError.ReadToEnd();

            process.WaitForExit(timeout);
            int exitCode = process.ExitCode;

            process.Close();

            if (verbose)
            {
                if (StringHelper.hasValue(stdoutx))
                {
                    LoggingHelper.log("OUT::" + stdoutx);
                }

                if (StringHelper.hasValue(stderrx))
                {
                    LoggingHelper.log("ERROR::" + stderrx);
                }
            }

            return(exitCode);
        }
示例#5
0
        private static void runTask(object toRun)
        {
            IRunnable r = (IRunnable)toRun;

            LoggingHelper.log("Executing async [" + toRun.ToString()
                              + "] on thread ["
                              + Thread.CurrentThread.Name + "::"
                              + Thread.CurrentThread.ManagedThreadId + "]");
            r.run();
        }
示例#6
0
        public static string FormatNumer(object value, string format)
        {
            try
            {
                if (value is double)
                {
                    return(((double)value).ToString(format));
                }

                else if (value is decimal)
                {
                    return(((decimal)value).ToString(format));
                }

                else if (value is long)
                {
                    return(((long)value).ToString(format));
                }

                else if (value is int)
                {
                    return(((int)value).ToString(format));
                }

                else if (value is Int16)
                {
                    return(((Int16)value).ToString(format));
                }

                else if (value is Int32)
                {
                    return(((Int32)value).ToString(format));
                }

                else if (value is Int64)
                {
                    return(((Int64)value).ToString(format));
                }

                else
                {
                    LoggingHelper.log("_HelpClasses.NumericFunctions.FormatNumer::Type [" + value.GetType().ToString() + " not supported.");
                }

                return("0,00");
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
                return("");
            }
            finally
            {
            }
        }
示例#7
0
 public static bool safeRegisterChannel(IChannel ch)
 {
     try
     {
         ChannelServices.RegisterChannel(ch, false);
         return(true);
     }
     catch (Exception ex)
     {
         LoggingHelper.log(ex);
         return(false);
     }
 }
示例#8
0
        public static string BuildNumberPatternEN(int GroupSize, int DecimalSize, int MaxIntegerSize)
        {
            string s = "";

            try
            {
                if (GroupSize == 0)
                {
                    s = new string( '#', MaxIntegerSize - 1 );
                }
                else
                {
                    for (int i = 1; i < MaxIntegerSize; i++)
                    {
                        if ((i % (GroupSize + 1)) == 0)
                        {
                            s += ",";
                        }
                        else
                        {
                            s += "#";
                        }
                    }
                }

                if (DecimalSize == 0)
                {
                    return(s + "0");
                }

                s += ".";

                for (int i = 0; i < DecimalSize - 1; i++)
                {
                    s += "#";
                }
                s += "0";

                return(s);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
                return("");
            }
            finally
            {
            }
        }
示例#9
0
 public static string Format(DateTime dt)
 {
     try
     {
         return(Format(dt, FORMAT_ddMMyyyy));
     }
     catch (Exception ex)
     {
         LoggingHelper.log(ex);
         return(dt.ToString());
     }
     finally
     {
     }
 }
示例#10
0
 public static bool CompareEqual(DateTime d1, DateTime d2)
 {
     try
     {
         return(d1 == d2);
     }
     catch (Exception ex)
     {
         LoggingHelper.log(ex);
         return(false);
     }
     finally
     {
     }
 }
示例#11
0
 public static int Compare(DateTime d1, DateTime d2)
 {
     try
     {
         return(DateTime.Compare(d1, d2));
     }
     catch (Exception ex)
     {
         LoggingHelper.log(ex);
         throw ex;
     }
     finally
     {
     }
 }
示例#12
0
 public static string BuildNumberPatternEN()
 {
     try
     {
         return(BuildNumberPatternEN(3, 2, 20));
     }
     catch (Exception ex)
     {
         LoggingHelper.log(ex);
         return("");
     }
     finally
     {
     }
 }
示例#13
0
 public static string Format(DateTime dt, string fmt)
 {
     try
     {
         return(dt.ToString(fmt));
     }
     catch (Exception ex)
     {
         LoggingHelper.log(ex);
         return(dt.ToString());
     }
     finally
     {
     }
 }
示例#14
0
        public static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            try
            {
                string   probingPath = Application.StartupPath;
                string[] paths       = probingPath.Split(new char[] { ';' });

                for (int i = 0; i < paths.Length; i++)
                {
                    string assemblyPath = paths[i];
                    string assemblyName = "";

                    if (args.Name.IndexOf(",") != -1)
                    {
                        assemblyName = args.Name.Substring(0, args.Name.IndexOf(","));
                    }
                    else
                    {
                        assemblyName = args.Name;
                    }

                    if (!assemblyName.EndsWith(".dll"))
                    {
                        assemblyName += ".dll";
                    }

                    string assemblyFullName = Path.Combine(assemblyPath, assemblyName);
                    if (!File.Exists(assemblyFullName))
                    {
                        continue;
                    }

                    Assembly theAssembly = Assembly.LoadFrom(assemblyFullName);

                    return(theAssembly);
                }

                return(null);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
                return(null);
            }
            finally
            {
            }
        }
示例#15
0
 /*
  * If (condition1 == TRUE) OR (condition2 == TRUE), throw exception
  */
 public static void validate(bool condition1, bool condition2, string message)
 {
     try
     {
         validate(condition1, message);
         validate(condition2, message);
     }
     catch (Exception ex)
     {
         LoggingHelper.log(ex);
         throw ex;
     }
     finally
     {
     }
 }
示例#16
0
 /*
  * If (condition == TRUE), throw message as exception
  */
 public static void validate(bool condition, string message)
 {
     try
     {
         if (condition)
         {
             throw new Exception(message);
         }
     }
     catch (Exception ex)
     {
         LoggingHelper.log(ex);
         throw ex;
     }
     finally
     {
     }
 }
示例#17
0
 public static void reportVoices()
 {
     try
     {
         SpeechSynthesizer ss = new System.Speech.Synthesis.SpeechSynthesizer();
         for (int i = 0; i < ss.GetInstalledVoices().Count; i++)
         {
             LoggingHelper.log(ss.GetInstalledVoices()[i].VoiceInfo.Name);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
     }
 }
示例#18
0
        public static bool SubCreateFileFromBase64(string FilePath, string EncodedFile)
        {
            FileStream fs = null;

            byte[] ba = null;
            char[] ca = null;

            try
            {
                fs = new FileStream(FilePath, FileMode.Create);
                ca = EncodedFile.ToCharArray();

                ba = Convert.FromBase64CharArray(ca, 0, ca.Length);

                if (ba.Length <= int.MaxValue)
                {
                    fs.Write(ba, 0, ba.Length);
                }
                else
                {
                    for (int i = 0; i < ba.Length; i++)
                    {
                        fs.WriteByte(ba[i]);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
                //throw ex;
                return(false);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
示例#19
0
        public DataSet RemoveTable(DataSet source, string tableName)
        {
            try
            {
                if (source == null)
                {
                    return(null);
                }

                for (int i = 0; i < source.Tables.Count; i++)
                {
                    if (source.Tables[i].TableName.ToLower().Equals(tableName.ToLower()))
                    {
                        if (source.Tables[i].ParentRelations.Count != 0)
                        {
                            source.Tables[i].ParentRelations.Clear();
                        }
                        if (source.Tables[i].ChildRelations.Count != 0)
                        {
                            source.Tables[i].ChildRelations.Clear();
                        }
                        if (source.Tables[i].Constraints.Count != 0)
                        {
                            source.Tables[i].Constraints.Clear();
                        }

                        source.Tables.Remove(source.Tables[i]);
                    }
                }

                return(source);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
                return(source);
            }
            finally
            {
            }
        }
示例#20
0
        public static byte[] SubToBase64ByteArray(object obj)
        {
            BinaryFormatter bf = null;
            MemoryStream    ms = null;

            byte[] ba = null;

            try
            {
                ba = (byte[])obj;

                return(ba);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
            }
            finally
            {
            }

            try
            {
                bf = new BinaryFormatter();
                ms = new MemoryStream();
                bf.Serialize(ms, obj);
                ba = ms.ToArray();

                return(ba);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
            }
            finally
            {
            }

            return(null);
        }
示例#21
0
        public DataSet RemoveAllTables(DataSet source)
        {
            try
            {
                if (source == null)
                {
                    return(null);
                }

                for (int i = source.Tables.Count - 1; i >= 0; i--)
                {
                    if (source.Tables[i].ParentRelations.Count != 0)
                    {
                        source.Tables[i].ParentRelations.Clear();
                    }
                    if (source.Tables[i].ChildRelations.Count != 0)
                    {
                        source.Tables[i].ChildRelations.Clear();
                    }
                    if (source.Tables[i].Constraints.Count != 0)
                    {
                        source.Tables[i].Constraints.Clear();
                    }

                    source.Tables.RemoveAt(i);
                }

                return(source);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
                return(source);
            }
            finally
            {
            }
        }
示例#22
0
        public static string SubToBase64String(object obj)
        {
            byte[] ba = null;

            try
            {
                ba = SubToBase64ByteArray(obj);
                if (ba == null)
                {
                    return("");
                }

                return(Convert.ToBase64String(ba, Base64FormattingOptions.None));
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
            }
            finally
            {
            }

            return(null);
        }
示例#23
0
        public DataTable ArrayToDatatable(Array source, bool AddTypeColumn, string TableName, string[] properties)
        {
            DataTable dt = null;
            DataRow   dr = null;
            Type      t  = null;

            PropertyInfo[] pia = null;

            try
            {
                if (source == null)
                {
                    return(null);
                }

                dt = new DataTable();
                if (TableName.Trim().Length != 0)
                {
                    dt.TableName = TableName;
                }

                t = source.GetValue(0).GetType();
                if (properties == null)
                {
                    pia        = t.GetProperties();
                    properties = new string[pia.Length];
                    for (int i = 0; i < pia.Length; i++)
                    {
                        properties[i] = pia[i].Name;
                    }
                }

                //for (int i = 0; i < pia.Length; i++)
                //    dt.Columns.Add( pia[i].Name, pia[i].PropertyType );
                for (int i = 0; i < properties.Length; i++)
                {
                    dt.Columns.Add(properties[i], PropertyParser.getPropertyType(properties[i], source.GetValue(0)));
                }

                if (AddTypeColumn)
                {
                    dt.Columns.Add(DataHelper.DATATABLE_OBJECT_TYPE_CLASS_NAME_COLUMN, typeof(string));
                }

                object v = null;
                for (int j = 0; j < source.Length; j++)
                {
                    dr = dt.NewRow();
                    for (int i = 0; i < properties.Length; i++)
                    {
                        //v = pia[i].GetValue( source.GetValue( j ), null );
                        //v = valueForType( pia[i].PropertyType, dt.Columns[pia[i].Name].DataType, v );
                        v = PropertyParser.getPropertyValue(properties[i], source.GetValue(j));
                        dr[properties[i]] = v;
                    }

                    if (AddTypeColumn)
                    {
                        dr[DataHelper.DATATABLE_OBJECT_TYPE_CLASS_NAME_COLUMN] = t.ToString();
                    }

                    dt.Rows.Add(dr);
                }
                dt.AcceptChanges();

                return(dt);
            }
            catch (Exception ex)
            {
                LoggingHelper.log(ex);
                return(null);
            }
            finally
            {
                dr = null;
                t  = null;
                if (pia != null)
                {
                    Array.Clear(pia, 0, pia.Length);
                }
                pia = null;
            }
        }