コード例 #1
0
        private async Task CableDefaults()
        {
            using (var odw = new OracleDatabaseWorker(tbOracleConnectionStringText))
            {
                List <string> classes        = odw.GetListForDataColumn(@"select distinct class from (
                                                                                Select  case when cable_type=1 then 'COPPER' else case when cable_type=2 then 'FIBER' else 'UNKNOWN' end end as Class
                                                                                from cable_Type where cable_type is not null order by cable_type)");
                List <string> sizes          = odw.GetListForDataColumn("Select distinct capacity from cable_type where capacity is not null order by capacity");
                List <string> wiredimensions = odw.GetListForDataColumn("Select diameter from cable_type where diameter is not null order by diameter");
                List <string> media          = new List <string>()
                {
                    "Media"
                };
                List <string> types = odw.GetListForDataColumn("Select distinct std_code from cable_Type where std_code is not null order by std_code");
                ;
                List <string> statuses = odw.GetListForDataColumn(@"select distinct CABLESTATUS from(
                                                                                            select CASE cast(cs.Status as varchar(50)) WHEN '5' 
                                                                                            THEN 'Active' 
                                                                                            when '6' then 'UNKNOWN'
                                                                                            else cast(cs.Status as varchar(50)) end   AS CABLESTATUS
                                                                                            from cable_seg cs)
                                                                                                                                ");

                List <string> classrelationships = odw.GetListForDataColumn(@"select  Capacity||'|'||std_code||'|'||class  as sizetypeclass from(
                Select DISTINCT  case when Capacity is null then 0 else Capacity end as CAPACITY,case when  std_code is null then  'null' else std_code end as std_code, case when cable_type=1 then 'COPPER' else case when cable_type=2 then 'FIBER' else 'UNKNOWN' end end as CLASS
                from cable_Type where capacity is not null order by capacity)");
                /// will be size|type|class if size is null 0, if type null then 'null'
                List <string> routes = odw.GetDistinctDataColumn(cablesWithOUTSpansTable, "CABLEROUTE");

                //run types through ffunction to normalize the names
                //   temptypes.ForEach((x) => types.Add(ImporterHelper.GetAllUntilNumber(x)));
                //extras
                //class
                var del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        foreach (var str in lst.Where(s => s != ""))
                        {
                            if (!uow.Query <CableClass>().Any(x => x.TypeName == str))
                            {
                                CableClass cs = new CableClass(uow)
                                {
                                    TypeName = str, TypeDescription = str
                                };
                                uow.CommitChanges();
                            }
                        }
                    }
                    return(true);
                });
                del.Invoke(classes);//**

                //type
                del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        foreach (var rawData in lst.Where(s => s != ""))
                        {
                            // add to dictionary
                            string normalizedData = GetAllUntilNumber(rawData.Trim());
                            CableTypeDictionary[rawData.Trim()] = normalizedData;
                            if (!uow.Query <CableType>().Any(x => "" + x.TypeName == normalizedData))
                            {
                                CableType cs = new CableType(uow)
                                {
                                    TypeName = normalizedData, TypeDescription = rawData
                                };
                                uow.CommitChanges();
                            }
                        }
                    }
                    return(true);
                });
                del.Invoke(types);//**

                //size
                del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        foreach (var str in lst.Where(s => s != ""))
                        {
                            if (!uow.Query <CableSize>().Any(x => x.Code == str))
                            {
                                CableSize cs = new CableSize(uow)
                                {
                                    Count = int.Parse(str), Code = str
                                };
                                uow.CommitChanges();
                            }
                        }
                    }
                    return(true);
                });
                del.Invoke(sizes);//**
                //media
                del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        foreach (var str in lst
                                 .Where(s => s != ""))
                        {
                            if (!uow.Query <CableMedia>().Any(x => x.TypeName == str))

                            {
                                CableMedia cs = new CableMedia(uow)
                                {
                                    TypeName = str, TypeDescription = str
                                };
                                //put media in all classes for this one
                                foreach (var item in uow.Query <CableClass>())
                                {
                                    item.CableMedia.Add(cs);
                                }
                                uow.CommitChanges();
                            }
                        }
                        return(true);
                    }
                });
                del.Invoke(media);//**

                //wiredimensions
                del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        foreach (var str in lst.Where(s => s != ""))
                        {
                            if (!uow.Query <WireDimension>().Any(x => "" + x.Gauge == str))
                            {
                                WireDimension cs = new WireDimension(uow)
                                {
                                    Gauge = str
                                };
                                uow.CommitChanges();
                            }
                        }
                    }
                    return(true);
                });
                del.Invoke(wiredimensions);//**

                //routes
                del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        foreach (var str in lst
                                 .Where(s => s != ""))
                        {
                            if (!uow.Query <Route>().Any(x => x.Name == str))
                            {
                                Route cs = new Route(uow)
                                {
                                    Name = str
                                };
                                uow.CommitChanges();
                            }
                        }
                    }
                    return(true);
                });
                IAsyncResult routeres = del.BeginInvoke(routes, null, null);//**

                //status
                del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        foreach (var str in lst
                                 .Where(s => s != ""))
                        {
                            if (!uow.Query <CableStatus>().Any(x => x.StatusName == str))
                            {
                                CableStatus cs = new CableStatus(uow)
                                {
                                    StatusName = str
                                };
                                uow.CommitChanges();
                            }
                        }
                        return(true);
                    }
                });
                del.Invoke(statuses);//**

                //have to wait for this stuff to finish before the next

                //size typ class rel
                del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        CableClass cclass = null;
                        CableMedia cmedia = uow.Query <CableMedia>()
                                            .FirstOrDefault(x => x.TypeName == "Media");
                        foreach (var str in lst
                                 .Where(s => s != ""))
                        {
                            //pipdelimited str   Capacity||'|'||std_code||'|'||class  as size|type|class
                            var arr     = str.Split('|');
                            string size = arr[0], cls = arr[2], type = "";
                            if (DataConvert.CableTypeDictionary.ContainsKey(arr[1].Trim()))
                            {
                                type = DataConvert.CableTypeDictionary[arr[1].Trim()];
                            }

                            cclass          = uow.Query <CableClass>().FirstOrDefault(x => x.TypeName == cls);
                            CableType ctype = uow.Query <CableType>().FirstOrDefault(x => x.TypeName == type);
                            CableSize csize = uow.Query <CableSize>().FirstOrDefault(x => x.Count.ToString() == size);
                            if (cclass != null)
                            {
                                //add size and tyype to class but mae sur we don't get dupes
                                if (ctype != null && !cclass.CableTypes.Contains(ctype))
                                {
                                    cclass.CableTypes.Add(ctype);
                                }
                                if (csize != null && !cclass.CableSizes.Contains(csize))
                                {
                                    cclass.CableSizes.Add(csize);
                                }
                                uow.CommitChanges();
                            }
                        }
                        //add media
                        if (cmedia != null)
                        {
                            if (!cclass.CableMedia.Contains(cmedia))
                            {
                                cclass.CableMedia.Add(cmedia);
                            }
                        }
                        return(true);
                    }
                });
                del.Invoke(classrelationships);
                NewNetServices.Module.Core.StaticHelperMethods.WriteOut($"TYPES DICTIONARY {CableTypeDictionary.Count} items from {types.Count} total.\n{string.Join(" ", CableTypeDictionary.Select(x => $"\t{x.Key} ->  {x.Value}\t|"))}");
                await Task.FromResult(routeres);
            }
        }
