Exemple #1
0
        /// <summary>
        /// Starts session locally without trying to connect to server.
        /// </summary>
        private static bool StartSessionLocally()
        {
            bool succeeded = false;

            // Enable offline required metadata collection which is needed to verify client cache,
            // during connecting to server (switching to connected mode for first server operation)
            ApplicationSourcesManager.GetInstance().OfflineRequiredMetadataCollection.Enabled = true;

            // switch session status from "Uninitialized" to "Local"
            ClientManager.Instance.GetService <IConnectionStateManager>().ConnectionDropped();

            Logger.Instance.WriteServerToLog("Attempting to start locally (Offline mode)");
            succeeded = LocalCommandsProcessor.GetInstance().StartSession();
            if (succeeded)
            {
                // Set server last access status
                RemoteCommandsProcessor.GetInstance().ServerLastAccessStatus = ServerAccessStatus.SkippedConnectionToServer;
            }
            else
            {
                Logger.Instance.WriteServerToLog("Cannot start locally. Terminating client.");
            }

            if (Logger.Instance.IsAccumulatingMessages())
            {
                Logger.Instance.FlushAccumulatedMessages();
            }

            // No cache files should be collected once the session is started.
            ApplicationSourcesManager.GetInstance().OfflineRequiredMetadataCollection.Enabled = false;

            return(succeeded);
        }
Exemple #2
0
        /// <summary>
        /// get the commands processor according to the session status.
        /// </summary>
        /// <returns></returns>
        internal static CommandsProcessorBase GetCommandsProcessor()
        {
            if (SessionStatus == SessionStatusEnum.Local)
            {
                ClientManager.Instance.SetService(typeof(TaskServiceBase), new LocalTaskService());
                return((CommandsProcessorBase)LocalCommandsProcessor.GetInstance());
            }

            return((CommandsProcessorBase)RemoteCommandsProcessor.GetInstance());
        }
Exemple #3
0
 /// <summary>
 /// get the CommandsProcessor to use for executing the defined task
 /// </summary>
 /// <param name="taskDefinitionId"></param>
 /// <returns></returns>
 internal static CommandsProcessorBase GetCommandsProcessor(TaskDefinitionId taskDefinitionId)
 {
     if (ClientManager.Instance.LocalManager.ApplicationDefinitions.TaskDefinitionIdsManager.IsOfflineTask(taskDefinitionId))
     {
         return(LocalCommandsProcessor.GetInstance());
     }
     else
     {
         return(RemoteCommandsProcessor.GetInstance());
     }
 }
Exemple #4
0
 /// <summary>
 /// CTOR
 /// </summary>
 /// <param name="isOfflineTask"></param>
 public CommonCommandProcessorStrategy(bool isOfflineTask)
 {
     if (isOfflineTask)
     {
         taskService = LocalCommandsProcessor.GetInstance();
     }
     else
     {
         taskService = RemoteCommandsProcessor.GetInstance();
     }
 }
