private SolutionImportConditions CheckIfImportRequired(XmlNode xImport, string name, Version thisversion)
        {
            log.StartSection("CheckIfImportRequired");
            SolutionImportConditions result = SolutionImportConditions.Create;
            bool overwritesame  = CintXML.GetBoolAttribute(xImport, "OverwriteSameVersion", true);
            bool overwritenewer = CintXML.GetBoolAttribute(xImport, "OverwriteNewerVersion", false);
            CintDynEntityCollection cSolutions = GetExistingSolutions();

            foreach (CintDynEntity cdSolution in cSolutions)
            {
                if (cdSolution.Property("uniquename", "") == name)
                {   // Now we have found the same solution in target environment
                    result = SolutionImportConditions.Update;
                    var existingversion = new Version(cdSolution.Property("version", "1.0.0.0"));
                    log.Log("Existing solution has version: {0}", existingversion);
                    var comparison = thisversion.CompareTo(existingversion);
                    if (!overwritesame && comparison == 0)
                    {
                        result = SolutionImportConditions.Skip;
                        SendLine("Solution {0} {1} already exists in target", name, thisversion);
                    }
                    else if (!overwritenewer && comparison < 0)
                    {
                        result = SolutionImportConditions.Skip;
                        SendLine("Existing solution {0} {1} is newer than {2}", name, existingversion, thisversion);
                    }
                    else if (existingversion == thisversion)
                    {
                        SendLine("Updating version {0}", thisversion);
                    }
                    else
                    {
                        SendLine("Replacing version {0} with {1}", existingversion, thisversion);
                    }
                    break;
                }
            }
            log.Log("Import Condition: {0}", result);
            log.EndSection();
            return(result);
        }
        private ItemImportResult ImportSolutionBlock(XmlNode xBlock)
        {
            log.StartSection("ImportSolutionBlock");
            var importResult = ItemImportResult.None;

            if (xBlock.Name != "SolutionBlock")
            {
                throw new ArgumentOutOfRangeException("Type", xBlock.Name, "Invalid Block type");
            }
            XmlNode xImport = CintXML.FindChild(xBlock, "Import");

            if (xImport != null)
            {
                string name = CintXML.GetAttribute(xBlock, "Name");
                log.Log("Block: {0}", name);
                SendStatus(name, null);
                string type = CintXML.GetAttribute(xImport, "Type");
                SendLine();
                SendLine("Importing solution: {0}", name);

                string filename = GetSolutionFilename(xBlock, name, type);
                var    version  = ExtractVersionFromSolutionZip(filename);
                try
                {
                    ValidatePreReqs(xImport, version);
                    SolutionImportConditions ImportCondition = CheckIfImportRequired(xImport, name, version);
                    if (ImportCondition != SolutionImportConditions.Skip)
                    {
                        if (DoImportSolution(xImport, filename, version))
                        {
                            if (ImportCondition == SolutionImportConditions.Create)
                            {
                                importResult = ItemImportResult.Created;
                            }
                            else
                            {
                                importResult = ItemImportResult.Updated;
                            }
                        }
                        else
                        {
                            importResult = ItemImportResult.Failed;
                            log.Log("Failed during import");
                        }
                        bool publish = CintXML.GetBoolAttribute(xImport, "PublishAll", false);
                        if (publish)
                        {
                            SendLine("Publishing customizations");
                            crmsvc.Execute(new PublishAllXmlRequest());
                        }
                    }
                    else
                    {
                        importResult = ItemImportResult.Skipped;
                        log.Log("Skipped due to import condition");
                    }
                }
                catch (Exception ex)
                {
                    log.Log(ex);
                    importResult = ItemImportResult.Failed;
                    if (stoponerror)
                    {
                        throw;
                    }
                }
            }
            log.EndSection();
            return(importResult);
        }