Exemple #1
0
        private void newBrandLauncherView(Interop.SystemTime time, Brand brand)
        {
            BrandLauncherView view = new BrandLauncherView(this.time)
            {
                Top           = Application.Current.MainWindow.Top,
                Left          = Application.Current.MainWindow.Left + base.Width,
                Height        = Application.Current.MainWindow.Height,
                DataContext   = brand,
                Title         = brand.NameAndFolder,
                ShowActivated = false,
                Owner         = this
            };

            _dictBrandLauncherView.Add(brand.BrandId, view);
            view.EventNewBrowserLauncherView += new Action <Interop.SystemTime, BrandProvider>(showBrowserLauncherView);
            view.Closing += new CancelEventHandler(closingViewer <BrandLauncherView>);

            this.currentBrandLauncher = view;
            this.currentBrandLauncher.Show();
        }
Exemple #2
0
        public LauncherSettings DownloadSettings(bool force, bool FullLoad = true)
        {
            string           nameFileDbSerialize = new CatalogApi.Settings.File(ConfigurationManager.AppSettings["FileDbSerialize"]).Name;
            LauncherSettings graph = new LauncherSettings();

            // режим "force" принажатии кнопки брэнда
            if ((force == true) &&
                (System.IO.File.Exists(nameFileDbSerialize) == true))
            {
                System.IO.File.Delete(nameFileDbSerialize);
            }
            else
            {
                ;
            }

            if (System.IO.File.Exists(nameFileDbSerialize) == true)
            {
                // для режима forse=false - прочитать и вернуть копию БД
                Stream          stream    = System.IO.File.OpenRead(nameFileDbSerialize);
                BinaryFormatter formatter = new BinaryFormatter();
                graph = (LauncherSettings)formatter.Deserialize(stream);
                stream.Close();

                return(graph);
            }
            else
            {
                ;
            }

            #region чтение БД, заполнение объектов значениями
            using (AvtoritetEntities entities = new AvtoritetEntities())
            {
                List <NewLauncher.DataContext.Brand> list = (from r in entities.Brand
                                                             where r.Enable
                                                             orderby r.NameAndFolder
                                                             select r).ToList <NewLauncher.DataContext.Brand>();
                List <Provider> list2 = (from r in entities.Provider
                                         where r.Enable & FullLoad
                                         orderby r.Order
                                         select r).ToList <Provider>();
                List <ProviderAccount> list3 = (from t in entities.ProviderAccount
                                                where t.Enable & FullLoad
                                                select t).ToList <ProviderAccount>();
                List <NewLauncher.DataContext.CommandFile> list4 = (from t in entities.CommandFile
                                                                    where FullLoad
                                                                    select t).ToList <NewLauncher.DataContext.CommandFile>();
                List <NewLauncher.DataContext.ProviderFile> list5 = (from t in entities.ProviderFile
                                                                     where FullLoad
                                                                     select t).ToList <NewLauncher.DataContext.ProviderFile>();
                List <Group> list6 = (from t in entities.Group
                                      where t.Enable
                                      orderby t.Order
                                      select t).ToList <Group>();
                List <NewLauncher.DataContext.GroupBox> list7 = (from r in entities.GroupBox
                                                                 where r.Enable
                                                                 orderby r.Title
                                                                 select r).ToList <NewLauncher.DataContext.GroupBox>();
                foreach (Group group in list6)
                {
                    GroupSet item = new GroupSet {
                        Name      = group.Name,
                        Width     = group.Width.Value,
                        Height    = group.Height.Value,
                        GroupBoxs = new List <CatalogApi.Settings.GroupBox>()
                    };
                    foreach (NewLauncher.DataContext.GroupBox box in list7)
                    {
                        if (box.GroupId == group.GroupId)
                        {
                            CatalogApi.Settings.GroupBox box2 = new CatalogApi.Settings.GroupBox {
                                Left          = box.Left.Value,
                                Top           = box.Top.Value,
                                Width         = box.Width.Value,
                                Height        = box.Height.Value,
                                Title         = box.Title,
                                VisibleBorder = box.VisibleBorder.Value,
                                Brands        = new List <CatalogApi.Settings.Brand>()
                            };
                            foreach (NewLauncher.DataContext.Brand brand in list)
                            {
                                if (brand.GroupBoxId == box.GroupBoxId)
                                {
                                    CatalogApi.Settings.Brand brand2 = new CatalogApi.Settings.Brand {
                                        NameAndFolder = brand.NameAndFolder,
                                        IconPath      = brand.IconPath,
                                        IconPath2     = brand.IconPath2,
                                        IconPathImg   = brand.IconPathImg,
                                        IconPath2Img  = brand.IconPath2Img
                                    };
                                    int?top = brand.Top;
                                    brand2.Top         = top.HasValue ? top.GetValueOrDefault() : 0;
                                    top                = brand.Left;
                                    brand2.Left        = top.HasValue ? top.GetValueOrDefault() : 0;
                                    top                = brand.Width;
                                    brand2.Width       = top.HasValue ? top.GetValueOrDefault() : 0;
                                    top                = brand.Height;
                                    brand2.Height      = top.HasValue ? top.GetValueOrDefault() : 0;
                                    brand2.BrandId     = brand.BrandId;
                                    brand2.ButtonStyle = brand.ButtonStyle;
                                    brand2.MenuWindow  = brand.MenuWindow.Value;
                                    brand2.Providers   = new List <BrandProvider>();
                                    foreach (Provider provider in list2)
                                    {
                                        int providerId;
                                        if (provider.BrandId != brand.BrandId)
                                        {
                                            continue;
                                        }
                                        BrandProvider provider2 = new BrandProvider {
                                            Uri        = provider.Uri.Trim(),
                                            IconPath   = provider.IconPath,
                                            Title      = provider.Title,
                                            Commands   = provider.commandcontent,
                                            ProviderId = provider.ProviderId,
                                            Login      = "",
                                            Password   = ""
                                        };
                                        foreach (ProviderAccount account in list3)
                                        {
                                            if (account.ProviderId == provider.ProviderId)
                                            {
                                                provider2.Login    = (account != null) ? account.Login.Trim() : string.Empty;
                                                provider2.Password = (account != null) ? account.Password.Trim() : string.Empty;
                                                break;
                                            }
                                        }
                                        provider2.CommandFiles = new List <CatalogApi.Settings.CommandFile>();
                                        foreach (NewLauncher.DataContext.CommandFile file in list4)
                                        {
                                            top        = file.ProviderId;
                                            providerId = provider.ProviderId;
                                            if ((top.GetValueOrDefault() == providerId) && top.HasValue)
                                            {
                                                CatalogApi.Settings.CommandFile file2 = new CatalogApi.Settings.CommandFile {
                                                    FileName    = file.FileName,
                                                    FileContent = file.FileContent
                                                };
                                                provider2.CommandFiles.Add(file2);
                                            }
                                        }
                                        provider2.ProviderFiles = new List <CatalogApi.Settings.ProviderFile>();
                                        foreach (NewLauncher.DataContext.ProviderFile file3 in list5)
                                        {
                                            top        = file3.ProviderId;
                                            providerId = provider.ProviderId;
                                            if ((top.GetValueOrDefault() == providerId) && top.HasValue)
                                            {
                                                CatalogApi.Settings.ProviderFile file4 = new CatalogApi.Settings.ProviderFile {
                                                    FileName    = file3.FileName,
                                                    FileExt     = file3.FileExt,
                                                    FileSize    = file3.FileSize.Value,
                                                    FileContent = file3.FileContent
                                                };
                                                provider2.ProviderFiles.Add(file4);
                                            }
                                        }
                                        brand2.Providers.Add(provider2);
                                    }
                                    box2.Brands.Add(brand2);
                                }
                            }
                            item.GroupBoxs.Add(box2);
                        }
                    }
                    graph.Groups.Add(item);
                }
            }
            #endregion

            if (System.IO.File.Exists(nameFileDbSerialize) == true)
            {
                //??? никогда не выполняется
                // , если forse=true файл будет удален
                // , если forse=false произодет возврат значения и выход из функции
                System.IO.File.Delete(nameFileDbSerialize);
            }
            else
            {
                ;
            }

            Stream serializationStream = System.IO.File.Create(nameFileDbSerialize);
            new BinaryFormatter().Serialize(serializationStream, graph);
            serializationStream.Close();

            if (force == true)
            {
                this.ExtractResourcesToFolder(graph);
            }
            else
            {
                ;
            }

            return(graph);
        }
