为Dynamics 365写一个简单程序实现解决方案一键迁移
public static IServiceManagement<IOrganizationService> sm;
static void Main(string[] args)
{
try
{
sm = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri("https://demo.luoyong.me/XRMServices/2011/Organization.svc"));
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = "crmadmin@luoyong.me";
credentials.UserName.Password = "Pass";
using (var _serviceProxy = new OrganizationServiceProxy(sm, credentials))
{
_serviceProxy.Timeout = new TimeSpan(, , );//默认为两分钟,这里设置为20分钟
_serviceProxy.EnableProxyTypes();
Console.WriteLine("Dynamics 365中可见的解决方案列表:" + DateTime.Now.ToLongTimeString());
QueryExpression qe = new QueryExpression("solution");
qe.ColumnSet = new ColumnSet("uniquename", "friendlyname", "version", "solutionpackageversion", "ismanaged");
qe.Criteria.AddCondition("isvisible", ConditionOperator.Equal, true);
qe.AddOrder("uniquename", OrderType.Ascending);
var solutions = _serviceProxy.RetrieveMultiple(qe);
foreach(var item in solutions.Entities)
{
Console.WriteLine(string.Format("uniquename={0};friendlyname={1};version={2};solutionpackageversion={3};ismanaged={4}",
item.GetAttributeValue<string>("uniquename"),
item.GetAttributeValue<string>("friendlyname"),
item.GetAttributeValue<string>("version"),
item.GetAttributeValue<string>("solutionpackageversion"),
item.GetAttributeValue<bool>("ismanaged")));
Console.WriteLine(new String('-',));
}
Console.WriteLine("开始查询要导出的解决方案并更改版本信息" + DateTime.Now.ToLongTimeString());
var toExpSolutionUniqueName = "DemoSolution";
qe = new QueryExpression("solution");
qe.ColumnSet = new ColumnSet("version");
qe.Criteria.AddCondition("uniquename", ConditionOperator.Equal, toExpSolutionUniqueName);
qe.TopCount = ;
solutions = _serviceProxy.RetrieveMultiple(qe);
if(solutions.Entities.Count >= )
{
var solution = solutions.Entities[];
solution["version"] = string.Format("8.2.{0}.{1}", DateTime.Now.Month, DateTime.Now.Day);
_serviceProxy.Update(solution);
}
Console.WriteLine("开始发布所有自定义项" + DateTime.Now.ToLongTimeString());
PublishAllXmlRequest pubReq = new PublishAllXmlRequest();
_serviceProxy.Execute(pubReq);
Console.WriteLine("开始导出" + DateTime.Now.ToLongTimeString());
ExportSolutionRequest exportSolutionRequest = new ExportSolutionRequest();
exportSolutionRequest.Managed = false;
exportSolutionRequest.SolutionName = toExpSolutionUniqueName;
exportSolutionRequest.TargetVersion = "8.2";//Dynamics 365导出时候可以选择目标环境用什么版本
ExportSolutionResponse exportSolutionResponse = (ExportSolutionResponse)_serviceProxy.Execute(exportSolutionRequest);
byte[] exportXml = exportSolutionResponse.ExportSolutionFile;
string filename = string.Format("{0}_{1}.zip", toExpSolutionUniqueName, solutions.Entities[].GetAttributeValue<string>("version").Replace('.','_'));
File.WriteAllBytes(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments).Replace("Documents", "Downloads") + "\\" + filename, exportXml);
Console.WriteLine("开始导入" + DateTime.Now.ToLongTimeString());
byte[] fileBytes = File.ReadAllBytes(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments).Replace("Documents", "Downloads") + "\\" + filename);
ImportSolutionRequest impReq = new ImportSolutionRequest()
{
CustomizationFile = fileBytes,
PublishWorkflows = true
};
_serviceProxy.Execute(impReq);
Console.WriteLine("开始发布所有自定义项" + DateTime.Now.ToLongTimeString());
pubReq = new PublishAllXmlRequest();
_serviceProxy.Execute(pubReq);
Console.WriteLine("程序运行成功!");
Console.ReadKey();
}
}
catch (FaultException ex)
{
Console.WriteLine("程序出现异常:ex.Message=" + ex.Message);
Console.ReadKey();
}
}
展示效果如下图:展示效果如下图:
为Dynamics 365写一个简单程序实现解决方案一键迁移的更多相关文章
- 写一个ajax程序就是如此简单
写一个ajax程序就是如此简单 ajax介绍: 1:AJAX全称为Asynchronous JavaScript and XML(异步JavaScript和XML),指一种创建交互式网页应用的网页开发 ...
- (原创)如何使用boost.asio写一个简单的通信程序(一)
boost.asio相信很多人听说过,作为一个跨平台的通信库,它的性能是很出色的,然而它却谈不上好用,里面有很多地方稍不注意就会出错,要正确的用好asio还是需要花一番精力去学习和实践的,本文将通过介 ...
- (原创)如何使用boost.asio写一个简单的通信程序(二)
先说下上一篇文章中提到的保持io_service::run不退出的简单办法.因为只要异步事件队列中有事件,io_service::run就会一直阻塞不退出,所以只要保证异步事件队列中一直有事件就行了, ...
- Dynamics 365中的应用程序介绍
本人微信和易信公众号:微软动态CRM专家罗勇 ,回复275或者20180630可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong.me ...
- 如何写一个简单的http服务器
最近几天用C++写了一个简单的HTTP服务器,作为学习网络编程和Linux环境编程的练手项目,这篇文章记录我在写一个HTTP服务器过程中遇到的问题和学习到的知识. 服务器的源代码放在Github. H ...
- 如何写一个简单的shell
如何写一个简单的shell 看完<UNIX环境高级编程>后我就一直想写一个简单的shell来作为练习,因为有事断断续续的写了好几个月,如今写了差不多来总结一下. 源代码放在了Github: ...
- 分享:计算机图形学期末作业!!利用WebGL的第三方库three.js写一个简单的网页版“我的世界小游戏”
这几天一直在忙着期末考试,所以一直没有更新我的博客,今天刚把我的期末作业完成了,心情澎湃,所以晚上不管怎么样,我也要写一篇博客纪念一下我上课都没有听,还是通过强大的度娘完成了我的作业的经历.(当然作业 ...
- 学了C语言,如何利用CURL写一个下载程序?—用nmake编译CURL并安装
在这一系列的前一篇文章学了C语言,如何为下载狂人写一个磁盘剩余容量监控程序?中,我们为下载狂人写了一个程序来监视磁盘的剩余容量,防止下载的东西撑爆了硬盘.可是,这两天,他又抱怨他的下载程序不好用,让我 ...
- 一步一步写一个简单通用的makefile(三)
上一篇一步一步写一个简单通用的makefile(二) 里面的makefile 实现对通用的代码进行编译,这一章我将会对上一次的makefile 进行进一步的优化. 优化后的makefile: #Hel ...
随机推荐
- R + ggplot2 Graph Catalog(转)
Joanna Zhao’s and Jenny Bryan’s R graph catalog is meant to be a complement to the physical book,Cre ...
- haproxy-代码阅读-内存管理
haproxy内存池概述 内存池按照类型分类,每个类型的内存池都有一个名字,用链表记录空闲的内存块,每个内存块大小相等,并按照16字节对齐. haporxy用pool_head 结构记录内存池 str ...
- Zepto源码分析-event模块
源码注释 // Zepto.js // (c) 2010-2015 Thomas Fuchs // Zepto.js may be freely distributed under the MIT l ...
- day_ha配置文件
流程图: 代码 #!/sur/bin/env python # -*- coding: utf-8 -*- #{"backend": "www.oldboy.org&qu ...
- 每篇半小时1天入门MongoDB——2.MongoDB环境变量配置和Shell操作
上一篇:每篇半小时1天入门MongoDB——1.MongoDB介绍和安装 配置环境变量 Win10系统为例 右键单击“此电脑”——属性——高级系统设置——高级——环境变量,添加C:\Program F ...
- 解析PHP面向对象的三大特征
class BenHang extends Card{ /*构造函数与及构造的继承*/ function __construct($cardno,$pwd, $name,$money){ parent ...
- awk内引用shell变量【自己手动加精】
题目 [root@localhost ~]# cat 1.txt iii sss ddd 执行命令 [root@localhost ~]# A=0 [root@localhost ~]# awk '{ ...
- 简单两步快速学会使用Mybatis-Generator自动生成entity实体、dao接口和简单mapper映射(用mysql和oracle举例)
前言: mybatis-generator是根据配置文件中我们配置的数据库连接参数自动连接到数据库并根据对应的数据库表自动的生成与之对应mapper映射(比如增删改查,选择性增删改查等等简单语句)文件 ...
- 使用可视化图表对 Webpack 2 的编译与打包进行统计分析
此文主要对使用可视化图表对 Webpack 2 的编译与打包进行统计分析进行了详细地讲解,供您更加直观地参考. 在之前更新的共十七章节中,我们陆续讲解了 Webpack 2 从配置到打包.压缩优化到调 ...
- ASP.NET MVC开发学习过程中遇到的细节问题以及注意事项
1.datagrid中JS函数传值问题: columns: { field: 'TypeName', title: '分类名称', width: 120, sortable: true, format ...