Exemplo n.º 1
0
 //+
 //- ~Write- //
 internal String Write(ClientController controller)
 {
     String provider = controller.FrameworkElement.Provider;
     if (!String.IsNullOrEmpty(provider))
     {
         Provider = Nalarium.Activation.ObjectCreator.CreateAs<ProviderBase>(provider);
         if (Provider == null)
         {
             throw new InvalidOperationException("Framework provider for " + controller.Framework() + " not found (" + provider + ").");
         }
     }
     if (Provider == null)
     {
         switch (controller.Framework().ToLower())
         {
             case Nalarium.Client.Framework.None:
                 Provider = new NoneProvider();
                 break;
             case Nalarium.Client.Framework.Basic:
                 Provider = new BasicProvider();
                 break;
             case Nalarium.Client.Framework.Enhanced:
                 Provider = new EnhancedProvider();
                 break;
             case Nalarium.Client.Framework.Prototype:
                 Provider = new PrototypeProvider();
                 break;
             case Nalarium.Client.Framework.JQuery:
                 Provider = new JQueryProvider();
                 break;
             default:
                 if (String.IsNullOrEmpty(provider))
                 {
                     throw new InvalidOperationException("Framework provider for " + controller.Framework() + " not set.");
                 }
                 break;
         }
     }
     //+
     Provider.Controller = controller;
     this.Provider.ImportInto(this);
     ScriptResourceList = ScriptResourceList.OrderBy(s => s.ScriptPriority()).ToList();
     //++ copy for serialization
     Combine = controller.Combine();
     Minimize = controller.Minimize();
     Compress = controller.Compress();
     IncludeTracing = controller.IncludeTracing;
     DomLoadTemplate = Provider.DomLoadTemplate;
     PageLoadTemplate = Provider.PageLoadTemplate;
     Framework = Provider.Framework;
     //+ flatten data
     String leftover = String.Empty;
     String volatileData = GetVolatileData(this);
     //+
     String scriptBasePath = controller.ScriptBasePath;
     //+
     StringBuilder output = new StringBuilder();
     if (this.Combine)
     {
         String data = ScriptCatalog.Serialize(this);
         SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
         String hash = UTF8Encoding.UTF8.GetString(sha1.ComputeHash(UTF8Encoding.UTF8.GetBytes(data)));
         String base64Id = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(hash));
         lock (this)
         {
             if (_scriptCache.ContainsKey(base64Id))
             {
                 _scriptCache.Remove(base64Id);
             }
             _scriptCache.Add(base64Id, data);
         }
         List<ScriptInclude> doNotCombineIncludeList = ScriptIncludeList.Where(p => p.DoNotCombine()).ToList();
         List<ScriptInclude> remoteIncludeList = ScriptIncludeList.Where(p => !p.DoNotCombine() && p.Path().StartsWith("http://") || p.Path().StartsWith("https://")).ToList();
         //+
         remoteIncludeList.ForEach(p => Http.Page.ClientScript.RegisterClientScriptInclude(p.Path(), p.Path()));
         doNotCombineIncludeList.ForEach(p => Http.Page.ClientScript.RegisterClientScriptInclude(p.Path(), p.Path()));
         String path = Nalarium.Client.Configuration.ClientSection.GetConfigSection().ResourceHandlerPath + "?c=" + base64Id;
         if (controller.OutputMode() == OutputMode.Manual)
         {
             Http.Page.ClientScript.RegisterClientScriptInclude("__$ClientResource", path);
         }
         else
         {
             Http.Response.Write(CreateScriptElement(path));
         }
         //+
         leftover = volatileData;
     }
     else
     {
         if (controller.OutputMode() == OutputMode.Classic)
         {
             FrameworkCoreIncludeList.ForEach(p => Http.Page.ClientScript.RegisterClientScriptInclude(p.Path(), p.Path()));
             ScriptResourceList.ForEach(p => Http.Page.ClientScript.RegisterClientScriptResource(p.ScriptType(), p.ResourceName()));
             ScriptIncludeList.ForEach(p => Http.Page.ClientScript.RegisterClientScriptInclude(p.Path(), p.Path()));
             leftover = GetNonVolatileData(this) + "\n" + volatileData;
             Http.Page.ClientScript.RegisterClientScriptBlock(_type, "AdHoc", CreateScriptWrapElement(leftover));
         }
         else
         {
             FrameworkCoreIncludeList.ForEach(p => output.AppendLine(CreateScriptElement(p.Path())));
             ScriptResourceList.ForEach(p =>
             {
                 //String contentType;
                 //output.AppendLine(ResourceReader.ReadResource(p.ScriptType.Assembly.FullName, p.ResourceName, out contentType));
                 output.AppendLine(CreateScriptElement(CreateExternalResourceUrl(new ResourceItem
                 {
                     AssemblyName = p.ScriptType().Assembly.FullName,
                     ResourceName = p.ResourceName()
                 })));
             });
             ScriptIncludeList.ForEach(p => output.AppendLine(CreateScriptElement(p.Path())));
             output.AppendLine(CreateScriptWrapElement(GetNonVolatileData(this) + "\n" + volatileData));
         }
         //+
         //+
         return output.ToString();
     }
     //+
     return leftover;
 }
Exemplo n.º 2
0
 //+
 //- @Ctor -//
 public ClientHelper(ClientController controller)
 {
     controller.OutputMode(OutputMode.Manual);
     _controller = controller;
 }
Exemplo n.º 3
0
 public ClientManager()
 {
     CheckAndSave();
     _controller = new ClientController();
     _controller.Framework(Nalarium.Client.Framework.None);
     IncludeTracing = true;
 }
Exemplo n.º 4
0
 public static void RegisterToPage(System.Web.UI.Page page, ClientController controller)
 {
     RegisterToPage(page, new ClientManager(controller));
 }
Exemplo n.º 5
0
 //+
 //- @Ctor -//
 public ClientManager(ClientController controller)
 {
     if (_controller == null)
     {
         throw new InvalidOperationException("Controller may not be null");
     }
     CheckAndSave();
     _controller = controller;
     _controller.Framework(Nalarium.Client.Framework.None);
     IncludeTracing = true;
 }