Exemple #1
0
 protected virtual void SanitizeSharingContext(SharingContext context)
 {
     if (context.SharingConfiguration.Expiry > _sharingOptions.MaxExpiry ||
         context.SharingConfiguration.Expiry < _sharingOptions.MinExpiry)
     {
         context.SharingConfiguration.Expiry = _sharingOptions.DefaultExpiry;
     }
 }
Exemple #2
0
        private AnnounceResponse CreateResponseFromContext(SharingContext context)
        {
            var response = new AnnounceResponse();

            response.Complete   = 1;
            response.Incomplete = 0;
            response.Peers      = context.User.UserAddress.Addresses.Select(address => new Peer(null, address.Host, address.Port));
            response.Interval   = TimeSpan.FromHours(1).Seconds;
            return(response);
        }
Exemple #3
0
        public int UpgradeSharedPyramid(SharingContext context)
        {
            var executeSqlString = @"spUpgradeSharedPyramid";

            using (var database = this.databaseFactory.GenerateDatabase(isWriteOnly: true)) {
                var parameters = new Dapper.DynamicParameters();
                parameters.Add("@sharedByOpenId", context.SharedBy.OpenId, System.Data.DbType.String);
                parameters.Add("@currentOpenId", context.Current.OpenId, System.Data.DbType.String);
                parameters.Add("@appid", context.Current.AppId, System.Data.DbType.String);
                return(database.Execute(executeSqlString, parameters, System.Data.CommandType.StoredProcedure, true));
            }
        }
        public bool UpgradeSharedPyramid(SharingContext context)
        {
            if (context.Current == null || context.SharedBy == null)
            {
                return(false);
            }

            if (context.SharedBy.AppId != context.Current.AppId)
            {
                throw new ArgumentNullException("Current.AppId must be equals to SharedBy.AppId ");
            }

            if (context.SharedBy.OpenId == context.Current.OpenId)
            {
                return(false);
            }
            Logger.Info(context.SerializeToJson());
            return(client.UpgradeSharedPyramid(context) > 0);
        }
Exemple #5
0
        public async Task StartSharing(ShareRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            await _shareRequestValidator.ValidateAndThrowAsync(request, "default,write");

            var context  = SharingContext.Create(request);
            var existing = await _sharingRepository.GetSharingContextForUserByInfoHash(request.User.Id, context.InfoHash);

            if (existing != default)
            {
                throw new DuplicateSharingContextException();
            }

            SanitizeSharingContext(context);

            await _sharingRepository.CreateSharingContext(context);
        }
 public CharacteristicRepository(SharingContext dataBase)
 {
     _dataBase = dataBase;
 }
