Esempio n. 1
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Parses the string value from the given object - particularly useful for dates and uses the pretty date format used elsewhere
        /// </summary>
        public static string ParseRawVal(object rawObj)
        {
            string val = "";

            try {
                if (rawObj == null)
                {
                    val = "";
                }
                else
                {
                    // check to see if it is a date ....
                    if (rawObj.GetType() == (new DateTime().GetType()))
                    {
                        DateTime tempDT = new DateTime();
                        DateTime.TryParse(rawObj.ToString(), out tempDT);
                        val = DateTimeInformation.PrettyDateFormat(tempDT);
                    }
                    else
                    {
                        // integer or string ...
                        val = rawObj.ToString();
                    }
                }
            } catch (Exception ex) {
                //
                Logger.LogError(7, "Couldn't parse the raw value from the given object in GetFieldValue: " + ex.ToString());
            }

            return(val);
        }
        //-------------------------------------------------------------------------------------------------------------------------
        /// <summary>Formats the given date time string into the visuallly appealling 1 Jan 2007 23:01:01</summary>
        public static string PrettyTimeFormat(DateTime date)
        {
            string time = null;

            if (DateTimeInformation.IsNullDate(date) == false)
            {
                time = FormatDatabaseDate(date, true, true).Split(new string[] { " " }, StringSplitOptions.None)[1];
            }
            return(time);
        }
        //-------------------------------------------------------------------------------------------------------------------------
        /// <summary>Formats the given date time string into the visuallly appealling 1 Jan 2007</summary>
        public static string PrettyDateFormat(DateTime date)
        {
            string dateBit = null;

            if (DateTimeInformation.IsNullDate(date) == false)
            {
                dateBit = date.Day + " " + months[date.Month - 1] + " " + date.Year;
            }
            return(dateBit);
        }
Esempio n. 4
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------
        public static bool Test(bool writeToFile)
        {
            bool success = false;

            try {
                //////////////////////////////////
                string dir       = "C:\\Backups\\Photos_Testing_ImageResizing\\";
                string photoPath = dir + "ImageResizeTest1.jpg";
                int    width     = 1999;
                int    height    = 1999;

                MemoryStream ms = null;

                success = ImageProcessor.ResizeImage(photoPath, width, height, out ms);

                //_____ Convert this thumbnail image to a memory stream ....
                if (writeToFile)
                {
                    byte[] targetBytes = ms.ToArray();

                    // Finally - write this file back out ....
                    string fileName = dir + "Output_" + DateTimeInformation.GetCurrentDate("number")
                                      + "_" + DateTimeInformation.GetCurrentTime()
                                      + ".jpg";
                    //+ ".png";

//                    Image im = Image.FromStream(ms);
//                    im.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);


                    FileStream fs = new FileStream(fileName, FileMode.Create);

                    fs.Write(targetBytes, 0, targetBytes.Length);
                    fs.Flush();
                    fs.Close();

                    if (ms.Length > 0)
                    {
                        success = true;
                    }
                }
                else
                {
                    if (ms != null && ms.Length > 0)
                    {
                        success = true;
                    }
                }
            } catch (Exception ex) {
                string temp = ex.ToString();
            }

            return(success);
        }
        //-------------------------------------------------------------------------------------------------------------------------
        /// <summary>Formats the given date time string into the visuallly appealling 1 Jan 2007</summary>
        public static string PrettyDateFormat(DateTime date, bool includeDashes)
        {
            string dateBit = null;

            if (DateTimeInformation.IsNullDate(date) == false)
            {
                string filler = (includeDashes) ? "-" : " ";

                dateBit = date.Day + filler + months[date.Month - 1] + filler + date.Year;
            }
            return(dateBit);
        }
        //-------------------------------------------------------------------------------------------------------------------------
        /// <summary>Formats the given date time string into the visuallly appealling 1 Jan 2007</summary>
        public static string PrettyDateFormat(DateTime date, bool includeDay, bool includeMonth, bool includeYear)
        {
            string dateBit = null;

            if (DateTimeInformation.IsNullDate(date) == false)
            {
                dateBit =
                    ((includeDay) ? date.Day + " " : "") +
                    ((includeMonth) ? months[date.Month - 1] + " " : "") +
                    ((includeYear) ? date.Year.ToString() : "");
            }
            return(dateBit);
        }
