File size: 4,977 Bytes
e26fba6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Data.SQLite;
using System.Configuration;
using MovieFinder.Web.Data;
namespace MovieFinder.Web
{
public class DataService
{
private static string InstallFile;
private static string DownloadFile;
private static string ShowAdsFile;
static DataService ()
{
try
{
DownloadFile = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), "download.txt");
InstallFile = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), "install.txt");
ShowAdsFile = Path.Combine(HttpContext.Current.Server.MapPath("~/App_Data"), "showads.txt");
}
catch { }
}
public static void LogInstall(string message, string computername, string os, string uid)
{
lock (InstallFile)
{
try
{
if (!String.IsNullOrWhiteSpace(message) ||
!String.IsNullOrWhiteSpace(computername) ||
!String.IsNullOrWhiteSpace(os))
{
System.IO.File.AppendAllText(InstallFile,
String.Format("Machine:{0},UID:{1},OS:{2},Details:{3},Date:{4}{5}",
computername, uid, os, message, DateTime.Now.ToString(), Environment.NewLine));
}
}
catch { }
}
}
public static void LogDownload(string ip)
{
lock (DownloadFile)
{
File.AppendAllText(DownloadFile, String.Format("IP: {0}, Time: {1}{2}",
ip, DateTime.Now.ToString(),
Environment.NewLine));
}
}
public static void RemoveLink(Guid uid, string link)
{
try
{
using (var db = new MovieFinderEntities())
{
var r = db.AccessLogs.FirstOrDefault(x => x.UniqueID == uid );
if (r == null)
return;
var ml = db.MovieLinks.FirstOrDefault(x => x.DowloadUrl == link && x.FailedAttempts <= 3);
if (ml != null)
{
if (MovieTube.Client.Scraper.VideoScraperBase.ValidateUrl(ml.DowloadUrl) == MovieTube.Client.Scraper.ScraperResult.VideoDoesNotExist)
{
ml.FailedAttempts = 5;
ml.LastValidatedBy = uid;
db.SaveChanges();
}
}
}
}
catch { }
}
public static void LogShowAd(Guid uid, string ipAddress, string countryCode, DateTime clientTime, string pcName, string version)
{
try
{
using(var db = new MovieFinderEntities())
{
var r = db.AccessLogs.FirstOrDefault(x => x.UniqueID == uid);
if (r != null)
r.IPAddress = ipAddress;
else
{
r = new AccessLog
{
IPAddress = ipAddress,
UniqueID = uid
};
db.AccessLogs.AddObject(r);
}
r.PCName = pcName;
r.ClientTime = clientTime;
r.Timestamp = DateTime.Now;
r.CountryCode = countryCode;
r.Version = version;
r.AccessCount++;
db.SaveChanges();
}
}
catch { }
}
public static void LogAd()
{
}
public static int MovieDBVersion
{
get
{
var path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["MovieDBRaw"]);
using (var connection = new SQLiteConnection(String.Format("Data Source={0};Version=3;", path)))
{
connection.Open();
using (var cmd = new SQLiteCommand(connection))
{
cmd.CommandText = "SELECT * FROM Settings LIMIT 1";
using (var reader = cmd.ExecuteReader())
{
reader.Read();
return (int)reader["Version"];
}
}
}
}
}
}
} |