示例#1
0
        public void SetUserDecision(UserDecision userDecision)
        {
            DebugLogger.Log(string.Format("User deicision set to {0}.", userDecision));

            _userDecision = userDecision;
            _userDecisionSetEvent.Set();
        }
示例#2
0
 public void SetUserOptions(UserDecision request)
 {
     foreach (var item in request.Options)
     {
         ViewModel.Options.Add(item);
     }
     ViewModel.Request = request;
 }
示例#3
0
        private void ParametersetSGB_Click(object sender, RoutedEventArgs e)
        {
            var request = new UserDecision();

            request.Options = new string[] { "A", "B", "C" };
            request.Request();
            //CRFToolData.IsingData = new SoftwareGraphIsing();

            //var window = new MainView();
            //window.Show();
        }
示例#4
0
        /// <summary>
        /// Configuration wizard to support the user on scheduler configuration
        /// </summary>
        private void ConfigurationWizardScheduler()
        {
            ///Variable that store the user input
            string userInput = "";

            string defaultEnable = "";

            if (theSchedulerIsEnabled)
            {
                defaultEnable = "Yes";
            }
            else
            {
                defaultEnable = "No";
            }
            ///Request if the scheduler will be enabled
            userInput = UserDecision.ShowInputComboBox(defaultEnable, "Enable scheduler?", new string[] { "Yes", "No" });
            if (userInput == "")
            {
                MessageBox.Show("This value cannot be empty..."); return;
            }
            ;
            switch (userInput)
            {
            case "Yes":
                theSchedulerIsEnabled = true;
                break;

            case "No":
                theSchedulerIsEnabled = false;
                break;

            default:
                theSchedulerIsEnabled = false;
                MessageBox.Show("Invalid value!");
                return;
            }
            userInput = "";

            ///Request the OPC topic (address)
            DateTime newUserDate;

            newUserDate      = UserDecision.ShowTimePicker(DateTime.Now.ToString(), "Input the time:");
            theSchedulerTime = newUserDate;
            userInput        = "";

            //Save the new configurtaion and restart the application.
            GenerateConfigurationFile();
        }