Esempio n. 7
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Prints out the given information to the console using the thematic colouring
        /// </summary>
        /// <param name="info">The information to be logged.</param>
        /// <param name="useNewLine">
        ///     Whether or not to log the information on a new line.
        ///     Currently, this will always be true, apart from for processing information, that uses backspaces on the same line to overwrite the messages.
        /// </param>
        /// <param name="lht">The thematic classification to use to make the messages visually appealing.</param>
        /// <param name="severity">
        ///     The criticality of the information to be logged.  Normally in a range from 0 to 10, with 10 being the most critical.
        ///     2-4 are very low level, non critical errors.  5-7 are normal application errors (e.g. SQL errors).  8-10 are critical.
        ///     0 is normally reserved for information messages, and 1 for warnings.
        ///     As the logs have become more complicated, custom three digit severity codes are also now used for known issues.
        /// </param>
        public static void DoConsoleOutput(string info, bool useNewLine, LoggerHighlightType lht, int severity)
        {
            //-----1----- Set the thematic colouring to use for this message, based on the specified type of highlight
            if (LoggerHighlightType.Error == lht)
            {
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.Black;
            }
            else if (LoggerHighlightType.Warning == lht)
            {
                Console.BackgroundColor = ConsoleColor.Yellow;
                Console.ForegroundColor = ConsoleColor.Black;
            }
            else if (LoggerHighlightType.Processing == lht)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.DarkGray;
            }
            else if (LoggerHighlightType.Info == lht)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Gray;
            }
            else
            {
                // the defaults ...
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;
            }

            //-----2----- And lets write the information, incorporating the date and time and message severity if required.
            if (info != null)
            {
                if (info != "" && LoggerHighlightType.Processing != lht && logDateAndTime == true)
                {
                    info = DateTimeInformation.PrettyDateTimeFormat(DateTime.Now, 0) + ":" + severity + ": " + info;
                }
                if (useNewLine)
                {
                    Console.WriteLine(info);
                }
                else
                {
                    Console.Write(info);
                }
            }

            //-----3----- Reset the colours to the defaults ...
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
        }
        //-------------------------------------------------------------------------------------------------------------------------
        /// <summary>Formats the given date time string into the visuallly appealling 1 Jan 2007 23:01:01</summary>
//        public static string PrettyDateTimeFormat(DateTime date) {
        // this one will assume that the timezone offset is zero, but lets leave this blank for now ...
