コード例 #1
0
        private List <AttributeChange> GetLocalChanges(string dn, ObjectModificationType modType, SchemaType type, object source)
        {
            List <AttributeChange> attributeChanges = new List <AttributeChange>();

            CalendarResource calendar = source as CalendarResource;

            if (calendar == null)
            {
                throw new InvalidOperationException();
            }

            foreach (IAttributeAdapter typeDef in this.SchemaType.AttributeAdapters.Where(t => t.Api == this.Api))
            {
                if (typeDef.IsAnchor)
                {
                    continue;
                }

                foreach (AttributeChange change in typeDef.CreateAttributeChanges(dn, modType, calendar))
                {
                    if (type.HasAttribute(change.Name))
                    {
                        attributeChanges.Add(change);
                    }
                }
            }

            return(attributeChanges);
        }
コード例 #2
0
        public IList <AttributeChange> ApplyChanges(CSEntryChange csentry, SchemaType type, ref object target, bool patch = false)
        {
            bool hasChanged = false;
            List <AttributeChange> changes = new List <AttributeChange>();

            CalendarResource calendar = target as CalendarResource;

            if (calendar == null)
            {
                throw new InvalidOperationException();
            }

            hasChanged |= this.SetDNValue(csentry, calendar);

            foreach (IAttributeAdapter typeDef in this.SchemaType.AttributeAdapters.Where(t => t.Api == this.Api))
            {
                hasChanged |= typeDef.UpdateField(csentry, calendar);
            }

            if (hasChanged)
            {
                CalendarResource result;

                if (csentry.ObjectModificationType == ObjectModificationType.Add)
                {
                    result = this.config.ResourcesService.AddCalendar(this.customerID, calendar);
                    calendar.ResourceEmail = result.ResourceEmail;
                    System.Threading.Thread.Sleep(1500);
                }
                else if (csentry.ObjectModificationType == ObjectModificationType.Replace || csentry.ObjectModificationType == ObjectModificationType.Update)
                {
                    string id = csentry.GetAnchorValueOrDefault <string>("id");

                    if (patch)
                    {
                        result = this.config.ResourcesService.PatchCalendar(this.customerID, id, calendar);
                    }
                    else
                    {
                        result = this.config.ResourcesService.UpdateCalendar(this.customerID, id, calendar);
                    }
                }
                else
                {
                    throw new InvalidOperationException();
                }

                changes.AddRange(this.GetLocalChanges(csentry.DN, csentry.ObjectModificationType, type, result));
            }

            foreach (IApiInterface i in this.internalInterfaces)
            {
                foreach (AttributeChange c in i.ApplyChanges(csentry, type, ref target, patch))
                {
                    changes.Add(c);
                }
            }

            return(changes);
        }
コード例 #3
0
 public CalendarResource UpdateCalendar(string customerId, string id, CalendarResource item)
 {
     using (PoolItem <DirectoryService> connection = this.directoryServicePool.Take(NullValueHandling.Include))
     {
         ResourcesResource.CalendarsResource.UpdateRequest request = new ResourcesResource.CalendarsResource.UpdateRequest(connection.Item, item, customerId, id);
         return(request.ExecuteWithRetryOnBackoff());
     }
 }
コード例 #4
0
        public object CreateInstance(CSEntryChange csentry)
        {
            CalendarResource calendar = new CalendarResource();

            calendar.ResourceId = Guid.NewGuid().ToString("n");

            return(calendar);
        }
