Exemplo n.º 1
0
    /// <summary>
    /// Initializes the selector.
    /// </summary>
    public void InitSelector()
    {
        uniSelector.IsLiveSite = IsLiveSite;
        uniSelector.AdditionalSearchColumns = "CustomerFirstName,CustomerCompany,CustomerEmail";

        // Set resource prefix if specified
        if (!string.IsNullOrEmpty(ResourcePrefix))
        {
            uniSelector.ResourcePrefix = ResourcePrefix;
        }

        var where = new WhereCondition();

        // Do not filter customer by UserID if both Anonymous and Registered are requested
        if (!DisplayRegisteredCustomers || !DisplayAnonymousCustomers)
        {
            // Add registered customers
            if (DisplayRegisteredCustomers)
            {
                where.WhereNotNull("CustomerUserID");
            }

            // Add anonymous customers
            if (DisplayAnonymousCustomers)
            {
                where.WhereNull("CustomerUserID");
            }
        }

        // Add items which have to be on the list
        if (!string.IsNullOrEmpty(AdditionalItems) && !where.WhereIsEmpty)
        {
            where.Or().WhereIn("CustomerID", AdditionalItems.Split(','));
        }

        // Selected value must be on the list
        if ((CustomerID > 0) && !where.WhereIsEmpty)
        {
            where.Or().WhereEquals("CustomerID", CustomerID);
        }

        uniSelector.WhereCondition = where.ToString(true);
    }
    private WhereCondition GetCustomerCondition()
    {
        var where = new WhereCondition();

        // Add registered customers
        if (DisplayRegisteredCustomers)
        {
            where.WhereNotNull("CustomerUserID");
        }

        // Add anonymous customers
        if (DisplayAnonymousCustomers)
        {
            var condition = new WhereCondition().WhereNull("CustomerUserID")
                            .And()
                            .WhereEquals("CustomerSiteID", CurrentSite.SiteID);

            if (where.WhereIsEmpty)
            {
                where.Where(condition);
            }
            else
            {
                where.Or(condition);
            }
        }

        // Add items which have to be on the list
        if (!string.IsNullOrEmpty(AdditionalItems) && !where.WhereIsEmpty)
        {
            where.Or().WhereIn("CustomerID", AdditionalItems.Split(','));
        }

        // Selected value must be on the list
        if ((CustomerID > 0) && !where.WhereIsEmpty)
        {
            where.Or().WhereEquals("CustomerID", CustomerID);
        }

        return(where);
    }
    /// <summary>
    /// Reloads the data in the selector.
    /// </summary>
    public void ReloadData()
    {
        uniSelector.IsLiveSite = IsLiveSite;
        if (!DisplayNoDataMessage)
        {
            uniSelector.ZeroRowsText = string.Empty;
        }

        // Need to set uni-selector value again after basic form reload
        if (AllowMultipleChoice)
        {
            uniSelector.Value = mMultipleChoiceValue;
        }

        var where = new WhereCondition();

        if (ProductOptionCategoryID > 0)
        {
            where.WhereEquals("SKUOptionCategoryID", ProductOptionCategoryID);
        }
        else
        {
            var productSiteWhere = new WhereCondition();

            // Add global products
            if (DisplayGlobalProducts)
            {
                productSiteWhere.Where(w => w.WhereNull("SKUOptionCategoryID")
                                       .WhereNull("SKUSiteID"));
            }

            // Add site specific products
            if (DisplaySiteProducts)
            {
                productSiteWhere.Or().Where(w => w.WhereNull("SKUOptionCategoryID")
                                            .WhereEquals("SKUSiteID", SiteID));
            }

            where.Where(productSiteWhere);
        }

        // Exclude standard products if needed
        if (!DisplayStandardProducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Product.ToStringRepresentation());
        }

        // Exclude memberships if needed
        if (!DisplayMemberships)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Membership.ToStringRepresentation());
        }

        // Exclude e-products if needed
        if (!DisplayEproducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.EProduct.ToStringRepresentation());
        }

        // Exclude bundles if needed
        if (!DisplayBundles)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Bundle.ToStringRepresentation());
        }

        // Exclude products with product options if needed
        if (DisplayOnlyProductsWithoutOptions)
        {
            where.WhereNotIn("SKUID", new IDQuery <SKUOptionCategoryInfo>("SKUID"));
        }

        if (DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            var optionsSiteWhere = new WhereCondition();

            // Add global options
            if (DisplayGlobalOptions)
            {
                optionsSiteWhere.Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                       .WhereNull("SKUSiteID"));
            }

            // Add site specific options
            if (DisplaySiteOptions)
            {
                optionsSiteWhere.Or().Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                            .WhereEquals("SKUSiteID", SiteID));
            }

            where.Or().Where(optionsSiteWhere);
            where = new WhereCondition().Where(where);
        }

        // Filter out only enabled items
        if (DisplayOnlyEnabled)
        {
            where.WhereTrue("SKUEnabled");
        }

        if (!DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            where.WhereNull("SKUOptionCategoryID");
        }

        if (DisplayProductVariants)
        {
            // Alias for COM_SKU
            var parents = new QuerySourceTable("COM_SKU", "parentIDs");

            // Select IDs of all products that are not parents of variants
            var ids = new IDQuery <SKUInfo>()
                      .Columns(new QueryColumn("COM_SKU.SKUID"))
                      .Source(s => s.LeftJoin(parents, "COM_SKU.SKUID", "parentIDs.SKUParentSKUID"))
                      .Where(new WhereCondition().WhereNull("parentIDs.SKUID"));

            where.WhereIn("SKUID", ids);
        }
        else
        {
            // Do not display variants
            where.WhereNull("SKUParentSKUID");
        }

        // Add items which have to be on the list
        var additionalList = AdditionalItems.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

        if (additionalList.Length > 0)
        {
            var ids = ValidationHelper.GetIntegers(additionalList, 0);
            where.Or().WhereIn("SKUID", ids);
        }

        // Selected value must be on the list
        if (SKUID > 0)
        {
            where.Or().WhereEquals("SKUID", SKUID);
        }

        uniSelector.WhereCondition = where.ToString(true);
    }
