public void Map()
        {
            var random = new Random();
            var expected = new Dictionary<string, object>();
            expected.Add("Id", random.Next());
            expected.Add("Stringy", Guid.NewGuid().ToString());
            expected.Add("Wee", Guid.NewGuid());

            var returned = expected.Map();

            Assert.IsNotNull(returned);
            Assert.AreEqual(expected["Id"], returned.Id);
            Assert.AreEqual(expected["Stringy"], returned.Stringy);
            Assert.AreEqual(expected["Wee"], returned.Wee);
        }
        public void MapDictionary()
        {
            var random = new Random();
            var expected = new FillObject()
            {
                Id = random.Next(),
                Band = Guid.NewGuid().ToString(),
                Song = Guid.NewGuid(),
                Ecode = Encoding.BigEndianUnicode,
                NullableByte = null,
                NullableEnum = null,
                SuperEnum = HappyLand.MarioLand,
                TheGuid = null,
            };

            var dic = new Dictionary<string, object>();
            dic.Add("Id", expected.Id);
            dic.Add("Band", expected.Band);
            dic.Add("Song", expected.Song);
            dic.Add("Ecode", expected.Ecode);
            dic.Add("NullableByte", expected.NullableByte);
            dic.Add("NullableEnum", expected.NullableEnum);
            dic.Add("SuperEnum", expected.SuperEnum);
            dic.Add("TheGuid", expected.TheGuid);

            var returned = dic.Map<FillObject>();

            Assert.IsNotNull(returned);
            Assert.AreEqual(expected.Id, returned.Id);
            Assert.AreEqual(expected.Band, returned.Band);
            Assert.AreEqual(expected.Song, returned.Song);
            Assert.AreEqual(expected.Ecode, returned.Ecode);
            Assert.AreEqual(expected.NullableByte, returned.NullableByte);
            Assert.AreEqual(expected.SuperEnum, returned.SuperEnum);
            Assert.AreEqual(expected.NullableEnum, returned.NullableEnum);
            Assert.AreEqual(expected.TheGuid, returned.TheGuid);
        }
Example #3
0
        public List<PostmanRequest> GetRequests(Postman request, string parentId, IEnumerable<Operation> operations)
        {
            var ret = new List<PostmanRequest>();
            var feature = HostContext.GetPlugin<PostmanFeature>();

            var headers = feature.Headers ?? ("Accept: " + MimeTypes.Json);

            var httpRes = Response as IHttpResponse;
            if (httpRes != null)
            {
                if (request.ssopt != null
                    || request.sspid != null
                    || request.ssid != null)
                {
                    if (feature.EnableSessionExport != true)
                    {
                        throw new ArgumentException("PostmanFeature.EnableSessionExport is not enabled");
                    }
                }

                if (request.ssopt != null)
                {
                    Request.AddSessionOptions(request.ssopt);
                }
                if (request.sspid != null)
                {
                    httpRes.Cookies.AddPermanentCookie(SessionFeature.PermanentSessionId, request.sspid);
                }
                if (request.ssid != null)
                {
                    httpRes.Cookies.AddSessionCookie(SessionFeature.SessionId, request.ssid,
                        (HostContext.Config.OnlySendSessionCookiesSecurely && Request.IsSecureConnection));
                }
            }

            foreach (var op in operations)
            {
                if (!HostContext.Metadata.IsVisible(base.Request, op))
                    continue;

                var allVerbs = op.Actions.Concat(
                    op.Routes.SelectMany(x => x.Verbs))
                        .SelectMany(x => x == ActionContext.AnyAction
                        ? feature.DefaultVerbsForAny
                        : new List<string> { x })
                    .ToHashSet();

                var propertyTypes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
                op.RequestType.GetSerializableFields()
                    .Each(x => propertyTypes[x.Name] = x.FieldType.AsFriendlyName(feature));
                op.RequestType.GetSerializableProperties()
                    .Each(x => propertyTypes[x.Name] = x.PropertyType.AsFriendlyName(feature));

                foreach (var route in op.Routes)
                {
                    var routeVerbs = route.Verbs.Contains(ActionContext.AnyAction)
                        ? feature.DefaultVerbsForAny.ToArray()
                        : route.Verbs;

                    var restRoute = route.ToRestRoute();

                    foreach (var verb in routeVerbs)
                    {
                        allVerbs.Remove(verb); //exclude handled verbs

                        var routeData = restRoute.QueryStringVariables
                            .Map(x => new PostmanData
                            {
                                key = x,
                                value = "",
                                type = "text",
                            })
                            .ApplyPropertyTypes(propertyTypes);

                        ret.Add(new PostmanRequest
                        {
                            collectionId = parentId,
                            id = SessionExtensions.CreateRandomSessionId(),
                            method = verb,
                            url = Request.GetBaseUrl().CombineWith(restRoute.Path.ToPostmanPathVariables()),
                            name = GetName(feature, request, op.RequestType, restRoute.Path),
                            description = op.RequestType.GetDescription(),
                            pathVariables = !verb.HasRequestBody()
                                ? restRoute.Variables.Concat(routeData.Select(x => x.key))
                                    .ApplyPropertyTypes(propertyTypes)
                                : null,
                            data = verb.HasRequestBody()
                                ? routeData
                                : null,
                            dataMode = "params",
                            headers = headers,
                            version = 2,
                            time = DateTime.UtcNow.ToUnixTimeMs(),
                        });
                    }
                }

                var emptyRequest = op.RequestType.CreateInstance();
                var virtualPath = emptyRequest.ToReplyUrlOnly();

                var requestParams = propertyTypes
                    .Map(x => new PostmanData
                    {
                        key = x.Key,
                        value = x.Value,
                        type = "text",
                    });

                ret.AddRange(allVerbs.Select(verb =>
                    new PostmanRequest
                    {
                        collectionId = parentId,
                        id = SessionExtensions.CreateRandomSessionId(),
                        method = verb,
                        url = Request.GetBaseUrl().CombineWith(virtualPath),
                        pathVariables = !verb.HasRequestBody()
                            ? requestParams.Select(x => x.key)
                                .ApplyPropertyTypes(propertyTypes)
                            : null,
                        name = GetName(feature, request, op.RequestType, virtualPath),
                        description = op.RequestType.GetDescription(),
                        data = verb.HasRequestBody()
                            ? requestParams
                            : null,
                        dataMode = "params",
                        headers = headers,
                        version = 2,
                        time = DateTime.UtcNow.ToUnixTimeMs(),
                    }));
            }

            return ret;
        }
