Пример #1
0
        public ISynoCSVReportPair GetReport(DateTime ts, SynoReportType first, SynoReportType second)
        {
            ISynoCSVReportPair result = null;

            DownloadUpdate?.Invoke(this, new SynoReportCacheDownloadEventArgs(CacheStatus.Processing));
            if (_allreports.ContainsKey(ts))
            {
                if (_allreports[ts].ContainsKey(first) && _allreports[ts].ContainsKey(second))
                {
                    switch ((1 + (int)first) * (1 + (int)second))
                    {
                    case ((1 + (int)SynoReportType.ShareList) * (1 + (int)SynoReportType.VolumeUsage)):
                    {
                        result = new SynoReportVolumePieData(GetReport(ts, first), GetReport(ts, second));
                    }
                    break;

                    default:
                        break;
                    }
                }
            }
            DownloadUpdate?.Invoke(this, new SynoReportCacheDownloadEventArgs(CacheStatus.Idle));
            return(result);
        }
Пример #2
0
        public async void CBDownloadMadeProgress(object sender, AppCastItem item, ItemDownloadProgressEventArgs e)
        {
            await Task.Run(() => {
                if (LastProgressPercentage != e.ProgressPercentage)
                {
                    LastProgressPercentage = e.ProgressPercentage;

                    string DownloadLog = string.Format($"The download made some progress! {e.ProgressPercentage}% done.");
                    SparkleInst.LogWriter.PrintMessage(DownloadLog);

                    if (IsCancelRequested == false)
                    {
                        string DownloadInfo = string.Format($"{item.AppName} {item.Version}<br>The download made some progress! {e.ProgressPercentage}% done.");
                        DownloadUpdate?.UpdateProgress(DownloadInfo, e.ProgressPercentage);
                    }
                    else
                    {
                        if (IsCanceled == false)
                        {
                            IsCanceled = true;
                            Task.Delay(100);
                            DownloadUpdate?.ClosePopUp();
                        }
                    }
                }
            });
        }
Пример #3
0
 public void ScanCachedReports()
 {
     DownloadUpdate?.Invoke(this, new SynoReportCacheDownloadEventArgs(CacheStatus.Processing));
     foreach (FileInfo local in new DirectoryInfo(Path).GetFiles())
     {
         CSVToCategory(local);
     }
     DownloadUpdate?.Invoke(this, new SynoReportCacheDownloadEventArgs(CacheStatus.Idle));
 }
Пример #4
0
        public async void CBStartedDownloading(AppCastItem item, string path)
        {
            await Task.Run(() => {
                IsCancelRequested   = false;
                IsCanceled          = false;
                string DownloadLog  = string.Format($"{item.AppName} {item.Version} Started downloading... : [{path}]");
                string DownloadInfo = string.Format($"{item.AppName} {item.Version}<br>Started downloading...");

                SparkleInst.LogWriter.PrintMessage(DownloadLog);
                DownloadUpdate?.OpenPopUp(DownloadInfo);
            });
        }
Пример #5
0
 public async void CBDownloadError(AppCastItem item, string path, Exception exception)
 {
     // Display in progress when error occured -> DownloadInfo.Text = "We had an error during the download process :( -- " + exception.Message;
     await Task.Run(() => {
         string DownloadLog = string.Format($"{item.AppName} {item.Version}, We had an error during the download process :( -- {exception.Message}");
         CLog.Here().Error(DownloadLog);
         DownloadUpdate?.ClosePopUp();
         File.Delete(path);
         IsCancelRequested = false;
         IsCanceled        = false;
     });
 }
Пример #6
0
        public async void CBDownloadCanceled(AppCastItem item, string path)
        {
            await Task.Run(() => {
                CLog.Here().Information($"AppUpdaterService - CBDownloadCanceled : [ {item.AppName} {item.Version} Cancel downloading! : [{path}] ]");

                if (IsCanceled == false)
                {
                    IsCancelRequested = false;
                    IsCanceled        = true;
                    DownloadUpdate?.ClosePopUp();
                }
            });
        }
