public override void DoWork()
        {
            try
            {
                Progressing();

                Logger.Debug("ClearUploadTempFiles Running");

                var portals = PortalController.Instance.GetPortals();

                if (portals == null || portals.Count == 0)
                {
                    Logger.Debug("No portals were found.");
                }
                else
                {
                    Logger.DebugFormat("Found {0} portals to attempt to process.", portals.Count);
                }

                foreach (PortalInfo portal in portals)
                {
                    Logger.DebugFormat("Processing Portal: {0}", portal.PortalID);

                    var folderPath = string.Format("\\Portals\\{0}\\Hotcakes\\Data\\temp\\", portal.PortalID);
                    var fullPath   = System.Web.Hosting.HostingEnvironment.MapPath(folderPath);

                    Logger.DebugFormat("folderPath: {0}", folderPath);
                    Logger.DebugFormat("fullPath: {0}", fullPath);

                    var tempFolder = new System.IO.DirectoryInfo(fullPath);

                    if (tempFolder != null && tempFolder.Exists)
                    {
                        Logger.Debug("Recursively deleting the contents of the folder.");
                        // delete everything inside of the folder, but leave the folder in place
                        tempFolder.Empty();
                    }
                }

                Logger.Debug("ClearUploadTempFiles Completed");

                //Show success
                ScheduleHistoryItem.Succeeded = true;
            }
            catch (Exception ex)
            {
                ScheduleHistoryItem.Succeeded = false;
                LogError(ex.Message, ex);
                Errored(ref ex);
                Exceptions.LogException(ex);
            }
        }
示例#2
0
        //timer event for grabbing EOD data
        //it is a 15 minute timer
        //if the attemp is successful on first attempt, the timer is
        //disable untill next day. if unsuccessfull a total of txtNumTry
        //attempt is made
        private void timerEODGrabber_Tick(object sender, EventArgs e)
        {
            if (isEODDone == true)
            {
                return;
            }

            bool eod_done = true;

            // try to get EOD mst
            try
            {
                lstMessages.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), @"Grabbing MST file..." }));
                Application.DoEvents();

                EODDataGrabber dseEOD = new EODDataGrabber(dataFolder);
                dseEOD.GrabAndSave();
                string dbConString = @"Data Source=" + txtDBPath.Text + ";Version=3;";
                dseEOD.StoreToDB(dbConString);

                int lastItem = lstMessages.Items.Count - 1;
                lstMessages.Items[lastItem].SubItems[1].Text = @"Grabbing MST file... Done. Took " + dseEOD.linkTime + " sec";
            }
            catch (Exception ex)
            {
                lstErrors.Items.Add(new ListViewItem(new string[] { DateTime.Now.ToString(), @"timerEODGrabber_Tick " + ex.Message }));
            }

            // if success
            if (eod_done)
            {
                timerEODGrabber.Enabled = false;
                isEODDone = true;
                //end of trading day
                isTradingDay = false;

                //some cleanup
                System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(tempFolder + @"\dldata\");
                directory.Empty();
            }
            else
            {
                //if fails
                nCurEODRetry += 1;                                 // try again
                if (nCurEODRetry >= Int32.Parse(txtNumRetry.Text)) // too many retry
                {
                    timerEODGrabber.Enabled = false;
                }
            }
        }
        public override ConsoleResultModel Run()
        {
            try
            {
                var messages = new List <PromptMessage>();
                var portals  = PortalController.Instance.GetPortals();

                if (portals == null || portals.Count == 0)
                {
                    messages.Add(new PromptMessage(LocalizeString("NoPortalsFound")));
                }
                else
                {
                    messages.Add(new PromptMessage(string.Format(LocalizeString("PortalsFound"), portals.Count)));
                }

                foreach (PortalInfo portal in portals)
                {
                    messages.Add(new PromptMessage(string.Format(LocalizeString("ClearingImages"), portal.PortalName)));

                    var folderPath = string.Format("\\Portals\\{0}\\Hotcakes\\Data\\temp\\", portal.PortalID);
                    var fullPath   = System.Web.Hosting.HostingEnvironment.MapPath(folderPath);

                    var tempFolder = new System.IO.DirectoryInfo(fullPath);

                    if (tempFolder != null && tempFolder.Exists)
                    {
                        // delete everything inside of the folder, but leave the folder in place
                        tempFolder.Empty();
                    }
                }

                // clearing DNN CRM cache
                ClientResourceManager.ClearCache();
                messages.Add(new PromptMessage(LocalizeString("ClearedCrmCache")));

                // clearing cache in each portal
                foreach (PortalInfo portal in portals)
                {
                    DataCache.ClearPortalCache(portal.PortalID, true);
                    messages.Add(new PromptMessage(string.Format(LocalizeString("ClearedPortalCache"), portal.PortalName)));
                }

                // clear DNN cache
                DataCache.ClearCache();
                DotNetNuke.Web.Client.ClientResourceManagement.ClientResourceManager.ClearCache();
                messages.Add(new PromptMessage(LocalizeString("ClearedDnnCache")));

                // clear HCC cache here
                CacheManager.ClearAll();
                messages.Add(new PromptMessage(LocalizeString("ClearedHccCache")));

                return(new ConsoleResultModel
                {
                    Data = messages,
                    Output = string.Concat(Constants.OutputPrefix, string.Format(LocalizeString("ClearedCache")))
                });
            }
            catch (Exception e)
            {
                LogError(e);
                return(new ConsoleErrorResultModel(string.Concat(Constants.OutputPrefix, LocalizeString("ErrorOccurred"))));
            }
        }