コード例 #2
0
        public async Task DesignationGroupDefaults()
        {
            using (var odw = new OracleDatabaseWorker(tbOracleConnectionStringText))
            {
                //List<string> cableclass = odw.GetListForDataColumn(@"select distinct class from designationgroups");
                //List<string> cablesizes = odw.GetListForDataColumn(@"SELECT distinct mc.MaxCount  from designationgroups");
                List <string> cablestatuses = new List <string>()
                {
                    "Active"
                };

                List <string> classrelationships = odw.GetListForDataColumn(@"select distinct classsize from
(SELECT   class ||'|'|| MaxCount as classsize from designationgroups where maxcount is not null order by maxcount)"); /// will be size|type|class if size is null 0, if type null then 'null'


                //status
                var del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        foreach (var str in lst
                                 .Where(s => s != ""))
                        {
                            if (!uow.Query <CableStatus>().Any(x => x.StatusName == str))
                            {
                                CableStatus cs = new CableStatus(uow)
                                {
                                    StatusName = str
                                };
                                uow.CommitChanges();
                            }
                        }
                        return(true);
                    }
                });
                IAsyncResult statusres = del.BeginInvoke(cablestatuses, null, null);


                //size typ class rel
                del = new MyDelegate((lst) =>
                {
                    using (var uow = new UnitOfWork(Tsdl))
                    {
                        CableClass cclass = null;
                        CableMedia cmedia = uow.Query <CableMedia>().FirstOrDefault(x => x.TypeName == "Media");
                        foreach (var str in lst
                                 .Where(s => s != ""))
                        {
                            //pipdelimited str
                            var arr = str.Split('|');
                            //making type the same as the class per andyrew
                            cclass          = uow.Query <CableClass>().FirstOrDefault(x => x.TypeName == arr[0]);
                            CableType ctype = uow.Query <CableType>().FirstOrDefault(x => x.TypeName == arr[0]);
                            //create class
                            if (cclass == null)
                            {
                                cclass = new CableClass(uow)
                                {
                                    TypeName = arr[0], TypeDescription = arr[0]
                                };
                                if (cmedia != null)
                                {
                                    cclass.CableMedia.Add(cmedia);
                                }
                                uow.CommitChanges();
                            }
                            //create type
                            if (ctype == null)
                            {
                                ctype = new CableType(uow)
                                {
                                    TypeName = arr[0], TypeDescription = arr[0]
                                };
                                cclass.CableTypes.Add(ctype);
                                uow.CommitChanges();
                            }

                            //have to do his check so that we associate desgroups sizes and classes separate from regular cables
                            CableSize csize = cclass.CableSizes.FirstOrDefault(x => x.Count.ToString() == arr[1]);
                            //create size
                            if (csize == null && int.TryParse(arr[1], out int count))
                            {
                                csize = new CableSize(uow)
                                {
                                    Count = count, Code = "" + count
                                };
                                cclass.CableSizes.Add(csize);
                                uow.CommitChanges();
                            }
                            uow.CommitChanges();
                        }

                        return(true);
                    }
                });
                IAsyncResult relres = del.BeginInvoke(classrelationships, null, null);

                await Task.FromResult(statusres);

                await Task.FromResult(relres);
            }
        }