Пример #7
0
        public ISynoCSVReport GetReport(ICachedReportFile file)
        {
            DownloadUpdate?.Invoke(this, new SynoReportCacheDownloadEventArgs(CacheStatus.Processing));
            ISynoCSVReport report = null;

            switch (file.Type)
            {
            case SynoReportType.DuplicateCandidates:
                report = SynoCSVReader <SynoReportDuplicateCandidates> .LoadReport(file.LocalFile);

                break;

            case SynoReportType.VolumeUsage:
                report = SynoCSVReader <SynoReportVolumeUsageValues> .LoadReport(file.LocalFile);

                break;

            case SynoReportType.ShareList:
                report = SynoCSVReader <SynoReportSharesValues> .LoadReport(file.LocalFile);

                break;

            case SynoReportType.LargeFiles:
            case SynoReportType.LeastModified:
            case SynoReportType.MostModified:
                report = SynoCSVReader <SynoReportFileDetails> .LoadReport(file.LocalFile);

                break;

            case SynoReportType.FileGroup:
                report = SynoCSVReader <SynoReportGroups> .LoadReport(file.LocalFile);

                break;

            case SynoReportType.FileOwner:
                report = SynoCSVReader <SynoReportOwners> .LoadReport(file.LocalFile);

                break;

            default:
            {
                report = SynoCSVReader <SynoReportContents> .LoadReport(file.LocalFile);

                break;
            }
            }
            DownloadUpdate?.Invoke(this, new SynoReportCacheDownloadEventArgs(CacheStatus.Idle));
            return(report);
        }
Пример #8
0
        public ISynoCSVReport GetReport(DateTime ts, SynoReportType type)
        {
            ISynoCSVReport result = null;

            DownloadUpdate?.Invoke(this, new SynoReportCacheDownloadEventArgs(CacheStatus.Processing));
            if (_allreports.ContainsKey(ts))
            {
                if (_allreports[ts].ContainsKey(type))
                {
                    result = GetReport(_allreports[ts][type]);
                }
            }
            DownloadUpdate?.Invoke(this, new SynoReportCacheDownloadEventArgs(CacheStatus.Idle));
            return(result);
        }
Пример #9
0
        public async void CBFinishedDownloading(AppCastItem item, string path)
        {
            await Task.Run(() => {
                if (IsCancelRequested == false)
                {
                    string DownloadLog  = string.Format($"{item.AppName} {item.Version} Done downloading! : [{path}]");
                    string DownloadInfo = string.Format($"{item.AppName} {item.Version}<br>Done downloading!");

                    SparkleInst.LogWriter.PrintMessage(DownloadLog);
                    DownloadUpdate?.UpdateProgress(DownloadInfo, 100);
                    Task.Delay(1000);

                    DownloadUpdate?.ClosePopUp();
                    DownloadPath = path;

                    string FinishedDownloadInfo = string.Format($"{item.AppName} {item.Version}");
                    FinishedDownload?.OpenPopUp(FinishedDownloadInfo);
                }
                else
                {
                    string DownloadLog = string.Format($"{item.AppName} {item.Version} Force Cancel downloading! : [{path}]");
                    SparkleInst.LogWriter.PrintMessage(DownloadLog);

                    string DownloadInfo = string.Format($"{item.AppName} {item.Version}<br>Cancel downloading!");
                    DownloadUpdate?.UpdateProgress(DownloadInfo, 100);
                    Task.Delay(1000);

                    if (IsCanceled == false)
                    {
                        IsCancelRequested = false;
                        IsCanceled        = true;
                        DownloadUpdate?.ClosePopUp();
                        File.Delete(path);
                    }
                }
            });
        }