Example #4
0
        static void ProcessDirectory(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents,
            List<string> defaultFeatureComponents, List<string> autoGeneratedComponents, XElement parent)
        {
            XElement dirItem = AddDir(parent, wDir);

            if (wDir.Files.Count() == 0 && wDir.Shortcuts.Count() == 0 && wDir.Dirs.Count() == 0 && wDir.Permissions.Count() == 0)
            {
                var existingCompElement = dirItem.Elements("Component");

                if (existingCompElement.Count() == 0)
                {
                    string compId = wDir.Id + ".EmptyDirectory";

                    if (wDir.Feature != null)
                    {
                        featureComponents.Map(wDir.Feature, compId);
                    }
                    else
                    {
                        defaultFeatureComponents.Add(compId);
                    }

                    dirItem.AddElement(
                        new XElement("Component",
                            new XAttribute("Id", compId),
                            new XAttribute("Guid", WixGuid.NewGuid(compId))));
                }


                //insert MergeModules
                ProcessMergeModules(wDir, dirItem, featureComponents, defaultFeatureComponents);

                foreach (Dir subDir in wDir.Dirs)
                    ProcessDirectory(subDir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirItem);

                return;
            }

            if (wDir.Feature != null)
            {
                string compId = "Component." + wDir.Id;
                featureComponents.Map(wDir.Feature, compId);
                dirItem.AddElement(
                        new XElement("Component",
                            new XAttribute("Id", compId),
                            new XAttribute("Guid", WixGuid.NewGuid(compId))));
            }

            #region Process Files

            //insert files in the last leaf directory node
            foreach (File wFile in wDir.Files)
            {
                string fileId = wFile.Id;
                string compId = "Component." + wFile.Id;

                if (wFile.Feature != null)
                {
                    featureComponents.Map(wFile.Feature, compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                    new XElement("Component",
                        new XAttribute("Id", compId),
                        new XAttribute("Guid", WixGuid.NewGuid(compId))));

                if (wFile.Condition != null)
                    comp.AddElement(
                        new XElement("Condition", new XCData(wFile.Condition.ToCData()))
                            .AddAttributes(wFile.Condition.Attributes));

                XElement file = comp.AddElement(
                    new XElement("File",
                        new XAttribute("Id", fileId),
                        new XAttribute("Source", Utils.PathCombine(wProject.SourceBaseDir, wFile.Name)))
                        .AddAttributes(wFile.Attributes));

                if (wFile.ServiceInstaller != null)
                    comp.Add(wFile.ServiceInstaller.ToXml(wProject));

                if (wFile is Assembly && (wFile as Assembly).RegisterInGAC)
                {
                    file.Add(new XAttribute("KeyPath", "yes"),
                             new XAttribute("Assembly", ".net"),
                             new XAttribute("AssemblyManifest", fileId),
                             new XAttribute("ProcessorArchitecture", ((Assembly)wFile).ProcessorArchitecture.ToString()));
                }

                //insert file associations
                foreach (FileAssociation wFileAssociation in wFile.Associations)
                {
                    XElement progId;
                    comp.Add(progId = new XElement("ProgId",
                                          new XAttribute("Id", wFileAssociation.Extension + ".file"),
                                          new XAttribute("Advertise", wFileAssociation.Advertise.ToYesNo()),
                                          new XAttribute("Description", wFileAssociation.Description),
                                          new XElement("Extension",
                                              new XAttribute("Id", wFileAssociation.Extension),
                                              new XAttribute("ContentType", wFileAssociation.ContentType),
                                              new XElement("Verb",
                                                  wFileAssociation.Advertise ?
                                                     new XAttribute("Sequence", wFileAssociation.SequenceNo) :
                                                     new XAttribute("TargetFile", fileId),
                                                  new XAttribute("Id", wFileAssociation.Command),
                                                  new XAttribute("Command", wFileAssociation.Command),
                                                  new XAttribute("Argument", wFileAssociation.Arguments)))));

                    if (wFileAssociation.Icon != null)
                    {
                        progId.Add(
                            new XAttribute("Icon", wFileAssociation.Icon != "" ? wFileAssociation.Icon : fileId),
                            new XAttribute("IconIndex", wFileAssociation.IconIndex));
                    }
                }

                //insert file owned shortcuts
                foreach (Shortcut wShortcut in wFile.Shortcuts)
                {
                    string locationDirId;

                    if (wShortcut.Location.IsEmpty())
                    {
                        locationDirId = wDir.Id;
                    }
                    else
                    {
                        Dir locationDir = wProject.FindDir(wShortcut.Location);

                        if (locationDir != null)
                        {
                            locationDirId = locationDir.Id;
                        }
                        else
                        {
                            if (!autogeneratedShortcutLocations.ContainsKey(wShortcut.Location))
                                autogeneratedShortcutLocations.Add(wShortcut.Location, wShortcut.Feature);

                            locationDirId = wShortcut.Location.Expand();
                        }
                    }

                    var shortcutElement =
                        new XElement("Shortcut",
                            new XAttribute("Id", "Shortcut." + wFile.Id + "." + wShortcut.Id),
                            new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : locationDirId),
                            new XAttribute("Directory", locationDirId),
                            new XAttribute("Name", wShortcut.Name.IsNullOrEmpty() ? IO.Path.GetFileNameWithoutExtension(wFile.Name) : wShortcut.Name + ".lnk"));

                    wShortcut.EmitAttributes(shortcutElement);

                    file.Add(shortcutElement);
                }

                //insert file related IIS virtual directories
                InsertIISElements(dirItem, comp, wFile.IISVirtualDirs, wProject);

                //insert file owned permissions
                ProcessFilePermissions(wProject, wFile, file);
            }

            #endregion

            #region Process Shorcuts

            //insert directory owned shortcuts
            foreach (Shortcut wShortcut in wDir.Shortcuts)
            {
                string compId = wShortcut.Id;
                if (wShortcut.Feature != null)
                {
                    if (!featureComponents.ContainsKey(wShortcut.Feature))
                        featureComponents[wShortcut.Feature] = new List<string>();

                    featureComponents[wShortcut.Feature].Add(compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                   new XElement("Component",
                       new XAttribute("Id", compId),
                       new XAttribute("Guid", WixGuid.NewGuid(compId))));

                if (wShortcut.Condition != null)
                    comp.AddElement(
                        new XElement("Condition", wShortcut.Condition.ToCData())
                            .AddAttributes(wShortcut.Condition.Attributes));

                XElement sc;
                sc = comp.AddElement(
                   new XElement("Shortcut",
                       new XAttribute("Id", wDir.Id + "." + wShortcut.Id),
                    //new XAttribute("Directory", wDir.Id), //not needed for Wix# as this attributed is required only if the shortcut is not nested under a Component element.
                       new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : GetShortcutWorkingDirectopry(wShortcut.Target)),
                       new XAttribute("Target", wShortcut.Target),
                       new XAttribute("Arguments", wShortcut.Arguments),
                       new XAttribute("Name", wShortcut.Name + ".lnk")));

                wShortcut.EmitAttributes(sc);
            }


            #endregion

            //insert MergeModules
            ProcessMergeModules(wDir, dirItem, featureComponents, defaultFeatureComponents);

            ProcessDirPermissions(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem);

            foreach (Dir subDir in wDir.Dirs)
                ProcessDirectory(subDir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirItem);
        }