Exemple #5
0
        /// <summary>
        /// Read old data source repository
        /// </summary>
        /// <param name="dataDefinitionIdsUrl"> repository url to read old repository </param>
        /// <returns>returns old data source repository only if it is modified</returns>
        private DataSourceDefinitionManager GetOldDataSourceDefinitions(String dataDefinitionIdsUrl)
        {
            DataSourceDefinitionManager oldDataSourceDefinitionManager = null;

            try
            {
                // Get old data source repository url from last offline response
                String oldDataDefinitionIdsUrl = GetLastDataSourcesIdUrl();

                // Last offline response can not be available if startup program is modified or in case of executing non-offline program.
                // In this case , read the repository file available in cache without remote time constraint
                if (oldDataDefinitionIdsUrl == null)
                {
                    // split the url --> url and remote time
                    string[] urlAndRemoteTimePair = HttpUtility.UrlDecode(dataDefinitionIdsUrl, Encoding.UTF8).Split('|');
                    oldDataDefinitionIdsUrl = urlAndRemoteTimePair[0];
                }

                // read content form data source repository
                byte[] oldRepositoryContents = null;
                // the old (i.e. without the '_tmp' suffix) DbhDataIds may not be found in case this is the first access to the application.
                if (PersistentOnlyCacheManager.GetInstance().IsCompleteCacheRequestURLExistsLocally(oldDataDefinitionIdsUrl))
                {
                    oldRepositoryContents = LocalCommandsProcessor.GetInstance().GetContent(oldDataDefinitionIdsUrl, true);
                }

                // if contents are modified then return old data source repository
                if (oldRepositoryContents != null && (oldRepositoryContents.Length != NewDataSourceRepositoryContents.Length ||
                                                      !Misc.CompareByteArray(oldRepositoryContents, NewDataSourceRepositoryContents, NewDataSourceRepositoryContents.Length)))
                {
                    // parse repository content and read data sources and build the data source definition collection
                    oldDataSourceDefinitionManager = new DataSourceDefinitionManager();
                    oldDataSourceDefinitionManager.DataSourceBuilder.DataSourceReader = GetOldDataSourceBuffer;
                    new DataSourceDefinitionManagerSaxHandler(oldRepositoryContents, oldDataSourceDefinitionManager);
                }

                // new repository contents are not needed more for datasource converter
                NewDataSourceRepositoryContents = null;
            }
            catch (Exception ex)
            {
                Logger.Instance.WriteExceptionToLog(ex);
            }

            CommandsProcessorManager.SessionStatus = CommandsProcessorManager.SessionStatusEnum.Remote;

            return(oldDataSourceDefinitionManager);
        }
Exemple #6
0
        /// <summary>
        /// get last data repository url from initial response
        /// </summary>
        /// <returns></returns>
        private string GetLastDataSourcesIdUrl()
        {
            string dataDefinitionIdsUrl = null;

            if (LocalCommandsProcessor.GetInstance().CanStartWithoutNetwork)
            {
                String    lastOfflineInitialResponse = LocalCommandsProcessor.GetInstance().GetLastOfflineInitialResponse();
                XmlParser parser = new XmlParser(lastOfflineInitialResponse);

                parser.setCurrIndex(parser.getXMLdata().IndexOf(ConstInterface.MG_TAG_DBH_DATA_IDS_URL, parser.getCurrIndex()) + ConstInterface.MG_TAG_DBH_DATA_IDS_URL.Length + 1);

                int           endContext   = parser.getXMLdata().IndexOf(XMLConstants.TAG_CLOSE, parser.getCurrIndex());
                List <string> tokensVector = XmlParser.getTokens(parser.getXMLsubstring(endContext), XMLConstants.XML_ATTR_DELIM);
                Debug.Assert(tokensVector[0].Equals(XMLConstants.MG_ATTR_VALUE));

                dataDefinitionIdsUrl = XmlParser.unescape(tokensVector[1]);
            }

            return(dataDefinitionIdsUrl);
        }
Exemple #7
0
 /// <summary>
 /// Reads contents of a datasource indicated by sourceUrl using LocalCommandsProcessor.
 /// </summary>
 /// <param name="sourceUrl"></param>
 /// <returns></returns>
 private byte[] GetOldDataSourceBuffer(String sourceUrl)
 {
     return(LocalCommandsProcessor.GetInstance().GetContent(sourceUrl, true));
 }