示例#5
0
        public void Execute()
        {
            //    - Prerequisites:
            //	  - Graphstructure
            //    - Training Data
            //    - 2 Node Classifications
            TrainingData   = new List <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >();
            EvaluationData = new List <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >();

            // decision wether user wants to train or load pre-trained data
            var requestTraining = new UserDecision("Use Training.", "Load Training Result.");

            requestTraining.Request();

            if (requestTraining.Decision == 0) // use training
            {
                //    -n characteristics for each node
                {
                    var request = new UserInput(UserInputLookFor.Folder);
                    request.DefaultPath = "..\\..\\CRFToolApp\\bin\\Graphs";
                    request.TextForUser = "******";
                    request.Request();
                    GraphDataFolder = request.UserText;

                    foreach (var file in Directory.EnumerateFiles(GraphDataFolder))
                    {
                        var graph = JSONX.LoadFromJSON <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >(file);
                        TrainingData.Add(graph);
                    }
                }

                //   - Step 1:

                //   - discretize characteristics
                #region Use Training Pede
                {
                    // create features
                    CreateFeatures(Dataset, TrainingData);
                    InitCRFScores(TrainingData);

                    var request = new OLMRequest(OLMVariant.Ising, TrainingData);
                    request.BasisMerkmale.AddRange(Dataset.NodeFeatures);
                    request.BasisMerkmale.AddRange(Dataset.EdgeFeatures);

                    request.LossFunctionValidation = OLM.LossRatio;

                    request.Request();

                    // zugehörige Scores erzeugen für jeden Graphen (auch Evaluation)
                    CreateCRFScores(TrainingData, Dataset.NodeFeatures, request.Result.ResultingWeights);

                    // store trained Weights
                    Dataset.NumberIntervals    = NumberIntervals;
                    Dataset.Characteristics    = TrainingData.First().Data.Characteristics.ToArray();
                    Dataset.EdgeCharacteristic = "IsingEdgeCharacteristic";
                    Dataset.Weights            = request.Result.ResultingWeights;
                    Dataset.SaveAsJSON("results.json");
                }

                #endregion
            }
            else
            { // load pre-trained data
                var request = new UserInput();
                request.TextForUser = "******";
                request.Request();
                var file           = request.UserText;
                var trainingResult = JSONX.LoadFromJSON <WorkflowOneDataset>(file);
                Dataset = trainingResult;
            }
            //- Step2:

            // User Choice here
            {
                var request = new UserInput(UserInputLookFor.Folder);
                request.TextForUser = "******";
                request.Request();
                GraphDataFolder = request.UserText;

                foreach (var file in Directory.EnumerateFiles(GraphDataFolder))
                {
                    var graph = JSONX.LoadFromJSON <GWGraph <CRFNodeData, CRFEdgeData, CRFGraphData> >(file);
                    EvaluationData.Add(graph);
                }
            }

            // remove double edges
            {
                var edgesToRemove = new LinkedList <GWEdge <CRFNodeData, CRFEdgeData, CRFGraphData> >();
                foreach (var graph in EvaluationData)
                {
                    foreach (var edge in graph.Edges.ToList())
                    {
                        if (graph.Edges.Any(e => (e != edge) && ((e.Foot == edge.Head && e.Head == edge.Foot && e.GWId.CompareTo(edge.GWId) < 0) || (e.Foot == edge.Foot && e.Head == edge.Head && e.GWId.CompareTo(edge.GWId) < 0))))
                        {
                            edgesToRemove.Add(edge);
                            graph.Edges.Remove(edge);
                        }
                    }
                }
                foreach (var edge in edgesToRemove)
                {
                    edge.Foot.Edges.Remove(edge);
                    edge.Head.Edges.Remove(edge);
                }
            }


            //scores erzeugen
            CreateCRFScores(EvaluationData, Dataset.NodeFeatures, Dataset.Weights);

            //   - Create ROC Curve
            {
            }
            //   - Give Maximum with Viterbi
            {
                foreach (var graph in EvaluationData)
                {
                    var request = new SolveInference(graph, null, 2);
                    request.Request();
                    graph.Data.AssginedLabeling = request.Solution.Labeling;
                }

                //show results in 3D Viewer
                {
                    //var request = new ShowGraphs();
                    //request.Graphs = EvaluationData;
                    //request.Request();
                }
            }
            //   - Give Sample with MCMC
            {
                foreach (var graph in EvaluationData)
                {
                    SoftwareGraphLearningParameters parameters = new SoftwareGraphLearningParameters();
                    parameters.NumberOfGraphs          = 60;
                    parameters.NumberNodes             = 50;
                    parameters.NumberLabels            = 2;
                    parameters.NumberCategories        = 4;
                    parameters.IntraConnectivityDegree = 0.15;
                    parameters.InterConnectivityDegree = 0.01;


                    //sample parameters
                    var samplerParameters = new MHSamplerParameters();
                    var sglGraph          = graph.Convert((nodeData) => new SGLNodeData()
                    {
                    }, (edgeData) => new SGLEdgeData(), (graphData) => new SGLGraphData());

                    samplerParameters.Graph        = sglGraph;
                    samplerParameters.NumberChains = 1;

                    //sampler starten
                    var gibbsSampler = new MHSampler();
                    gibbsSampler.Do(samplerParameters);
                }
            }
        }