//        }
        //-------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Formats the given date time string and also appends the UTC timezone differential (e.g. UTC +3.5).
        ///     The timezone offset is derived from the client machine via javascript in the login, passwordRequestReset or passwordReset pages
        ///     And renders the date and time in the visuallly appealling "1 Jan 2007 23:01:01 (UTC +1)" format
        /// </summary>
        public static string PrettyDateTimeFormat(DateTime date, int timezoneOffset)
        {
            string dateBit = null;

            if (DateTimeInformation.IsNullDate(date) == false)
            {
                // the default if the tz is zero
                string utcText = TimezoneText(timezoneOffset);

                string time = FormatDatabaseDate(date, true, true).Split(new string[] { " " }, StringSplitOptions.None)[1];
                dateBit = date.Day + " " + months[date.Month - 1] + " " + date.Year + " " + time + " (" + utcText + ")";
            }
            return(dateBit);
        }
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------
        public static bool Test(bool writeToFile)
        {
            bool success = false;

            try {
                ImageProcessorGDI ipGDI = new ImageProcessorGDI();
                MemoryStream      ms    = null;

                string dir       = "C:\\Backups\\Photos_Testing_ImageResizing\\";
                string photoPath = dir + "ImageResizeTest1.jpg";

                success = ImageProcessorGDI.ResizeImage(photoPath, 1999, 1999, out ms);

                //_____ Convert this thumbnail image to a memory stream ....
                if (writeToFile)
                {
                    Image im = Image.FromStream(ms);
//                    byte[] targetBytes = ms.ToArray();

                    im.Save(dir + "OutputGDI_" + DateTimeInformation.GetCurrentDate("number")
                            + "_" + DateTimeInformation.GetCurrentTime() + ".jpg", ImageFormat.Jpeg);

                    // Finally - write this file back out ....
//                    FileStream fs = new FileStream(, FileMode.Create);

//                    fs.Write(targetBytes, 0, targetBytes.Length);
                    //fs.Flush();
//                    fs.Close();

//                    if (targetBytes.Length > 0) {
                    success = true;
//                    }
                }
                else
                {
                    if (ms != null && ms.Length > 0)
                    {
                        success = true;
                    }
                }
            } catch (Exception ex) {
                Logger.LogError(5, "Problem resulted in crash in ImageProcessorGDI.Test(): " + ex.ToString());
//                string temp = "";
            }

            return(success);
        }
        //---------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>The dates should be in the pretty format 1 Jan 2006</summary>
        public static string DateQueryGetPseudoCode(DateTime fromDate, DateTime toDate)
        {
            string fromDateStr = null;

            if (IsNullDate(fromDate) == false)
            {
                fromDateStr = DateTimeInformation.PrettyDateFormat(fromDate);
            }

            string toDateStr = null;

            if (IsNullDate(toDate) == false)
            {
                toDateStr = DateTimeInformation.PrettyDateFormat(toDate);
            }

            return(DateQueryGetPseudoCode(fromDateStr, toDateStr));
        }
Esempio n. 11
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Generates the log file name.  Normally a concatenation of the action and the date and time.
        ///     For error messages, the severity is also prefixed to the log file for easier reading of web related issues
        ///     19-Nov-2015 - modified so that the directory is not passed in
        /// </summary>
        /// <param name="logAction">A description of the action that this log is performing</param>
        /// <returns>The name of the log file</returns>
        public static string GenerateLogFileName(string logAction)
        {
            // Generate the fileName here based on the action and the current date and time
            string date = DateTimeInformation.GetCurrentDate(null);
            string time = DateTimeInformation.GetCurrentTime();

            // 8-Oct-2015 - Added the milliseconds so that we can better see what is happening in more complex situations
            string tempFileName = logAction + "_" + date + "_" + time + "_" + DateTimeInformation.GetCurrentMilliseconds() + ".txt";

            // check to see if this fileName exists already (i.e. there is another log file with the same action for exactly the same second!!!
            // If this has happened, add the number of milliseconds too
            if (File.Exists(fileName))   // SimpleIO.FileExists(fileName)) {
            //tempFileName = logDirectory + "/" + logAction + "_" + date + "_" + time + "_" + DateTimeInformation.GetCurrentMilliseconds() + ".txt";
            {
                tempFileName = logAction + "_" + date + "_" + time + "_" + DateTimeInformation.GetCurrentMilliseconds() + ".txt";
            }

            return(tempFileName);
        }
        //---------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>The dates should be in the pretty format 1 Jan 2006</summary>
        public static string DateQueryGetDatabaseFormat(DateTime fromDate, DateTime toDate)
        {
            string clause = null;

            string fromDateStr = null;

            if (IsNullDate(fromDate) == false)
            {
                fromDateStr = DateTimeInformation.FormatDatabaseDate(fromDate, true, true);
            }

            string toDateStr = null;

            if (IsNullDate(toDate) == false)
            {
                // add one to the toDate as MySQL BETWEEN is inclusive of the start and exclusive of the end ....
                toDate    = toDate.AddDays(1);
                toDateStr = DateTimeInformation.FormatDatabaseDate(toDate, true, true);
            }

            if (fromDateStr != null && fromDateStr != "" && toDateStr != null && toDateStr != "")
            {
                clause = "Between " + QuoteDate(fromDateStr) + " and " + QuoteDate(toDateStr);
            }
            else if (fromDateStr != null && fromDateStr != "")
            {
                clause = ">= " + QuoteDate(fromDateStr);
            }
            else if (toDateStr != null && toDateStr != "")
            {
                clause = "<= " + QuoteDate(toDateStr);
            }
            else
            {
                // Noone has used this new sexy tool.  Boo hoo
            }

            return(clause);
        }
