コード例 #1
0
        private void CreateAndInsertDeltaOperation(string mrid, ResourceDescription rd)
        {
            long        negGid  = 0;
            DeltaOpType deltaOp = DeltaOpType.Insert;
            DMSType     type    = (DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(rd.Id);

            if (ModelCodeHelper.ExtractEntityIdFromGlobalId(rd.Id) < 0 && !NegativeGidToMrid.ContainsKey(rd.Id))
            {
                negGid = rd.Id;
                NegativeGidToMrid.Add(rd.Id, mrid);
            }

            if (MridToPositiveGidFromServer.ContainsKey(mrid))
            {
                rd.Id   = MridToPositiveGidFromServer[mrid];
                deltaOp = DeltaOpType.Update;
            }

            delta.AddDeltaOperation(deltaOp, rd, true);

            if (!MridsFromConcreteModel.Contains(mrid))
            {
                MridsFromConcreteModel.Add(mrid);
            }

            report.Report.Append("Operation: ").Append(deltaOp).Append(" ").Append(type)
            .Append(" mrid: ").Append(mrid)
            .Append(" ID: ").Append(string.Format("0x{0:X16}", negGid))
            .Append(" after correction is GID: ").AppendLine($"0x{rd.Id:X16}");
        }
コード例 #2
0
        private void CorrectNegativeReferences()
        {
            foreach (ResourceDescription rd in delta.InsertOperations)
            {
                foreach (Property prop in rd.Properties)
                {
                    if (prop.Type == PropertyType.Reference)
                    {
                        long targetGid = prop.AsLong();

                        if (ModelCodeHelper.ExtractEntityIdFromGlobalId(targetGid) < 0)
                        {
                            if (NegativeGidToMrid.ContainsKey(targetGid))
                            {
                                string mrid = NegativeGidToMrid[targetGid];
                                if (MridToPositiveGidFromServer.ContainsKey(mrid))
                                {
                                    long positiveGid = MridToPositiveGidFromServer[mrid];
                                    prop.SetValue(positiveGid);
                                }
                            }
                        }
                    }
                }
            }

            foreach (ResourceDescription rd in delta.UpdateOperations)
            {
                foreach (Property prop in rd.Properties)
                {
                    if (prop.Type == PropertyType.Reference)
                    {
                        long targetGid = prop.AsLong();

                        if (ModelCodeHelper.ExtractEntityIdFromGlobalId(targetGid) < 0)
                        {
                            if (NegativeGidToMrid.ContainsKey(targetGid))
                            {
                                string mrid = NegativeGidToMrid[targetGid];
                                if (MridToPositiveGidFromServer.ContainsKey(mrid))
                                {
                                    long positiveGid = MridToPositiveGidFromServer[mrid];
                                    prop.SetValue(positiveGid);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        private bool PopulateNmsDataFromServer(ModelResourcesDesc resourcesDesc)
        {
            bool   success = false;
            string message = "Getting nms data from server started.";

            Logger.LogInfo(message);

            using (NetworkModelGDAProxy nmsProxy = proxyFactory.CreateProxy <NetworkModelGDAProxy, INetworkModelGDAContract>(EndpointNames.NetworkModelGDAEndpoint))
            {
                if (nmsProxy == null)
                {
                    string errMessage = "NetworkModelGdaClient is null.";
                    Logger.LogWarn(errMessage);
                    throw new NullReferenceException(errMessage);
                }

                HashSet <ModelCode> requiredEntityTypes = new HashSet <ModelCode>();

                foreach (DMSType dmsType in Enum.GetValues(typeof(DMSType)))
                {
                    if (dmsType == DMSType.MASK_TYPE)
                    {
                        continue;
                    }

                    ModelCode mc = resourcesDesc.GetModelCodeFromType(dmsType);

                    if (!requiredEntityTypes.Contains(mc))
                    {
                        requiredEntityTypes.Add(mc);
                    }
                }

                List <ModelCode> mrIdProp = new List <ModelCode>()
                {
                    ModelCode.IDOBJ_MRID
                };

                foreach (ModelCode modelCodeType in requiredEntityTypes)
                {
                    int iteratorId        = 0;
                    int resourcesLeft     = 0;
                    int numberOfResources = 10000;                     //TODO: connfigurabilno

                    try
                    {
                        iteratorId    = nmsProxy.GetExtentValues(modelCodeType, mrIdProp);
                        resourcesLeft = nmsProxy.IteratorResourcesLeft(iteratorId);

                        while (resourcesLeft > 0)
                        {
                            List <ResourceDescription> gdaResult = nmsProxy.IteratorNext(numberOfResources, iteratorId);

                            foreach (ResourceDescription rd in gdaResult)
                            {
                                if (rd.Properties[0].Id != ModelCode.IDOBJ_MRID)
                                {
                                    continue;
                                }

                                string mrId = rd.Properties[0].PropertyValue.StringValue;

                                if (!MridToPositiveGidFromServer.ContainsKey(mrId))
                                {
                                    MridToPositiveGidFromServer.Add(mrId, rd.Id);
                                }
                                else
                                {
                                    throw new NotImplementedException("Method PopulateNmsDataFromServer() -> MridToPositiveGid.ContainsKey(mrId) == true");
                                }
                            }

                            resourcesLeft = nmsProxy.IteratorResourcesLeft(iteratorId);
                        }

                        nmsProxy.IteratorClose(iteratorId);

                        message = "Getting nms data from server successfully finished.";
                        Logger.LogInfo(message);
                        success = true;
                    }
                    catch (Exception e)
                    {
                        message = string.Format("Getting extent values method failed for {0}.\n\t{1}", modelCodeType, e.Message);
                        Logger.LogError(message);
                        success = false;
                    }
                }
            }

            return(success);
        }