Beispiel #1
0
        /// <summary>
        /// executes a create DER SOAP command
        /// </summary>
        /// <param name="DERGroupName">name of der group to create</param>
        /// <param name="members">list of der's (their names) to create, defaultNull = all</param>
        /// <returns></returns>
        public int createDERGroup(String DERGroupName, String[] members)
        {
            if (DERGroupName == null || DERGroupName.Length < 1)
            {
                throw new DERConfigureException("createDERGroup illegal argument, DERGroup name not set");
            }

            // intialize service
            CIMChangeDERGroup.DERGroup_PortClient client;
            CIMData.header header = _data.CreateDERHeader;

            if (!hasData(header.EndPoint))
            {
                throw new DERConfigureException("End Point required");
            }

            client = new CIMChangeDERGroup.DERGroup_PortClient("DERGroup_Port", header.EndPoint);

            // Initialize service vars
            DERMSInterface.CIMChangeDERGroup.DERGroupRequestMessageType req = new DERMSInterface.CIMChangeDERGroup.DERGroupRequestMessageType();
            CIMChangeDERGroup.HeaderType to = new CIMChangeDERGroup.HeaderType();
            req.Header = to;

            // initialize  header
            CIMChangeDERGroup.HeaderTypeVerb v = new CIMChangeDERGroup.HeaderTypeVerb();
            if (header.Verb != null && Enum.TryParse(header.Verb, out v))
            {
                to.Verb = v;
            }
            else
            {
                to.Verb = CIMChangeDERGroup.HeaderTypeVerb.change;
            }
            to.Noun         = header.Noun;
            to.ReplyAddress = header.ReplyAddress;
            to.Revision     = header.Revision;
            to.Source       = header.Source;
            to.AckRequired  = header.AckRequired;
            if (to.AckRequired == true)
            {
                to.AckRequiredSpecified = true;
            }

            to.Comment = header.Comment;
            to.Context = header.Context;
            if (hasData(header.UserOrganization) || hasData(header.UserID))
            {
                to.User              = new CIMChangeDERGroup.UserType();
                to.User.UserID       = (hasData(header.UserID)) ? header.UserID : "epri"; // required
                to.User.Organization = header.UserOrganization;                           // optional
            }

            // initialize the payload
            req.Payload                                  = new CIMChangeDERGroup.DERGroupPayloadType();
            req.Payload.DERGroups                        = new CIMChangeDERGroup.EndDeviceGroup[1];
            req.Payload.DERGroups[0]                     = new CIMChangeDERGroup.EndDeviceGroup();
            req.Payload.DERGroups[0].Version             = new CIMChangeDERGroup.EndDeviceGroupVersion();
            req.Payload.DERGroups[0].Version.major       = _data.Version.Major;
            req.Payload.DERGroups[0].Version.minor       = _data.Version.Minor;
            req.Payload.DERGroups[0].Version.revision    = _data.Version.Revision;
            req.Payload.DERGroups[0].Version.versionDate = _data.Version.Date;

            // find the data that matches the DER name passed
            CIMData.DERGroup group = _data.Groups.Find(x => x.GroupName.Equals(DERGroupName));
            if (group == null)
            {
                throw new DERConfigureException("DERGroup Name " + DERGroupName + " not found in configuration file");
            }
            else
            {
                req.Payload.DERGroups[0].name = group.GroupName;
                req.Payload.DERGroups[0].mRID = group.Mrid;
                List <CIMChangeDERGroup.DERMember> DERMembers = new List <CIMChangeDERGroup.DERMember>();

                // load the ders that go with the DER Group
                foreach (CIMData.device dev in group.Devices)
                {
                    // todo : Is the purpose of members to filter our DERS to be created?
                    if (members == null || (members != null && Array.Find(members, x => x.Equals(dev.Name)) != null))
                    {
                        CIMChangeDERGroup.DERMember d = new CIMChangeDERGroup.DERMember();
                        DERMembers.Add(d);
                        d.name                                    = dev.Name;
                        d.mRID                                    = dev.Mrid;
                        d.CapabilityList                          = new CIMChangeDERGroup.DERMemberCapabilityList();
                        d.CapabilityList.ActivePower              = new CIMChangeDERGroup.ActivePower();
                        d.CapabilityList.ActivePower.value        = (float)dev.WattCapacity;
                        d.CapabilityList.ActivePower.multiplier   = CIMChangeDERGroup.multiplier.k;
                        d.CapabilityList.ActivePower.unit         = "W";
                        d.CapabilityList.ReactivePower            = new CIMChangeDERGroup.ReactivePower();
                        d.CapabilityList.ReactivePower.value      = (float)dev.VarCapacity;
                        d.CapabilityList.ReactivePower.multiplier = CIMChangeDERGroup.multiplier.k;
                        d.CapabilityList.ReactivePower.unit       = "VAr";

                        // TODO : New xsd, add the watts etc...
                    }
                }
                req.Payload.DERGroups[0].EndDevice = DERMembers.ToArray();

                // Log outbound, send the message to DER Server, log return message
                _lastMessageSent = logMessage <DERMSInterface.CIMChangeDERGroup.DERGroupRequestMessageType>(req);
                DERMSInterface.CIMChangeDERGroup.DERGroupResponseMessageType reply = client.CreateDERGroup(req);
                _lastMessageReceived = logMessage <DERMSInterface.CIMChangeDERGroup.DERGroupResponseMessageType>(reply);

                if (reply.Reply.Result.CompareTo(CIMChangeDERGroup.ReplyTypeResult.OK) == 0)
                {
                    return(0);
                }
                return(1);
            }
        }
