学习Altas 笔记[JS简单调用服务端方法]

      在Ajax框架中,Asp.net方面最强当属Altas最强,以前使用AjaxPro. Net和MagicAjax. 最几个都比较好用。这几个月来Altas已经进入CTP版本,是开始学习研究Altas的时机了。准备利用Altas为 http://www.yupsky.com 开发成员之间在线通讯的类似于MSN这样的功能。今天初步的学习了一下Altas,最基础的学习内容就是使用javascript调用服务端代码。
     Altas和AjaxPro.Net类似,但比AjaxPro.Net强大很多。学习结果记录如下:
     程序的原型来自http://weblogs.asp.net/scottgu/archive/2005/09/14/425131.aspx,但是这个是beta版时候的教程。
     1、下载altas框架,到http://www.asp.net/default.aspx?tabindex=8&tabid=47上去下载,上面有很多内容
     2、使用VS2005创建一个WebSite或者Web Application.
     3、配置Web.config如下:
ContractedBlock.gif ExpandedBlockStart.gif Web.config配置
None.gif<?xml version="1.0"?>
None.gif
None.gif
<configuration>
None.gif  
<configSections>
None.gif    
<sectionGroup name="microsoft.web" type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup">
None.gif      
<section name="converters" type="Microsoft.Web.Configuration.ConvertersSection" requirePermission="false" />
None.gif      
<section name="webServices" type="Microsoft.Web.Configuration.WebServicesSection" requirePermission="false" />
None.gif      
<section name="authenticationService" type="Microsoft.Web.Configuration.AuthenticationServiceSection" requirePermission="false" />
None.gif      
<section name="profileService" type="Microsoft.Web.Configuration.ProfileServiceSection" requirePermission="false" />
None.gif    
</sectionGroup>
None.gif  
</configSections>
None.gif  
None.gif  
<!-- 
None.gif      The microsoft.web section defines items required for the Atlas framework.
None.gif  
-->
None.gif  
<microsoft.web>
None.gif    
<converters>
None.gif      
<add type="Microsoft.Web.Script.Serialization.Converters.DataSetConverter"/>
None.gif      
<add type="Microsoft.Web.Script.Serialization.Converters.DataRowConverter"/>
None.gif      
<add type="Microsoft.Web.Script.Serialization.Converters.DataTableConverter"/>
None.gif    
</converters>
None.gif    
<webServices enableBrowserAccess="true" />
None.gif    
<authenticationService enabled="true" />
None.gif    
<!-- The example application needs the profileService to be enabled and to specify the dragOverlayPosition property. -->
None.gif    
<profileService
None.gif      
enabled="false" 
None.gif      setProperties
="dragOverlayPosition" 
None.gif      getProperties
="dragOverlayPosition" />
None.gif  
</microsoft.web>
None.gif
None.gif  
<connectionStrings >
None.gif    
<remove name="LocalSqlServer" />
None.gif    
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf" />
None.gif    
<add name="AltasMsn" connectionString="Data Source=localhost;user id=sa;password=;initial catalog=msn" providerName="System.Data.SqlClient"/>
None.gif  
</connectionStrings>
None.gif
None.gif  
<system.web>
None.gif
None.gif    
<pages>
None.gif      
<controls>
None.gif        
<add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
None.gif        
<add namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
None.gif      
</controls>
None.gif    
</pages>
None.gif
None.gif    
<compilation debug="false">
None.gif      
<buildProviders>
None.gif        
<add extension=".asbx" type="Microsoft.Web.Services.BridgeBuildProvider" />
None.gif      
</buildProviders>
None.gif    
</compilation>
None.gif    
None.gif    
<membership>
None.gif      
<providers>
None.gif        
<remove name="AspNetSqlMembershipProvider" />
None.gif        
<add name="AspNetSqlMembershipProvider" 
None.gif                     type
="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
None.gif                     connectionStringName
="LocalSqlServer" 
None.gif                     enablePasswordRetrieval
="false" 
None.gif                     enablePasswordReset
="true" 
None.gif                     requiresQuestionAndAnswer
="false" 
None.gif                     applicationName
="/" 
None.gif                     requiresUniqueEmail
="false" 
None.gif                     passwordFormat
="Hashed" 
None.gif                     maxInvalidPasswordAttempts
="100" 
None.gif                     passwordAttemptWindow
="10"
None.gif                     minRequiredPasswordLength
="1" 
None.gif                     minRequiredNonalphanumericCharacters
="0" 
None.gif                     passwordStrengthRegularExpression
="" />
None.gif      
</providers>
None.gif    
</membership>
None.gif    
None.gif    
<!-- The SimpleList application needs profile to be enabled, and to allow anonymous users access to the property. -->
None.gif    
<profile enabled="false">
None.gif      
<properties>
None.gif        
<add allowAnonymous="true" name="dragOverlayPosition" defaultValue="" serializeAs="String" />
None.gif      
</properties>
None.gif    
</profile>
None.gif
None.gif    
<httpHandlers>
None.gif      
<remove verb="*" path="*.asmx"/>
None.gif      
<add verb="*" path="*.asmx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
None.gif      
<add verb="*" path="*.asbx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
None.gif    
</httpHandlers>
None.gif    
<httpModules>
None.gif      
<add name="ScriptModule" type="Microsoft.Web.Services.ScriptModule"/>
None.gif      
<add name="BridgeModule" type="Microsoft.Web.Services.BridgeModule"/>
None.gif      
<add name="WebResourceCompression" type="Microsoft.Web.Services.WebResourceCompressionModule"/>
None.gif    
</httpModules>
None.gif
None.gif        
<!--
None.gif            The <authentication> section enables configuration 
None.gif            of the security authentication mode used by 
None.gif            ASP.NET to identify an incoming user. 
None.gif        
-->
None.gif        
<authentication mode="Forms" />
None.gif        
<!--
None.gif            The <customErrors> section enables configuration 
None.gif            of what to do if/when an unhandled error occurs 
None.gif            during the execution of a request. Specifically, 
None.gif            it enables developers to configure html error pages 
None.gif            to be displayed in place of a error stack trace.
None.gif
None.gif        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
None.gif            <error statusCode="403" redirect="NoAccess.htm" />
None.gif            <error statusCode="404" redirect="FileNotFound.htm" />
None.gif        </customErrors>
None.gif        
-->
None.gif    
</system.web>
None.gif
</configuration>