示例#6
0
        private void ThreadWaitForUserDecision(CancellationToken cancellationToken)
        {
            try
            {
                DebugLogger.Log("Waiting for user decision...");

                _state.Value = PatcherState.WaitingForUserDecision;

                bool isInstalled = _app.IsFullyInstalled();

                DebugLogger.LogVariable(isInstalled, "isInstalled");

                bool canRepairApp          = false;        // not implemented
                bool canInstallApp         = !isInstalled;
                bool canCheckForAppUpdates = isInstalled;
                bool canStartApp           = isInstalled;

                _isAppInstalled.Value = isInstalled;

                _canRepairApp.Value          = false;
                _canInstallApp.Value         = false;
                _canCheckForAppUpdates.Value = false;
                _canStartApp.Value           = false;

                if (canInstallApp && _configuration.AutomaticallyInstallApp && !_hasAutomaticallyInstalledApp)
                {
                    DebugLogger.Log("Automatically deciding to install app.");
                    _hasAutomaticallyInstalledApp        = true;
                    _hasAutomaticallyCheckedForAppUpdate = true;
                    _userDecision = UserDecision.InstallAppAutomatically;
                    return;
                }

                if (canCheckForAppUpdates && _configuration.AutomaticallyCheckForAppUpdates &&
                    !_hasAutomaticallyCheckedForAppUpdate)
                {
                    DebugLogger.Log("Automatically deciding to check for app updates.");
                    _hasAutomaticallyInstalledApp        = true;
                    _hasAutomaticallyCheckedForAppUpdate = true;
                    _userDecision = UserDecision.CheckForAppUpdatesAutomatically;
                    return;
                }

                var updatesOnly = Environment.GetCommandLineArgs().Any(arg => arg.Equals("--updateOnly", StringComparison.OrdinalIgnoreCase));
                if (canStartApp && updatesOnly)
                {
                    _canStartApp.Value = true;
                    _userDecision      = UserDecision.AppUpdatesOnly;
                    return;
                }
                else
                {
                    if (canStartApp && _configuration.AutomaticallyStartApp && !_hasAutomaticallyStartedApp)
                    {
                        DebugLogger.Log("Automatically deciding to start app.");
                        _hasAutomaticallyStartedApp = true;
                        _userDecision = UserDecision.StartAppAutomatically;
                        return;
                    }

                    _canRepairApp.Value          = canRepairApp;
                    _canInstallApp.Value         = canInstallApp;
                    _canCheckForAppUpdates.Value = canCheckForAppUpdates;
                    _canStartApp.Value           = canStartApp;
                }
                _userDecisionSetEvent.Reset();
                using (cancellationToken.Register(() => _userDecisionSetEvent.Set()))
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    _userDecisionSetEvent.WaitOne();
                }

                _canRepairApp.Value          = false;
                _canInstallApp.Value         = false;
                _canCheckForAppUpdates.Value = false;
                _canStartApp.Value           = false;

                cancellationToken.ThrowIfCancellationRequested();

                DebugLogger.Log(string.Format("Waiting for user decision result: {0}.", _userDecision));
            }
            catch (OperationCanceledException)
            {
                DebugLogger.Log("Waiting for user decision cancelled.");
            }
            catch (ThreadInterruptedException)
            {
                DebugLogger.Log("Waiting for user decision interrupted: thread has been interrupted. Rethrowing exception.");
                throw;
            }
            catch (ThreadAbortException)
            {
                DebugLogger.Log("Waiting for user decision aborted: thread has been aborted. Rethrowing exception.");
                throw;
            }
            catch (Exception)
            {
                DebugLogger.LogWarning("Error while waiting for user decision: an exception has occured. Rethrowing exception.");
                throw;
            }
        }
示例#7
0
        /// <summary>
        /// Configuration wizard to support the user on OPC setup
        /// </summary>
        private void ConfigurationWizardKeepAliveMonitor()
        {
            ///Variable that store the user input
            string userInput = "";

            string defaultEnable = "";

            if (theKeepAliveMonitorIsEnabled)
            {
                defaultEnable = "Yes";
            }
            else
            {
                defaultEnable = "No";
            }
            ///Request if the keep alive monitor will be enabled
            userInput = UserDecision.ShowInputComboBox(defaultEnable, "Enable auto-restart by server state?", new string[] { "Yes", "No" });
            if (userInput == "")
            {
                MessageBox.Show("This value cannot be empty..."); return;
            }
            ;
            switch (userInput)
            {
            case "Yes":
                theKeepAliveMonitorIsEnabled = true;
                break;

            case "No":
                theKeepAliveMonitorIsEnabled = false;
                break;

            default:
                theKeepAliveMonitorIsEnabled = false;
                MessageBox.Show("Invalid value!");
                return;
            }
            userInput = "";

            ///Request the OPC Type
            userInput = UserDecision.ShowInputComboBox(theOPCServerType.ToString(), "Input the OPC server type", new string[] { eOPCServerType.DataFEED.ToString(), eOPCServerType.INAT.ToString(), eOPCServerType.KEPWare.ToString(), eOPCServerType.RsLinx.ToString(), eOPCServerType.SoftingS7.ToString() });
            if (userInput == "")
            {
                MessageBox.Show("This value cannot be empty..."); return;
            }
            ;
            theOPCServerType = (eOPCServerType)Enum.Parse(typeof(eOPCServerType), userInput);
            userInput        = "";

            ///Request the OPC topic (address)
            string defaultTopicConfig;

            switch (theOPCServerType)
            {
            case eOPCServerType.DataFEED:
                defaultTopicConfig = "Softing.OPC.DF.S7.DA.1";
                break;

            case eOPCServerType.INAT:
                defaultTopicConfig = "INAT TcpIpH1 OPC Server";
                break;

            case eOPCServerType.KEPWare:
                defaultTopicConfig = "";
                break;

            case eOPCServerType.RsLinx:
                defaultTopicConfig = "RsLinx OPC Server";
                break;

            case eOPCServerType.SoftingS7:
                defaultTopicConfig = "Softing.OPC.S7.DA.1";
                break;

            default:
                defaultTopicConfig = "";
                break;
            }
            userInput = UserDecision.ShowInputString(defaultTopicConfig, "Input the OPC topic (address)");
            if (userInput == "")
            {
                MessageBox.Show("This value cannot be empty..."); return;
            }
            ;
            theOPCServerTopic = userInput;
            userInput         = "";

            ///Request the process name
            string defaultProcessName;

            switch (theOPCServerType)
            {
            case eOPCServerType.DataFEED:
                defaultProcessName = "OSF_Service";
                break;

            case eOPCServerType.INAT:
                defaultProcessName = "TCPIPH1";
                break;

            case eOPCServerType.KEPWare:
                defaultProcessName = "";
                break;

            case eOPCServerType.RsLinx:
                defaultProcessName = "RSLINX";
                break;

            case eOPCServerType.SoftingS7:
                defaultProcessName = "S7OPCsvc";
                break;

            default:
                defaultProcessName = "";
                break;
            }
            userInput = UserDecision.ShowInputString(defaultProcessName, "Input the name of OPC process (Windows)");
            if (userInput == "")
            {
                MessageBox.Show("This value cannot be empty..."); return;
            }
            ;
            theOPCServerProcessName = userInput;
            userInput = "";

            ///Request the cycle timer
            userInput = UserDecision.ShowInputString(theCycleTime.ToString(), "Input the cycle timer in [ms]");
            int newCycleTimer;

            if (userInput == "")
            {
                MessageBox.Show("This value cannot be empty..."); return;
            }
            ;
            if (int.TryParse(userInput, out newCycleTimer) == false)
            {
                MessageBox.Show("Input value was not valid. Please use just numbers..."); return;
            }
            ;
            theCycleTime = newCycleTimer;
            userInput    = "";

            //Save the new configurtaion and restart the application.
            GenerateConfigurationFile();
        }
