Example #1
0
        public GetLocation GetLocation(int yearlyMaintenanceId)
        {
            GetLocation getLocation = new GetLocation();
            IEnumerable <GetLocation> data;

            data = (from yearly in _ObjContext.YearlyMaintainence
                    join address in _ObjContext.AAYHSContactAddresses on yearly.LocationAddressId equals address.AAYHSContactAddressId
                    where yearly.YearlyMaintainenceId == yearlyMaintenanceId
                    select new GetLocation
            {
                AAYHSContactAddressId = address.AAYHSContactAddressId,
                Name = yearly.Location,
                Address = address.Address,
                City = address.City,
                StateId = address.StateId,
                ZipCode = address.ZipCode,
                Phone = address.Phone
            });

            if (data.Count() != 0)
            {
                getLocation = data.FirstOrDefault();
            }
            return(getLocation);
        }
Example #2
0
 public static void Prepare(InitLocation _initLoc, GetLocation _getLoc, GetLocation _getLocLat, GetLocation _getLocLong)
 {
     initLoc    = _initLoc;
     getLoc     = _getLoc;
     getLocLat  = _getLocLat;
     getLocLong = _getLocLong;
 }
        private async void LocateNow()
        {
            CurrentLocation = await GetLocation.LocateMobile();

            var OpenStreetMapAPI = new OpenStreetMapAPI();

            MyAdress = await OpenStreetMapAPI.GetCurrentAdressAsync(CurrentLocation);
        }
Example #4
0
 public View_Keyword(IUser user, string keyword)
 {
     this.user    = user;
     this.keyword = keyword;
     mostDetails  = new KeywordTweetsDetails(keyword);
     userDetails  = new KeywordUserDetails(keyword);
     location     = new GetLocation();
     hashtags     = new GetUserMostHashtags(this.user);
 }
Example #5
0
        public View_Connections(IUser user)
        {
            this.user = user;
            ToDate    = DateTime.Today;
            FromDate  = DateTime.Today.AddMonths(-1);

            location     = new GetLocation();
            userDetails  = new GetUserDetails(this.user);
            profileGraph = new Graph(user, FromDate, ToDate);
        }
Example #6
0
    // Use this for initialization
    void Start()
    {
        myGPS = GetComponent <GetLocation>();

        posX = (7.008536f - lon) * multiX;
        posZ = (50.935340f - lat) * multiY;
        print("7.008536f" + lon);

        playername = PlayerPrefs.GetString("playername");
        playercode = PlayerPrefs.GetString("playercode");
        playerteam = PlayerPrefs.GetInt("playerteam");

        //richtigen playercharcter anzeigen
        Invader.SetActive(false);
        Pacman.SetActive(false);
        Galaga.SetActive(false);

        switch (playerteam)
        {
        case 1:
            Invader.SetActive(true);
            Pacman.SetActive(false);
            Galaga.SetActive(false);
            break;

        case 2:
            Pacman.SetActive(true);
            Invader.SetActive(false);
            Galaga.SetActive(false);
            break;

        case 3:
            Pacman.SetActive(false);
            Invader.SetActive(false);
            Galaga.SetActive(true);
            break;

        default:
            Debug.Log("Incorrect intelligence level.");
            break;
        }

        StartCoroutine(SendPos());
    }
Example #7
0
        public async Task <GetLocation> GetlocationForEdit(NullableIdDto <long> input)
        {
            var output = new GetLocation();
            var query  = _locationRepository
                         .GetAll().Where(p => p.Id == input.Id);

            if (query.Count() > 0)
            {
                var location = (from a in query select new LocationListDto {
                    Id = a.Id, LocationName = a.LocationName, LocationCode = a.LocationCode, CityId = a.citys.Id, CityName = a.citys.CityName
                }).FirstOrDefault();
                output = new GetLocation
                {
                    Locations = location
                };
            }

            return(output);
        }