Step 1: 产生一个Web服务 推荐使用WebService  atlas使用webService时,对于webService并没有特殊要求
    

ContractedBlock.gif ExpandedBlockStart.gif WebService 代码
None.gifusing System;
None.gif
using System.Data;
None.gif
using System.Web;
None.gif
using System.Collections;
None.gif
using System.Collections.Generic;
None.gif
using System.Web.Services;
None.gif
using System.Web.Services.Protocols;
None.gif
None.gif
namespace AltasMsn
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Summary description for $codebehindclassname$
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [WebService(Namespace = "http://tempuri.org/")]
InBlock.gif    [WebServiceBinding(ConformsTo 
= WsiProfiles.BasicProfile1_1)]
InBlock.gif    
public class LapService : System.Web.Services.WebService
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        [WebMethod]
InBlock.gif        
public ProcessData[] GetProcesses()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            
return this.GetAllProcesses().ToArray();
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        [WebMethod]
InBlock.gif        
public ProcessData[] MatchProcesses(string expression)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            List
<ProcessData> data = this.GetAllProcesses();
InBlock.gif
InBlock.gif            
if (String.IsNullOrEmpty(expression))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                
return data.ToArray();
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
string[] words = expression.Split(' ');
InBlock.gif
InBlock.gif            
return data.FindAll(new Predicate<ProcessData>(delegate(ProcessData process)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                
return System.Text.RegularExpressions.Regex.IsMatch(process.Name, expression);
InBlock.gif
ExpandedSubBlockEnd.gif            }
)).ToArray();
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
private List<ProcessData> GetAllProcesses()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            List
<ProcessData> data = new List<ProcessData>();
InBlock.gif
InBlock.gif            System.Diagnostics.Process[] processes 
= System.Diagnostics.Process.GetProcesses();
InBlock.gif
InBlock.gif            
foreach (System.Diagnostics.Process process in processes)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                data.Add(
new ProcessData(process.ProcessName, process.WorkingSet64, process.Threads.Count));
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif            
return data;
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif    
public class ProcessData
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
InBlock.gif        
private string _name;
InBlock.gif
InBlock.gif        
private long _workingSet;
InBlock.gif
InBlock.gif        
private int _threadCount;
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
public string Name
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _name; }
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _name = value; }
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
public long WorkingSet
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _workingSet; }
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _workingSet = value; }
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
public long WorkingSetInMB
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _workingSet / (1024 * 1000); }
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
private set dot.gif{ }
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
public int ThreadCount
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _threadCount; }
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ _threadCount = value; }
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public ProcessData() dot.gif{ }
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
public ProcessData(string name, long workingSet, int threadCount)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            _name 
= name;
InBlock.gif
InBlock.gif            _workingSet 
= workingSet;
InBlock.gif
InBlock.gif            _threadCount 
= threadCount;
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}

