Esempio n. 1
0
 public DatabaseDataFormat(
     string server, string catalog, string username,
     string password, string dbSystem,
     string source, List <string> KeepValues, SourceDataType sourceDataType,
     string port = ""
     ) : base(source, KeepValues, sourceDataType)
 {
     DB = new DB(server, catalog, username, password, dbSystem, port);
 }
Esempio n. 2
0
        private async Task <string> LoadData(SourceDataType sourceDataType)
        {
            //todo check if readable + secure reading
            string data = (sourceDataType == SourceDataType.FILE) ?
                          File.ReadAllText(workerOptions.DataURLOrFilePath) :
                          new WebClient().DownloadString(workerOptions.DataURLOrFilePath);

            return(data);
        }
Esempio n. 3
0
        public QshConverter(string satStoragePath, SourceDataType sourceDataType)
        {
            _sourceDataType = sourceDataType;

            if (!Directory.Exists(satStoragePath))
            {
                Directory.CreateDirectory(satStoragePath);
            }

            _storage = new Storage(satStoragePath);
        }
Esempio n. 4
0
        public static IDataLoader CreateDataLoader(SourceDataType type, DataLoadingTarget target, string fileSetName, TableOverwriteMode overwriteMode, bool sourceOrder)
        {
            string dir  = Directory.GetCurrentDirectory();
            string file = string.Concat(fileSetName, DataLoaderConstants.FileExtConfig);

            using (var stream = File.Open(Path.Combine(dir, file), FileMode.Open, FileAccess.Read))
                switch (type)
                {
                case SourceDataType.DbfAndKml:
                    return(CreateLoader <DbaseKmlToTablesDataLoaderParams, DbaseKmlEntityProducer>(fileSetName, target, stream, sourceOrder, overwriteMode));

                case SourceDataType.Csv:
                    return(CreateLoader <CsvToTablesDataLoaderParams, CsvEntityProducer>(fileSetName, target, stream, sourceOrder, overwriteMode));

                case SourceDataType.Kml:
                    return(CreateLoader <KmlToTablesDataLoaderParams, KmlEntityProducer>(fileSetName, target, stream, sourceOrder, overwriteMode));
                }
            throw new NotSupportedException(type.ToString());
        }
Esempio n. 5
0
        public DataFormat(string source, List <string> KeepValues, SourceDataType sourceDataType)
        {
            switch (sourceDataType)
            {
            case SourceDataType.API:
                DataObjects = API(source, KeepValues);
                break;

            case SourceDataType.Excel:
                DataObjects = Excel(source, KeepValues);
                break;

            case SourceDataType.JSON:
                DataObjects = JSON(source, KeepValues);
                break;

            case SourceDataType.XML:
                DataObjects = XML(source, KeepValues);
                break;
            }
        }