Exemple #8
0
        /// <summary>
        /// Start session (Remote/Local)
        /// </summary>
        /// <returns></returns>
        internal static bool StartSession()
        {
            bool succeeded = false;
            bool startInConnectedModeToSyncMetadata = false;
            bool skipConnectionToServer             = false;

            using (Logger.Instance.AccumulateMessages())
            {
                // Check if client is required to start in disconnected mode even when network is available
                // Skip connection if,
                //   1. ConnectOnStartup = N in execution properties
                //   2. LastOffline does not contain "UnsyncronizedMetadata=Y" [which means connect server to sync metadata].
                if (LocalCommandsProcessor.GetInstance().CanStartWithoutNetwork&& !ClientManager.Instance.GetConnectOnStartup())
                {
                    LocalCommandsProcessor.GetInstance().VerifyLastOfflineInitialResponseFile();
                    if (LocalCommandsProcessor.GetInstance().CanStartWithoutNetwork)
                    {
                        if (LocalCommandsProcessor.GetInstance().IsUnsyncronizedMetadata())
                        {
                            startInConnectedModeToSyncMetadata = true;
                        }
                        else
                        {
                            skipConnectionToServer = true;
                        }
                    }
                }

                // Create a communications failure handler and pass it to the Http connection layer.
                HttpManager.GetInstance().SetCommunicationsFailureHandler(
                    LocalCommandsProcessor.GetInstance().CanStartWithoutNetwork
                           ? (ICommunicationsFailureHandler)(new SilentCommunicationsFailureHandler())
                           : (ICommunicationsFailureHandler)(new InteractiveCommunicationsFailureHandler()));

                if (skipConnectionToServer)
                {
                    succeeded = StartSessionLocally();
                }
                else
                {
                    try
                    {
                        ApplicationSourcesManager.GetInstance().OfflineRequiredMetadataCollection.Enabled = true;

                        // access the Server: if accessed - continue remotely, otherwise - locally.
                        succeeded = RemoteCommandsProcessor.GetInstance().StartSession();

                        // Notify the Connection State Manager that a successful connection was established.
                        // The first time this happens, the connection state manager will move from 'Unknown' to 'Connected'.
                        ClientManager.Instance.GetService <IConnectionStateManager>().ConnectionEstablished();
                    }
                    catch (Exception ex)
                    {
                        if (ex is InvalidSourcesException)
                        {
                            throw;
                        }

                        // If client started in connected mode (even when ConnectOnStartup=N in execution properties) because,
                        // UnsyncronisedMetadata was occurred in last execution, and if any sever error occurred during initialization then,
                        // ServerLastAccessStatus() should return 1 (UnsynchroizedMetadata). This way client will avoid trying any server operation.
                        if (startInConnectedModeToSyncMetadata)
                        {
                            RemoteCommandsProcessor.GetInstance().ServerLastAccessStatus = ServerAccessStatus.UnsynchroizedMetadata;
                        }

                        Logger.Instance.WriteServerToLog("Failed connecting to the server: " + ex.Message);
                        if (LocalCommandsProcessor.GetInstance().CanStartWithoutNetwork)
                        {
                            if (Logger.Instance.ShouldLog())
                            {
                                Logger.Instance.FlushAccumulatedMessages();
                            }
                            else
                            {
                                Logger.Instance.DiscardAccumulatedMessages();
                            }
                            Logger.Instance.StopMessageAccumulation();
                            Logger.Instance.WriteServerToLog("Attempting to start locally (Offline mode)");
                            succeeded = LocalCommandsProcessor.GetInstance().StartSession();
                        }

                        if (!succeeded)
                        {
                            Logger.Instance.WriteServerToLog("Cannot start locally. Terminating client.");
                            throw;
                        }
                    }
                    finally
                    {
                        if (Logger.Instance.IsAccumulatingMessages())
                        {
                            Logger.Instance.FlushAccumulatedMessages();
                        }

                        // all offline required cache files are retrieved when the server is started, in the initial response after the two handshake requests.
                        // therefore, no cache files should be collected once the session is started [i.e. StartSession() was executed].
                        ApplicationSourcesManager.GetInstance().OfflineRequiredMetadataCollection.Enabled = false;
                    }
                }
            }

            // if a startupProgram should be started locally then load it locally.
            if (GetCommandsProcessor().ShouldLoadOfflineStartupProgram())
            {
                LocalCommandsProcessor.GetInstance().LoadStartupProgram();
            }

            // From this point onward, all comm failures should show a message.
            HttpManager.GetInstance().SetCommunicationsFailureHandler(new InteractiveCommunicationsFailureHandler());

            return(succeeded);
        }