Example #8
0
        /// </remarks>
        public override void ExecuteCRMWorkFlowActivity(CodeActivityContext executionContext, LocalWorkflowContext crmWorkflowContext)
        {
            var locationDetailEnt = new EntityReference(defra_locationdetails.EntityLogicalName, Guid.NewGuid());
            var addressEnt        = new EntityReference(defra_address.EntityLogicalName, Guid.NewGuid());


            if (crmWorkflowContext == null)
            {
                throw new ArgumentNullException("crmWorkflowContext");
            }

            var tracingService = executionContext.GetExtension <ITracingService>();
            var service        = crmWorkflowContext.OrganizationService;
            var context        = crmWorkflowContext.WorkflowExecutionContext;

            var locationId       = GetLocation.Get(executionContext).Id;
            var locationdeatilId = Guid.Empty;
            var addressId        = Guid.Empty;

            var locationDetailFetch = string.Format(@"<fetch >
                  <entity name='defra_locationdetails'>
                    <attribute name='defra_locationdetailsid' />
    
                    <filter type='and'>
                      <condition attribute='defra_locationid' operator='eq' uiname='My Main Site' uitype='defra_location' value='{0}' />
                    </filter>
                  </entity>
                </fetch>", locationId.ToString());

            tracingService.Trace(locationDetailFetch);

            tracingService.Trace("try to run RetrieveMultiple on locationDetailFetch");
            var l = service.RetrieveMultiple(new FetchExpression(locationDetailFetch)).Entities.FirstOrDefault();

            if (l != null)
            {
                locationDetailEnt = new EntityReference(defra_locationdetails.EntityLogicalName, l.Id);

                var addressFetch = string.Format(@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
                  <entity name='defra_address'>
                    <attribute name='defra_addressid' />
    
                    <link-entity name='defra_locationdetails' from='defra_addressid' to='defra_addressid' link-type='inner' alias='aa'>
                      <filter type='and'>
                        <condition attribute='defra_locationdetailsid' operator='eq'  uitype='defra_locationdetails' value='{0}' />
                      </filter>
                    </link-entity>
                  </entity>
                </fetch>", l.Id.ToString());

                tracingService.Trace(addressFetch);

                tracingService.Trace("try to run RetrieveMultiple on addressFetch");
                var a = service.RetrieveMultiple(new FetchExpression(addressFetch)).Entities.FirstOrDefault();
                if (a != null)
                {
                    addressEnt = new EntityReference("defra_address.EntityLogicalName", a.Id);
                }
            }
            GetLocationDetail.Set(executionContext, locationDetailEnt);
            GetLocationDetailAddress.Set(executionContext, addressEnt);
            //throw new Exception("ok");
        }
Example #9
0
 public ILocationModel Any(GetLocation request)
 {
     return(workflow.Get(request.ID));
 }
Example #10
0
        public void update(GameTime gameTime)
        {
            KeyboardState state = Keyboard.GetState();
            if (state.IsKeyDown(Keys.Escape)) { Menu = true; paused = true; createCounter = 0; }

            if (Menu)
            {
                if (state.IsKeyDown(Keys.Z)) { Menu = false; paused = false; }
                if (paused && state.IsKeyDown(Keys.C)) { this.reset(); Menu = false; paused = false; createCounter = 0; }
            }
            else if (!End)
            {
                if (leaves.Count < 1) { End = true; }
                for (int i = 0; i < arms.Count; i++)
                {
                    if (arms[i].tobedeleted) { arms.RemoveAt(i); i--; }
                }
                for (int i = 0; i < thorns.Count; i++)
                {
                    if (thorns[i].tobedeleted) { thorns.RemoveAt(i); i--; }
                }
                if (devTimer > 1000) { DEV = !DEV; devTimer = 0; }

                if (DEV)
                {
                    current = components[compIndex % components.Count];

                    if (createCounter >= 320 && state.IsKeyDown(Keys.D1))
                    {
                        components.Add(new Component(null, string.Format("smallBranch-{0}", components.FindAll(a => a.tag.Split('-')[0].Equals("smallBranch")).Count), smallBranch, 0f, ZERO, false));
                        createCounter = 0;
                        compIndex = components.Count - 1;
                    }
                    if (createCounter >= 320 && state.IsKeyDown(Keys.D2))
                    {
                        components.Add(new Component(null, string.Format("thorn-{0}", components.FindAll(a => a.tag.Split('-')[0].Equals("thorn")).Count), thorn, 0f, ZERO, false));
                        createCounter = 0;
                        compIndex = components.Count - 1;
                    }
                    if (createCounter >= 320 && state.IsKeyDown(Keys.D3))
                    {
                        components.Add(new Component(null, string.Format("plant-{0}", components.FindAll(a => a.tag.Split('-')[0].Equals("plant")).Count), plant, 0f, ZERO, false));
                        createCounter = 0;
                        compIndex = components.Count - 1;
                    }
                    if (createCounter >= 320 && state.IsKeyDown(Keys.D4))
                    {
                        components.Add(new Component(null, string.Format("bigBranch-{0}", components.FindAll(a => a.tag.Split('-')[0].Equals("bigBranch")).Count), bigBranch, 0f, ZERO, false));
                        createCounter = 0;
                        compIndex = components.Count - 1;
                    }

                    if (tabCounter >= 120 && state.IsKeyDown(Keys.Tab)) { compIndex++; tabCounter = 0; }
                    if (tabCounter < 120) { tabCounter += gameTime.ElapsedGameTime.Milliseconds; }
                    if (createCounter < 320) { createCounter += gameTime.ElapsedGameTime.Milliseconds; }

                    if (state.IsKeyDown(Keys.W)) { current.location.Y -= 1; }
                    if (state.IsKeyDown(Keys.A)) { current.location.X -= 1; }
                    if (state.IsKeyDown(Keys.D)) { current.location.X += 1; }
                    if (state.IsKeyDown(Keys.S)) { current.location.Y += 1; }
                    if (state.IsKeyDown(Keys.Q)) { current.rotation -= .02f; }
                    if (state.IsKeyDown(Keys.E)) { current.rotation += .02f; }
                }
                else if (!Choosing)
                {
                    if (tabCounter < 120) { tabCounter += gameTime.ElapsedGameTime.Milliseconds; }
                    if (createCounter < 320) { createCounter += gameTime.ElapsedGameTime.Milliseconds; }

                    if (createCounter >= 320 && state.IsKeyDown(Keys.Z))
                    {
                        if (current.hasLeft()) { current = current.leftChild; }
                        else if (!current.terminal)
                        {
                            Choosing = true;
                            setChild = current.setLeft;
                            getLocation = current.getLeftLocation;
                            tempDraw = parts[partString[choiceIndex]];
                            /*
                            components.Add(current.setLeft("bigBranch"));
                            current = components[0];
                            createCounter = 0;
                            */
                        }
                        else
                        {
                            current = components[0];
                        }
                        createCounter = 0;
                    }
                    if (createCounter >= 320 && state.IsKeyDown(Keys.C))
                    {
                        if (current.hasRight()) { current = current.rightChild; }
                        else if (!current.terminal)
                        {
                            Choosing = true;
                            setChild = current.setRight;
                            getLocation = current.getRightLocation;
                            tempDraw = parts[partString[choiceIndex]];
                            /*
                            components.Add(current.setRight("bigBranch"));
                            current = components[0];
                            createCounter = 0;
                            */
                        }
                        else
                        {
                            current = components[0];
                        }
                        createCounter = 0;
                    }
                }
                if (Choosing)
                {
                    if (createCounter < 320) { createCounter += gameTime.ElapsedGameTime.Milliseconds; }

                    if (state.IsKeyDown(Keys.Z) && createCounter >= 320)
                    {
                        Component collidedWith;
                        if (!collides(partString[choiceIndex], getLocation().Item1, getLocation().Item2, out collidedWith, "NONE"))
                        {
                            components.Add(setChild(partString[choiceIndex]));
                            if (partString[choiceIndex].Equals("leaf")) { leaves.Add(components[components.Count - 1]); growth++; }
                            else if (partString[choiceIndex].Equals("thorn")) { thorns.Add(components[components.Count - 1]); }

                            Color color = new Color(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255), 255);
                            foreach (Tuple<Vector2, Vector2> line in Component.getLines(hitboxes[partString[choiceIndex]], getLocation().Item1, getLocation().Item2))
                            {
                                lines.Add(new Tuple<Vector2, Vector2, Color>(line.Item1, line.Item2, color));
                            }

                        }
                        Choosing = false;
                        current = components[0];
                        choiceIndex = 0;
                        createCounter = 0;
                    }
                    else if (state.IsKeyDown(Keys.C) && createCounter >= 320)
                    {
                        choiceIndex++;
                        choiceIndex = choiceIndex % (parts.Count - 1);
                        tempDraw = parts[partString[choiceIndex]];
                        createCounter = 0;
                    }
                }

                foreach (Arm arm in arms)
                {
                    arm.update();
                    Component collidedWith;
                    if (!arm.retreating && collides(arm.tag, arm.location, arm.rotation, out collidedWith, "thorn"))
                    {
                        try
                        {
                            dropThorn(collidedWith);
                            arm.retreat();
                            break;
                        }
                        catch (Exception)
                        {
                            break;
                        }
                    }
                    /*
                    foreach (Component thorn in thorns)
                    {
                        if (thorn.intersects(arm.hand, arm.location, arm.rotation))
                        {
                            dropThorn(thorn);
                            arm.retreat();
                            break;
                        }
                    }*/
                }

                armTimer += gameTime.ElapsedGameTime.Milliseconds;
                if (armTimer > newArm - leaves.Count * 400 && leaves.Count > 0)
                {
                    newArm -= 400;
                    Random rand = new Random();
                    int ind = rand.Next(0, 2);
                    switch (ind)
                    {
                        case 0:
                            {
                                arms.Add(new Arm("hand1", hand1, arm1, leaves[rand.Next(0, leaves.Count)], armSpawns[rand.Next(0, armSpawns.Count)], this));
                                break;
                            }
                        case 1:
                            {
                                arms.Add(new Arm("hand2", hand2, arm2, leaves[rand.Next(0, leaves.Count)], armSpawns[rand.Next(0, armSpawns.Count)], this));
                                break;
                            }
                    }
                    armTimer = 0;
                }

                for (int i = 0; i < droppingLeaves.Count; i++)
                {
                    droppingLeaves[i].location.Y += 4;
                    if (droppingLeaves[i].location.Y > 780) { droppingLeaves.RemoveAt(i); i--; }
                }
            }
            else
            {
                if (state.IsKeyDown(Keys.Z))
                {
                    this.reset();
                    this.End = false;
                }
            }
        }
Example #11
0
    // Use this for initialization
    void Start()
    {
        myGPS = GetComponent<GetLocation>();

        posX = (7.008536f - lon)*multiX;
        posZ = (50.935340f - lat)*multiY;
        print ("7.008536f"+lon);

        playername = PlayerPrefs.GetString("playername");
        playercode = PlayerPrefs.GetString("playercode");
        playerteam = PlayerPrefs.GetInt("playerteam");

        //richtigen playercharcter anzeigen
        Invader.SetActive(false);
        Pacman.SetActive(false);
        Galaga.SetActive(false);

        switch (playerteam)
        {
        case 1:
            Invader.SetActive(true);
            Pacman.SetActive(false);
            Galaga.SetActive(false);
            break;
        case 2:
            Pacman.SetActive(true);
            Invader.SetActive(false);
            Galaga.SetActive(false);
            break;
        case 3:
            Pacman.SetActive(false);
            Invader.SetActive(false);
            Galaga.SetActive(true);
            break;
        default:
            Debug.Log("Incorrect intelligence level.");
            break;
        }

        StartCoroutine(SendPos());
    }
Example #12
0
    public async Task Invoke(HttpContext context)
    {
        string   userAgent = context.Request.Headers["User-Agent"].ToString();
        DateTime dt        = DateTime.Now.Date;

        if (string.IsNullOrEmpty(userAgent))
        {
            await _requestDelegate(context);
        }
        var        uaparser   = Parser.GetDefault();
        ClientInfo userinfo   = uaparser.Parse(userAgent);
        string     iduserBase = null;

        if (context.User != null)
        {
            if (context.User.Identity.IsAuthenticated)
            {
                iduserBase = context.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            }
        }



        if (Chack(context))
        {
            //don the necessary staffs here to save the count by one
            string key = Guid.NewGuid().ToString();
            context.Response.Cookies.Append("VisitorId", key, new CookieOptions()
            {
                Expires = DateTime.Now.AddMinutes(20)
            });
            context.Session.SetString("VisitorId", key);

            stOnlion.Set(new On()
            {
                Key = key, Time = DateTime.Now.AddMinutes(20)
            });

            ApplicationDbContext appA = new ApplicationDbContext(new Microsoft.EntityFrameworkCore.DbContextOptions <ApplicationDbContext>());



            var os = appA.Osses.Where(a => a.Osname == userinfo.OS.Family && userinfo.OS.Major == a.Oskey).FirstOrDefault();
            if (os == null)
            {
                appA.Osses.Add(new Oss()
                {
                    Oskey     = userinfo.OS.Major,
                    Osname    = userinfo.OS.Family,
                    ImageName = "..."
                });

                appA.SaveChanges();
                os = appA.Osses.Where(a => a.Osname == userinfo.OS.Family && userinfo.OS.Major == a.Oskey).FirstOrDefault();
            }

            var bo = appA.Browsers.Where(a => a.BrowsersName == userinfo.UA.Family && userinfo.UA.Major == a.BrowsersKey).SingleOrDefault();

            if (bo == null)
            {
                appA.Browsers.Add(new Browser()
                {
                    BrowsersKey  = userinfo.UA.Major,
                    BrowsersName = userinfo.UA.Family,
                    ImageName    = "..."
                });

                appA.SaveChanges();

                bo = appA.Browsers.Where(a => a.BrowsersName == userinfo.UA.Family && userinfo.UA.Major == a.BrowsersKey).SingleOrDefault();
            }


            var q = appA.Statestics.Where(a => a.Day.Value.Year == dt.Date.Year &&
                                          a.Day.Value.Month == dt.Date.Month &&
                                          a.Day.Value.Day == dt.Date.Day).FirstOrDefault();

            if (q == null)
            {
                appA.Statestics.Add(new Statestic()
                {
                    Counter = 1,
                    Day     = DateTime.Now.Date
                });
                appA.SaveChanges();
            }
            else
            {
                q.Counter += 1;
                appA.Statestics.Update(q);
                appA.SaveChanges();
            }

            var qnow = appA.Statestics.Where(a => a.Day.Value.Year == dt.Date.Year &&
                                             a.Day.Value.Month == dt.Date.Month &&
                                             a.Day.Value.Day == dt.Date.Day).FirstOrDefault();



            appA.StUsers.Add(new StUser()
            {
                KeyId    = key,
                OsId     = os.Id,
                BroserId = bo.Id,
                StId     = qnow.Id,
                Iduser   = iduserBase
            });

            appA.SaveChanges();

            int iduser = appA.StUsers
                         .Where(a => a.StId == qnow.Id)
                         .Where(a => a.KeyId == key).FirstOrDefault().Id;

            Microsoft.AspNetCore.Http.Headers.RequestHeaders header = context.Request.GetTypedHeaders();
            Uri uriReferer = header.Referer;
            var loc        = new GetLocation().get(context.Connection.RemoteIpAddress.ToString());
            int idreffer   = StRefferSave(context.Request.Host.ToString(), context.Request.Host + context.Request.Path, context.Request.Headers["Referer"].ToString(), appA, userinfo.Device.IsSpider);



            StatesticsDetil detils = new StatesticsDetil()
            {
                Date       = DateTime.Now,
                Ip         = context.Connection.RemoteIpAddress.ToString(),
                IdstReffer = idreffer,
                Url        = context.Request.Host + context.Request.Path,
                UserId     = iduser,
                City       = loc == null?"...":loc.city,
                Country    = loc == null?"...":loc.country
            };

            appA.StatesticsDetils.Add(detils);
            appA.SaveChanges();
        }
        else
        {
            string key = getkay(context);

            ApplicationDbContext appA = new ApplicationDbContext(new Microsoft.EntityFrameworkCore.DbContextOptions <ApplicationDbContext>());



            var os = appA.Osses.Where(a => a.Osname == userinfo.OS.Family && userinfo.OS.Major == a.Oskey).FirstOrDefault();

            if (os == null)
            {
                appA.Osses.Add(new Oss()
                {
                    Oskey     = userinfo.OS.Major,
                    Osname    = userinfo.OS.Family,
                    ImageName = "..."
                });

                appA.SaveChanges();
                os = appA.Osses.Where(a => a.Osname == userinfo.OS.Family && userinfo.OS.Major == a.Oskey).FirstOrDefault();
            }

            var bo = appA.Browsers.Where(a => a.BrowsersName == userinfo.UA.Family && userinfo.UA.Major == a.BrowsersKey).SingleOrDefault();

            if (bo == null)
            {
                appA.Browsers.Add(new Browser()
                {
                    BrowsersKey  = userinfo.UA.Major,
                    BrowsersName = userinfo.UA.Family,
                    ImageName    = "..."
                });

                appA.SaveChanges();

                bo = appA.Browsers.Where(a => a.BrowsersName == userinfo.UA.Family && userinfo.UA.Major == a.BrowsersKey).SingleOrDefault();
            }

            var q = appA.Statestics.Where(a => a.Day.Value.Year == dt.Date.Year &&
                                          a.Day.Value.Month == dt.Date.Month &&
                                          a.Day.Value.Day == dt.Date.Day).FirstOrDefault();

            if (q == null)

            {
                appA.Statestics.Add(new Statestic()
                {
                    Counter = 1,
                    Day     = DateTime.Now.Date
                });

                appA.SaveChanges();

                var qnow = appA.Statestics.Where(a => a.Day.Value.Year == dt.Date.Year &&
                                                 a.Day.Value.Month == dt.Date.Month &&
                                                 a.Day.Value.Day == dt.Date.Day).FirstOrDefault();

                int iduser = appA.StUsers
                             .Where(a => a.StId == qnow.Id)
                             .Where(a => a.KeyId == key).FirstOrDefault().Id;

                Microsoft.AspNetCore.Http.Headers.RequestHeaders header = context.Request.GetTypedHeaders();
                Uri uriReferer = header.Referer;


                int             idreffer = StRefferSave(context.Request.Host.ToString(), context.Request.Host + context.Request.Path, context.Request.Headers["Referer"].ToString(), appA, userinfo.Device.IsSpider);
                var             loc      = new GetLocation().get(context.Connection.RemoteIpAddress.ToString());
                StatesticsDetil detils   = new StatesticsDetil()
                {
                    Date       = DateTime.Now,
                    Ip         = context.Connection.RemoteIpAddress.ToString(),
                    IdstReffer = idreffer,
                    Url        = context.Request.Host + context.Request.Path,
                    UserId     = iduser,
                    City       = loc == null ? "..." : loc.city,
                    Country    = loc == null ? "..." : loc.country
                };
                appA.StatesticsDetils.Add(detils);
                appA.SaveChanges();
            }
            else
            {
                q.Counter += 1;
                appA.Statestics.Update(q);
                appA.SaveChanges();

                //var a = appA.StUsers
                //        .Where(a => a.StId == q.Id)
                //        .Where(a => a.KeyId == key).FirstOrDefault();

                int iduser = appA.StUsers
                             .Where(a => a.StId == q.Id)
                             .Where(a => a.KeyId == key).FirstOrDefault().Id;

                Microsoft.AspNetCore.Http.Headers.RequestHeaders header = context.Request.GetTypedHeaders();
                Uri uriReferer = header.Referer;

                int idreffer = StRefferSave(context.Request.Host.ToString(), context.Request.Host + context.Request.Path, context.Request.Headers["Referer"].ToString(), appA, userinfo.Device.IsSpider);
                var loc      = new GetLocation().get(context.Connection.RemoteIpAddress.ToString());

                StatesticsDetil detils = new StatesticsDetil()
                {
                    Date       = DateTime.Now,
                    Ip         = context.Connection.RemoteIpAddress.ToString(),
                    IdstReffer = idreffer,
                    Url        = context.Request.Host + context.Request.Path,
                    UserId     = iduser,

                    City    = loc == null ? "..." : loc.city,
                    Country = loc == null ? "..." : loc.country
                };
                //try
                //{

                appA.StatesticsDetils.Add(detils);
                appA.SaveChanges();

                //}
                //catch {
                //    appA.StatesticsDetils.Update(detils);
                //    appA.SaveChanges();
                //}
            }



            context.Response.Cookies.Delete("VisitorId", new CookieOptions()
            {
                Expires = DateTime.Now.AddMinutes(20)
            });
            context.Session.Remove("VisitorId");

            stOnlion.Update(key);

            context.Response.Cookies.Append("VisitorId", key, new CookieOptions()
            {
                Expires = DateTime.Now.AddMinutes(20)
            });

            context.Session.SetString("VisitorId", key);
        }
        await _requestDelegate(context);
    }
Example #13
0
        public void GetLocation_Test_Success()
        {
            //ARRANGE
            string bingKey       = "GOOD-KEY";
            string country       = "US";
            string stateProvince = "WA";
            string city          = "Redmond";
            string postalCode    = "98052";
            string address       = "1 Microsoft Way";


            //get new GetLocation object
            GetLocation getLocation = new GetLocation();

            //instantiate the workflowinvoker
            var invoker = new WorkflowInvoker(getLocation);

            //create our mocks
            var serviceMock         = new Mock <IOrganizationService>();
            var factoryMock         = new Mock <IOrganizationServiceFactory>();
            var tracingServiceMock  = new Mock <ITracingService>();
            var workflowContextMock = new Mock <IWorkflowContext>();

            //set up a mock service to act like the CRM organization service
            IOrganizationService service = serviceMock.Object;

            //set up a mock workflowcontext
            var workflowUserId           = Guid.NewGuid();
            var workflowCorrelationId    = Guid.NewGuid();
            var workflowInitiatingUserId = Guid.NewGuid();

            workflowContextMock.Setup(t => t.InitiatingUserId).Returns(workflowInitiatingUserId);
            workflowContextMock.Setup(t => t.CorrelationId).Returns(workflowCorrelationId);
            workflowContextMock.Setup(t => t.UserId).Returns(workflowUserId);
            var workflowContext = workflowContextMock.Object;

            //set up a mock tracingservice - will write output to console for now. maybe should store somewhere and read for asserts later?
            tracingServiceMock.Setup(t => t.Trace(It.IsAny <string>(), It.IsAny <object[]>())).Callback <string, object[]>((t1, t2) => Console.WriteLine(t1, t2));
            var tracingService = tracingServiceMock.Object;

            //set up a mock servicefactory
            factoryMock.Setup(t => t.CreateOrganizationService(It.IsAny <Guid>())).Returns(service);
            var factory = factoryMock.Object;

            invoker.Extensions.Add <ITracingService>(() => tracingService);
            invoker.Extensions.Add <IWorkflowContext>(() => workflowContext);
            invoker.Extensions.Add <IOrganizationServiceFactory>(() => factory);

            var inputs = new Dictionary <string, object>
            {
                { "BingKey", bingKey },
                { "Country", country },
                { "StateProvince", stateProvince },
                { "City", city },
                { "PostalCode", postalCode },
                { "Address", address }
            };
            string mockResponse = "";

            using (System.IO.StreamReader sr = new System.IO.StreamReader("map-response-good.xml"))
            {
                String line = sr.ReadToEnd();
                mockResponse += line;
            }

            string expectedUrl = "http://dev.virtualearth.net/REST/v1/Locations/US/WA/98052/Redmond/1%20Microsoft%20Way?o=xml&key=GOOD-KEY";

            WebRequest.RegisterPrefix(expectedUrl, new TestWebRequestCreate());
            TestWebRequest request = TestWebRequestCreate.CreateTestRequest(mockResponse);

            //ACT
            var    outputs = invoker.Invoke(inputs);
            string lat     = Convert.ToString(outputs["Latitude"]);
            string lon     = Convert.ToString(outputs["Longitude"]);

            //ASSERT
            Assert.AreEqual("47.640120461583138", lat);
            Assert.AreEqual("-122.12971039116383", lon);
        }
        public void GetLocation_Test_Success()
        {
            //ARRANGE
            string bingKey = "GOOD-KEY";
            string country = "US";
            string stateProvince = "WA";
            string city = "Redmond";
            string postalCode = "98052";
            string address = "1 Microsoft Way";

            //get new GetLocation object
            GetLocation getLocation = new GetLocation();

            //instantiate the workflowinvoker
            var invoker = new WorkflowInvoker(getLocation);

            //create our mocks
            var serviceMock = new Mock<IOrganizationService>();
            var factoryMock = new Mock<IOrganizationServiceFactory>();
            var tracingServiceMock = new Mock<ITracingService>();
            var workflowContextMock = new Mock<IWorkflowContext>();

            //set up a mock service to act like the CRM organization service
            IOrganizationService service = serviceMock.Object;

            //set up a mock workflowcontext
            var workflowUserId = Guid.NewGuid();
            var workflowCorrelationId = Guid.NewGuid();
            var workflowInitiatingUserId = Guid.NewGuid();

            workflowContextMock.Setup(t => t.InitiatingUserId).Returns(workflowInitiatingUserId);
            workflowContextMock.Setup(t => t.CorrelationId).Returns(workflowCorrelationId);
            workflowContextMock.Setup(t => t.UserId).Returns(workflowUserId);
            var workflowContext = workflowContextMock.Object;

            //set up a mock tracingservice - will write output to console for now. maybe should store somewhere and read for asserts later?
            tracingServiceMock.Setup(t => t.Trace(It.IsAny<string>(), It.IsAny<object[]>())).Callback<string, object[]>((t1, t2) => Console.WriteLine(t1, t2));
            var tracingService = tracingServiceMock.Object;

            //set up a mock servicefactory
            factoryMock.Setup(t => t.CreateOrganizationService(It.IsAny<Guid>())).Returns(service);
            var factory = factoryMock.Object;

            invoker.Extensions.Add<ITracingService>(() => tracingService);
            invoker.Extensions.Add<IWorkflowContext>(() => workflowContext);
            invoker.Extensions.Add<IOrganizationServiceFactory>(() => factory);

            var inputs = new Dictionary<string, object>
            {
                { "BingKey", bingKey},
                { "Country", country},
                { "StateProvince", stateProvince},
                { "City", city},
                { "PostalCode", postalCode},
                { "Address", address}
            };
            string mockResponse = "";
            using (System.IO.StreamReader sr = new System.IO.StreamReader("map-response-good.xml"))
            {
                String line = sr.ReadToEnd();
                mockResponse += line;
            }

            string expectedUrl = "http://dev.virtualearth.net/REST/v1/Locations/US/WA/98052/Redmond/1%20Microsoft%20Way?o=xml&key=GOOD-KEY";
            WebRequest.RegisterPrefix(expectedUrl, new TestWebRequestCreate());
            TestWebRequest request = TestWebRequestCreate.CreateTestRequest(mockResponse);

            //ACT
            var outputs = invoker.Invoke(inputs);
            string lat = Convert.ToString(outputs["Latitude"]);
            string lon = Convert.ToString(outputs["Longitude"]);

            //ASSERT
            Assert.AreEqual("47.640120461583138", lat);
            Assert.AreEqual("-122.12971039116383", lon);
        }