Exemplo n.º 1
0
        private void CompareUserListInsert(DownloadShowList downloadShowList)
        {
            //Insert Show in UserList
            ShowList showList = UserDataMgr.GetThe().ShowList;

            bool bRentedShowIDFound_Flag = false;
            bool bNewShowInserted        = false;

            if (downloadShowList != null)
            {
                foreach (DownloadShow downloadShow in downloadShowList)
                {
                    bRentedShowIDFound_Flag = false;
                    bRentedShowIDFound_Flag = showList.ContainsByRentedShowID(downloadShow.RentedShowID);
                    if (!bRentedShowIDFound_Flag)
                    {
                        //Insert Show In User List
                        Logger.LogInfo(this, "CompareUserListInsert", "Insert Show In User List");
                        AddDownloadShowToList(showList, downloadShow);
                        bNewShowInserted = true;
                    }
                }

                //Write User Xml if any show is inserted
                if (bNewShowInserted)
                {
                    // Write user XML
                    UserDataMgr.GetThe().SaveShowList(showList);
                    //Session.GetThe().WriteUserDataToXML(userData);
                }
            }
        }
Exemplo n.º 2
0
 public DownloadServiceMgr()
 {
     fConfigDataMgr = ConfigDataMgr.Initialize();
     fUserDataMgr   = UserDataMgr.Initialize(fConfigDataMgr.GetConfig()
                                             .General.LoopIntervalSecs.Value);
     Logger.Initialize(fUserDataMgr.EnableLog.Value);
 }
Exemplo n.º 3
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
         Init();
     }
 }