Example #5
0
        static void ProcessDirectoryFiles(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, XElement dirItem)
        {
            //insert files in the last leaf directory node
            foreach (File wFile in wDir.Files)
            {
                string fileId = wFile.Id;
                string compId = "Component." + wFile.Id;

                if (wFile.Feature != null)
                {
                    featureComponents.Map(wFile.Feature, compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                    new XElement("Component",
                        new XAttribute("Id", compId),
                        new XAttribute("Guid", WixGuid.NewGuid(compId))));

                if (wFile.Condition != null)
                    comp.AddElement(
                        new XElement("Condition", new XCData(wFile.Condition.ToCData()))
                            .AddAttributes(wFile.Condition.Attributes));

                XElement file = comp.AddElement(
                    new XElement("File",
                        new XAttribute("Id", fileId),
                        new XAttribute("Source", Utils.PathCombine(wProject.SourceBaseDir, wFile.Name)))
                        .AddAttributes(wFile.Attributes));

                if (wFile.ServiceInstaller != null)
                    comp.Add(wFile.ServiceInstaller.ToXml(wProject));

                if (wFile is Assembly && (wFile as Assembly).RegisterInGAC)
                {
                    file.Add(new XAttribute("KeyPath", "yes"),
                             new XAttribute("Assembly", ".net"),
                             new XAttribute("AssemblyManifest", fileId),
                             new XAttribute("ProcessorArchitecture", ((Assembly)wFile).ProcessorArchitecture.ToString()));
                }

                wFile.DriverInstaller.Compile(wProject, comp);

                //insert file associations
                foreach (FileAssociation wFileAssociation in wFile.Associations)
                {
                    XElement progId;
                    comp.Add(progId = new XElement("ProgId",
                                          new XAttribute("Id", wFileAssociation.Extension + ".file"),
                                          new XAttribute("Advertise", wFileAssociation.Advertise.ToYesNo()),
                                          new XAttribute("Description", wFileAssociation.Description),
                                          new XElement("Extension",
                                              new XAttribute("Id", wFileAssociation.Extension),
                                              new XAttribute("ContentType", wFileAssociation.ContentType),
                                              new XElement("Verb",
                                                  wFileAssociation.Advertise ?
                                                     new XAttribute("Sequence", wFileAssociation.SequenceNo) :
                                                     new XAttribute("TargetFile", fileId),
                                                  new XAttribute("Id", wFileAssociation.Command),
                                                  new XAttribute("Command", wFileAssociation.Command),
                                                  new XAttribute("Argument", wFileAssociation.Arguments)))));

                    if (wFileAssociation.Icon != null)
                    {
                        progId.Add(
                            new XAttribute("Icon", wFileAssociation.Icon != "" ? wFileAssociation.Icon : fileId),
                            new XAttribute("IconIndex", wFileAssociation.IconIndex));
                    }
                }

                //insert file owned shortcuts
                foreach (Shortcut wShortcut in wFile.Shortcuts)
                {
                    string locationDirId;

                    if (wShortcut.Location.IsEmpty())
                    {
                        locationDirId = wDir.Id;
                    }
                    else
                    {
                        Dir locationDir = wProject.FindDir(wShortcut.Location);

                        if (locationDir != null)
                        {
                            locationDirId = locationDir.Id;
                        }
                        else
                        {
                            if (!autogeneratedShortcutLocations.ContainsKey(wShortcut.Location))
                                autogeneratedShortcutLocations.Add(wShortcut.Location, wShortcut.Feature);

                            locationDirId = wShortcut.Location.Expand();
                        }
                    }

                    var shortcutElement =
                        new XElement("Shortcut",
                            new XAttribute("Id", "Shortcut." + wFile.Id + "." + wShortcut.Id),
                            new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : locationDirId),
                            new XAttribute("Directory", locationDirId),
                            new XAttribute("Name", wShortcut.Name.IsNullOrEmpty() ? IO.Path.GetFileNameWithoutExtension(wFile.Name) : wShortcut.Name + ".lnk"));

                    wShortcut.EmitAttributes(shortcutElement);

                    file.Add(shortcutElement);
                }

                //insert file related IIS virtual directories
                InsertIISElements(dirItem, comp, wFile.IISVirtualDirs, wProject);

                //insert file owned permissions
                ProcessFilePermissions(wProject, wFile, file);
            }
        }