Esempio n. 6
0
        public UploadParam(SourceDataType type)
        {
            Type      = type;
            IsPlanned = true;

            switch (type)
            {
            case SourceDataType.Csv:
                _dataLoaderParams = CsvToTablesDataLoaderParams.FromFile(this);
                break;

            case SourceDataType.DbfAndKml:
                break;

            case SourceDataType.Kml:
                _dataLoaderParams = Kml.KmlToTablesDataLoaderParams.FromFile(this);
                break;

            default:
                throw new InvalidOperationException();
            }
        }
 public XmlDataFormat(string source, List <string> KeepValues, SourceDataType sourceDataType) :
     base(source, KeepValues, sourceDataType)
 {
 }
 private void RetrieveTextAttributeByType(string entityLogicalName, SourceDataType sourceDataType)
 {
     Cursor = Cursors.WaitCursor;
     WorkAsync(string.Format("Loading attributes valid for {0}...", sourceDataType),
         dwea =>
         {
             dwea.Result = MetadataHelper.RetrieveEntity(entityLogicalName, Service);
             var entityMetadata = MetadataHelper.RetrieveEntity(entityLogicalName, Service);
             switch (sourceDataType)
             {
                 case SourceDataType.Url:
                     dwea.Result = entityMetadata.Attributes.Where(x => x.AttributeType.Value == AttributeTypeCode.String
                     && ((StringAttributeMetadata)x).Format.Value == Microsoft.Xrm.Sdk.Metadata.StringFormat.Url);
                     break;
                 case SourceDataType.Email:
                     dwea.Result = entityMetadata.Attributes.Where(x => x.AttributeType.Value == AttributeTypeCode.String
                     && ((StringAttributeMetadata)x).Format.Value == Microsoft.Xrm.Sdk.Metadata.StringFormat.Email);
                     break;
                 case SourceDataType.TwitterHandle:
                 case SourceDataType.Folder:
                     dwea.Result = entityMetadata.Attributes.Where(x => x.AttributeType.Value == AttributeTypeCode.String
                     && ((StringAttributeMetadata)x).Format.Value == Microsoft.Xrm.Sdk.Metadata.StringFormat.Text);
                     break;
                 default:
                     break;
             }
         },
         dwea =>
         {
             Cursor = Cursors.Default;
             if (dwea.Error != null)
             {
                 string errorMessage = CrmExceptionHelper.GetErrorMessage(dwea.Error, true);
                 CommonDelegates.DisplayMessageBox(ParentForm, errorMessage, "Error", MessageBoxButtons.OK,
                                                   MessageBoxIcon.Error);
             }
             else
             {
                 var attributeMetadata = (IEnumerable<AttributeMetadata>)dwea.Result;
                 foreach (var attribute in attributeMetadata)
                 {
                     if (attribute.DisplayName.LocalizedLabels.Any())
                     {
                         var item = new ListViewItem { Text = attribute.DisplayName.UserLocalizedLabel != null ? attribute.DisplayName.UserLocalizedLabel.Label : attribute.LogicalName, Tag = attribute.LogicalName };
                         item.SubItems.Add(attribute.SchemaName);
                         item.SubItems.Add(attribute.Description.UserLocalizedLabel != null ? attribute.Description.UserLocalizedLabel.Label : "");
                         item.SubItems.Add(entityLogicalName);
                         ListViewDelegates.AddItem(lvAttributes, item);
                     }
                 }
             }
         });
 }
Esempio n. 9
0
        public static List <DataObject> FromRouter(string source, List <string> keepValues, SourceDataType sourceDataType)
        {
            switch (sourceDataType)
            {
            case SourceDataType.API:
                return(From.API(source, keepValues));

            case SourceDataType.Excel:
                return(From.Excel(source, keepValues));

            case SourceDataType.JSON:
                return(From.JSON(source, keepValues));

            case SourceDataType.XML:
                return(From.XML(source, keepValues));

            default:
                return(From.JSON(source, keepValues));
            }
        }