Beispiel #2
0
        /// <summary>
        /// executes a create DERdispatch soap command
        /// </summary>
        /// <param name="DERGroupName">DERGroup name</param>
        /// <param name="q">realPower or reactivePower</param>
        /// <param name="isOverride">send overrideValue instead of value from cimdata</param>
        /// <param name="overrideValue">value to be used for dispatch</param>
        /// <returns></returns>
        public int DispatchDERGroup(String MRID, quantity q, Boolean isOverride = false, double overrideValue = 0.0)
        {
            CIMDERGroupDispatches.DERGroupDispatches_PortClient client;
            CIMData.header header = _data.DispatchDERHeader;

            if (!hasData(header.EndPoint))
            {
                throw new DERConfigureException("End Point required");
            }

            // initialize SOAP server
            client = new CIMDERGroupDispatches.DERGroupDispatches_PortClient("DERGroupDispatches_Port", header.EndPoint);

            // intiailize service arguments
            CIMDERGroupDispatches.HeaderType to = new CIMDERGroupDispatches.HeaderType();
            CIMDERGroupDispatches.DERGroupDispatchesPayloadType payload = new CIMDERGroupDispatches.DERGroupDispatchesPayloadType();

            CIMDERGroupDispatches.DERGroupDispatchesRequestMessageType req = new CIMDERGroupDispatches.DERGroupDispatchesRequestMessageType();
            req.Payload = payload;
            req.Header  = to;

            // set service header arguments
            CIMDERGroupDispatches.HeaderTypeVerb v = new CIMDERGroupDispatches.HeaderTypeVerb();
            if (header.Verb != null && Enum.TryParse(header.Verb, out v))
            {
                to.Verb = v;
            }
            else
            {
                to.Verb = CIMDERGroupDispatches.HeaderTypeVerb.create;
            }
            to.Noun         = header.Noun;
            to.ReplyAddress = header.ReplyAddress;
            to.Revision     = header.Revision;
            to.Source       = header.Source;
            to.AckRequired  = header.AckRequired;
            if (to.AckRequired == true)
            {
                to.AckRequiredSpecified = true;
            }
            to.Comment = header.Comment;
            to.Context = header.Context;
            if (hasData(header.UserOrganization) || hasData(header.UserID))
            {
                to.User              = new CIMDERGroupDispatches.UserType();
                to.User.UserID       = (hasData(header.UserID)) ? header.UserID : "epri"; // required
                to.User.Organization = header.UserOrganization;                           // optional
            }

            // load the data for the SOAP call
            CIMData.DERGroup group = _data.Groups.Find(x => x.Mrid.Equals(MRID));
            if (group != null)
            {
                payload.DERGroupDispatches                  = new CIMDERGroupDispatches.DERGroupDispatch[1];
                payload.DERGroupDispatches[0]               = new CIMDERGroupDispatches.DERGroupDispatch();
                payload.DERGroupDispatches[0].DERGroup      = new CIMDERGroupDispatches.DERGroup();
                payload.DERGroupDispatches[0].DERGroup.mRID = group.Mrid;
                payload.DERGroupDispatches[0].DERGroup.name = group.GroupName;
                // TODO : Docs say mrid, but name is required in wsdl. Ask Gerry.
                payload.DERGroupDispatches[0].RequestedCapability = new CIMDERGroupDispatches.RequestedCapability();
                payload.DERGroupDispatches[0].RequestedCapability.capabilityType = (CIMDERGroupDispatches.capabilityType)Enum.Parse(typeof(CIMDERGroupDispatches.capabilityType), q.ToString());

                // load with value passed, or reactive value, or real value
                if (isOverride == true)
                {
                    payload.DERGroupDispatches[0].RequestedCapability.value = (float)overrideValue;
                }
                else if (q.Equals(quantity.ApparentPower))
                {
                    payload.DERGroupDispatches[0].RequestedCapability.value = (float)group.getVarCapacity();
                }
                else
                {
                    payload.DERGroupDispatches[0].RequestedCapability.value = (float)group.getWattCapacity();
                }

                // set the multiplier and units
                if (q.Equals(quantity.RealPower))
                {
                    payload.DERGroupDispatches[0].RequestedCapability.capabilityMultiplier = CIMDERGroupDispatches.UnitMultiplier.k;
                    payload.DERGroupDispatches[0].RequestedCapability.capabilityUnits      = "W";
                }
                else
                {
                    payload.DERGroupDispatches[0].RequestedCapability.capabilityMultiplier = CIMDERGroupDispatches.UnitMultiplier.k;
                    payload.DERGroupDispatches[0].RequestedCapability.capabilityUnits      = "VAr";
                }


                // log message to be sent, send message, log result
                _lastMessageSent = logMessage <DERMSInterface.CIMDERGroupDispatches.DERGroupDispatchesRequestMessageType>(req);
                CIMDERGroupDispatches.DERGroupDispatchesResponseMessageType reply = client.CreateDERGroupDispatches(req);
                _lastMessageReceived = logMessage <CIMDERGroupDispatches.DERGroupDispatchesResponseMessageType>(reply);

                if (reply.Reply.Result.CompareTo(CIMDERGroupDispatches.ReplyTypeResult.OK) == 0)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
            else
            {
                throw new DERConfigureException("DERGroup MRID " + MRID + " not found in configuration file");
            }
        }