Exemplo n.º 4
0
        internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder)
        {
            string targetFolder = Path.Combine(targetTestAsset.Path, this.Name);

            Directory.CreateDirectory(targetFolder);

            string targetProjectPath = Path.Combine(targetFolder, this.Name + ".csproj");

            string sourceProject;
            string sourceProjectBase = Path.Combine(testProjectsSourceFolder, "ProjectConstruction");

            if (IsSdkProject)
            {
                sourceProject = Path.Combine(sourceProjectBase, "SdkProject", "SdkProject.csproj");
            }
            else
            {
                sourceProject = Path.Combine(sourceProjectBase, "NetFrameworkProject", "NetFrameworkProject.csproj");
            }

            //  Copy any additional files from template
            foreach (var file in Directory.GetFiles(Path.GetDirectoryName(sourceProject)))
            {
                if (file != sourceProject)
                {
                    File.Copy(file, Path.Combine(targetFolder, Path.GetFileName(file)));
                }
            }

            var projectXml = XDocument.Load(sourceProject);

            var ns = projectXml.Root.Name.Namespace;

            var propertyGroup = projectXml.Root.Elements(ns + "PropertyGroup").First();

            var packageReferenceItemGroup = projectXml.Root.Elements(ns + "ItemGroup")
                                            .FirstOrDefault(itemGroup => itemGroup.Elements(ns + "PackageReference").Count() > 0);

            if (packageReferenceItemGroup == null)
            {
                packageReferenceItemGroup = projectXml.Root.Elements(ns + "ItemGroup")
                                            .FirstOrDefault();
            }
            if (packageReferenceItemGroup == null)
            {
                packageReferenceItemGroup = new XElement(ns + "ItemGroup");
                projectXml.Root.Add(packageReferenceItemGroup);
            }

            foreach (TestPackageReference packageReference in PackageReferences)
            {
                var packageReferenceElement = new XElement(ns + "PackageReference",
                                                           new XAttribute("Include", packageReference.ID));
                if (packageReference.Version != null)
                {
                    packageReferenceElement.Add(new XAttribute("Version", packageReference.Version));
                }
                if (packageReference.PrivateAssets != null)
                {
                    packageReferenceElement.Add(new XAttribute("PrivateAssets", packageReference.PrivateAssets));
                }
                packageReferenceItemGroup.Add(packageReferenceElement);
            }

            foreach (TestPackageReference dotnetCliToolReference in DotNetCliToolReferences)
            {
                packageReferenceItemGroup.Add(new XElement(ns + "DotNetCliToolReference",
                                                           new XAttribute("Include", $"{dotnetCliToolReference.ID}"),
                                                           new XAttribute("Version", $"{dotnetCliToolReference.Version}")));
            }

            //  If targeting .NET Framework and a required targeting pack isn't installed, add a
            //  PackageReference to get the targeting pack from a NuGet package
            if (NeedsReferenceAssemblyPackages())
            {
                packageReferenceItemGroup.Add(new XElement(ns + "PackageReference",
                                                           new XAttribute("Include", $"Microsoft.NETFramework.ReferenceAssemblies"),
                                                           new XAttribute("Version", $"1.0.0-alpha-5")));

                propertyGroup.Add(new XElement(ns + "RestoreAdditionalProjectSources", "$(RestoreAdditionalProjectSources);https://dotnet.myget.org/F/roslyn-tools/api/v3/index.json"));
            }

            var targetFrameworks = IsSdkProject ? TargetFrameworks.Split(';') : new[] { "net" };

            if (IsSdkProject)
            {
                if (this.TargetFrameworks.Contains(";"))
                {
                    propertyGroup.Add(new XElement(ns + "TargetFrameworks", this.TargetFrameworks));
                }
                else
                {
                    propertyGroup.Add(new XElement(ns + "TargetFramework", this.TargetFrameworks));
                }

                if (!string.IsNullOrEmpty(this.RuntimeFrameworkVersion))
                {
                    propertyGroup.Add(new XElement(ns + "RuntimeFrameworkVersion", this.RuntimeFrameworkVersion));
                }

                if (!string.IsNullOrEmpty(this.RuntimeIdentifier))
                {
                    propertyGroup.Add(new XElement(ns + "RuntimeIdentifier", this.RuntimeIdentifier));
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(this.TargetFrameworkProfile))
                {
                    propertyGroup.Add(new XElement(ns + "TargetFrameworkProfile", this.TargetFrameworkProfile));

                    //  To construct an accurate PCL project file, we must modify the import of the CSharp targets;
                    //    building/testing the SDK requires a VSDev command prompt which sets 'VSINSTALLDIR'
                    var importGroup = projectXml.Root.Elements(ns + "Import").Last();
                    importGroup.Attribute("Project").Value = "$(VSINSTALLDIR)\\MSBuild\\Microsoft\\Portable\\$(TargetFrameworkVersion)\\Microsoft.Portable.CSharp.targets";
                }

                propertyGroup.Element(ns + "TargetFrameworkVersion").SetValue(this.TargetFrameworkVersion);
            }

            foreach (var additionalProperty in AdditionalProperties)
            {
                propertyGroup.Add(new XElement(ns + additionalProperty.Key, additionalProperty.Value));
            }

            if (AdditionalItems.Any())
            {
                foreach (var additionalItem in AdditionalItems)
                {
                    var additionalItemGroup = projectXml.Root.Elements(ns + "ItemGroup").FirstOrDefault();
                    if (additionalItemGroup == null)
                    {
                        additionalItemGroup = new XElement(ns + "ItemGroup");
                        projectXml.Root.Add(packageReferenceItemGroup);
                    }
                    additionalItemGroup.Add(new XElement(
                                                ns + additionalItem.Key,
                                                new XAttribute("Include", additionalItem.Value)));
                }
            }

            if (this.IsExe)
            {
                propertyGroup.Element(ns + "OutputType").SetValue("Exe");
            }

            if (this.ReferencedProjects.Any())
            {
                var projectReferenceItemGroup = projectXml.Root.Elements(ns + "ItemGroup")
                                                .FirstOrDefault(itemGroup => itemGroup.Elements(ns + "ProjectReference").Count() > 0);
                if (projectReferenceItemGroup == null)
                {
                    projectReferenceItemGroup = new XElement(ns + "ItemGroup");
                    packageReferenceItemGroup.AddBeforeSelf(projectReferenceItemGroup);
                }
                foreach (var referencedProject in ReferencedProjects)
                {
                    projectReferenceItemGroup.Add(new XElement(ns + "ProjectReference",
                                                               new XAttribute("Include", $"../{referencedProject.Name}/{referencedProject.Name}.csproj")));
                }
            }

            if (this.References.Any())
            {
                var referenceItemGroup = projectXml.Root.Elements(ns + "ItemGroup")
                                         .FirstOrDefault(itemGroup => itemGroup.Elements(ns + "Reference").Count() > 0);
                if (referenceItemGroup == null)
                {
                    referenceItemGroup = new XElement(ns + "ItemGroup");
                    packageReferenceItemGroup.AddBeforeSelf(referenceItemGroup);
                }

                foreach (var reference in References)
                {
                    referenceItemGroup.Add(new XElement(ns + "Reference",
                                                        new XAttribute("Include", reference)));
                }
            }

            if (this.CopyFilesTargets.Any())
            {
                foreach (var copyFilesTarget in CopyFilesTargets)
                {
                    var target = new XElement(ns + "Target",
                                              new XAttribute("Name", copyFilesTarget.TargetName),
                                              new XAttribute("AfterTargets", copyFilesTarget.TargetToRunAfter));

                    target.Add(new XElement(ns + "Copy",
                                            new XAttribute("SourceFiles", copyFilesTarget.SourceFiles),
                                            new XAttribute("DestinationFolder", copyFilesTarget.Destination)));

                    projectXml.Root.Add(target);
                }
            }

            using (var file = File.CreateText(targetProjectPath))
            {
                projectXml.Save(file);
            }

            if (SourceFiles.Count == 0)
            {
                string source;

                if (this.IsExe)
                {
                    source =
                        @"using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(""Hello World!"");
";

                    foreach (var dependency in this.ReferencedProjects)
                    {
                        source += $"        Console.WriteLine({dependency.Name}.{dependency.Name}Class.Name);" + Environment.NewLine;
                        source += $"        Console.WriteLine({dependency.Name}.{dependency.Name}Class.List);" + Environment.NewLine;
                    }

                    source +=
                        @"    }
}";
                }
                else
                {
                    source =
                        $@"using System;
using System.Collections.Generic;

namespace {this.Name}
{{
    public class {this.Name}Class
    {{
        public static string Name {{ get {{ return ""{this.Name}""; }} }}
        public static List<string> List {{ get {{ return null; }} }}
";
                    foreach (var dependency in this.ReferencedProjects)
                    {
                        source += $"        public string {dependency.Name}Name {{ get {{ return {dependency.Name}.{dependency.Name}Class.Name; }} }}" + Environment.NewLine;
                        source += $"        public List<string> {dependency.Name}List {{ get {{ return {dependency.Name}.{dependency.Name}Class.List; }} }}" + Environment.NewLine;
                    }

                    source +=
                        @"    }
}";
                }
                string sourcePath = Path.Combine(targetFolder, this.Name + ".cs");

                File.WriteAllText(sourcePath, source);
            }
            else
            {
                foreach (var kvp in SourceFiles)
                {
                    File.WriteAllText(Path.Combine(targetFolder, kvp.Key), kvp.Value);
                }
            }

            foreach (var kvp in EmbeddedResources)
            {
                File.WriteAllText(Path.Combine(targetFolder, kvp.Key), kvp.Value);
            }
        }
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="Microsoft.Rest.ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (AdditionalItems != null)
     {
         AdditionalItems.Validate();
     }
     if (AdditionalProperties != null)
     {
         AdditionalProperties.Validate();
     }
     if (AllOf != null)
     {
         foreach (var element in AllOf)
         {
             if (element != null)
             {
                 element.Validate();
             }
         }
     }
     if (AnyOf != null)
     {
         foreach (var element1 in AnyOf)
         {
             if (element1 != null)
             {
                 element1.Validate();
             }
         }
     }
     if (DefaultProperty != null)
     {
         DefaultProperty.Validate();
     }
     if (Definitions != null)
     {
         foreach (var valueElement in Definitions.Values)
         {
             if (valueElement != null)
             {
                 valueElement.Validate();
             }
         }
     }
     if (Dependencies != null)
     {
         foreach (var valueElement1 in Dependencies.Values)
         {
             if (valueElement1 != null)
             {
                 valueElement1.Validate();
             }
         }
     }
     if (EnumProperty != null)
     {
         foreach (var element2 in EnumProperty)
         {
             if (element2 != null)
             {
                 element2.Validate();
             }
         }
     }
     if (Example != null)
     {
         Example.Validate();
     }
     if (Items != null)
     {
         Items.Validate();
     }
     if (Not != null)
     {
         Not.Validate();
     }
     if (OneOf != null)
     {
         foreach (var element3 in OneOf)
         {
             if (element3 != null)
             {
                 element3.Validate();
             }
         }
     }
     if (PatternProperties != null)
     {
         foreach (var valueElement2 in PatternProperties.Values)
         {
             if (valueElement2 != null)
             {
                 valueElement2.Validate();
             }
         }
     }
     if (Properties != null)
     {
         foreach (var valueElement3 in Properties.Values)
         {
             if (valueElement3 != null)
             {
                 valueElement3.Validate();
             }
         }
     }
 }