Esempio n. 10
0
        private async Task DoWork(CancellationToken cancellationToken)
        {
            logger.LogInformation($"Launching CTU60G, current version: {Assembly.GetExecutingAssembly().GetName().Version}");
            SourceDataType sourceDataType = default;

            mailing = CheckEmailOptionValues();
            if (await CheckWorkerOptionValues(cancellationToken, sourceDataType))
            {
                logger.LogInformation($"Synchronization type set to: {workerOptions.Synchronization }");
                string msg = $"Run type set to: {workerOptions.Run}";
                msg += (workerOptions.Run == RunTypeEnum.InSpecifedTime.ToString()) ? $", app will run every day in {workerOptions.RunTimeSpecification.Hours}:{workerOptions.RunTimeSpecification.Minutes}":"";
                msg += (workerOptions.Run == RunTypeEnum.AfterSpecifedTime.ToString()) ? $", app will run always after {workerOptions.RunTimeSpecification}":"";
                logger.LogInformation(msg);
                do
                {
                    //Loading source data from file or url
                    logger.LogInformation("Loading data");
                    string loadedData = default;
                    try
                    {
                        loadedData = await LoadData(sourceDataType);
                    }
                    catch (Exception e)
                    {
                        logger.LogError("Could not obtain source data, exception message:\n {0}.", e.Message);
                        TaskCompletionSource.SetResult(false);
                        appLifetime.StopApplication();
                        return;
                    }

                    //parsing loaded source data
                    logger.LogInformation("parsing loaded data");
                    List <WirelessSite> parsedSites = await ParseData(cancellationToken, loadedData);

                    cancellationToken.ThrowIfCancellationRequested();
                    try
                    {
                        logger.LogInformation("LoggingIn");
                        using (CTUClient client = new CTUClient(workerOptions.CTULogin, workerOptions.CTUPass, workerOptions.SignalIsolationConsentIfMyOwn))
                        {
                            logger.LogInformation("LoggedIn");
                            OnSiteData ctuMetaData = new OnSiteData(await client.GetMyStationsAsync());

                            foreach (var site in parsedSites)
                            {
                                cancellationToken.ThrowIfCancellationRequested();
                                if ((DateTime.Now - ctuMetaData.LasTimeRefreshed).TotalSeconds > 10)
                                {
                                    ctuMetaData.Refresh(await client.GetMyStationsAsync());
                                }

                                if (site.Infos.SiteType == "ptp")
                                {
                                    List <P2PSite> pairs = (ProcessWUnitCreation(site) as List <P2PSite>);
                                    if (pairs != null)
                                    {
                                        foreach (var pair in pairs)
                                        {
                                            RegistrationJournal regJournal = default;
                                            if (pair.StationB.CTUId > 0) // update already existing site
                                            {
                                                ProcessRegistrationJournal(regJournal = await client.UpdatePTPConnectionAsync(pair), site);
                                            }
                                            else // create new site
                                            {
                                                ProcessRegistrationJournal(regJournal = await client.AddPTPSiteAsync(pair), site);
                                                if (regJournal.Phase == RegistrationJournalPhaseEnum.Published && !string.IsNullOrEmpty(workerOptions.ResponseWithCTUID))
                                                {
                                                    HttpClient          cl = new HttpClient();
                                                    HttpResponseMessage rm = await cl.GetAsync(workerOptions.ResponseWithCTUID + $"&id={pair.StationA.OwnerId}&ctuId={regJournal.RegistrationId}");

                                                    HttpResponseMessage rm2 = await cl.GetAsync(workerOptions.ResponseWithCTUID + $"&id={pair.StationB.OwnerId}&ctuId={regJournal.RegistrationId}");
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (site.Infos.SiteType == "ptmp")
                                {
                                    WigigPTMPUnitInfo wigig = (ProcessWUnitCreation(site) as WigigPTMPUnitInfo);
                                    if (wigig != null)
                                    {
                                        ProcessRegistrationJournal(await client.AddWIGIG_PTP_PTMPConnectionAsync(wigig), site);
                                    }
                                }
                                else if (site.Infos.SiteType == "delete" && workerOptions.Synchronization == SynchronizationTypeEnum.Manual.ToString())
                                {
                                    ProcessDeletion(site, client);
                                }
                                else
                                {
                                    logger.LogWarning($"{site.Infos.Ssid} site type is missing or has unrecognizable value, dont know where to publish:\n" +
                                                      $"original source:\n" +
                                                      JsonConvert.SerializeObject(site, Formatting.Indented));
                                }
                            }
                        }
                    }
                    catch (InvalidMailOrPasswordException)
                    {
                        logger.LogError("Invalid login credentials");
                        TaskCompletionSource.SetResult(false);
                        appLifetime.StopApplication();
                        return;
                    }
                    catch (WebServerException e)
                    {
                        logger.LogError($"Web server exception occured during comunication with ctu\n{e.Message} {e.Status.ToString()}\n {e.StackTrace}");
                        TaskCompletionSource.SetResult(false);
                        appLifetime.StopApplication();
                        return;
                    }
                    catch (OperationCanceledException e)
                    {
                        logger.LogError($"Task was stopped as respond to system signal\n{e.Message}");
                        TaskCompletionSource.SetResult(false);
                        appLifetime.StopApplication();
                        return;
                    }
                    catch (Exception e)
                    {
                        logger.LogError($"unknown exception occured during login\n{e.Message}\n {e.StackTrace}");
                        logger.LogInformation(e.Message);
                        logger.LogWarning("Shuting service down");
                        TaskCompletionSource.SetResult(false);
                        appLifetime.StopApplication();
                        return;
                    }

                    if (workerOptions.Run == RunTypeEnum.AfterSpecifedTime.ToString())
                    {
                        Log.Information($"task goes to sleep, will resume at {DateTime.Now + workerOptions.RunTimeSpecification}");
                        await Task.Delay(workerOptions.RunTimeSpecification, cancellationToken);
                    }
                    if (workerOptions.Run == RunTypeEnum.InSpecifedTime.ToString())
                    {
                        TimeSpan timeToWait = DateTime.Today + workerOptions.RunTimeSpecification - DateTime.Now;
                        if (timeToWait < TimeSpan.Zero)
                        {
                            timeToWait += new TimeSpan(1, 0, 0, 0);
                        }
                        Log.Information($"task goes to sleep, will resume at {DateTime.Now + timeToWait}");
                        await Task.Delay(timeToWait, cancellationToken);
                    }
                }while (!cancellationToken.IsCancellationRequested && (RunTypeEnum)Enum.Parse(typeof(RunTypeEnum), workerOptions.Run) != RunTypeEnum.Once);
                logger.LogInformation("allDone");
            }



            void ProcessRegistrationJournal(RegistrationJournal regJournal, WirelessSite site)
            {
                using (LogContext.PushProperty("phase", regJournal.Phase.ToString()))
                    using (LogContext.PushProperty("type", regJournal.Type.ToString()))
                        using (LogContext.PushProperty("id", regJournal.RegistrationId))
                        {
                            switch (regJournal.Phase)
                            {
                            case RegistrationJournalPhaseEnum.InputValidation:
                            {
                                logger.LogWarning("{phase}\nid:{id}\n{type}\nwas not possible due to Invalid values\n" +
                                                  "No records were created/updated");
                            }
                            break;

                            case RegistrationJournalPhaseEnum.Localization:
                            {
                                if (regJournal.ThrownException.GetType() == typeof(WebServerException))
                                {
                                    logger.LogWarning("{phase}\nid:{id}\n{type}\nwas not possible due to unexpected web behaviour\n" +
                                                      $"No record were created");
                                }
                                else
                                {
                                    logger.LogWarning("{phase}\nid:{id}\n{type}\nwas not possible due to unexpected behaviour\n" +
                                                      $"No record were created");
                                }
                            }
                            break;

                            case RegistrationJournalPhaseEnum.TechnicalSpecification:
                            {
                                using (LogContext.PushProperty("record", "Draft"))
                                {
                                    if (regJournal.ThrownException.GetType() == typeof(WebServerException))
                                    {
                                        logger.LogWarning("{phase}\nid:{id}\n{type}\nwas not possible due to unexpected web behaviour\n" +
                                                          "Record is now in state {record}");
                                    }
                                    else
                                    {
                                        logger.LogWarning("{phase}\nid:{id}\n{type}\nwas not possible due to unexpected behaviour\n" +
                                                          "Record is now in state {record}");
                                    }
                                }
                            }
                            break;

                            case RegistrationJournalPhaseEnum.CollissionSummary:
                            {
                                using (LogContext.PushProperty("record", "WAITING"))
                                {
                                    if (regJournal.ThrownException.GetType() == typeof(WebServerException))
                                    {
                                        logger.LogWarning("{phase}\nid:{id}\n{type}\nwas not possible due to unexpected web behaviour\n" +
                                                          "Record is now in state {record}");
                                    }
                                    else if (regJournal.ThrownException.GetType() == typeof(CollisionDetectedException))
                                    {
                                        logger.LogWarning("{phase}\nid:{id}\n{type}\nwas not possible due to possible collision with another connection\n" +
                                                          "Record is now in state {record}");
                                        NotifyViaMail(regJournal);
                                    }
                                    else
                                    {
                                        logger.LogWarning("{phase}\nid:{id}\n{type}\nwas not possible due to unexpected behaviour\n" +
                                                          "Record is now in state {record}");
                                    }
                                }
                            }
                            break;

                            case RegistrationJournalPhaseEnum.Published:
                            {
                                using (LogContext.PushProperty("record", "PUBLISHED"))
                                {
                                    logger.LogInformation("{phase}\nid:{id}\n{type}\nwas successfully published\n" +
                                                          "Record is now in state {record}");
                                }
                            }
                            break;

                            default:
                                break;
                            }
                        }
            }

            async Task ZeroDatabase(List <WirelessSite> sites)
            {
                foreach (var site in sites)
                {
                    HttpClient cl = new HttpClient();
                    if (site.Ap != null)
                    {
                        foreach (var item in site?.Ap)
                        {
                            if (!string.IsNullOrEmpty(workerOptions.ResponseOnDelete))
                            {
                                HttpResponseMessage rm2 = await cl.GetAsync(workerOptions.ResponseOnDelete + $"&id={item.Id}");

                                if (await rm2.Content.ReadAsStringAsync() != "ok")
                                {
                                }
                            }
                        }
                    }
                    if (site.Stations != null)
                    {
                        foreach (var item in site?.Stations)
                        {
                            if (!string.IsNullOrEmpty(workerOptions.ResponseOnDelete))
                            {
                                HttpResponseMessage rm2 = await cl.GetAsync(workerOptions.ResponseOnDelete + $"&id={item.Id}");

                                if (await rm2.Content.ReadAsStringAsync() != "ok")
                                {
                                }
                            }
                        }
                    }
                }
            }

            object ProcessWUnitCreation(WirelessSite site)
            {
                try
                {
                    if (site.Infos.SiteType == "ptp")
                    {
                        return(WirellesUnitFactory.CreatePTP(site));
                    }
                    else if (site.Infos.SiteType == "ptmp")
                    {
                        return(WirellesUnitFactory.CreateWigigPTMP(site));
                    }
                }
                catch (MissingParameterException e)
                {
                    using (LogContext.PushProperty("ci", "missing critical information"))
                    {
                        logger.LogWarning($"{site.Infos.Ssid} will not be possible to publish, because of" + "{ci}:\n" +
                                          $"{e.Message}\n" +
                                          $"original source:\n" +
                                          JsonConvert.SerializeObject(site, Formatting.Indented));
                    }
                }
                catch (InvalidPropertyValueException e)
                {
                    using (LogContext.PushProperty("ci", "invalid critical information"))
                    {
                        logger.LogWarning($"{site.Infos.Ssid} will not be possible to publish, because of" + "{ci} :\n" +
                                          $"Expected value: {e.ExpectedVauleInfo}\n" +
                                          $"Current value: {e.CurrentValue}\n" +
                                          $"original source:\n" +
                                          JsonConvert.SerializeObject(site, Formatting.Indented));
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }

                return(null);
            }

            void ProcessDeletion(WirelessSite site, CTUClient client)
            {
                try
                {
                    if (site.Stations.Count > 0)
                    {
                        foreach (var item in site.Stations)
                        {
                            List <CtuWirelessUnit> stations = default;
                            stations = client.GetStationByIdAsync(item.CtuReported).Result;
                        }
                    }
                    else
                    {
                        List <CtuWirelessUnit> stations = default;
                        stations = client.GetStationByIdAsync(site.Ap.FirstOrDefault()?.CtuReported).Result;
                        if (stations.Count > 0)
                        {
                            client.DeleteConnectionAsync(site.Ap.FirstOrDefault()?.CtuReported);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            TaskCompletionSource.SetResult(true);
            appLifetime.StopApplication();
            return;
        }
Esempio n. 11
0
 private async Task <bool> CheckWorkerOptionValues(CancellationToken stoppingToken, SourceDataType sourceDataType)
 {
     if (workerOptions.CTULogin == string.Empty || workerOptions.CTUPass == string.Empty)
     {
         logger.LogError("Missing credentials for www.60ghz.ctu.cz");
         appLifetime.StopApplication();
         return(false);
     }
     if ((sourceDataType = GetSourceDataType(workerOptions.DataURLOrFilePath)) == SourceDataType.ERR)
     {
         logger.LogError("Not valid file path or web url");
         appLifetime.StopApplication();
         return(false);
     }
     if (String.IsNullOrEmpty(workerOptions.Synchronization))
     {
         logger.LogError("Synchronization type not specified");
         appLifetime.StopApplication();
         return(false);
     }
     if (String.IsNullOrEmpty(workerOptions.Run))
     {
         logger.LogError("Run type not specified");
         appLifetime.StopApplication();
         return(false);
     }
     return(true);
 }
        private void RetrieveTextAttributeByType(string entityLogicalName, SourceDataType sourceDataType)
        {
            Cursor = Cursors.WaitCursor;
            WorkAsync(new WorkAsyncInfo($"Loading attributes valid for {sourceDataType}...", dwea =>
            {
                var entityMetadata = MetadataHelper.RetrieveEntity(entityLogicalName, Service);

                var stringAttributes = entityMetadata.Attributes
                .Where(x => x.AttributeType.Value == AttributeTypeCode.String);

                switch (sourceDataType)
                {
                    case SourceDataType.Url:
                        stringAttributes = stringAttributes.Where(x => ((StringAttributeMetadata)x).Format.Value == Microsoft.Xrm.Sdk.Metadata.StringFormat.Url);
                        break;
                    case SourceDataType.Email:
                        stringAttributes = stringAttributes.Where(x => ((StringAttributeMetadata)x).Format.Value == Microsoft.Xrm.Sdk.Metadata.StringFormat.Email);
                        break;
                }
                dwea.Result = stringAttributes;
            })
            { PostWorkCallBack = c =>
            {
                Cursor = Cursors.Default;
                if (c.Error != null)
                {
                    string errorMessage = CrmExceptionHelper.GetErrorMessage(c.Error, true);
                    CommonDelegates.DisplayMessageBox(ParentForm, errorMessage, "Error", MessageBoxButtons.OK,
                                                      MessageBoxIcon.Error);
                }
                else
                {
                    var attributeMetadata = (IEnumerable<AttributeMetadata>)c.Result;
                    foreach (var attribute in attributeMetadata)
                    {
                        if (attribute.IsLogical.GetValueOrDefault()) continue;
                        var item = new ListViewItem { Text = attribute.DisplayName.UserLocalizedLabel?.Label, Tag = attribute.LogicalName };
                        item.SubItems.Add(attribute.SchemaName);
                        item.SubItems.Add(attribute.Description?.UserLocalizedLabel?.Label);
                        item.SubItems.Add(entityLogicalName);
                        ListViewDelegates.AddItem(lvAttributes, item);
                    }
                }
            }});
        }
 public MultiDataFormat(string source, IEnumerable <string> keepValues, SourceDataType sourceDataType)
 {
     Source     = source;
     KeepValues = keepValues;
     dataType   = sourceDataType;
 }