示例#8
0
        private void ThreadWaitForUserDecision(CancellationToken cancellationToken)
        {
            try
            {
                DebugLogger.Log("Waiting for user decision...");

                _state.Value = PatcherState.WaitingForUserDecision;

                bool isInstalled = _app.IsInstalled();

                DebugLogger.LogVariable(isInstalled, "isInstalled");

                _canRepairApp.Value          = false; // not implemented
                _canInstallApp.Value         = !isInstalled;
                _canCheckForAppUpdates.Value = isInstalled;
                _canStartApp.Value           = isInstalled;

                if (_canInstallApp.Value && _configuration.AutomaticallyInstallApp && !_hasAutomaticallyInstalledApp)
                {
                    DebugLogger.Log("Automatically deciding to install app.");
                    _hasAutomaticallyInstalledApp = true;
                    _userDecision = UserDecision.InstallAppAutomatically;
                    return;
                }

                if (_canCheckForAppUpdates.Value && _configuration.AutomaticallyCheckForAppUpdates &&
                    !_hasAutomaticallyCheckedForAppUpdate)
                {
                    DebugLogger.Log("Automatically deciding to check for app updates.");
                    _hasAutomaticallyCheckedForAppUpdate = true;
                    _userDecision = UserDecision.CheckForAppUpdatesAutomatically;
                    return;
                }

                if (_canStartApp.Value && _configuration.AutomaticallyStartApp && !_hasAutomaticallyStartedApp)
                {
                    DebugLogger.Log("Automatically deciding to start app.");
                    _hasAutomaticallyStartedApp = true;
                    _userDecision = UserDecision.StartAppAutomatically;
                    return;
                }

                _userDecisionSetEvent.Reset();
                using (cancellationToken.Register(() => _userDecisionSetEvent.Set()))
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    _userDecisionSetEvent.WaitOne();
                }
                cancellationToken.ThrowIfCancellationRequested();

                DebugLogger.Log(string.Format("Waiting for user decision result: {0}.", _userDecision));
            }
            catch (OperationCanceledException)
            {
                DebugLogger.Log("Waiting for user decision cancelled.");
            }
            catch (ThreadInterruptedException)
            {
                DebugLogger.Log("Waiting for user decision interrupted: thread has been interrupted. Rethrowing exception.");
                throw;
            }
            catch (ThreadAbortException)
            {
                DebugLogger.Log("Waiting for user decision aborted: thread has been aborted. Rethrowing exception.");
                throw;
            }
            catch (Exception)
            {
                DebugLogger.LogWarning("Error while waiting for user decision: an exception has occured. Rethrowing exception.");
                throw;
            }
        }