Exemple #7
0
        public static void Initialize(SharingContext _modelContext)
        {
            _modelContext.Database.EnsureCreated();

            var mediumAction1 = new MediumAction()
            {
                Id     = 0,
                Medium = "Ground",
            };
            var mediumAction2 = new MediumAction()
            {
                Id     = 1,
                Medium = "Air",
            };
            var mediumAction3 = new MediumAction()
            {
                Id     = 1,
                Medium = "Air-Ground",
            };


            if (!_modelContext.MediumActions.Any())
            {
                _modelContext.MediumActions.Add(mediumAction1);
                _modelContext.MediumActions.Add(mediumAction2);
                _modelContext.MediumActions.Add(mediumAction3);
            }

            var applicationMode1 = new ApplicationMode()
            {
                Id   = 0,
                Mode = "Entertainment"
            };

            if (!_modelContext.MediumActions.Any())
            {
                _modelContext.ApplicationModes.Add(applicationMode1);
            }

            var machineType1 = new MachineType()
            {
                Id = 0,
                ApplicationMode = applicationMode1,
                MediumAction    = mediumAction1
            };
            var machineType2 = new MachineType()
            {
                Id = 1,
                ApplicationMode = applicationMode1,
                MediumAction    = mediumAction2
            };
            var machineType3 = new MachineType()
            {
                Id = 2,
                ApplicationMode = applicationMode1,
                MediumAction    = mediumAction3
            };

            if (!_modelContext.MediumActions.Any())
            {
                _modelContext.MachineTypes.Add(machineType1);
                _modelContext.MachineTypes.Add(machineType1);
                _modelContext.MachineTypes.Add(machineType1);
            }

            var location1 = new Location()
            {
                Id        = 0,
                Continent = "Europe",
                Country   = "Germany",
                City      = "Berlin",
                House     = "11n",
                Street    = "Street"
            };

            if (!_modelContext.Locations.Any())
            {
                _modelContext.Locations.Add(location1);
            }

            var characteristic1 = new Characteristic()
            {
                Id           = 0,
                Accelaration = 3,
                ActionRadius = 50,
                Speed        = 34,
                Weight       = 3,
                WorkTime     = new DateTime(0, 0, 0, 3, 30, 0)
            };

            if (!_modelContext.Characteristics.Any())
            {
                _modelContext.Characteristics.Add(characteristic1);
            }

            var machine2 = new Machine()
            {
                Id             = 0,
                Discount       = 9.5m,
                IsAvailable    = true,
                MachineType    = machineType2,
                Name           = "Machine can fly",
                Price          = 12.5m,
                Characteristic = characteristic1
            };

            var machine1 = new Machine()
            {
                Id             = 1,
                Discount       = 9.5m,
                IsAvailable    = true,
                MachineType    = machineType1,
                Name           = "Machine with wheels",
                Price          = 15.5m,
                Characteristic = characteristic1
            };
            var machine3 = new Machine()
            {
                Id             = 2,
                Discount       = 9.5m,
                IsAvailable    = true,
                MachineType    = machineType3,
                Name           = "Machine with wheels can fly",
                Price          = 15.5m,
                Characteristic = characteristic1
            };

            if (!_modelContext.Machines.Any())
            {
                _modelContext.Machines.Add(machine3);
                _modelContext.Machines.Add(machine1);
                _modelContext.Machines.Add(machine2);
            }



            _modelContext.SaveChanges();
        }
 public RenterRepository(SharingContext dataBase)
 {
     _dataBase = dataBase;
 }
Exemple #9
0
 internal override void ParseSharingMessageProvider(SharingContext context, SharingMessageProvider sharingMessageProvider)
 {
     context.FolderEwsId = sharingMessageProvider.FolderId;
     context.MailboxId   = HexConverter.HexStringToByteArray(sharingMessageProvider.MailboxId);
 }
Exemple #10
0
 internal override void FillSharingMessageProvider(SharingContext context, SharingMessageProvider sharingMessageProvider)
 {
     sharingMessageProvider.FolderId  = context.FolderEwsId;
     sharingMessageProvider.MailboxId = HexConverter.ByteArrayToHexString(context.MailboxId);
 }
Exemple #11
0
 protected override PerformInvitationResults InternalPerformInvitation(MailboxSession mailboxSession, SharingContext context, ValidRecipient[] recipients, IFrontEndLocator frontEndLocator)
 {
     using (CalendarFolder calendarFolder = CalendarFolder.Bind(mailboxSession, context.FolderId, CalendarFolderSchema.ConsumerCalendarProperties))
     {
         Guid a = calendarFolder.ConsumerCalendarGuid;
         Guid consumerCalendarPrivateFreeBusyId = calendarFolder.ConsumerCalendarPrivateFreeBusyId;
         Guid consumerCalendarPrivateDetailId   = calendarFolder.ConsumerCalendarPrivateDetailId;
         if (a == Guid.Empty)
         {
             a = (calendarFolder.ConsumerCalendarGuid = Guid.NewGuid());
         }
         if (consumerCalendarPrivateFreeBusyId == Guid.Empty)
         {
             Guid guid = calendarFolder.ConsumerCalendarPrivateFreeBusyId = Guid.NewGuid();
         }
         if (consumerCalendarPrivateDetailId == Guid.Empty)
         {
             Guid guid2 = calendarFolder.ConsumerCalendarPrivateDetailId = Guid.NewGuid();
         }
         if (calendarFolder.IsDirty)
         {
             FolderSaveResult folderSaveResult = calendarFolder.Save();
             if (folderSaveResult.OperationResult != OperationResult.Succeeded)
             {
                 throw folderSaveResult.ToException(new LocalizedString("TODO: LOC: Failed to share the calendar."));
             }
         }
         context.FolderEwsId = a.ToString();
         context.MailboxId   = ((IUserPrincipal)mailboxSession.MailboxOwner).NetId.ToByteArray();
         context.FolderName  = (context.IsPrimary ? string.Format("TODO: LOC: {0}'s Calendar", context.InitiatorName) : calendarFolder.DisplayName);
         context.IsPrimary   = false;
     }
     return(new PerformInvitationResults(recipients));
 }