None.gif

这个服务用于查询当前系统中正在活动进程。
Step2 : Simple Invocation of the Web Service
使用很简单,使用Javascript调用远程服务。
页面代码如下:

ContractedBlock.gif ExpandedBlockStart.gif 页面的Html
ExpandedBlockStart.gifContractedBlock.gif<%dot.gif@ Page Language="C#" AutoEventWireup="true" CodeBehind="SimapleAjax.aspx.cs" Inherits="AltasMsn.SimapleAjax" %>
None.gif
None.gif
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
None.gif
None.gif
<html xmlns="http://www.w3.org/1999/xhtml" >
None.gif
<head runat="server">
None.gif    
<title>Untitled Page</title>
None.gif
</head>
None.gif  
<atlas:ScriptManager id="scriptManager1" runat="server">
None.gif    
<Services>
None.gif        
<atlas:ServiceReference Path="~/LapService.asmx" />
None.gif    
</Services>
None.gif  
</atlas:ScriptManager> 
None.gif
ExpandedBlockStart.gifContractedBlock.gif  
<script language="javascript" type="text/javascript">dot.gif 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
function Button1_onclick() dot.gif{
InBlock.gif
InBlock.gif            
var text1 = document.getElementById("Text1");
InBlock.gif
InBlock.gif            AltasMsn.LapService.MatchProcesses(text1.value, onSearchComplete);
ExpandedSubBlockEnd.gif        }
      
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
function onSearchComplete(results) dot.gif{
InBlock.gif
InBlock.gif            
var searchResults = document.getElementById("searchResults");           
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
for (var i=0; i<results.get_length(); i++dot.gif{
InBlock.gif              searchResults.innerHTML 
+= results[i].Name + "<br>";
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedBlockEnd.gif  
</script>
None.gif
None.gif
<body>
None.gif    
<form id="form1" runat="server">
None.gif     
<div id="logo">
None.gif      Process Explorer
None.gif
None.gif    
</div>
None.gif    
<div id="header">
None.gif      Search:
None.gif      
<input id="Text1" type="text" />
None.gif      
<input id="Button1" type="button" value="Search" onclick="Button1_onclick();" />
None.gif
None.gif    
</div>
None.gif    
<div id="content">
None.gif      
<div class="left">
None.gif        
<span id="searchResults"></span>
None.gif      
</div>   
None.gif    
</div>
None.gif    
</form>
None.gif
</body>
None.gif
</html>
None.gif

示例的结果如下:
r_ajaxmsn.jpg
Unity Atlas(Unity图集)是一种将多个小图像合并成一个大图像的技术,以减少内存和渲染开销。使用Unity Atlas可以将多个Sprite(精灵)打包到一个图像中,并通过一个脚本来管理和使用这些精灵。 在Unity中,可以使用Sprite Packer工具将多个精灵打包到一个图集中。首先,我们需要为我们的asset文件创建一个脚本,该脚本需要继承自ScriptableObject,并使用[Serializable]将其转化为资源文件,以实现序列化和反序列化。然后,我们可以创建一个UGUISpriteAsset类,继承自ScriptableObject,用于存储图像资源和其他Sprite信息。该类包含一个Texture类型的变量用于存储图像资源,以及一个SpriteAssetInfor类型的列表用于存储具体的Sprite信息。 接下来,我们需要设置输出尺寸和图像深度。根据选择的字符数量确定输出尺寸,一般常用中文字体加一块大概四千左右的大小的图片即可完全容纳。设置图像深度为32比特,因为我们需要用到Alpha通道。在Presets选项下选择带有Alpha通道的输出设置,可以选择白色或黑色作为字体颜色,然后将Textures设置为PNG格式。 最后,我们可以编写一个测试脚本ChangeUGUISprite,在Update函数中不停地切换图片。这个脚本可以通过索引或名称来获取Sprite,并将其赋值给Image组件的sprite属性。 总结起来,Unity Atlas是一种将多个Sprite打包到一个图集中的技术,在Unity中可以通过使用ScriptableObject和Serializable来实现序列化和反序列化,并通过Sprite Packer工具进行打包和管理。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Unity 图集Atlas功能需求实现](https://blog.csdn.net/qq_45506643/article/details/107505454)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [NGUI系列教程四(自定义Atlas,Font)](https://blog.csdn.net/jbjwpzyl3611421/article/details/10593567)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值