Ejemplo n.º 1
0
        public void ProcessIcons(Credentials user, WebServiceAPI service)
        {
            var watch = Stopwatch.StartNew();

            Logger.Default.Info(LogLocation, string.Format("LoadWebPartView: Start creating icons {0}", DateTime.Now));

            PublishedApplication[] apps = Page.Session["PublishedApps"] as PublishedApplication[];
            var iconsApp = service.GetApplicationsByCredentialsEx(user, "", "", new string[] { "icon-info" }, new string[] { "all" }, new string[] { "all" });

            if ((apps != null) && (iconsApp != null))
            {
                for (int i = 0; i < apps.Length; i++)
                {
                    apps[i].LargeIcon = "";
                    apps[i].SmallIcon = "";

                    try
                    {
                        var iconInfoApp = iconsApp.FirstOrDefault(x => x.Item.InternalName.Equals(apps[i].Item.InternalName, StringComparison.OrdinalIgnoreCase));
                        if (iconInfoApp != null)
                        {
                            if (!IconsManager.CheckLargeIcon(apps[i].IconFileName, IconsExpirationPeriod))
                            {
                                apps[i].LargeIcon = service.GetApplicationIcon(iconInfoApp.Item, 32, 32, "ICO", user, apps[i].FarmName);
                                if (apps[i].LargeIcon != null)
                                {
                                    IconsManager.CreateLargeIcon(apps[i]);
                                    apps[i].LargeIcon = apps[i].IconFileName;
                                }
                            }
                            else
                            {
                                apps[i].LargeIcon = apps[i].IconFileName;
                            }

                            if (!IconsManager.CheckSmallIcon(apps[i].IconFileName, IconsExpirationPeriod))
                            {
                                apps[i].SmallIcon = service.GetApplicationIcon(iconInfoApp.Item, 16, 32, "ICO", user, apps[i].FarmName);
                                if (apps[i].SmallIcon == null)
                                {
                                    apps[i].SmallIcon = service.GetApplicationIcon(iconInfoApp.Item, 8, 32, "ICO", user, apps[i].FarmName);
                                }
                                if (apps[i].SmallIcon == null)
                                {
                                    apps[i].SmallIcon = service.GetApplicationIcon(iconInfoApp.Item, 4, 32, "ICO", user, apps[i].FarmName);
                                }

                                if (apps[i].SmallIcon != null)
                                {
                                    IconsManager.CreateSmallIcon(apps[i]);
                                    apps[i].SmallIcon = apps[i].IconFileName;
                                }
                            }
                            else
                            {
                                apps[i].SmallIcon = apps[i].IconFileName;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Default.Error(LogLocation, "User - " + user.UserName + " ; Error = " + ex.Message, ex);
                    }
                }
                Page.Session["PublishedApps"] = apps;
            }
            Logger.Default.Info(LogLocation, string.Format("LoadWebPartView: End creating icons {0}", watch.Elapsed));
        }