private void SetGlobalVariables()
        {
            if (SourcesList.Any(s => s.Type == "Stem" && s.Name == "Clipper"))
            {
                _sourceClipper = SourcesList.FirstOrDefault(s => s.Type == "Stem" && s.Name == "Clipper").Id;
            }

            if (PortsList.Any(p => p.Name.ToLower().Contains("unallocated")))
            {
                _portUnallocated = PortsList.FirstOrDefault(p => p.Name.ToLower().Contains("unallocated")).Id;
            }
            else
            {
                throw new Exception("Add unallocated port to use as parent for new ports");
            }

            if (GradesList.Any(p => p.Name.ToLower().Contains("unallocated")))
            {
                _gradeUnallocated = GradesList.FirstOrDefault(g => g.Name.ToLower().Contains("unallocated")).Id;
            }
            else
            {
                throw new Exception("Add unallocated grade to use as parent for new grades");
            }
        }
Exemple #2
0
        public object GetDmsSources()
        {
            SourcesList listOfListOfSources = new SourcesList()
            {
                sources = new List <Source>()
                {
                    new Source()
                    {
                        id          = "/devperts-qmhandbuch/sources/mysource",
                        displayName = "QM-Handbuch",
                        categories  = new List <Category>()
                        {
                            new Category()
                            {
                                key         = "qm-documents",
                                displayName = "QM Documents"
                            }
                        },
                        properties = new List <Property>()
                        {
                            new Property("chapter", "Chapter Number"),
                            new Property("headline", "Headline"),
                            new Property("parent", "Parent Chapter")
                        }
                    }
                }
            };

            string requestDMSApp = JsonConvert.SerializeObject(listOfListOfSources);

            Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(listOfListOfSources, Formatting.Indented));
            return(Content(requestDMSApp));
//            return Content("{	\"sources\" : [{		\"id\" : \"/devperts-qmhandbuch/sources/mysource\",		\"displayName\" : \"QM-Handbuch\",		\"categories\": [{			\"key\": \"qm-documents\",          \"displayName\": \"QM Dokumente\"		}],		\"properties\" : [{			\"key\" : \"chapter\",			\"displayName\" : \"Kapitelnummer\"		},{			\"key\" : \"headline\",			\"displayName\" : \"Überschrift\"		},{			\"key\" : \"parent\",			\"displayName\" : \"Parent Chapter\"		}]	}]}", "application/json");
        }
 private void Init(bool isDefault)
 {
     if (isDefault)
     {
         SelectedSection  = SectionsList[0];
         SelectedType     = TypesList[0];
         SelectedStatus   = StatusesList[0];
         SelectedSource   = SourcesList[0];
         SelectedCustomer = CustomersList[0];
         SelectedBroker   = BrokersList[0];
         SelectedTrader   = TradersList[0];
     }
     else
     {
         SelectedSection  = SectionsList.First(s => s.id == Auction.sectionId);
         SelectedType     = TypesList.First(t => t.id == Auction.typeId);
         SelectedStatus   = StatusesList.First(s => s.Id == Auction.StatusId);
         SelectedSource   = SourcesList.First(s => s.id == Auction.SiteId);
         SelectedCustomer = CustomersList.First(c => c.id == Auction.CustomerId);
         SelectedBroker   = BrokersList.First(b => b.Id == Auction.BrokerId);
         SelectedTrader   = TradersList.First(t => t.id == Auction.TraderId);
     }
 }
Exemple #4
0
        private void HandleSources(string pszSources)
        {
            if (string.IsNullOrEmpty(pszSources))
            {
                return;
            }

            bool bAllowSources;
            int  nYear, nMonth, nDay;

            ushort nCount = 0;
            uint   dwID;
            ushort nPort;
            uint   dwServerIP  = 0;
            ushort nServerPort = 0;

            int nInvalid = 0;

            int pCh = pszSources.IndexOf("sources");

            if (pCh < 0)
            {
                return;
            }

            pCh = pCh + 7; // point to char after "sources"
            int pEnd = pszSources.Length;

            bAllowSources = true;

            // if there's an expiration date...
            if (pszSources[pCh] == '@' && (pEnd - pCh) > 7)
            {
                // after '@'
                pCh++;

                int.TryParse(pszSources.Substring(pCh, 2), out nYear);
                nYear += 2000;
                pCh   += 2;

                int.TryParse(pszSources.Substring(pCh, 2), out nMonth);
                pCh += 2;

                int.TryParse(pszSources.Substring(pCh, 2), out nDay);
                pCh += 2;

                DateTime expirationDate = DateTime.Now;

                try
                {
                    expirationDate = new DateTime(nYear, nMonth, nDay);
                }
                catch
                {
                }

                bAllowSources = expirationDate != null;

                if (bAllowSources)
                {
                    bAllowSources = (DateTime.Today < expirationDate);
                }
            }

            // increment pCh to point to the first "ip:port" and check for sources
            if (bAllowSources && ++pCh < pEnd)
            {
                SourcesList = MpdObjectManager.CreateSafeMemFile(256);
                // init to 0, we'll fix this at the end.
                SourcesList.WriteUInt16(nCount);
                // for each "ip:port" source string until the end
                // limit to prevent overflow (ushort due to CPartFile::AddClientSources)
                while (pCh < pEnd && nCount < ushort.MaxValue)
                {
                    string strIP = string.Empty;
                    int    pIP   = pCh;

                    // find the end of this ip:port string & start of next ip:port string.
                    if ((pCh = pszSources.IndexOf(',', pCh)) >= 0)
                    {
                        strIP = pszSources.Substring(pIP, pCh - pIP);

                        pCh++; // point to next "ip:port"
                    }
                    else
                    {
                        pCh = pEnd;
                    }

                    // if port is not present for this ip, go to the next ip.
                    int pPort = -1;

                    if ((pPort = strIP.IndexOf(':')) < 0)
                    {
                        nInvalid++;
                        continue;
                    }

                    string strPort = strIP.Substring(pPort + 1);        // terminate ip string
                    strIP = strIP.Substring(0, pPort);

                    if (!ushort.TryParse(strPort, out nPort))
                    {
                        nInvalid++;
                        continue;
                    }

                    // skip bad ips / ports
                    if (nPort > 0xFFFF || nPort == 0)   // port
                    {
                        nInvalid++;
                        continue;
                    }

                    IPAddress address = null;

                    if (!IPAddress.TryParse(strIP, out address))
                    {
                        // hostname?
                        if (strIP.Length > 512)
                        {
                            nInvalid++;
                            continue;
                        }

                        UnresolvedHostname hostname =
                            MuleApplication.Instance.ED2KObjectManager.CreateUnresolvedHostname();

                        hostname.Port     = nPort;
                        hostname.HostName = strIP;

                        hostnameSourcesList_.Add(hostname);
                        continue;
                    }

                    //TODO: This will filter out *.*.*.0 clients. Is there a nice way to fix?
                    dwID = BitConverter.ToUInt32(address.GetAddressBytes(), 0);

                    if (MuleUtilities.IsLowID(dwID))    // ip
                    {
                        nInvalid++;
                        continue;
                    }

                    SourcesList.WriteUInt32(dwID);
                    SourcesList.WriteUInt16(nPort);
                    SourcesList.WriteUInt32(dwServerIP);
                    SourcesList.WriteUInt16(nServerPort);
                    nCount++;
                }

                SourcesList.SeekToBegin();
                SourcesList.WriteUInt16(nCount);
                SourcesList.SeekToBegin();

                if (nCount == 0)
                {
                    SourcesList = null;
                }
            }
        }