예제 #1
0
        private bool HavingPricesToUpdate(ProjectSettings project)
        {
            Properties.Settings.Default.PropertyValues["suzadbConnectionString"].PropertyValue = project.ConnectionString;
            var d = new DataClasses1DataContext();
            d.Connection.Open();

            var di = new DirectoryInfo(project.DirWithPrices);

            var pricesToUpdate = (from f in di.GetFiles("*", SearchOption.AllDirectories)
                                  join pl in d.PriceLists on f.Name.Replace(f.Extension, "").ToLower() equals pl.PriceListName.ToLower()
                                  where (pl.UpdateMode > 0 /*|| pl.LastUpdate < f.LastWriteTime*/) && pl.UpdateFromMail
                                  orderby pl.PriceListName
                                  select new { f, pl }).Distinct();
            if (pricesToUpdate.Count() > 0)
            {
                file.WriteLine(DateTime.Now + "\t" + project.DirWithProgramm + "\tНовых прайсов: " + pricesToUpdate.Count());

                /*file.WriteLine(DateTime.Now + "\t" + pricesToUpdate.FirstOrDefault().f.FullName
                    + "\t" + pricesToUpdate.FirstOrDefault().pl.PriceListID
                    + "\t" + pricesToUpdate.FirstOrDefault().pl.LastUpdate
                    + "\t" + pricesToUpdate.FirstOrDefault().f.LastWriteTime);*/
                file.Flush();
                return true;
            }
            //file.WriteLine(DateTime.Now + "\tНовых прайсов: 0");
            //file.Flush();
            return false;
        }
예제 #2
0
        private bool LoadSettings()
        {
            file = new StreamWriter(new FileStream("Service1.log", System.IO.FileMode.Append));
            try
            {
                ListOfSettings = new List<ProjectSettings>();
                var disk = Environment.GetEnvironmentVariable("windir").Split(':')[0];
                var di = new DirectoryInfo(disk + ":\\Inetpub\\wwwroot");
                if (!di.Exists)
                {
                    file.WriteLine(DateTime.Now + "\tПапка " + disk + ":\\Inetpub\\wwwroot не найден");
                    file.Flush();
                    file.Close();
                    return false;
                }
                var projectsSettingsFiles = di.GetFiles("Settings.xml", SearchOption.AllDirectories);
                foreach (var settingsFile in projectsSettingsFiles)
                {
                    XmlDocument xd = new XmlDocument();
                    xd.Load(settingsFile.FullName);
                    XmlNode root = xd.DocumentElement;
                    var x = Properties.Settings.Default.suzadbConnectionString;
                    Properties.Settings.Default.PropertyValues["suzadbConnectionString"].PropertyValue = root.SelectSingleNode("ConnectionString").InnerText;
                    var d = new DataClasses1DataContext();
                    d.Connection.Open();

                    ListOfSettings.Add(new ProjectSettings
                    {
                        ConnectionString = root.SelectSingleNode("ConnectionString").InnerText,
                        DirWithPrices = root.SelectSingleNode("DirWithPrices").InnerText,
                        DirWithProgramm = settingsFile.DirectoryName
                    });
                }
                file.WriteLine("Настройки загружены: " + ListOfSettings.Count);
                file.Flush();
            }
            catch (Exception ex)
            {
                file.WriteLine(DateTime.Now + "\tНастройки не загружены: " + ex.Message);
                file.Flush();
                file.Close();
                System.Threading.Thread.Sleep(60000);
                LoadSettings();
            }
            return true;
        }