Пример #10
0
        public ClientModule()
        {
            Get[PATH_CLIENT + "/getPOApplicationStatus"] = parameter =>
            {
                try
                {
                    Process[]     processes        = Process.GetProcesses();
                    List <string> processImageName = new List <string>();
                    try
                    {
                        foreach (Process p in processes)
                        {
                            if (!String.IsNullOrEmpty(p.MainWindowTitle))
                            {
                                processImageName.Add(p.MainModule.ModuleName);
                            }
                        }
                    }
                    catch { }

                    var isRunning = processImageName.Select(x => string.Compare(x, ProjectName) == 0 ||
                                                            string.Compare(x, ProjectName64) == 0).FirstOrDefault();

                    var message = "Applikasi Tidak Ditemukan";
                    if (isRunning)
                    {
                        message = "Aplikasi sedang running";
                    }
                    return(Response.AsJson(new { IsRunning = isRunning, message = message }));
                }
                catch (Exception ex)
                {
                    return(Response.AsJson(new { IsRunning = false, message = ex.Message }, HttpStatusCode.ExpectationFailed));
                }
            };

            //overwrite local file with file from server
            Post[PATH_CLIENT + "/overwriteXmlSetting"] = parameter =>
            {
                var message = string.Empty;
                try
                {
                    log.Info("Mulai : /client/overwriteXmlSetting");
                    log.Info($"Request dari IP:{this.Request.UserHostAddress}");
                    var body = Nancy.IO.RequestStream.FromStream(Request.Body).AsString();
                    log.Info("Memparsing isi dari request API ");
                    RequestOverwriteXmlSetting setting = JsonConvert.DeserializeObject <RequestOverwriteXmlSetting>(body);
                    log.Info("Parsing sukses");

                    log.Info($"Mencari file {setting.file_name} di direktori :  { AssemblyDirectory }");
                    System.IO.DirectoryInfo dir  = new System.IO.DirectoryInfo(AssemblyDirectory);
                    System.IO.FileInfo      info = new System.IO.FileInfo(setting.file_name);
                    if (info.Exists)
                    {
                        log.Info($"file {setting.file_name} ditemukan");
                        //overwrite existing xml with content
                        //StreamReader reader = new StreamReader(info.FullName,false);
                        using (StreamWriter writer = new StreamWriter(info.Name, true))
                        {
                            {
                                writer.Write(setting.file_content);
                            }
                            writer.Close();
                        }

                        message = $"Sukses mengganti content xml file {setting.file_name}";
                        log.Info("End : /client/overwriteXmlSetting");
                        return(Response.AsJson(new { message = message }));
                    }
                    else
                    {
                        log.Info($"Setting xml {setting.file_name} tidak ditemukan");
                        message = $"File Setting {setting.file_name} Tidak Ditemukan pada Client";
                        log.Info("End : /client/overwriteXmlSetting");
                        return(Response.AsJson(new { message = message }, HttpStatusCode.NotFound));
                    }
                }
                catch (System.Exception ex)
                {
                    log.Fatal("Error : /client/overwriteXmlSetting", ex);
                    message = $"Error, {ex.Message}";
                    return(Response.AsJson(new { message = message }, HttpStatusCode.ExpectationFailed));
                }
            };

            Post[PATH_CLIENT + "/downloadFile"] = parameter =>
            {
                log.Info("Start : /client/downloadUpdateFile");
                log.Info($"incoming request from IP:{this.Request.UserHostAddress}");
                var body = Nancy.IO.RequestStream.FromStream(Request.Body).AsString();
                log.Info("Deserialize object from json body");
                DownloadUpdate setting = JsonConvert.DeserializeObject <DownloadUpdate>(body);

                string[] files  = Directory.GetFiles(AssemblyDirectory);
                var      result = string.Empty;
                foreach (string item in files)
                {
                    FileInfo localFile = new FileInfo(item);
                    if (string.Compare(localFile.Name, setting.fileName) == 0)
                    {
                        result = item;
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(result))
                {
                    FileInfo info = new FileInfo(result);
                    if (info.Exists)
                    {
                        var file = new System.IO.FileStream(info.FullName, System.IO.FileMode.Open);

                        var response = new Nancy.Responses.StreamResponse(() => file, MimeTypes.GetMimeType(setting.fileName));
                        return(response.AsAttachment(setting.fileName));
                    }
                    else
                    {
                        return(Response.AsJson(new { message = "File Tidak Ditemukan" }, HttpStatusCode.NoContent));
                    }
                }
                else
                {
                    return(Response.AsJson(new { message = "File Tidak Ditemukan" }, HttpStatusCode.NoContent));
                }
            };

            Post[PATH_CLIENT + "/restartSender"] = parameter =>
            {
                log.Info("Start : /client/restartSender");
                log.Info($"incoming request from IP:{this.Request.UserHostAddress} @{DateTime.Now}");
                var body = Nancy.IO.RequestStream.FromStream(Request.Body).AsString();
                log.Info("Deserialize object from json body");
                RestartRequest request = JsonConvert.DeserializeObject <RestartRequest>(body);

                try
                {
                    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                    startInfo.CreateNoWindow = false;
                    startInfo.FileName       = request.ApplicationName;
                    foreach (var process in System.Diagnostics.Process.GetProcessesByName(request.ApplicationName))
                    {
                        process.Kill();
                        break;
                    }

                    System.Diagnostics.Process.Start(startInfo);

                    return(Response.AsJson(new { message = "Aplikasi Sukses Di Restart" }, HttpStatusCode.NoContent));
                }
                catch
                {
                    return(Response.AsJson(new { message = "Aplikasi Gagal DiRestart" }, HttpStatusCode.NoContent));
                }
            };
        }
Пример #11
0
        public UpdateModule(IUpdateVersionBusiness updateVersionBusiness)
        {
            _updateVersionBusiness = updateVersionBusiness;

            //Get["download/update2"] = pars => Response.AsFile("devModule.rar", "application/x-rar-compressed, application/octet-stream");

            Get[GET_LATEST_VERSION] = parameter =>
            {
                log.Debug("Start:/download/getLatestVersion");
                List <UpdateVersion> latestVers = new List <UpdateVersion>();
                string version = string.Empty;
                try
                {
                    latestVers = _updateVersionBusiness.GetVersion();
                    version    = string.IsNullOrEmpty(latestVers.FirstOrDefault()?.version) ? "-" : latestVers.FirstOrDefault().version;
                    log.Debug(string.Format("Get Version Success (v.{0})", version));
                }
                catch (Exception ex)
                {
                    //log.Debug( "Get User Failed : " + ex.Message );
                    log.Fatal("Error:/setting/getLatestVersion", ex);
                    return(Response.AsJson(new { code = HttpStatusCode.InternalServerError, message = $"Error, {ex.Message}" }));
                }

                var pathDir = latestVers.FirstOrDefault() == null ? "-" : latestVers.First().path_directory;
                return(Response.AsJson(new { code = HttpStatusCode.OK, message = "Ok", Version = version, PathDir = pathDir }));
            };

            Post[UPDATE] = parameter =>
            {
                log.Info("Start : /download/update");
                log.Info($"incoming request from IP:{this.Request.UserHostAddress}");
                var body = Nancy.IO.RequestStream.FromStream(Request.Body).AsString();
                log.Info("Deserialize object from json body");
                DownloadUpdate setting = JsonConvert.DeserializeObject <DownloadUpdate>(body);

                string[] files  = Directory.GetFiles(AssemblyDirectory);
                var      result = string.Empty;
                foreach (string item in files)
                {
                    FileInfo localFile = new FileInfo(item);
                    if (string.Compare(localFile.Name, setting.fileName) == 0)
                    {
                        result = item;
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(result))
                {
                    FileInfo info = new FileInfo(setting.fileName);
                    if (info.Exists)
                    {
                        var    file     = new FileStream(setting.fileName, FileMode.Open);
                        string fileName = info.Name;//set a filename

                        var response = new StreamResponse(() => file, MimeTypes.GetMimeType(fileName));
                        return(response.AsAttachment(fileName));
                    }
                    else
                    {
                        return(Response.AsJson(new { message = "File Update Tidak Ditemukan" }, HttpStatusCode.NoContent));
                    }
                }
                else
                {
                    return(Response.AsJson(new { message = "File Update Tidak Ditemukan" }, HttpStatusCode.NoContent));
                }
            };
        }
Пример #12
0
 protected void OnDownloadUpdate(object sender, SynoReportCacheDownloadEventArgs e)
 {
     DownloadUpdate?.Invoke(sender, e);
 }