예제 #1
0
        /// <summary>
        /// Read csv file;
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            // Read list from Database.
            var listImagesCSV = ReadWriteCSV.ReadCSV(pathCSV);

            // Change Active For LockScreen
            foreach (var item in listImagesCSV.Where(x => x.Type == "LockScreen").ToList())
            {
                // Check TimeTo duedate to change default images to active
                if (item.TimeTo > DateTime.Now)
                {
                    StartMove(-item.ID, item.TimeTo, Directory.GetFiles(pathDefaultLockScreen)[0], pathLockScreen + "default.jpg", item.Type);
                }
                // Check TimeForm to change images list to active images
                if (item.TimeFrom > DateTime.Now)
                {
                    StartMove(item.ID, item.TimeFrom, pathImages + item.Name, pathLockScreen + "default.jpg", item.Type);
                }
            }
            // Change Activ For ScreenSaver
            foreach (var item in listImagesCSV.Where(x => x.Type == "ScreenSaver").ToList())
            {
                // Check TimeTo duedate to change default images to active
                if (item.TimeTo > DateTime.Now)
                {
                    StartRemove(-item.ID, item.TimeTo, pathScreenSaver, item.Name);
                }
                // Check TimeStart to change images list to active images
                if (item.TimeFrom > DateTime.Now)
                {
                    StartMove(item.ID, item.TimeFrom, pathImages + item.Name, pathScreenSaver + item.Name, item.Type);
                }
            }
        }
예제 #2
0
        public void RecordExists_Invalid_ShouldReturnFalse(string key, int column)
        {
            File.Delete(@"test.txt");
            var sut = new ReadWriteCSV("test.txt", ';');
            //sut.AddRecord("1;2;3");
            //sut.AddRecord("a;b;c");
            var response = sut.RecordExists(key, column);

            Assert.False(response.Result);
            Assert.True(response.IsSuccessStatusCode);
        }
예제 #3
0
 protected void SaveToCSV(bool start, string name, string column1, string column2)
 {
     //MessageBox.Show(start.ToString() + " ; " + dataTable.Rows.Count.ToString());
     if (start && dataTable.Rows.Count > 2)
     {
         ReadWriteCSV readWriteCSV = new ReadWriteCSV(CreatePath.CreateReportPath(name, fileEnding));
         readWriteCSV.WriteToCSV(column1, column2);
         for (int i = 0; i < dataTable.Rows.Count; i++)
         {
             readWriteCSV.WriteToCSV(dataTable.Rows[i][0].ToString(), dataTable.Rows[i][1].ToString());
         }
     }
 }
예제 #4
0
        public JsonResult DeleteAll()
        {
            try
            {
                string type = ((int)Session["Type"] != 2) ? "ScreenSaver" : "LockScreen";

                // Remove all images in ImagesUpload and Uploaded
                List <ImageModel> removeList = (List <ImageModel>)Session["Images"];
                foreach (var item in removeList.Where(x => x.Type == type).ToList())
                {
                    // Check if not exists other type
                    if (!removeList.Exists(x => x.Type != type && x.Name == item.Name))
                    {
                        System.IO.File.Delete(Path.Combine(Server.MapPath(pathTempImages), item.Name));
                        System.IO.File.Delete(Path.Combine(pathImages, item.Name));
                    }
                    // Remove Active Images
                    if (item.TimeFrom < DateTime.Now && item.TimeTo > DateTime.Now)
                    {
                        if (item.Type == "ScreenSaver")
                        {
                            RemoveActiveToDefault(pathScreenSaver, item.Name, pathDefaultScreenSaver);
                        }
                        else
                        {
                            RemoveActiveToDefault(pathLockScreen, "default.jpg", pathDefaultLockScreen);
                        }
                    }
                }

                List <ImageModel> tempList = (List <ImageModel>)Session["Images"];
                tempList.RemoveAll(x => x.Type == type);
                Session["Images"] = tempList;
                //ReadWriteCSV.WriteCSV(new List<ImageModel>());
                ReadWriteCSV.WriteCSV(tempList);
                // Remove all schedule
                JobsSchedule.RemoveAllSchedule();
                Notification("Notify", "Remove all list images successfuly", MyConstants.NOTIFY_SUCCESS);
                return(Json(new { status = true }));
            }
            catch (Exception)
            {
                Notification("Error", "Remove all list images failure", MyConstants.NOTIFY_ERROR);
                return(Json(new { status = false }));

                throw;
            }
        }