Exemple #12
0
 protected override void InternalPerformRevocation(MailboxSession mailboxSession, SharingContext context)
 {
 }
Exemple #13
0
        public static void Initialize(SharingContext _modelContext)
        {
            _modelContext.Database.EnsureCreated();


            var mediumAction1 = new MediumAction()
            {
                Medium = "Ground",
            };
            var mediumAction2 = new MediumAction()
            {
                Medium = "Air",
            };
            var mediumAction3 = new MediumAction()
            {
                Medium = "Air-Ground",
            };


            //if (!_modelContext.MediumActions.Any())
            //{
            //    _modelContext.MediumActions.Add(mediumAction1);
            //    _modelContext.MediumActions.Add(mediumAction2);
            //    _modelContext.MediumActions.Add(mediumAction3);
            //}

            var applicationMode1 = new ApplicationMode()
            {
                Mode = "Entertainment"
            };

            if (!_modelContext.ApplicationModes.Any())
            {
                _modelContext.ApplicationModes.Add(applicationMode1);
            }

            var machineType1 = new MachineType()
            {
                ApplicationMode = applicationMode1,
                MediumAction    = mediumAction1
            };
            var machineType2 = new MachineType()
            {
                ApplicationMode = applicationMode1,
                MediumAction    = mediumAction2
            };
            var machineType3 = new MachineType()
            {
                ApplicationMode = applicationMode1,
                MediumAction    = mediumAction3
            };

            if (!_modelContext.MachineTypes.Any())
            {
                _modelContext.MachineTypes.Add(machineType1);
                _modelContext.MachineTypes.Add(machineType2);
                _modelContext.MachineTypes.Add(machineType3);
            }

            var location1 = new Location()
            {
                Continent = "Europe",
                Country   = "Germany",
                City      = "Berlin",
                House     = "11n",
                Street    = "Street"
            };

            if (!_modelContext.Locations.Any())
            {
                _modelContext.Locations.Add(location1);
            }

            var characteristic1 = new Characteristic()
            {
                Accelaration = 3,
                ActionRadius = 50,
                Speed        = 34,
                Weight       = 3,
                WorkTime     = new DateTime().AddHours(2)
            };

            if (!_modelContext.Characteristics.Any())
            {
                _modelContext.Characteristics.Add(characteristic1);
            }

            var machine2 = new CloudResource()
            {
                Discount       = 9.5m,
                IsAvailable    = true,
                MachineType    = machineType2,
                Name           = "Machine can fly",
                Price          = 12.5m,
                Characteristic = characteristic1
            };

            var machine1 = new CloudResource()
            {
                Discount       = 9.5m,
                IsAvailable    = true,
                MachineType    = machineType1,
                Name           = "Machine with wheels",
                Price          = 15.5m,
                Characteristic = characteristic1
            };
            var machine3 = new CloudResource()
            {
                Discount       = 9.5m,
                IsAvailable    = true,
                MachineType    = machineType3,
                Name           = "Machine with wheels can fly",
                Price          = 15.5m,
                Characteristic = characteristic1
            };

            if (!_modelContext.Machines.Any())
            {
                _modelContext.Machines.Add(machine3);
                _modelContext.Machines.Add(machine1);
                _modelContext.Machines.Add(machine2);
            }

            var renter1 = new Customer()
            {
                FirstName = "1",
                LastName  = "1",
                Money     = 300,
                UserName  = "******"
            };

            if (!_modelContext.Renters.Any())
            {
                _modelContext.Renters.Add(renter1);
            }

            var renteredMachine1 = new RenteredResource()
            {
                ActivationCode = "1",
                FinishDate     = DateTime.Now.AddDays(30),
                StartDate      = DateTime.Now,
                CloudResource  = machine1,
                Price          = machine1.Price - machine1.Discount,
                Customer       = renter1
            };

            var renteredMachine2 = new RenteredResource()
            {
                ActivationCode = "2",
                FinishDate     = DateTime.Now.AddDays(30),
                StartDate      = DateTime.Now,
                CloudResource  = machine2,
                Price          = machine2.Price - machine2.Discount,
                Customer       = renter1
            };

            if (!_modelContext.RenteredMachines.Any())
            {
                _modelContext.RenteredMachines.Add(renteredMachine1);
                _modelContext.RenteredMachines.Add(renteredMachine2);
            }

            _modelContext.SaveChanges();
        }
