public void Post(IEnumerable <ISite> sites)
        {
            List <SiteBinding> siteBindings = new List <SiteBinding>();

            foreach (ISite site in sites)
            {
                if (site.AppType != "Root")
                {
                    continue;
                }

                IEnumerable <SiteBinding> bindings = site.Bindings();
                string xConsoleString = string.Join(",", bindings.Select(x => $"SiteId:{x.SiteId} Host:{x.Host} Port:{x.Port} SSL:{x.IsSSLBound}"));
                XConsole.WriteLine(xConsoleString);
                siteBindings.AddRange(bindings);
            }

            if (siteBindings.Count > 0)
            {
                PackageManager packageManager = PackageManager.GetManager();
                IEnumerable    packs          = packageManager.GetPacks(siteBindings);
                foreach (IEnumerable <SiteBinding> pack in packs)
                {
                    WebTransfer.PostSiteBinding(pack);
                }
            }
        }
        public void Post(IEnumerable <ISite> sites)
        {
            List <SiteEndpoint> siteEndpoints = new List <SiteEndpoint>();

            foreach (ISite site in sites)
            {
                if (site.AppType != "Root")
                {
                    continue;
                }

                IEnumerable <SiteEndpoint> endpoints = site.GetRawEndpoints();

                if (endpoints != null)
                {
                    siteEndpoints.AddRange(endpoints);
                }
            }
            if (siteEndpoints.Count > 0)
            {
                PackageManager packageManager = PackageManager.GetManager();
                IEnumerable    packs          = packageManager.GetPacks(siteEndpoints);
                foreach (IEnumerable <SiteEndpoint> pack in packs)
                {
                    WebTransfer.PostSiteEndpoint(pack);
                }
            }
        }
Esempio n. 3
0
        public void Post(IEnumerable <ISite> sites)
        {
            List <SiteConnectionString> siteConnectionStrings = new List <SiteConnectionString>();

            foreach (ISite site in sites)
            {
                if (site.AppType != "Root")
                {
                    continue;
                }

                ISiteWebConfiguration webconfig = site.GetConfiguration();
                if (webconfig == null)
                {
                    continue;
                }

                IEnumerable <SiteConnectionString> connectionStrings = site.GetRawConnectionStrings();

                if (connectionStrings != null)
                {
                    siteConnectionStrings.AddRange(connectionStrings);
                }
            }

            if (siteConnectionStrings.Count > 0)
            {
                PackageManager packageManager = PackageManager.GetManager();
                IEnumerable    packs          = packageManager.GetPacks(siteConnectionStrings);
                foreach (IEnumerable <SiteConnectionString> pack in packs)
                {
                    WebTransfer.PostSiteConnectionString(pack);
                }
            }
        }
        public void Post(IEnumerable <ISite> sites)
        {
            List <SiteWebConfiguration> siteWebConfigurations = new List <SiteWebConfiguration>();

            foreach (ISite site in sites)
            {
                if (site.AppType != "Root")
                {
                    continue;
                }
                IEnumerable <SiteWebConfiguration> webConfiguration = Get(site);
                if (webConfiguration != null)
                {
                    siteWebConfigurations.AddRange(webConfiguration);
                }
            }

            if (siteWebConfigurations.Count > 0)
            {
                PackageManager packageManager = PackageManager.GetManager();
                IEnumerable    packs          = packageManager.GetPacks(siteWebConfigurations);
                foreach (IEnumerable <SiteWebConfiguration> pack in packs)
                {
                    WebTransfer.PostSiteWebConfiguration(pack);
                }
            }
        }
        public void Post(ISite site)
        {
            IEnumerable <SitePackage> packages = site.Packages();

            if (packages != null)
            {
                WebTransfer.PostSitePackage(packages);
            }
        }
        public void Post(ISite site)
        {
            IEnumerable <SiteWebConfiguration> webConfiguration = Get(site);

            if (webConfiguration != null)
            {
                WebTransfer.PostSiteWebConfiguration(webConfiguration);
            }
        }
        public static void SendAlert(ISiteConnectionString connectionString)
        {
            ISite site = connectionString.Site;

            if (site == null)
            {
                return;
            }
            bool isSiteAvailable = connectionString.Site.State.Swap() == AppServices.IIS.Models.SiteState.Started;

            string statusFormatted     = connectionString.ServerName + "," + connectionString.Port + "&" + connectionString.DatabaseName;
            string appVersionFormatted = $"Bulid {FileOperations.AssemblyVersion}";

            string availabilityFormatted;
            string isAvailableFormatted;
            string leftImageContent;
            string titleColorContent;

            if (isSiteAvailable)
            {
                availabilityFormatted = "WARNING! site is running but the dependency service not resolved.";
                isAvailableFormatted  = "Yes";
                leftImageContent      = MailService.BASE64_WARNING;
                titleColorContent     = MailService.TITLE_COLOR_YELLOW;
            }
            else
            {
                availabilityFormatted = "CRITICAL CASE! site is not accessible and the dependency service not resolved.";
                isAvailableFormatted  = "No";
                leftImageContent      = MailService.BASE64_CRITICAL_CASE;
                titleColorContent     = MailService.TITLE_COLOR_RED;
            }

            MailMessage mailMessage = new MailMessage
            {
                MailTitle         = "ConnectionString Availability test failed!",
                MailSubTitle      = statusFormatted,
                MailStatus1       = "DATABASE Connection Check FAILED!",
                MailStatus2       = availabilityFormatted,
                MailMachineName   = site.MachineName,
                MailSiteUrl       = site.Name,
                MailSiteName      = site.Name,
                MailSiteAvailable = isAvailableFormatted,
                MailCheckTime     = connectionString.LastCheckTime.ToString(),
                MailAppVersion    = appVersionFormatted,
                MailLeftImage     = leftImageContent,
                MailTitleColor    = titleColorContent
            };

            IISMailQueue mail = new IISMailQueue {
                MailContent = mailMessage.MailContent
            };

            WebTransfer.PostMail(mail);
        }