Exemple #3
0
        private void button_onClick(Brand brandown)
        {
            LoadUpdates();
            //minimizeMemory();
            if (HaveNewUpdate)
            {
                this.BuildWindow();
                HaveNewUpdate = false;
            }

            string url = "";

            try
            {
                if (brandown != null)
                {
                    if (brandown.MenuWindow)
                    {
                        if (_dictBrandLauncherView.ContainsKey(brandown.BrandId) == false)
                        {
                            EventNewBrandLauncherView?.Invoke(this.time, brandown);
                        }
                        else
                        {
                            _dictBrandLauncherView[brandown.BrandId].Activate();
                        }
                    }
                    else if (brandown.Providers.Count > 0)
                    {
                        url = brandown.Providers[0].Uri;
                        if (IsUrlAsHttp(url) == true)
                        {
                            showBrowserLauncherView(this.time, brandown.Providers[0]);
                        }
                        else
                        {
                            url = GetPathBrandToProcess(url, brandown.NameAndFolder);

                            using (Process process = new Process {
                                StartInfo =
                                {
                                    UseShellExecute = false
                                    , FileName      = url
                                    , CreateNoWindow= true
                                    , Verb          = url
                                }
                            }) {
                                process.Start();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorLogHelper.AddErrorInLog(string.Format("button_onClick (brand.Id={0}, provider.Id={1}, url={2}", brandown.BrandId, brandown.Providers[0].ProviderId, url)
                                             , string.Format("{0} | {1}", e.Message, e.StackTrace));
                MessageBox.Show(string.Format("{0} | {1}", e.Message, e.StackTrace));
            }

            //Func<CatalogApi.Settings.Brand, bool> predicate = null;
            ////LoadUpdates();
            //minimizeMemory();
            //if (HaveNewUpdate)
            //{
            //    this.BuildWindow();
            //    HaveNewUpdate = false;
            //}
            //Button d = (Button)sender;
            //int brandId = ButtonBehavior.GetBrandId(d);
            //if (this.brandLauncher != null)
            //{
            //    this.brandLauncher.Close();
            //}
            //foreach (GroupSet set in launcherSettings.Groups)
            //{
            //    foreach (CatalogApi.Settings.GroupBox box in set.GroupBoxs)
            //    {
            //        string url = "";
            //        try
            //        {
            //            if (predicate == null)
            //            {
            //                predicate = t => t.BrandId == brandId;
            //            }
            //            CatalogApi.Settings.Brand brand = box.Brands.FirstOrDefault<CatalogApi.Settings.Brand>(predicate);
            //            if (brand != null)
            //            {
            //                if (brand.MenuWindow)
            //                {
            //                    BrandLauncherView view = new BrandLauncherView(this.time)
            //                    {
            //                        Top = Application.Current.MainWindow.Top,
            //                        Left = Application.Current.MainWindow.Left + base.Width,
            //                        Height = Application.Current.MainWindow.Height,
            //                        DataContext = brand,
            //                        Title = brand.NameAndFolder,
            //                        ShowActivated = false,
            //                        Owner = this
            //                    };
            //                    this.brandLauncher = view;
            //                    this.brandLauncher.Show();
            //                }
            //                else if (brand.Providers.Count > 0)
            //                {
            //                    string loginFromDB = SettingsFactory.GetLoginFromDB(brand.Providers[0].ProviderId);
            //                    string pswFromDB = SettingsFactory.GetPswFromDB(brand.Providers[0].ProviderId);
            //                    string title = brand.Providers[0].Title;
            //                    url = brand.Providers[0].Uri;
            //                    if (url.StartsWith("http") || url.StartsWith("https"))
            //                    {
            //                        new BrowserLauncherView(url, title, this.time, loginFromDB, pswFromDB).Show();
            //                    }
            //                    else
            //                    {
            //                        url = (url.StartsWith("http") || url.StartsWith("https")) ? url : Path.Combine(ResourceManager.Root, brand.NameAndFolder, url);
            //                        string str6 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ResourceManager.Root, brand.NameAndFolder);
            //                        using (Process process = new Process { StartInfo = { UseShellExecute = false, FileName = url, CreateNoWindow = true, Verb = url } })
            //                        {
            //                            process.Start();
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //        catch (Exception exception)
            //        {
            //            ErrorLogHelper.AddErrorInLog("Button_Click", url + " | " + exception.Message + " | " + exception.StackTrace);
            //            MessageBox.Show(exception.Message + url + " | " + exception.StackTrace);
            //        }
            //    }
            //}
        }
        public LauncherSettings DownloadSettings(bool force, bool FullLoad = true)
        {
            string           path  = "launcherDBSettings.dat";
            LauncherSettings graph = new LauncherSettings();

            if (force && File.Exists(path))
            {
                File.Delete(path);
            }
            if (File.Exists(path))
            {
                Stream          stream    = File.OpenRead(path);
                BinaryFormatter formatter = new BinaryFormatter();
                graph = (LauncherSettings)formatter.Deserialize(stream);
                stream.Close();
                return(graph);
            }
            using (AvtoritetEntities entities = new AvtoritetEntities())
            {
                List <NewLauncher.DataContext.Brand> list = (from r in entities.Brand
                                                             where r.Enable
                                                             orderby r.NameAndFolder
                                                             select r).ToList <NewLauncher.DataContext.Brand>();
                List <Provider> list2 = (from r in entities.Provider
                                         where r.Enable & FullLoad
                                         orderby r.Order
                                         select r).ToList <Provider>();
                List <ProviderAccount> list3 = (from t in entities.ProviderAccount
                                                where t.Enable & FullLoad
                                                select t).ToList <ProviderAccount>();
                List <NewLauncher.DataContext.CommandFile> list4 = (from t in entities.CommandFile
                                                                    where FullLoad
                                                                    select t).ToList <NewLauncher.DataContext.CommandFile>();
                List <NewLauncher.DataContext.ProviderFile> list5 = (from t in entities.ProviderFile
                                                                     where FullLoad
                                                                     select t).ToList <NewLauncher.DataContext.ProviderFile>();
                List <Group> list6 = (from t in entities.Group
                                      where t.Enable
                                      orderby t.Order
                                      select t).ToList <Group>();
                List <NewLauncher.DataContext.GroupBox> list7 = (from r in entities.GroupBox
                                                                 where r.Enable
                                                                 orderby r.Title
                                                                 select r).ToList <NewLauncher.DataContext.GroupBox>();
                foreach (Group group in list6)
                {
                    GroupSet item = new GroupSet {
                        Name      = group.Name,
                        Width     = group.Width.Value,
                        Height    = group.Height.Value,
                        GroupBoxs = new List <CatalogApi.Settings.GroupBox>()
                    };
                    foreach (NewLauncher.DataContext.GroupBox box in list7)
                    {
                        if (box.GroupId == group.GroupId)
                        {
                            CatalogApi.Settings.GroupBox box2 = new CatalogApi.Settings.GroupBox {
                                Left          = box.Left.Value,
                                Top           = box.Top.Value,
                                Width         = box.Width.Value,
                                Height        = box.Height.Value,
                                Title         = box.Title,
                                VisibleBorder = box.VisibleBorder.Value,
                                Brands        = new List <CatalogApi.Settings.Brand>()
                            };
                            foreach (NewLauncher.DataContext.Brand brand in list)
                            {
                                if (brand.GroupBoxId == box.GroupBoxId)
                                {
                                    CatalogApi.Settings.Brand brand2 = new CatalogApi.Settings.Brand {
                                        NameAndFolder = brand.NameAndFolder,
                                        IconPath      = brand.IconPath,
                                        IconPath2     = brand.IconPath2,
                                        IconPathImg   = brand.IconPathImg,
                                        IconPath2Img  = brand.IconPath2Img
                                    };
                                    int?top = brand.Top;
                                    brand2.Top         = top.HasValue ? top.GetValueOrDefault() : 0;
                                    top                = brand.Left;
                                    brand2.Left        = top.HasValue ? top.GetValueOrDefault() : 0;
                                    top                = brand.Width;
                                    brand2.Width       = top.HasValue ? top.GetValueOrDefault() : 0;
                                    top                = brand.Height;
                                    brand2.Height      = top.HasValue ? top.GetValueOrDefault() : 0;
                                    brand2.BrandId     = brand.BrandId;
                                    brand2.ButtonStyle = brand.ButtonStyle;
                                    brand2.MenuWindow  = brand.MenuWindow.Value;
                                    brand2.Providers   = new List <BrandProvider>();
                                    foreach (Provider provider in list2)
                                    {
                                        int providerId;
                                        if (provider.BrandId != brand.BrandId)
                                        {
                                            continue;
                                        }
                                        BrandProvider provider2 = new BrandProvider {
                                            Uri        = provider.Uri.Trim(),
                                            IconPath   = provider.IconPath,
                                            Title      = provider.Title,
                                            Commands   = provider.commandcontent,
                                            ProviderId = provider.ProviderId,
                                            Login      = "",
                                            Password   = ""
                                        };
                                        foreach (ProviderAccount account in list3)
                                        {
                                            if (account.ProviderId == provider.ProviderId)
                                            {
                                                provider2.Login    = (account != null) ? account.Login.Trim() : string.Empty;
                                                provider2.Password = (account != null) ? account.Password.Trim() : string.Empty;
                                                break;
                                            }
                                        }
                                        provider2.CommandFiles = new List <CatalogApi.Settings.CommandFile>();
                                        foreach (NewLauncher.DataContext.CommandFile file in list4)
                                        {
                                            top        = file.ProviderId;
                                            providerId = provider.ProviderId;
                                            if ((top.GetValueOrDefault() == providerId) && top.HasValue)
                                            {
                                                CatalogApi.Settings.CommandFile file2 = new CatalogApi.Settings.CommandFile {
                                                    FileName    = file.FileName,
                                                    FileContent = file.FileContent
                                                };
                                                provider2.CommandFiles.Add(file2);
                                            }
                                        }
                                        provider2.ProviderFiles = new List <CatalogApi.Settings.ProviderFile>();
                                        foreach (NewLauncher.DataContext.ProviderFile file3 in list5)
                                        {
                                            top        = file3.ProviderId;
                                            providerId = provider.ProviderId;
                                            if ((top.GetValueOrDefault() == providerId) && top.HasValue)
                                            {
                                                CatalogApi.Settings.ProviderFile file4 = new CatalogApi.Settings.ProviderFile {
                                                    FileName    = file3.FileName,
                                                    FileExt     = file3.FileExt,
                                                    FileSize    = file3.FileSize.Value,
                                                    FileContent = file3.FileContent
                                                };
                                                provider2.ProviderFiles.Add(file4);
                                            }
                                        }
                                        brand2.Providers.Add(provider2);
                                    }
                                    box2.Brands.Add(brand2);
                                }
                            }
                            item.GroupBoxs.Add(box2);
                        }
                    }
                    graph.Groups.Add(item);
                }
            }
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            Stream serializationStream = File.Create(path);

            new BinaryFormatter().Serialize(serializationStream, graph);
            serializationStream.Close();
            if (force)
            {
                this.ExtractResourcesToFolder(graph);
            }
            return(graph);
        }
Exemple #5
0
 public static string ResolveBrandProviderImage(Brand brand, BrandProvider provider)
 {
     return(System.IO.Path.Combine(Root, brand.NameAndFolder, provider.IconPath));
 }
Exemple #6
0
 public static string ResolveBrandImage(Brand brand)
 {
     return(System.IO.Path.Combine(Root, brand.NameAndFolder, brand.IconPath2));
 }