Exemplo n.º 4
0
        public static bool CheckFileExistOnHDD(string fileName)
        {
            FileInfo fInfo = new FileInfo(Path.Combine(UserDataMgr.GetThe().LocalShowPath.ToString(), fileName));

            if (fInfo.Exists)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        private bool DownloadFile(String sDownloadURL, String sFileName)
        {
            HttpWebRequest  request   = null;
            HttpWebResponse resp      = null;
            Stream          rcvStream = null;
            FileStream      fs        = null;
            long            fileSize  = 0;

            try
            {
                request  = (HttpWebRequest)WebRequest.Create(sDownloadURL);
                resp     = (HttpWebResponse)request.GetResponse();
                fileSize = (resp.ContentLength / 1024) / 1024;

                //Check for Free space on Disk
                string localShowPath = UserDataMgr.GetThe().LocalShowPath.ToString();

                if (fileSize + DriveInfo.DirectorySize(localShowPath) <= DriveInfo.FreeSpceOnDisk(localShowPath))
                {
                    long maxSizeForShows = UserDataMgr.GetThe().MaxSizeForShows.Value * 1024;
                    //Chcek for Max size allocated for shows
                    if (fileSize + DriveInfo.DirectorySize(localShowPath) <= maxSizeForShows)
                    {
                        rcvStream = resp.GetResponseStream();
                        StreamUtil.StreamToFile(rcvStream, sFileName);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Logger.LogError(this, "DownloadFile", e);
                return(false);
            }
            finally
            {
                if (resp != null)
                {
                    resp.Close();
                }
                if (rcvStream != null)
                {
                    rcvStream.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Exemplo n.º 6
0
 private void CreateDataFiles()
 {
     try
     {
         ConfigDataMgr.CreateNew();
         UserDataMgr.CreateNew();
     }
     catch (Exception e)
     {
         String msg = String.Format("A failure occurred while creating the Storm data files, Message: {0}.",
                                    e.Message);
         MessageBox.Show(msg);
     }
 }
Exemplo n.º 7
0
        public static FileInfo ReturnFileInfo(string fileName)
        {
            //Check File Exist On HDD Return FileInfo
            FileInfo fInfo = new FileInfo(Path.Combine(UserDataMgr.GetThe().LocalShowPath.ToString(), fileName));

            if (fInfo.Exists)
            {
                return(fInfo);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 8
0
        private void CompareUserListHDDDelete()
        {
            ShowList showList    = UserDataMgr.GetThe().ShowList;
            ShowList newShowList = new ShowList();

            bool fileExistFlag  = false;
            bool showDeleteFlag = false;

            foreach (Show show in showList)
            {
                if (DownloadStatus.Completed.Equals(show.DownloadStatus))
                {
                    try
                    {
                        fileExistFlag = DriveInfo.CheckFileExistOnHDD(show.DataFileName.ToString());
                    }
                    catch (Exception e)
                    {
                        Logger.LogError(this, "CompareUserListHDDDelete", e);
                    }

                    if (!fileExistFlag)
                    {
                        //Delete File from the user list and download list
                        Logger.LogInfo(this, "CompareUserListHDDDelete", "Delete File from the userlist and downloadlist");
                        Session.GetThe().ReleaseShow(show.RentedShowID);
                        showDeleteFlag = true;
                    }
                    else
                    {
                        newShowList.Add(show);
                    }
                }
                else
                {
                    newShowList.Add(show);
                }
            }

            //if any show is deleted from showlist then Write new User.XML
            if (showDeleteFlag)
            {
                UserDataMgr.GetThe().SaveShowList(newShowList);
            }
        }
Exemplo n.º 9
0
        private void RunOnce()
        {
            try
            {
                // get the Session
                Session session = Session.GetThe();

                // get the user data manager
                UserDataMgr userDataMgr = UserDataMgr.GetThe();

                // fetch next processing time
                long nextProcessTimeTicks = userDataMgr.GetNextProcessTick();
                if (DateTime.Now.Ticks >= nextProcessTimeTicks)
                {
                    Logger.LogInfo(this, "RunOnce", "Processing");

                    if (session.HaveUserCredentials && (!session.IsUserLoggedOn || session.HasSessionExpired))
                    {
                        if (session.PingServer())
                        {
                            session.Signon();
                        }
                    }

                    if (session.IsUserLoggedOn)
                    {
                        DownloadShowList downloadShowList = session.DownloadShowList();
                        if ((downloadShowList != null) &&
                            (new UpdateUserDataShowList()).DoUpdate(downloadShowList))
                        {
                            return;                             // progess again immediately
                        }
                    }

                    // increment next processing time in UserData
                    userDataMgr.IncNextProcessTick(nextProcessTimeTicks);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(this, "RunOnce", e.StackTrace);
            }
        }
Exemplo n.º 10
0
        public void LoadFromConfig()
        {
            /************************************************************************/
            ConfigDataMgr configDataMgr = ConfigDataMgr.Initialize();
            Config        config        = configDataMgr.GetConfig();

            fNetworkURL = config.General.ServiceURL;
            fPlayer     = config.Player;

            DataRequestor.Initialize(fNetworkURL);
            /************************************************************************/

            /************************************************************************/
            UserDataMgr userDataMgr = UserDataMgr.Initialize(config.General.LoopIntervalSecs.Value);

            fUserID       = userDataMgr.UserLogonID;
            fUserPassword = userDataMgr.UserPIN;
            /************************************************************************/

            Logger.Initialize(userDataMgr.EnableLog.Value);
        }
Exemplo n.º 11
0
        private bool CompareUserListDownload()
        {
            ShowList showList = UserDataMgr.GetThe().ShowList;
            String   filePath = UserDataMgr.GetThe().LocalShowPath.ToString();

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

            foreach (Show show in showList)
            {
                if (DownloadStatus.NotStarted.Equals(show.DownloadStatus) ||
                    DownloadStatus.InProgress.Equals(show.DownloadStatus))
                {
                    //Download File
                    Logger.LogInfo(this, "CompareUserListDownload", "DownloadFile");

                    // Mark show as started download
                    show.DownloadStatus = DownloadStatus.InProgress;
                    UserDataMgr.GetThe().SaveShowList(showList);

                    String fullFileName = Path.Combine(filePath, show.DataFileName.ToString());
                    if (DownloadFile(show.ShowURL.ToString(), fullFileName))
                    {
                        //Update Show status
                        show.DownloadStatus = DownloadStatus.Completed;
                    }
                    else
                    {
                        show.DownloadStatus = DownloadStatus.NotStarted;
                    }

                    UserDataMgr.GetThe().SaveShowList(showList);
                    return(true); // only process one show at a time
                }
            }                     //End foreach(Show show in showList)

            return(false);
        }
Exemplo n.º 12
0
        private void CompareUserListDelete(DownloadShowList downloadShowList)
        {
            //Delete Show From UserList
            ShowList showList    = UserDataMgr.GetThe().ShowList;
            ShowList newShowList = new ShowList();

            bool bRentedShowIDFound_Flag = false;
            bool bShowDeleted            = false;

            foreach (Show show in showList)
            {
                bRentedShowIDFound_Flag = downloadShowList.ContainsByRentedShowID(show.RentedShowID);
                if (!bRentedShowIDFound_Flag)
                {
                    //Delete Show From User List
                    Logger.LogInfo(this, "CompareUserListDelete", "Delete Show From User List and HDD");
                    try
                    {
                        DriveInfo.DeleteShowFromHDD(show.DataFileName.ToString());
                        bShowDeleted = true;
                    }
                    catch (Exception e)
                    {
                        Logger.LogError(this, "CompareUserListDelete", e);
                    }
                }
                else
                {
                    newShowList.Add(show);
                }
            }

            // Write user XML if any show is deleted
            if (bShowDeleted)
            {
                UserDataMgr.GetThe().SaveShowList(newShowList);
            }
        }