コード例 #5
0
        public void CreateCalendar()
        {
            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.DN         = Guid.NewGuid().ToString();
            cs.ObjectType = SchemaConstants.Calendar;

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", "test-name"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("buildingId", "testbuilding1"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("capacity", 33L));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("floorName", "G"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("floorSection", "33B"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("resourceCategory", "CONFERENCE_ROOM"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("resourceDescription", "internal description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("userVisibleDescription", "user description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("features", new List <object> {
                "Test1", "Test2"
            }));

            string id = null;

            try
            {
                CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Calendar], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                id = result.AnchorAttributes["id"].GetValueAdd <string>();

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                CalendarResource c = UnitTestControl.TestParameters.ResourcesService.GetCalendar(UnitTestControl.TestParameters.CustomerID, id);
                Assert.AreEqual("test-name", c.ResourceName);
                Assert.IsNotNull(c.ResourceEmail);
                Assert.AreEqual("testbuilding1", c.BuildingId);
                Assert.AreEqual(33, c.Capacity);
                Assert.AreEqual("G", c.FloorName);
                Assert.AreEqual("33B", c.FloorSection);
                Assert.AreEqual("CONFERENCE_ROOM", c.ResourceCategory);
                Assert.AreEqual("internal description", c.ResourceDescription);
                Assert.AreEqual("user description", c.UserVisibleDescription);
                CollectionAssert.AreEquivalent(new string[] { "Test1", "Test2" }, ApiInterfaceCalendar.GetFeatureNames(c).ToList());
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteCalendar(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
コード例 #6
0
        public string GetDNValue(object target)
        {
            CalendarResource calendar = target as CalendarResource;

            if (calendar == null)
            {
                throw new InvalidOperationException();
            }

            return(calendar.ResourceEmail);
        }
コード例 #7
0
        public void CreateCalendarWithAcls()
        {
            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.DN         = Guid.NewGuid().ToString();
            cs.ObjectType = SchemaConstants.Calendar;

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", "test-name"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("buildingId", "testbuilding1"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("capacity", 33L));

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("owner", new List <object> {
                this.CreateAddress("owner1"), this.CreateAddress("owner2")
            }));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("reader", this.CreateAddress("reader")));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("writer", this.CreateAddress("writer")));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("freeBusyReader", this.CreateAddress("freebusyreader")));

            string id = null;

            try
            {
                CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Calendar], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                id = result.AnchorAttributes["id"].GetValueAdd <string>();

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                CalendarResource c = UnitTestControl.TestParameters.ResourcesService.GetCalendar(UnitTestControl.TestParameters.CustomerID, id);

                List <AclRule> acls = UnitTestControl.TestParameters.ResourcesService.GetCalendarAclRules(UnitTestControl.TestParameters.CustomerID, c.ResourceEmail).ToList();

                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "owner" && t.Scope.Value == this.CreateAddress("owner1")));
                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "owner" && t.Scope.Value == this.CreateAddress("owner2")));
                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "reader" && t.Scope.Value == this.CreateAddress("reader")));
                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "writer" && t.Scope.Value == this.CreateAddress("writer")));
                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "freeBusyReader" && t.Scope.Value == this.CreateAddress("freebusyreader")));
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteCalendar(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
コード例 #8
0
        internal static IEnumerable <string> GetFeatureNames(CalendarResource calendar, AttributeType type = AttributeType.String)
        {
            List <FeatureInstance> items = ((JArray)calendar?.FeatureInstances)?.ToObject <List <FeatureInstance> >();

            return(items?.Select(t =>
            {
                string featureName = t.Feature.Name;

                if (type == AttributeType.Reference)
                {
                    featureName = $"{featureName}{ApiInterfaceFeature.DNSuffix}";
                }

                return featureName;
            }));
        }
コード例 #9
0
        private bool SetDNValue(CSEntryChange csentry, CalendarResource calendar)
        {
            if (csentry.ObjectModificationType != ObjectModificationType.Replace && csentry.ObjectModificationType != ObjectModificationType.Update)
            {
                return(false);
            }

            string newDN = csentry.GetNewDNOrDefault <string>();

            if (newDN == null)
            {
                return(false);
            }

            throw new NotSupportedException("Renaming the DN of this object is not supported");
        }
コード例 #10
0
        public string GetAnchorValue(string name, object target)
        {
            CalendarResource calendar = target as CalendarResource;

            if (calendar == null)
            {
                throw new InvalidOperationException();
            }

            switch (name)
            {
            case "id":
                return(calendar.ResourceId);

            case "resourceEmail":
                return(calendar.ResourceEmail);

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #11
0
        public void UpdateCalendarClearValues()
        {
            CalendarResource calendar = new CalendarResource();

            calendar.ResourceId             = Guid.NewGuid().ToString("n");
            calendar.ResourceName           = "test-name";
            calendar.BuildingId             = "testbuilding2";
            calendar.Capacity               = 9;
            calendar.FloorName              = "G";
            calendar.FloorSection           = "39b";
            calendar.ResourceCategory       = "OTHER";
            calendar.ResourceDescription    = "internal description 1";
            calendar.UserVisibleDescription = "my description 2";
            calendar.FeatureInstances       = new List <FeatureInstance>()
            {
                new FeatureInstance()
                {
                    Feature = new Feature()
                    {
                        Name = "Test1"
                    }
                },
                new FeatureInstance()
                {
                    Feature = new Feature()
                    {
                        Name = "Test2"
                    }
                },
            };

            UnitTestControl.TestParameters.ResourcesService.AddCalendar(UnitTestControl.TestParameters.CustomerID, calendar);

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Update;
            cs.DN         = "*****@*****.**";
            cs.ObjectType = SchemaConstants.Calendar;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", calendar.ResourceId));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("buildingId"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("capacity"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("floorName"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("floorSection"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("resourceDescription"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("userVisibleDescription"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("features"));

            string id = calendar.ResourceId;

            try
            {
                CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Calendar], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                CalendarResource c = UnitTestControl.TestParameters.ResourcesService.GetCalendar(UnitTestControl.TestParameters.CustomerID, id);
                Assert.IsNull(c.BuildingId);
                Assert.IsNull(c.Capacity);
                Assert.IsNull(c.FloorName);
                Assert.IsNull(c.FloorSection);
                Assert.IsNull(c.ResourceDescription);
                Assert.IsNull(c.UserVisibleDescription);
                Assert.IsNull(c.FeatureInstances);
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteCalendar(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
コード例 #12
0
        public void UpdateCalendar()
        {
            CalendarResource calendar = new CalendarResource();

            calendar.ResourceId             = Guid.NewGuid().ToString("n");
            calendar.ResourceName           = "test-name";
            calendar.BuildingId             = "testbuilding2";
            calendar.Capacity               = 9;
            calendar.FloorName              = "G";
            calendar.FloorSection           = "39b";
            calendar.ResourceCategory       = "OTHER";
            calendar.ResourceDescription    = "internal description 1";
            calendar.UserVisibleDescription = "my description 2";
            calendar.FeatureInstances       = new List <FeatureInstance>()
            {
                new FeatureInstance()
                {
                    Feature = new Feature()
                    {
                        Name = "Test1"
                    }
                },
                new FeatureInstance()
                {
                    Feature = new Feature()
                    {
                        Name = "Test2"
                    }
                },
            };

            UnitTestControl.TestParameters.ResourcesService.AddCalendar(UnitTestControl.TestParameters.CustomerID, calendar);

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Update;
            cs.DN         = "*****@*****.**";
            cs.ObjectType = SchemaConstants.Calendar;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", calendar.ResourceId));

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("buildingId", new List <ValueChange>()
            {
                ValueChange.CreateValueAdd("testbuilding1")
            }));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("capacity", 33L));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("floorName", "G"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("floorSection", "33B"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("resourceCategory", "CONFERENCE_ROOM"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("resourceDescription", "internal description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("userVisibleDescription", "user description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("features", new List <ValueChange>()
            {
                ValueChange.CreateValueAdd("Test3"),
                ValueChange.CreateValueDelete("Test1"),
            }));

            string id = calendar.ResourceId;

            try
            {
                CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Calendar], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                CalendarResource c = UnitTestControl.TestParameters.ResourcesService.GetCalendar(UnitTestControl.TestParameters.CustomerID, id);
                Assert.AreEqual(cs.DN, "*****@*****.**");
                Assert.AreEqual("test-name", c.ResourceName);
                Assert.AreEqual("testbuilding1", c.BuildingId);
                Assert.AreEqual(33, c.Capacity);
                Assert.AreEqual("G", c.FloorName);
                Assert.AreEqual("33B", c.FloorSection);
                Assert.AreEqual("CONFERENCE_ROOM", c.ResourceCategory);
                Assert.AreEqual("internal description", c.ResourceDescription);
                Assert.AreEqual("user description", c.UserVisibleDescription);
                CollectionAssert.AreEquivalent(new string[] { "Test2", "Test3" }, ApiInterfaceCalendar.GetFeatureNames(c).ToList());
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteCalendar(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Updates a calendar resource.
        /// Documentation https://developers.google.com/directory/directory_v1/reference/calendars/update
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated directory service.</param>
        /// <param name="customer">The unique ID for the customer's Google account. As an account administrator, you can also use the my_customer alias to represent your account's customer ID.</param>
        /// <param name="calendarResourceId">The unique ID of the calendar resource to update.</param>
        /// <param name="body">A valid directory directory_v1 body.</param>
        /// <returns>CalendarResourceResponse</returns>
        public static CalendarResource Update(directoryService service, string customer, string calendarResourceId, CalendarResource body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (customer == null)
                {
                    throw new ArgumentNullException(customer);
                }
                if (calendarResourceId == null)
                {
                    throw new ArgumentNullException(calendarResourceId);
                }

                // Make the request.
                return(service.Calendars.Update(body, customer, calendarResourceId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Calendars.Update failed.", ex);
            }
        }
コード例 #14
0
ファイル: CalDav.cs プロジェクト: flechilla/CalDavServer
        /// <summary>
        ///     Method in charge of fill a CalendarResource and Return it.
        /// </summary>
        /// <param name="propertiesAndHeaders"></param>
        /// <param name="iCal"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        private async Task <CalendarResource> FillResource(Dictionary <string, string> propertiesAndHeaders,
                                                           ICalendarComponentsContainer iCal,
                                                           HttpResponse response)
        {
            #region Extracting Properties

            string calendarResourceId;
            propertiesAndHeaders.TryGetValue("calendarResourceId", out calendarResourceId);

            string url;
            propertiesAndHeaders.TryGetValue("url", out url);

            string principalId;
            propertiesAndHeaders.TryGetValue("principalId", out principalId);


            //var headers = response.GetTypedHeaders();

            #endregion

            // calculate etag that will notice a change in the resource
            var etag = $"\"{Guid.NewGuid()}\"";
            response.Headers["etag"] = etag;

            var resource = new CalendarResource(url, calendarResourceId);

            //add the owner property
            var principal    = _principalRepository.GetByIdentifier(principalId);
            var principalUrl = principal == null ? "" : principal.PrincipalURL;

            resource.Properties.Add(PropertyCreation.CreateOwner(principalUrl));
            resource.Properties.Add(PropertyCreation.CreateAclPropertyForUserCollections(principalUrl));
            resource.Properties.Add(PropertyCreation.CreateSupportedPrivilegeSetForResources());

            // await _resourceRespository.Add(resource);

            //adding the calculated etag in the getetag property of the resource
            var errorStack = new Stack <string>();
            await
            _resourceRespository.CreatePropertyForResource(resource, "getetag", "DAV:",
                                                           $"<D:getetag {_namespaces["D"]}>{etag}</D:getetag>",
                                                           errorStack, true);

            //updating the ctag of the collection noticing this way that the collection has changed.
            var stack = new Stack <string>();
            await
            _collectionRespository.CreateOrModifyProperty(
                url?.Remove(url.LastIndexOf("/", StringComparison.Ordinal) + 1), "getctag", _namespacesSimple["S"],
                $@"<S:getctag {_namespaces["S"]} >{Guid.NewGuid()}</S:getctag>", stack, true);

            //getting the uid
            var calendarComponents =
                iCal.CalendarComponents.FirstOrDefault(comp => comp.Key != "VTIMEZONE").Value;
            var calendarComponent = calendarComponents.FirstOrDefault();
            if (calendarComponent != null)
            {
                resource.Uid = calendarComponent.Properties["UID"].StringValue;
            }

            return(resource);
        }
コード例 #15
0
 internal static IEnumerable <string> GetFeatureNames(CalendarResource calendar, string attributeType)
 {
     return(ApiInterfaceCalendar.GetFeatureNames(calendar, attributeType == "Reference" ? AttributeType.Reference : AttributeType.String));
 }
コード例 #16
0
 private CSEntryChange GetCSEntryForCalendar(CalendarResource calendar, MmsSchema schema, IManagementAgentParameters config)
 {
     return(ImportProcessor.GetCSEntryChange(calendar, schema.Types[SchemaConstants.Calendar], config));
 }