Esempio n. 13
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Logs the given information
        /// </summary>
        /// <param name="info">The information to be logged.</param>
        /// <param name="lht">The type of formatting to use for the message in the console window.</param>
        /// <param name="severity">
        ///     The criticality of the information to be logged.  Normally in a range from 0 to 10, with 10 being the most critical.
        ///     As the logs have become more complicated, custom three digit severity codes are also now used for known issues.
        /// </param>
        public static void Log(string info, LoggerHighlightType lht, int severity)
        {
            if (LoggerHighlightType.Error == lht)
            {
                info = "ERROR - " + severity + " - " + (logDateAndTime ? DateTimeInformation.PrettyDateTimeFormat(DateTime.Now, 0) : "") + info;
            }
            else if (LoggerHighlightType.Warning == lht)
            {
                info = "WARNING - " + severity + " - " + (logDateAndTime ? DateTimeInformation.PrettyDateTimeFormat(DateTime.Now, 0) : "") + info;
            }
            else if (LoggerHighlightType.Processing == lht)
            {
                // Nothing to add for the processing messages
            }
            else if (LoggerHighlightType.Info == lht)
            {
                info = "INFO - " + severity + " - " + (logDateAndTime ? DateTimeInformation.PrettyDateTimeFormat(DateTime.Now, 0) : "") + info;
            }
            else
            {
                // NADA
            }

            // Store the info in the log list, if required
            if (storeLogList == true)
            {
                // Add the information in a threadsafe manner
                lock (logList) {
                    logList.Add(info);
                }
            }

            // write to the console if its a console application
            if (writeToConsole == true)
            {
                DoConsoleOutput(info, true, lht, severity);
            }
        }
Esempio n. 14
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------
        public static bool TestOriginal()
        {
            bool success = false;

            try {
                //////////////////////////////////
                string dir       = "C:\\Backups\\Photos_Testing_ImageResizing\\";
                string photoPath = dir + "ImageResizeTest1.jpg";
                int    width     = 1999;
                int    height    = 1999;



                //BitmapImage bi = new BitmapImage();
                //bi.BeginInit();
                //bi.UriSource = new Uri(photoPath);
                //bi.DecodePixelWidth = width;
                //bi.DecodePixelHeight = height;
                //bi.EndInit();

                //bi = null;

                FileStream photoStream = new FileStream(photoPath, FileMode.Open);

                BitmapDecoder photoDecoder = BitmapDecoder.Create(
                    photoStream,
                    BitmapCreateOptions.PreservePixelFormat,
                    BitmapCacheOption.None);

                BitmapFrame photo = photoDecoder.Frames[0];

                TransformedBitmap target = new TransformedBitmap(
                    photo,
                    new ScaleTransform(
                        width / photo.Width * 96 / photo.DpiX,
                        height / photo.Height * 96 / photo.DpiY,
                        0, 0));

                BitmapFrame thumbnail = BitmapFrame.Create(target);

                //_____ Convert this thumbnail image to a memory stream ....
                byte[] targetBytes = null;
                using (MemoryStream memoryStream = new MemoryStream()) {
                    JpegBitmapEncoder targetEncoder = new JpegBitmapEncoder(); // PngBitmapEncoder();
                    targetEncoder.Frames.Add(thumbnail);
                    targetEncoder.Save(memoryStream);
                    targetBytes = memoryStream.ToArray();
                }

                photoStream.Flush();
                photoStream.Close();

                // Finally - write this file back out ....
                FileStream fs = new FileStream(dir + "Output_" + DateTimeInformation.GetCurrentDate("number")
                                               + "_" + DateTimeInformation.GetCurrentTime() + ".jpg", FileMode.Create);

                fs.Write(targetBytes, 0, targetBytes.Length);
                fs.Flush();
                fs.Close();



                if (targetBytes.Length > 0)
                {
                    success = true;
                }
            } catch (Exception ex) {
                string temp = ex.ToString();
            }

            return(success);
        }