Ejemplo n.º 1
0
        protected override void ProcessRecord()
        {
            try
            {
                Session session = _packageDeploymentManager.CreateSession("K2Module" + DateTime.Now.ToString());

                session.SetOption("NoAnalyze", true);
                PackageItemOptions options = PackageItemOptions.Create();
                options.ValidatePackage = Validate;

                var typeRef = new TypeRef(Name, NameSpace);

                var query = QueryItemOptions.Create(typeRef);

                var results = session.FindItems(query).Result;
                foreach (var result in results)
                {
                    options.Include(result, PackageItemMode.IncludeDependencies);
                }
                options.PackageItemMode = IncludeDependenciesAsReference ? PackageItemMode.IncludeDependenciesAsReference : PackageItemMode.IncludeDependencies;
                session.PackageItems(options);
                var fileStream = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                session.Model.Save(fileStream);

                fileStream.Close();
                _packageDeploymentManager.CloseSession(session.Name);
            }
            catch (Exception ex)
            {
                ErrorHelper.Write(ex);
            }
        }
        protected override void ProcessRecord()
        {
            try
            {
                Session session = _packageDeploymentManager.CreateSession("K2Module" + DateTime.Now.ToString());
                session.SetOption("NoAnalyze", true);
                PackageItemOptions options = PackageItemOptions.Create();
                options.ValidatePackage = Validate;


                var    pathNamespace = "/root/";
                var    rootNamespace = "urn:SourceCode/Categories";
                string ns;
                string category;

                if (Category.Contains("\\"))
                {
                    var categories = Category.Split('\\');

                    var parentCats = string.Join("/", categories.Take(categories.Length - 1));
                    pathNamespace += parentCats + "/";

                    ns       = rootNamespace + "?root#Path." + Uri.EscapeDataString(pathNamespace);
                    category = categories.Last();
                }
                else
                {
                    ns       = rootNamespace;
                    category = Category;
                }

                var typeRef = new TypeRef(category, ns);

                var query   = QueryItemOptions.Create(typeRef);
                var results = session.FindItems(query).Result;
                foreach (var result in results)
                {
                    options.Include(result, PackageItemMode.IncludeDependencies);
                }
                options.PackageItemMode = IncludeDependenciesAsReference ? PackageItemMode.IncludeDependenciesAsReference : PackageItemMode.IncludeDependencies;
                session.PackageItems(options);
                var fileStream = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                session.Model.Save(fileStream);

                fileStream.Close();
                _packageDeploymentManager.CloseSession(session.Name);
            }
            catch (Exception ex)
            {
                ErrorHelper.Write(ex);
            }
        }