Exemple #14
0
 public CloudResourceRepository(SharingContext dataBase)
 {
     _dataBase = dataBase;
 }
 public RenteredMachineRepository(SharingContext dataBase)
 {
     _dataBase = dataBase;
 }
Exemple #16
0
        protected override SubscribeResults InternalPerformSubscribe(MailboxSession mailboxSession, SharingContext context)
        {
            NetID netID = new NetID(context.MailboxId);
            long  num   = checked ((long)netID.ToUInt64());

            if (num == 0L)
            {
                throw new InvalidOperationException("Invitation does not contain the owner ID.");
            }
            Guid guid;

            if (!Guid.TryParse(context.FolderEwsId, out guid))
            {
                throw new InvalidOperationException("Invitation does not contain the calendar ID.");
            }
            using (Folder folder = Folder.Bind(mailboxSession, DefaultFolderType.Root))
            {
                StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.DeletedItems);
                QueryFilter   queryFilter     = QueryFilter.AndTogether(new QueryFilter[]
                {
                    new ComparisonFilter(ComparisonOperator.Equal, CalendarFolderSchema.ConsumerCalendarGuid, guid),
                    new ComparisonFilter(ComparisonOperator.Equal, CalendarFolderSchema.ConsumerCalendarOwnerId, num)
                });
                using (IQueryResult queryResult = folder.IFolderQuery(FolderQueryFlags.DeepTraversal, queryFilter, null, new PropertyDefinition[]
                {
                    FolderSchema.Id,
                    FolderSchema.DisplayName,
                    StoreObjectSchema.ParentItemId
                }))
                {
                    bool flag = true;
                    while (flag)
                    {
                        object[][] rows = queryResult.GetRows(100, out flag);
                        if (rows == null || rows.Length == 0)
                        {
                            break;
                        }
                        foreach (object[] array2 in rows)
                        {
                            StoreObjectId storeObjectId = StoreId.GetStoreObjectId((StoreId)array2[2]);
                            if (!defaultFolderId.Equals(storeObjectId))
                            {
                                return(new SubscribeResults(context.DataType, context.InitiatorSmtpAddress, context.InitiatorName, context.FolderName, StoreId.GetStoreObjectId((StoreId)rows[0][0]), false, (string)rows[0][1]));
                            }
                        }
                    }
                }
            }
            SubscribeResults result;

            using (CalendarFolder calendarFolder = CalendarFolder.Create(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Root), StoreObjectType.CalendarFolder))
            {
                calendarFolder[FolderSchema.ExtendedFolderFlags] = (ExtendedFolderFlags.SharedIn | ExtendedFolderFlags.ExclusivelyBound | ExtendedFolderFlags.ExchangeConsumerShareFolder);
                calendarFolder.DisplayName             = (context.FolderName ?? context.InitiatorSmtpAddress);
                calendarFolder.ConsumerCalendarGuid    = guid;
                calendarFolder.ConsumerCalendarOwnerId = num;
                calendarFolder.SaveWithUniqueDisplayName(50);
                calendarFolder.Load();
                result = new SubscribeResults(context.DataType, context.InitiatorSmtpAddress, context.InitiatorName, context.FolderName, StoreId.GetStoreObjectId(calendarFolder.Id), true, calendarFolder.DisplayName);
            }
            return(result);
        }
 public LessorRepository(SharingContext dataBase)
 {
     _dataBase = dataBase;
 }
Exemple #18
0
 public Task CreateSharingContext(SharingContext context)
 {
     return(_collection.InsertOneAsync(context));
 }
Exemple #19
0
 public AuthRepository(SharingContext dataContext)
 {
     _dataContext = dataContext;
 }
Exemple #20
0
 public CustomerRepository(SharingContext dataBase)
 {
     _dataBase = dataBase;
 }