Example #6
0
        static void ProcessDirectory(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents,
            List<string> defaultFeatureComponents, List<string> autoGeneratedComponents, XElement parent)
        {
            XElement dirItem = AddDir(parent, wDir);

            bool isEmptyDir = wDir.Files.None() &&
                              wDir.Shortcuts.None() &&
                              wDir.Dirs.None() &&
                              wDir.MergeModules.None() &&
                              wDir.Permissions.None() &&
                              wDir.ODBCDataSources.None();

            if (isEmptyDir)
            {
                var existingCompElement = dirItem.Elements("Component");

                if (existingCompElement.Count() == 0)
                {
                    string compId = wDir.Id + ".EmptyDirectory";

                    if (wDir.Feature != null)
                    {
                        featureComponents.Map(wDir.Feature, compId);
                    }
                    else
                    {
                        defaultFeatureComponents.Add(compId);
                    }

                    dirItem.AddElement(
                        new XElement("Component",
                            new XAttribute("Id", compId),
                            new XAttribute("Guid", WixGuid.NewGuid(compId))));
                }
            }
            else
            {
                if (wDir.Feature != null)
                {
                    string compId = "Component." + wDir.Id;
                    featureComponents.Map(wDir.Feature, compId);
                    dirItem.AddElement(
                            new XElement("Component",
                                new XAttribute("Id", compId),
                                new XAttribute("Guid", WixGuid.NewGuid(compId))));
                }

                ProcessDirectoryFiles(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem);
                ProcessDirectoryShortcuts(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem);
                ProcessOdbcSources(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem);
                ProcessMergeModules(wDir, dirItem, featureComponents, defaultFeatureComponents);
                ProcessDirPermissions(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem);

                foreach (Dir subDir in wDir.Dirs)
                    ProcessDirectory(subDir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirItem);
            }
        }