예제 #5
0
        public JsonResult Delete(long id)
        {
            var    sessionCart = (List <ImageModel>)Session["Images"];
            string type        = ((int)Session["Type"] != 2) ? "ScreenSaver" : "LockScreen";

            // Remove that images: all information
            foreach (var item in sessionCart.Where(x => x.ID == id).ToList())
            {
                // Check if not exists other type
                if (!sessionCart.Exists(x => x.Type != type && x.Name == item.Name))
                {
                    System.IO.File.Delete(Path.Combine(Server.MapPath(pathTempImages), item.Name));
                    System.IO.File.Delete(Path.Combine(pathImages, item.Name));
                }

                // Remove active images
                if (item.TimeFrom < DateTime.Now && item.TimeTo > DateTime.Now)
                {
                    if (item.Type == "ScreenSaver")
                    {
                        RemoveActiveToDefault(pathScreenSaver, item.Name, pathDefaultScreenSaver);
                    }
                    else
                    {
                        RemoveActiveToDefault(pathLockScreen, "default.jpg", pathDefaultLockScreen);
                    }
                }
                // Remove all schedule apply
                JobsSchedule.RemoveAllSchedule();
            }

            sessionCart.RemoveAll(x => x.ID == id);
            Session["Images"] = sessionCart;
            ReadWriteCSV.WriteCSV(sessionCart);
            // Restart schedule apply after delete that item
            JobsSchedule.Start();
            if (sessionCart.Count == 0)
            {
                Session["Images"] = null;
            }
            return(Json(new
            {
                status = true
            }));
        }
예제 #6
0
 protected void SaveToCSV(bool start, string name, string column1, string column2)
 {
     //MessageBox.Show(start.ToString() + " ; " + dataTable.Rows.Count.ToString());
     if (start && dataTable.Rows.Count > 2)
     {
         string       year         = System.DateTime.Now.Year.ToString();
         string       month        = System.DateTime.Now.Month.ToString();
         string       day          = System.DateTime.Now.Day.ToString();
         string       hour         = System.DateTime.Now.Hour.ToString();
         string       minute       = System.DateTime.Now.Minute.ToString();
         ReadWriteCSV readWriteCSV = new ReadWriteCSV(@"D:\Chart\" + hour + "_" + minute + "_" + day + "_" + month + "_" + year + "_" + name + ".csv");
         readWriteCSV.WriteToCSV(column1, column2);
         for (int i = 0; i < dataTable.Rows.Count; i++)
         {
             readWriteCSV.WriteToCSV(dataTable.Rows[i][0].ToString(), dataTable.Rows[i][1].ToString());
         }
     }
 }
예제 #7
0
 public ActionResult Index()
 {
     try
     {
         if (ReadWriteCSV.ReadCSV(pathCSV).Count != 0)
         {
             Session["Images"] = ReadWriteCSV.ReadCSV(pathCSV);
         }
         else
         {
             Session["Images"] = null;
         }
     }
     catch (Exception ex)
     {
         Notification("Error", "Can't read CSV file!, " + ex.ToString(), MyConstants.NOTIFY_ERROR);
     }
     return(View());
 }
예제 #8
0
 protected void SaveToCSV(bool start, string name, string column1, string column2, string column3, string column4)
 {
     if (start && ValuesAfter1.Count > 2)
     {
         ReadWriteCSV readWriteCSV = new ReadWriteCSV(CreatePath.CreateReportPath(name, fileEnding));
         readWriteCSV.WriteToCSV("Height", column1, column2, column3, column4);
         for (int i = 0; i < ValuesBefore1.Count; i++)
         {
             if ((i < ValuesAfter1.Count))
             {
                 readWriteCSV.WriteToCSV(i.ToString(), ValuesBefore1[i].ToString(), ValuesBefore2[i].ToString(), ValuesAfter1[i].ToString(), ValuesAfter2[i].ToString());
             }
             else
             {
                 readWriteCSV.WriteToCSV(i.ToString(), ValuesBefore1[i].ToString(), ValuesBefore2[i].ToString());
             }
         }
     }
 }
예제 #9
0
        public JsonResult Done()
        {
            try
            {
                var imagesList = (List <ImageModel>)Session["Images"];
                if (imagesList != null)
                {
                    //Create list object - update url
                    List <ImageModel> newListImages = new List <ImageModel>();
                    newListImages = imagesList;
                    foreach (var item in newListImages)
                    {
                        if (!System.IO.File.Exists(pathImages + item.Name))
                        {
                            System.IO.File.Copy(Server.MapPath(pathTempImages) + item.Name, pathImages + item.Name);
                        }
                        item.Url = pathImages + item.Name;
                    }
                    //Save object to file.txt
                    ReadWriteCSV.WriteCSV(newListImages);
                    Session["Images"] = imagesList;
                    Notification("Notify", "Save list images successfuly", MyConstants.NOTIFY_SUCCESS);

                    // Start Schedule.
                    JobsSchedule.RemoveAllSchedule();
                    JobsSchedule.Start();
                    return(Json(new { status = true }));
                }
                else
                {
                    Notification("Error", "This list being empty", MyConstants.NOTIFY_ERROR);
                    return(Json(new { status = false }));
                }
            }
            catch (Exception e)
            {
                Notification("Error", "Have some error, Please contact with IT!", MyConstants.NOTIFY_ERROR);
                return(Json(new { status = e.ToString() }));
            }
        }