Esempio n. 8
0
 internal static (Version, string) FindArchivePath(string jsonArchivePath)
 {
     try
     {
         var searchData = Json.Deserialize <Dictionary <string, string> >(jsonArchivePath);
         if (searchData == default || !searchData.ContainsKey("regex") || !searchData.ContainsKey("source"))
         {
             throw new ArgumentInvalidException(nameof(jsonArchivePath));
         }
         var sourceUrl  = searchData["source"];
         var sourceText = WebTransfer.DownloadString(sourceUrl);
         if (string.IsNullOrWhiteSpace(sourceText))
         {
             if (!searchData.ContainsKey("mirror"))
             {
                 throw new PathNotFoundException(sourceUrl);
             }
             sourceUrl  = searchData["mirror"];
             sourceText = WebTransfer.DownloadString(sourceUrl);
         }
         var foundData = new Dictionary <Version, string>();
         var regex     = new Regex(searchData["regex"], RegexOptions.IgnoreCase);
         foreach (var match in regex.Matches(sourceText).Cast <Match>())
         {
             var versions  = match.Groups["Version"]?.Captures;
             var fileNames = match.Groups["FileName"]?.Captures;
             if (versions == null || fileNames == null || versions.Count != fileNames.Count)
             {
                 continue;
             }
             for (var i = 0; i < versions.Count; i++)
             {
                 var version = new Version(versions[i].Value.Trim());
                 if (foundData.ContainsKey(version))
                 {
                     continue;
                 }
                 var fileName = fileNames[i].Value.Trim();
                 foundData.Add(version, fileName);
             }
         }
         foundData = foundData.OrderByDescending(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
         var(lastVersion, lastArchivePath) = foundData.Select(x => (x.Key, PathEx.AltCombine(sourceUrl, x.Value))).FirstOrDefault();
         if (lastVersion == default || lastArchivePath == default)
         {
             throw new MissingFieldException();
         }
         return(lastVersion, lastArchivePath);
     }
     catch (Exception ex) when(ex.IsCaught())
     {
         Log.Write(ex);
         return(new Version("1.0.0.0"), string.Empty);
     }
 }
Esempio n. 9
0
 private void SetUpdateInfo(bool final, params string[] mirrors)
 {
     if (mirrors?.Any() != true)
     {
         return;
     }
     foreach (var mirror in mirrors)
     {
         try
         {
             var path = PathEx.AltCombine(mirror, "Last.ini");
             if (!NetEx.FileIsAvailable(path, 60000, UserAgents.Internal))
             {
                 throw new PathNotFoundException(path);
             }
             var data = WebTransfer.DownloadString(path, 60000, UserAgents.Internal);
             if (string.IsNullOrWhiteSpace(data))
             {
                 throw new ArgumentNullException(nameof(data));
             }
             var lastStamp = Ini.ReadOnly("Info", "LastStamp", data);
             if (string.IsNullOrWhiteSpace(lastStamp))
             {
                 throw new ArgumentNullException(nameof(lastStamp));
             }
             path = PathEx.AltCombine(mirror, $"{lastStamp}.ini");
             if (!NetEx.FileIsAvailable(path, 60000, UserAgents.Internal))
             {
                 throw new PathNotFoundException(path);
             }
             data = WebTransfer.DownloadString(path, 60000, UserAgents.Internal);
             if (string.IsNullOrWhiteSpace(data))
             {
                 throw new ArgumentNullException(nameof(data));
             }
             HashInfo = data;
             if (final)
             {
                 LastFinalStamp = lastStamp;
             }
             else
             {
                 LastStamp = lastStamp;
             }
         }
         catch (Exception ex) when(ex.IsCaught())
         {
             Log.Write(ex);
         }
         if (!string.IsNullOrWhiteSpace(HashInfo))
         {
             break;
         }
     }
 }
        public void Post(ISite site)
        {
            IEnumerable <SiteEndpoint> endpoints = site.GetRawEndpoints();

            if (endpoints == null)
            {
                return;
            }

            WebTransfer.PostSiteEndpoint(endpoints);
        }
        public void PostTrackerValues()
        {
            IEnumerable <Site> sites = WebTransfer.GetSites(Environment.MachineName);

            if (_trackerType == TrackerType.Endpoint)
            {
                WCF.TrackerEngine.TrackEndpoint(sites);
            }
            else if (_trackerType == TrackerType.ConnectionString)
            {
                ConnectionString.TrackerEngine.TrackConnectionString(sites);
            }
        }
Esempio n. 12
0
        public void Post(ISite site)
        {
            ISiteWebConfiguration webconfig = site.GetConfiguration();

            if (webconfig == null)
            {
                return;
            }

            IEnumerable <SiteConnectionString> connectionStrings = site.GetRawConnectionStrings();

            if (connectionStrings == null)
            {
                return;
            }
            WebTransfer.PostSiteConnectionString(connectionStrings);
        }
Esempio n. 13
0
        public void PostSites()
        {
            IEnumerable <Core.Models.Site> resultSet = WebTransfer.PostSite(Sites)?.ToList();

            logManager.Write("Post Method works fine.");

            IEnumerable <Core.Models.Site> query = _sites.Join(resultSet, target => target.IISSiteId, source => source.IISSiteId,
                                                               (source, target) => new Core.Models.Site
            {
                Id = target.Id,
                ApplicationPoolName = source.ApplicationPoolName,
                AppType             = source.AppType,
                DateDeleted         = source.DateDeleted,
                EnabledProtocols    = source.EnabledProtocols,
                IISSiteId           = source.IISSiteId,
                IsAvailable         = source.IsAvailable,
                LastCheckTime       = source.LastCheckTime,
                LastUpdated         = source.LastUpdated,
                LogFileDirectory    = source.LogFileDirectory,
                LogFileEnabled      = source.LogFileEnabled,
                LogFormat           = source.LogFormat,
                LogPeriod           = source.LogPeriod,
                MachineName         = source.MachineName,
                MaxBandwitdh        = source.MaxBandwitdh,
                MaxConnections      = source.MaxConnections,
                Name = source.Name,
                NetFrameworkVersion          = source.NetFrameworkVersion,
                PhysicalPath                 = source.PhysicalPath,
                RawBindings                  = source.RawBindings,
                SendAlertMailWhenUnavailable = source.SendAlertMailWhenUnavailable,
                ServerAutoStart              = source.ServerAutoStart,
                State = source.State,
                TraceFailedRequestsLoggingDirectory = source.TraceFailedRequestsLoggingDirectory,
                TraceFailedRequestsLoggingEnabled   = source.TraceFailedRequestsLoggingEnabled,
                WebConfigBackupDirectory            = source.WebConfigBackupDirectory,
                WebConfigLastBackupDate             = source.WebConfigLastBackupDate
            });

            _sites = query;
        }
Esempio n. 14
0
        private static void UpdateAppImagesFile(bool large)
        {
            var filePath = large ? CachePaths.AppImagesLarge : CachePaths.AppImages;
            var fileName = Path.GetFileName(filePath);

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            var fileDate = File.Exists(filePath) ? File.GetLastWriteTime(filePath) : DateTime.MinValue;

            foreach (var mirror in AppSupply.GetMirrors(AppSuppliers.Internal))
            {
                var link = PathEx.AltCombine(mirror, ".free", fileName);
                if (Log.DebugMode > 0)
                {
                    Log.Write($"Cache: Looking for '{link}'.");
                }
                if (!NetEx.FileIsAvailable(link, 30000, UserAgents.Internal))
                {
                    continue;
                }
                if (!((NetEx.GetFileDate(link, 30000, UserAgents.Internal) - fileDate).TotalSeconds > 0d))
                {
                    break;
                }
                WebTransfer.DownloadFile(link, filePath, 60000, UserAgents.Internal, false);
                if (!File.Exists(filePath))
                {
                    continue;
                }
                File.SetLastWriteTime(filePath, DateTime.Now);
                if (Log.DebugMode > 0)
                {
                    Log.Write($"Cache: '{filePath}' has been updated.");
                }
                break;
            }
        }
Esempio n. 15
0
 private void SetChangeLog(params string[] mirrors)
 {
     if (mirrors?.Any() == true)
     {
         var changes = string.Empty;
         foreach (var mirror in mirrors)
         {
             var path = PathEx.AltCombine(mirror, "ChangeLog.txt");
             if (string.IsNullOrWhiteSpace(path))
             {
                 continue;
             }
             changes = WebTransfer.DownloadString(path, 20000, UserAgents.Internal);
             if (!string.IsNullOrWhiteSpace(changes))
             {
                 break;
             }
         }
         if (SetChangeLogText(changes))
         {
             return;
         }
     }
     else
     {
         try
         {
             var atom = WebTransfer.DownloadString(CorePaths.RepoCommitsUrl, 60000, UserAgents.Default);
             if (string.IsNullOrEmpty(atom))
             {
                 throw new ArgumentNullException(nameof(atom));
             }
             const string nspace   = "{http://www.w3.org/2005/Atom}";
             var          document = XDocument.Parse(atom);
             var          changes  = new Dictionary <string, List <string> >();
             foreach (var entry in document.Descendants($"{nspace}feed").Descendants($"{nspace}entry"))
             {
                 var time    = DateTime.Parse(entry.Descendants($"{nspace}updated").Single().Value, CultureInfo.InvariantCulture);
                 var timeStr = time.ToString("dd MMMM yyyy", CultureInfo.CreateSpecificCulture("en-US"));
                 if (!changes.ContainsKey(timeStr))
                 {
                     changes.Add(timeStr, new List <string>());
                 }
                 var title = entry.Descendants($"{nspace}title").Single().Value.Trim();
                 if (title.ContainsEx("http://", "https://"))
                 {
                     title = title.Replace("https://", "http://");
                     title = title.Substring(0, title.IndexOf("http://", StringComparison.Ordinal)).Trim();
                 }
                 changes[timeStr].Add(title.TrimEnd('.'));
             }
             var builder = new StringBuilder();
             var lastKey = changes.Keys.Last();
             foreach (var key in changes.Keys)
             {
                 var values = changes[key];
                 if (!values.Any())
                 {
                     continue;
                 }
                 builder.AppendFormatLineDefault(" {0}:", key);
                 builder.AppendLine();
                 foreach (var value in values)
                 {
                     builder.AppendFormatLineDefault("  * {0}", value);
                 }
                 builder.AppendLine();
                 if (key != lastKey)
                 {
                     builder.Append('_', 84);
                     builder.AppendLine();
                     builder.AppendLine();
                 }
                 builder.AppendLine();
             }
             if (SetChangeLogText(string.Format(CultureInfo.InvariantCulture, Resources.ChangeLogTemplate, builder)))
             {
                 return;
             }
         }
         catch (Exception ex) when(ex.IsCaught())
         {
             Log.Write(ex);
         }
     }
     changeLog.Dock     = DockStyle.None;
     changeLog.Size     = new Size(changeLogPanel.Width, TextRenderer.MeasureText(changeLog.Text, changeLog.Font).Height);
     changeLog.Location = new Point(0, changeLogPanel.Height / 2 - changeLog.Height - 16);
     changeLog.SelectAll();
     changeLog.SelectionAlignment = HorizontalAlignment.Center;
     changeLog.DeselectAll();
 }
        public static ISiteLogPosition GetLastPosition(ISite site)
        {
            ISiteLogPosition position = WebTransfer.GetLogPosition(site.Id);

            return(position);
        }
Esempio n. 17
0
        internal static void DownloadArchiver()
        {
            var notifyBox = new NotifyBox();

            notifyBox.Show(Language.GetText(nameof(en_US.InitRequirementsNotify)), Resources.GlobalTitle, NotifyBoxStartPosition.Center);
            var mirrors = NetEx.InternalDownloadMirrors;
            var verMap  = new Dictionary <string, string>();

            foreach (var mirror in mirrors)
            {
                try
                {
                    var url = PathEx.AltCombine(mirror, ".redists", "Extra", "Last.ini");
                    if (!NetEx.FileIsAvailable(url, 30000))
                    {
                        throw new PathNotFoundException(url);
                    }
                    var data = WebTransfer.DownloadString(url);
                    if (string.IsNullOrWhiteSpace(data))
                    {
                        throw new ArgumentNullException(nameof(data));
                    }
                    const string name = "7z";
                    if (string.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                    var version = Ini.ReadOnly(name, "Version", data);
                    if (string.IsNullOrWhiteSpace(version))
                    {
                        continue;
                    }
                    verMap.Add(name, version);
                }
                catch (Exception ex) when(ex.IsCaught())
                {
                    Log.Write(ex);
                }
                if (verMap.Count > 0)
                {
                    break;
                }
            }
            foreach (var map in verMap)
            {
                var file = $"{map.Value}.zip";
                var path = PathEx.Combine(CachePaths.UpdateDir, file);
                foreach (var mirror in mirrors)
                {
                    try
                    {
                        var url = PathEx.AltCombine(mirror, ".redists", "Extra", map.Key, file);
                        if (!NetEx.FileIsAvailable(url, 30000))
                        {
                            throw new PathNotFoundException(url);
                        }
                        WebTransfer.DownloadFile(url, path);
                        Compaction.Unzip(path, CachePaths.UpdateDir);
                    }
                    catch (Exception ex) when(ex.IsCaught())
                    {
                        Log.Write(ex);
                    }
                    if (File.Exists(path))
                    {
                        break;
                    }
                }
            }
            notifyBox.Close();
        }
Esempio n. 18
0
 public DSMController(string authToken)
 {
     WebTransfer.Authorize(authToken);
 }
Esempio n. 19
0
 public IEnumerable <ISiteConnectionString> Get(ISite site)
 {
     return(WebTransfer.GetSiteConnectionStrings(site.Id));
 }
        public void Post(ISite site)
        {
            IEnumerable <SiteBinding> bindings = site.Bindings();

            WebTransfer.PostSiteBinding(bindings);
        }
 public IEnumerable <ISiteEndpoint> Get(ISite site)
 {
     return(WebTransfer.GetSiteEndpoints(site.Id));
 }
        public static IEnumerable <ISiteConnectionString> TrackConnectionString(IEnumerable <ISite> sites)
        {
            // Create Search Dictionary
            IEnumerable <ISiteConnectionString> dictionaryConnectionStrings = sites.GetSearchDictionary <ISiteConnectionString>(TrackerType.ConnectionString);

            if (dictionaryConnectionStrings == null)
            {
                return(null);
            }

            // Test ConnectionStrings in the Search Dictionary
            dictionaryConnectionStrings = dictionaryConnectionStrings.TestAvaiilabilty();

            IList <SiteConnectionString> retvals = new List <SiteConnectionString>();

            foreach (ISite site in sites) // for each sites..do
            {
                // Create list of deleted connection strings
                List <SiteConnectionString> deletedConnectionstrings = new List <SiteConnectionString>();

                // Get Connectionstrings from database.
                IEnumerable <SiteConnectionString> dbConnectionstrings = site.GetDBConnectionStrings();

                // Get Connectionstrings from live configuration file.
                IEnumerable <SiteConnectionString> currentConnectionstrings = site.GetConnectionStrings();


                // If live connectionstrings is null
                if (dbConnectionstrings.Count() < 1 && currentConnectionstrings == null)
                {
                    continue; // skip this iteration
                }

                deletedConnectionstrings = dbConnectionstrings.ToList();

                foreach (SiteConnectionString currConnectionstring in currentConnectionstrings) //foreach connectionstring
                {
                    // Search dictionary test results for site's current connectionstring
                    ISiteConnectionString siteConnectionString = dictionaryConnectionStrings.FirstOrDefault(dict => dict.RawConnectionString == currConnectionstring.RawConnectionString);

                    deletedConnectionstrings = deletedConnectionstrings.SkipWhile(x => x.ConnectionName == currConnectionstring.ConnectionName &&
                                                                                  x.RawConnectionString == currConnectionstring.RawConnectionString).ToList();

                    if (siteConnectionString == null) // If cannot found any result.
                    {
                        continue;                     // Skip this iteration.
                    }

                    currConnectionstring.LastCheckTime = DateTime.Now;         // Update Checkdate

                    retvals.Add(siteConnectionString as SiteConnectionString); // add this record to return values.

                    // If Connectionstring is not available and  mail status yes
                    if (!currConnectionstring.IsAvailable && currConnectionstring.SendAlertMailWhenUnavailable)
                    {
                        // send mail
                    }
                } // end of loop.

                if (deletedConnectionstrings.Count() > 0)
                {
                    deletedConnectionstrings.ForEach(dbcs => dbcs.DeleteDate = DateTime.Now);
                    WebTransfer.PostSiteConnectionString(retvals);
                }
            } // end of loop.

            if (retvals.Count() > 0)
            {
                WebTransfer.PostSiteConnectionString(retvals);
            }

            return(retvals.AsEnumerable());
        }
Esempio n. 23
0
        public static IEnumerable <ISiteEndpoint> TrackEndpoint(IEnumerable <ISite> sites)
        {
            // Create Search Dictionary
            IEnumerable <ISiteEndpoint> dictionaryEndpoints = sites.GetSearchDictionary <ISiteEndpoint>(TrackerType.Endpoint);

            if (dictionaryEndpoints == null)
            {
                return(null);
            }

            // Test Endpoints in the Search Dictionary
            dictionaryEndpoints = dictionaryEndpoints.TestAvailability();

            IList <SiteEndpoint> retvals = new List <SiteEndpoint>();

            foreach (ISite site in sites) // for each sites..do
            {
                //Create list of deleted endpoints.
                List <SiteEndpoint> deletedEndpoints = new List <SiteEndpoint>();

                // Get Endpoints from Database.
                IEnumerable <SiteEndpoint> dbEndpoints = site.GetDBEndpoints();

                // Get Endpoints from live configuration file.
                IEnumerable <SiteEndpoint> currentEndpoints = site.GetEndpoints();


                // If live endpoints is null
                if (dbEndpoints.Count() < 1 && currentEndpoints == null)
                {
                    continue; // skip this iteration
                }

                deletedEndpoints = dbEndpoints.ToList();

                foreach (SiteEndpoint currEndpoint in currentEndpoints) //foreach endpoint..do
                {
                    // Search dictionary test results for site's current endpoint.
                    ISiteEndpoint siteEndpoint = dictionaryEndpoints.FirstOrDefault(dict => dict.EndpointUrl == currEndpoint.EndpointUrl);

                    //pick out the current endpoint from deleted endpoint list.
                    deletedEndpoints = deletedEndpoints.SkipWhile(x => x.EndpointName == currEndpoint.EndpointName &&
                                                                  x.EndpointUrl == currEndpoint.EndpointUrl).ToList();
                    if (siteEndpoint == null) // If cannot found any result.
                    {
                        continue;             // Skip this iteration.
                    }

                    siteEndpoint.LastCheckDate = DateTime.Now; // Update Checkdate

                    retvals.Add(siteEndpoint as SiteEndpoint); // add this record to return values.

                    // If endpoint is not available and mail status yes
                    if (!siteEndpoint.IsAvailable && siteEndpoint.SendAlertMailWhenUnavailable)
                    {
                        // send mail.
                    }
                } // end of loop..

                //if  some records left in the deleted endpoints -> delete it.
                if (deletedEndpoints.Count() > 0)
                {
                    deletedEndpoints.ForEach(dbep => dbep.DeleteDate = DateTime.Now);
                    WebTransfer.PostSiteEndpoint(dbEndpoints);
                }
            }
            if (retvals.Count() > 0)
            {
                WebTransfer.PostSiteEndpoint(retvals);
            }

            return(retvals.AsEnumerable());
        }
Esempio n. 24
0
        private static void UpdateAppInfoFile()
        {
            ResetAppInfoFile();
            if (_appInfo?.Count > 430)
            {
                goto Shareware;
            }

            foreach (var mirror in AppSupply.GetMirrors(AppSuppliers.Internal))
            {
                var link = PathEx.AltCombine(mirror, ".free", "AppInfo.ini");
                if (Log.DebugMode > 0)
                {
                    Log.Write($"Cache: Looking for '{link}'.");
                }
                if (NetEx.FileIsAvailable(link, 30000, UserAgents.Internal))
                {
                    WebTransfer.DownloadFile(link, CachePaths.AppInfo, 60000, UserAgents.Internal, false);
                }
                if (!File.Exists(CachePaths.AppInfo))
                {
                    continue;
                }
                break;
            }

            var blacklist = Array.Empty <string>();

            if (File.Exists(CachePaths.AppInfo))
            {
                blacklist = Ini.GetSections(CachePaths.AppInfo).Where(x => Ini.Read(x, "Disabled", false, CachePaths.AppInfo)).ToArray();
                UpdateAppInfoData(CachePaths.AppInfo, blacklist);
            }

            var tmpDir = Path.Combine(CorePaths.TempDir, DirectoryEx.GetUniqueName());

            if (!DirectoryEx.Create(tmpDir))
            {
                return;
            }
            var tmpZip = Path.Combine(tmpDir, "AppInfo.7z");

            foreach (var mirror in AppSupply.GetMirrors(AppSuppliers.Internal))
            {
                var link = PathEx.AltCombine(mirror, ".free", "AppInfo.7z");
                if (Log.DebugMode > 0)
                {
                    Log.Write($"Cache: Looking for '{link}'.");
                }
                if (NetEx.FileIsAvailable(link, 30000, UserAgents.Internal))
                {
                    WebTransfer.DownloadFile(link, tmpZip, 60000, UserAgents.Internal, false);
                }
                if (!File.Exists(tmpZip))
                {
                    continue;
                }
                break;
            }
            if (!File.Exists(tmpZip))
            {
                var link = PathEx.AltCombine(AppSupplierHosts.PortableApps, "updater", "update.7z");
                if (Log.DebugMode > 0)
                {
                    Log.Write($"Cache: Looking for '{link}'.");
                }
                if (NetEx.FileIsAvailable(link, 60000, UserAgents.Empty))
                {
                    WebTransfer.DownloadFile(link, tmpZip, 60000, UserAgents.Empty, false);
                }
            }
            if (File.Exists(tmpZip))
            {
                using (var process = SevenZip.DefaultArchiver.Extract(tmpZip, tmpDir))
                    if (process?.HasExited == false)
                    {
                        process.WaitForExit();
                    }
                FileEx.TryDelete(tmpZip);
            }
            var tmpIni = DirectoryEx.GetFiles(tmpDir, "*.ini").FirstOrDefault();

            if (!File.Exists(tmpIni))
            {
                DirectoryEx.TryDelete(tmpDir);
                return;
            }
            UpdateAppInfoData(tmpIni, blacklist);

            FileEx.Serialize(CachePaths.AppInfo, AppInfo, true);
            DirectoryEx.TryDelete(tmpDir);

Shareware:
            if (!Shareware.Enabled)
            {
                return;
            }

            foreach (var srv in Shareware.GetAddresses())
            {
                var key = Shareware.FindAddressKey(srv);
                var usr = Shareware.GetUser(srv);
                var pwd = Shareware.GetPassword(srv);
                var url = PathEx.AltCombine(srv, "AppInfo.ini");
                if (Log.DebugMode > 0)
                {
                    Log.Write($"Shareware: Looking for '{{{key.Encode()}}}/AppInfo.ini'.");
                }
                if (!NetEx.FileIsAvailable(url, usr, pwd, 60000, UserAgents.Default))
                {
                    continue;
                }
                var appInfo = WebTransfer.DownloadString(url, usr, pwd, 60000, UserAgents.Default);
                if (string.IsNullOrWhiteSpace(appInfo))
                {
                    continue;
                }
                var srvKey = key?.Decode(BinaryToTextEncoding.Base85);
                UpdateAppInfoData(appInfo, null, srvKey?.Any() == true ? new ReadOnlyCollection <byte>(srvKey) : default);
            }
        }