Example #7
0
        public void DictionaryBaseTest()
        {
            var map = MapFactory.CreateMapRule<InnType, OutType2>();

            //Adding mapping rule for field that does not match on name.
            map.GetRule<InnType, OutType2>()
                .Add(type => type.DesimalValue, type => type.DesimalValue1, BasicTypes.Convertable);
            var target = new Dictionary<int, InnType>
            {
                {
                    1,
                    new InnType
                    {
                        DateTimeValue = DateTime.Now,
                        MyInts = new List<int>(),
                        StringValue = "test1",
                        DesimalValue = 1
                    }
                },
                {
                    2,
                    new InnType
                    {
                        DateTimeValue = DateTime.Now,
                        MyInts = new List<int>(),
                        StringValue = "test1",
                        DesimalValue = 2
                    }
                }                
            };
            var result = target.Map<int, InnType>().To<string, OutType2>(map);
            Assert.AreEqual(2, result.Count);
        }
Example #8
0
 public void MapWithDictionary()
 {
     var dict = new Dictionary<string, object> { { "Id", null }, { "Foo", "Bar" } };
     var bar = dict.Map(self =>
         {
             var dictMapper = Fn.Func((string name) => self[name] ?? "");
             return new
             {
                 Id = dictMapper("Id"),
                 Foo = dictMapper("Foo")
             };
         });
     Assert.AreEqual("", bar.Id);
     Assert.AreEqual("Bar", bar.Foo);
 }
Example #9
0
        public void RequestTestNulls()
        {
            var Request = new Dictionary<string, object> { { "id", 12 }, { "foo", null } };

            var request = Request.Map(self => new
            {
                id = self["id"] ?? 0,
                foo = self["foo"] ?? ""
            });

            Assert.AreEqual(12, request.id);
            Assert.AreEqual("", request.foo);
        }