public override Task OnActivateAsync()
 {
     logger = TraceLogger.GetLogger("GrainBasedMembershipTable", TraceLogger.LoggerType.Runtime);
     logger.Info(ErrorCode.MembershipGrainBasedTable1, "GrainBasedMembershipTable Activated.");
     table = new InMemoryMembershipTable();
     return TaskDone.Done;
 }
        internal VirtualBucketsRingProvider(SiloAddress siloAddr, int nBucketsPerSilo)
        {
            if (nBucketsPerSilo <= 0 )
                throw new IndexOutOfRangeException("numBucketsPerSilo is out of the range. numBucketsPerSilo = " + nBucketsPerSilo);

            logger = TraceLogger.GetLogger(typeof(VirtualBucketsRingProvider).Name);
                        
            statusListeners = new List<IRingRangeListener>();
            bucketsMap = new SortedDictionary<uint, SiloAddress>();
            sortedBucketsList = new List<Tuple<uint, SiloAddress>>();
            myAddress = siloAddr;
            numBucketsPerSilo = nBucketsPerSilo;
            lockable = new object();
            running = true;
            myRange = RangeFactory.CreateFullRange();

            logger.Info("Starting {0} on silo {1}.", typeof(VirtualBucketsRingProvider).Name, siloAddr.ToStringWithHashCode());

            StringValueStatistic.FindOrCreate(StatisticNames.CONSISTENTRING_RING, ToString);
            IntValueStatistic.FindOrCreate(StatisticNames.CONSISTENTRING_RINGSIZE, () => GetRingSize());
            StringValueStatistic.FindOrCreate(StatisticNames.CONSISTENTRING_MYRANGE_RINGDISTANCE, () => String.Format("x{0,8:X8}", ((IRingRangeInternal)myRange).RangeSize()));
            FloatValueStatistic.FindOrCreate(StatisticNames.CONSISTENTRING_MYRANGE_RINGPERCENTAGE, () => (float)((IRingRangeInternal)myRange).RangePercentage());
            FloatValueStatistic.FindOrCreate(StatisticNames.CONSISTENTRING_AVERAGERINGPERCENTAGE, () =>
            {
                int size = GetRingSize();
                return size == 0 ? 0 : ((float)100.0/(float) size);
            });           

            // add myself to the list of members
            AddServer(myAddress);
        }
예제 #3
0
        private AzureTableBasedGossipChannel gossipTable; // This type is internal

        public AzureGossipTableTests()
        {
            logger = TraceLogger.GetLogger("AzureGossipTableTests", TraceLogger.LoggerType.Application);
        
            globalServiceId = Guid.NewGuid();
            deploymentId = "test-" + globalServiceId;

            IPAddress ip;
            if (!IPAddress.TryParse("127.0.0.1", out ip))
            {
                logger.Error(-1, "Could not parse ip address");
                return;
            }
            IPEndPoint ep1 = new IPEndPoint(ip, 21111);
            siloAddress1 = SiloAddress.New(ep1, 0);
            IPEndPoint ep2 = new IPEndPoint(ip, 21112);
            siloAddress2 = SiloAddress.New(ep2, 0);

            logger.Info("DeploymentId={0}", deploymentId);

            GlobalConfiguration config = new GlobalConfiguration
            {
                ServiceId = globalServiceId,
                ClusterId = "0",
                DeploymentId = deploymentId,
                DataConnectionString = StorageTestConstants.DataConnectionString
            };

            gossipTable = new AzureTableBasedGossipChannel();
            var done = gossipTable.Initialize(config.ServiceId, config.DataConnectionString);
            if (!done.Wait(timeout))
            {
                throw new TimeoutException("Could not create/read table.");
            }
        }
예제 #4
0
        public async Task InitializeMembershipTable(GlobalConfiguration config, bool tryInitTableVersion, TraceLogger traceLogger)
        {
            logger = traceLogger;
            deploymentId = config.DeploymentId;

            if (logger.IsVerbose3) logger.Verbose3("SqlMembershipTable.InitializeMembershipTable called.");

            database = RelationalStorageUtilities.CreateGenericStorageInstance(config.AdoInvariant, config.DataConnectionString);

            //This initializes all of Orleans operational queries from the database using a well known view
            //and assumes the database with appropriate defintions exists already.
            queryConstants = await database.InitializeOrleansQueriesAsync();

            // even if I am not the one who created the table, 
            // try to insert an initial table version if it is not already there,
            // so we always have a first table version row, before this silo starts working.
            if(tryInitTableVersion)
            {
                var wasCreated = await InitTableAsync();
                if(wasCreated)
                {
                    logger.Info("Created new table version row.");
                }
            }
        }
예제 #5
0
 public override Task OnActivateAsync()
 {
     logger = TraceLogger.GetLogger(String.Format("GrainBasedReminderTable_{0}", Data.Address.ToString()), TraceLogger.LoggerType.Runtime);
     logger.Info("GrainBasedReminderTable {0} Activated. Full identity: {1}", Identity, Data.Address.ToFullString());
     remTable = new InMemoryRemindersTable();
     base.DelayDeactivation(TimeSpan.FromDays(10 * 365)); // Delay Deactivation for GrainBasedReminderTable virtually indefinitely.
     return TaskDone.Done;
 }
        public async Task Initialize(Guid serviceid, string connectionstring)
        {
            Name = "AzureTableBasedGossipChannel-" + ++sequenceNumber;
            logger = TraceLogger.GetLogger(Name, TraceLogger.LoggerType.Runtime);

            logger.Info("Initializing Gossip Channel for ServiceId={0} using connection: {1}, SeverityLevel={2}",
                serviceid, ConfigUtilities.RedactConnectionStringInfo(connectionstring), logger.SeverityLevel);

            tableManager = await GossipTableInstanceManager.GetManager(serviceid, connectionstring, logger);
        }
예제 #7
0
        public void TestInitialize()
        {
            logger = TraceLogger.GetLogger(GetType().Name, TraceLogger.LoggerType.Application);
            deploymentId = "test-" + Guid.NewGuid();

            logger.Info("DeploymentId={0}", deploymentId);

            var globalConfiguration = new GlobalConfiguration
            {
                DeploymentId = deploymentId,
                AdoInvariant = GetAdoInvariant(),
                DataConnectionString = GetConnectionString()
            };

            var mbr = CreateMembershipTable(logger);
            mbr.InitializeMembershipTable(globalConfiguration, true, logger).WithTimeout(TimeSpan.FromMinutes(1)).Wait();
            membershipTable = mbr;
        }
예제 #8
0
        public async Task InitializeMembershipTable(GlobalConfiguration config, bool tryInitTableVersion, TraceLogger traceLogger)
        {
            logger = traceLogger;
            AzureTableDefaultPolicies.MaxBusyRetries = config.MaxStorageBusyRetries;
            TraceLogger.SetExceptionDecoder(typeof(StorageException), AzureStorageUtils.PrintStorageException);

            tableManager = await OrleansSiloInstanceManager.GetManager(
                config.DeploymentId, config.DataConnectionString);

            // even if I am not the one who created the table, 
            // try to insert an initial table version if it is not already there,
            // so we always have a first table version row, before this silo starts working.
            if (tryInitTableVersion)
            {
                // ignore return value, since we don't care if I inserted it or not, as long as it is in there. 
                bool created = await tableManager.TryCreateTableVersionEntryAsync().WithTimeout(AzureTableDefaultPolicies.TableOperationTimeout);
                if(created) logger.Info("Created new table version row.");
            }
        }
예제 #9
0
        public void TestInitialize()
        {
            logger = TraceLogger.GetLogger(GetType().Name, TraceLogger.LoggerType.Application);
            var serviceId = Guid.NewGuid();
            var deploymentId = "test-" + serviceId;

            logger.Info("DeploymentId={0}", deploymentId);

            var globalConfiguration = new GlobalConfiguration
            {
                ServiceId = serviceId,
                DeploymentId = deploymentId,
                AdoInvariantForReminders = GetAdoInvariant(),
                DataConnectionStringForReminders = GetConnectionString()
            };

            var rmndr = CreateRemindersTable();
            rmndr.Init(globalConfiguration, logger).WithTimeout(TimeSpan.FromMinutes(1)).Wait();
            remindersTable = rmndr;
        }
예제 #10
0
        public GatewayManager(ClientConfiguration cfg, IGatewayListProvider gatewayListProvider)
        {
            config = cfg;
            knownDead = new Dictionary<Uri, DateTime>();
            rand = new SafeRandom();
            logger = TraceLogger.GetLogger("Messaging.GatewayManager", TraceLogger.LoggerType.Runtime);
            lockable = new object();
            gatewayRefreshCallInitiated = false;

            ListProvider = gatewayListProvider;

            var knownGateways = ListProvider.GetGateways().GetResult();

            if (knownGateways.Count == 0)
            {
                string gatewayProviderType = gatewayListProvider.GetType().FullName;
                string err = String.Format("Could not find any gateway in {0}. Orleans client cannot initialize.", gatewayProviderType);
                logger.Error(ErrorCode.GatewayManager_NoGateways, err);
                throw new OrleansException(err);
            }

            logger.Info(ErrorCode.GatewayManager_FoundKnownGateways, "Found {0} knownGateways from Gateway listProvider {1}", knownGateways.Count, Utils.EnumerableToString(knownGateways));

            if (ListProvider is IGatewayListObservable)
            {
                ((IGatewayListObservable)ListProvider).SubscribeToGatewayNotificationEvents(this);
            }

            roundRobinCounter = cfg.PreferedGatewayIndex >= 0 ? cfg.PreferedGatewayIndex : rand.Next(knownGateways.Count);

            cachedLiveGateways = knownGateways;

            lastRefreshTime = DateTime.UtcNow;
            if (ListProvider.IsUpdatable)
            {
                gatewayRefreshTimer = new SafeTimer(RefreshSnapshotLiveGateways_TimerCallback, null, config.GatewayListRefreshPeriod, config.GatewayListRefreshPeriod);
            }
        }
예제 #11
0
        /// <summary>
        /// Initialize this silo.
        /// </summary>
        public void InitializeOrleansSilo()
        {
    #if DEBUG
            AssemblyLoaderUtils.EnableAssemblyLoadTracing();
    #endif

            try
            {
                if (!ConfigLoaded)
                {
                    LoadOrleansConfig();
                }

                logger.Info(ErrorCode.SiloInitializing, "Initializing Silo {0} on host={1} CPU count={2} running .NET version='{3}' Is .NET 4.5={4} OS version='{5}'",
                            Name, Environment.MachineName, Environment.ProcessorCount, Environment.Version, ConfigUtilities.IsNet45OrNewer(), Environment.OSVersion);

                logger.Info(ErrorCode.SiloGcSetting, "Silo running with GC settings: ServerGC={0} GCLatencyMode={1}", GCSettings.IsServerGC, Enum.GetName(typeof(GCLatencyMode), GCSettings.LatencyMode));
                if (!GCSettings.IsServerGC)
                {
                    logger.Warn(ErrorCode.SiloGcWarning, "Note: Silo not running with ServerGC turned on - recommend checking app config : <configuration>-<runtime>-<gcServer enabled=\"true\"> and <configuration>-<runtime>-<gcConcurrent enabled=\"false\"/>");
                }

                orleans = new Silo(Name, Type, Config);
            }
            catch (Exception exc)
            {
                ReportStartupError(exc);
                orleans = null;
            }
        }
예제 #12
0
 public void TestCleanup()
 {
     logger.Info("Test {0} completed - Outcome = {1}", TestContext.TestName, TestContext.CurrentTestOutcome);
 }
예제 #13
0
        public OutsideRuntimeClient(ClientConfiguration cfg, GrainFactory grainFactory, bool secondary = false)
        {
            this.grainFactory = grainFactory;
            this.clientId     = GrainId.NewClientId();

            if (cfg == null)
            {
                Console.WriteLine("An attempt to create an OutsideRuntimeClient with null ClientConfiguration object.");
                throw new ArgumentException("OutsideRuntimeClient was attempted to be created with null ClientConfiguration object.", "cfg");
            }

            this.config = cfg;

            if (!TraceLogger.IsInitialized)
            {
                TraceLogger.Initialize(config);
            }
            StatisticsCollector.Initialize(config);
            SerializationManager.Initialize(config.UseStandardSerializer);
            logger    = TraceLogger.GetLogger("OutsideRuntimeClient", TraceLogger.LoggerType.Runtime);
            appLogger = TraceLogger.GetLogger("Application", TraceLogger.LoggerType.Application);

            try
            {
                LoadAdditionalAssemblies();

                PlacementStrategy.Initialize();

                callbacks           = new ConcurrentDictionary <CorrelationId, CallbackData>();
                localObjects        = new ConcurrentDictionary <GuidId, LocalObjectData>();
                CallbackData.Config = config;

                if (!secondary)
                {
                    UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnhandledException);
                }
                // Ensure SerializationManager static constructor is called before AssemblyLoad event is invoked
                SerializationManager.GetDeserializer(typeof(String));
                // Ensure that any assemblies that get loaded in the future get recorded
                AppDomain.CurrentDomain.AssemblyLoad += NewAssemblyHandler;

                // Load serialization info for currently-loaded assemblies
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    if (!assembly.ReflectionOnly)
                    {
                        SerializationManager.FindSerializationInfo(assembly);
                    }
                }

                clientProviderRuntime     = new ClientProviderRuntime(grainFactory);
                statisticsProviderManager = new StatisticsProviderManager("Statistics", clientProviderRuntime);
                var statsProviderName = statisticsProviderManager.LoadProvider(config.ProviderConfigurations)
                                        .WaitForResultWithThrow(initTimeout);
                if (statsProviderName != null)
                {
                    config.StatisticsProviderName = statsProviderName;
                }

                responseTimeout = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout;
                BufferPool.InitGlobalBufferPool(config);
                var localAddress = ClusterConfiguration.GetLocalIPAddress(config.PreferredFamily, config.NetInterface);

                // Client init / sign-on message
                logger.Info(ErrorCode.ClientInitializing, string.Format(
                                "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}",
                                BARS, config.DNSHostName, localAddress, clientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}'", BARS, RuntimeVersion.Current);
                startMsg = string.Format("{0} Config= " + Environment.NewLine + " {1}", startMsg, config);
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new ApplicationException("TestOnlyThrowExceptionDuringInit");
                }

                config.CheckGatewayProviderSettings();

                var generation          = -SiloAddress.AllocateNewGeneration(); // Client generations are negative
                var gatewayListProvider = GatewayProviderFactory.CreateGatewayListProvider(config)
                                          .WithTimeout(initTimeout).Result;
                transport = new ProxiedMessageCenter(config, localAddress, generation, clientId, gatewayListProvider);

                if (StatisticsCollector.CollectThreadTimeTrackingStats)
                {
                    incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver");
                }
            }
            catch (Exception exc)
            {
                if (logger != null)
                {
                    logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc);
                }
                ConstructorReset();
                throw;
            }
        }
예제 #14
0
파일: AzureSilo.cs 프로젝트: zfq308/orleans
        /// <summary>
        /// Initialize this Orleans silo for execution with the specified Azure deploymentId
        /// </summary>
        /// <param name="config">If null, Config data will be read from silo config file as normal, otherwise use the specified config data.</param>
        /// <param name="deploymentId">Azure DeploymentId this silo is running under</param>
        /// <param name="connectionString">Azure DataConnectionString. If null, defaults to the DataConnectionString setting from the Azure configuration for this role.</param>
        /// <returns><c>true</c> is the silo startup was successful</returns>
        public bool Start(ClusterConfiguration config, string deploymentId = null, string connectionString = null)
        {
            // Program ident
            Trace.TraceInformation("Starting {0} v{1}", this.GetType().FullName, RuntimeVersion.Current);

            // Check if deployment id was specified
            if (deploymentId == null)
            {
                deploymentId = serviceRuntimeWrapper.DeploymentId;
            }

            // Read endpoint info for this instance from Azure config
            string instanceName = serviceRuntimeWrapper.InstanceName;

            // Configure this Orleans silo instance
            if (config == null)
            {
                host = new SiloHost(instanceName);
                host.LoadOrleansConfig(); // Load config from file + Initializes logger configurations
            }
            else
            {
                host = new SiloHost(instanceName, config); // Use supplied config data + Initializes logger configurations
            }

            IPEndPoint myEndpoint    = serviceRuntimeWrapper.GetIPEndpoint(SiloEndpointConfigurationKeyName);
            IPEndPoint proxyEndpoint = serviceRuntimeWrapper.GetIPEndpoint(ProxyEndpointConfigurationKeyName);

            host.SetSiloType(Silo.SiloType.Secondary);

            int generation = SiloAddress.AllocateNewGeneration();

            // Bootstrap this Orleans silo instance

            myEntry = new SiloInstanceTableEntry
            {
                DeploymentId = deploymentId,
                Address      = myEndpoint.Address.ToString(),
                Port         = myEndpoint.Port.ToString(CultureInfo.InvariantCulture),
                Generation   = generation.ToString(CultureInfo.InvariantCulture),

                HostName  = host.Config.GetOrCreateNodeConfigurationForSilo(host.Name).DNSHostName,
                ProxyPort = (proxyEndpoint != null ? proxyEndpoint.Port : 0).ToString(CultureInfo.InvariantCulture),

                RoleName     = serviceRuntimeWrapper.RoleName,
                InstanceName = instanceName,
                UpdateZone   = serviceRuntimeWrapper.UpdateDomain.ToString(CultureInfo.InvariantCulture),
                FaultZone    = serviceRuntimeWrapper.FaultDomain.ToString(CultureInfo.InvariantCulture),
                StartTime    = TraceLogger.PrintDate(DateTime.UtcNow),

                PartitionKey = deploymentId,
                RowKey       = myEndpoint.Address + "-" + myEndpoint.Port + "-" + generation
            };

            if (connectionString == null)
            {
                connectionString = serviceRuntimeWrapper.GetConfigurationSettingValue(DataConnectionConfigurationSettingName);
            }

            try
            {
                siloInstanceManager = OrleansSiloInstanceManager.GetManager(
                    deploymentId, connectionString).WithTimeout(AzureTableDefaultPolicies.TableCreationTimeout).Result;
            }
            catch (Exception exc)
            {
                var error = String.Format("Failed to create OrleansSiloInstanceManager. This means CreateTableIfNotExist for silo instance table has failed with {0}",
                                          TraceLogger.PrintException(exc));
                Trace.TraceError(error);
                logger.Error(ErrorCode.AzureTable_34, error, exc);
                throw new OrleansException(error, exc);
            }

            // Always use Azure table for membership when running silo in Azure
            host.SetSiloLivenessType(GlobalConfiguration.LivenessProviderType.AzureTable);
            if (host.Config.Globals.ReminderServiceType == GlobalConfiguration.ReminderServiceProviderType.NotSpecified ||
                host.Config.Globals.ReminderServiceType == GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain)
            {
                host.SetReminderServiceType(GlobalConfiguration.ReminderServiceProviderType.AzureTable);
            }
            host.SetExpectedClusterSize(serviceRuntimeWrapper.RoleInstanceCount);
            siloInstanceManager.RegisterSiloInstance(myEntry);

            // Initialise this Orleans silo instance
            host.SetDeploymentId(deploymentId, connectionString);
            host.SetSiloEndpoint(myEndpoint, generation);
            host.SetProxyEndpoint(proxyEndpoint);

            host.InitializeOrleansSilo();
            logger.Info(ErrorCode.Runtime_Error_100288, "Successfully initialized Orleans silo '{0}' as a {1} node.", host.Name, host.Type);
            return(StartSilo());
        }
예제 #15
0
        public static void Main(string[] args)
        {
            ParseArgs(args, ToolName);

            InitializeLogger();

            PrintWelcome(ToolName);

            if (CreateContextMenuEntry)
            {
                // create context menu entry
                try
                {
                    TraceLogger.Info("Creating context menu entry for doc2x ...");
                    RegisterForContextMenu(GetContextMenuKey(ContextMenuInputExtension, ContextMenuText));
                    TraceLogger.Info("Succeeded.");
                }
                catch (Exception)
                {
                    TraceLogger.Info("Failed. Sorry :(");
                }
            }
            else
            {
                // convert
                try
                {
                    //copy processing file
                    ProcessingFile procFile = new ProcessingFile(InputFile);

                    //make output file name
                    if (ChoosenOutputFile == null)
                    {
                        if (InputFile.Contains("."))
                        {
                            ChoosenOutputFile = InputFile.Remove(InputFile.LastIndexOf(".")) + ".docx";
                        }
                        else
                        {
                            ChoosenOutputFile = InputFile + ".docx";
                        }
                    }

                    //open the reader
                    using (StructuredStorageReader reader = new StructuredStorageReader(procFile.File.FullName))
                    {
                        //parse the input document
                        WordDocument doc = new WordDocument(reader);

                        //prepare the output document
                        OpenXmlPackage.DocumentType outType = Converter.DetectOutputType(doc);
                        string conformOutputFile            = Converter.GetConformFilename(ChoosenOutputFile, outType);
                        WordprocessingDocument docx         = WordprocessingDocument.Create(conformOutputFile, outType);

                        //start time
                        DateTime start = DateTime.Now;
                        TraceLogger.Info("Converting file {0} into {1}", InputFile, conformOutputFile);

                        //convert the document
                        Converter.Convert(doc, docx);

                        DateTime end  = DateTime.Now;
                        TimeSpan diff = end.Subtract(start);
                        TraceLogger.Info("Conversion of file {0} finished in {1} seconds", InputFile, diff.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                    }
                }
                catch (DirectoryNotFoundException ex)
                {
                    TraceLogger.Error(ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (FileNotFoundException ex)
                {
                    TraceLogger.Error(ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (ReadBytesAmountMismatchException ex)
                {
                    TraceLogger.Error("Input file {0} is not a valid Microsoft Word 97-2003 file.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (MagicNumberException ex)
                {
                    TraceLogger.Error("Input file {0} is not a valid Microsoft Word 97-2003 file.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (UnspportedFileVersionException ex)
                {
                    TraceLogger.Error("File {0} has been created with a Word version older than Word 97.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (ByteParseException ex)
                {
                    TraceLogger.Error("Input file {0} is not a valid Microsoft Word 97-2003 file.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (MappingException ex)
                {
                    TraceLogger.Error("There was an error while converting file {0}: {1}", InputFile, ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (ZipCreationException ex)
                {
                    TraceLogger.Error("Could not create output file {0}.", ChoosenOutputFile);
                    //TraceLogger.Error("Perhaps the specified outputfile was a directory or contained invalid characters.");
                    TraceLogger.Debug(ex.ToString());
                }
                catch (Exception ex)
                {
                    TraceLogger.Error("Conversion of file {0} failed.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
            }
        }
예제 #16
0
 public override Task OnDeactivateAsync()
 {
     logger.Info("GrainBasedMembershipTable Deactivated.");
     return(TaskDone.Done);
 }
예제 #17
0
        public void SendMessage(Message msg)
        {
            if (msg == null)
            {
                throw new ArgumentNullException("msg", "Can't send a null message.");
            }

            if (stopped)
            {
                logger.Info(ErrorCode.Runtime_Error_100112, "Message was queued for sending after outbound queue was stopped: {0}", msg);
                return;
            }

            // Don't process messages that have already timed out
            if (msg.IsExpired)
            {
                msg.DropExpiredMessage(MessagingStatisticsGroup.Phase.Send);
                return;
            }

            if (!msg.ContainsMetadata(QUEUED_TIME_METADATA))
            {
                msg.SetMetadata(QUEUED_TIME_METADATA, DateTime.UtcNow);
            }

            // First check to see if it's really destined for a proxied client, instead of a local grain.
            if (messageCenter.IsProxying && messageCenter.TryDeliverToProxy(msg))
            {
                return;
            }

            if (!msg.ContainsHeader(Message.Header.TARGET_SILO))
            {
                logger.Error(ErrorCode.Runtime_Error_100113, "Message does not have a target silo: " + msg + " -- Call stack is: " + (new System.Diagnostics.StackTrace()));
                messageCenter.SendRejection(msg, Message.RejectionTypes.Unrecoverable, "Message to be sent does not have a target silo");
                return;
            }

            // Shortcut messages to this silo
            if (msg.TargetSilo.Equals(messageCenter.MyAddress))
            {
                if (logger.IsVerbose3)
                {
                    logger.Verbose3("Message has been looped back to this silo: {0}", msg);
                }
                MessagingStatisticsGroup.LocalMessagesSent.Increment();
                messageCenter.InboundQueue.PostMessage(msg);
            }
            else
            {
                if (stopped)
                {
                    logger.Info(ErrorCode.Runtime_Error_100115, "Message was queued for sending after outbound queue was stopped: {0}", msg);
                    return;
                }

                // check for simulation of lost messages
                if (Silo.CurrentSilo.TestHook.ShouldDrop(msg))
                {
                    logger.Info(ErrorCode.Messaging_SimulatedMessageLoss, "Message blocked by test");
                    messageCenter.SendRejection(msg, Message.RejectionTypes.Unrecoverable, "Message blocked by test");
                }

                // Prioritize system messages
                switch (msg.Category)
                {
                case Message.Categories.Ping:
                    pingSender.QueueRequest(msg);
                    break;

                case Message.Categories.System:
                    systemSender.QueueRequest(msg);
                    break;

                default:
                {
                    int index = Math.Abs(msg.TargetSilo.GetConsistentHashCode()) % senders.Length;
                    senders[index].Value.QueueRequest(msg);
                    break;
                }
                }
            }
        }
예제 #18
0
        public void Explore(string path)
        {
            if (!_exploredPaths.Contains(path))
            {
                lock (_lockObj)
                {
                    if (!_exploredPaths.Contains(path))
                    {
                        var logFormatters        = new List <ILogFormatter>();
                        var reportEventObservers = new List <IReportEventsObserver>();
                        var commandsListeners    = new List <ICommandsListener>();

                        var currentDirectory = new DirectoryInfo(path);

                        TraceLogger.Info($"Exploring extensions in '{currentDirectory}' directory.");

                        foreach (var file in currentDirectory.GetFiles("*ReportPortal*.dll"))
                        {
                            TraceLogger.Verbose($"Found '{file.Name}' and loading it into current AppDomain.");
                            AppDomain.CurrentDomain.Load(Path.GetFileNameWithoutExtension(file.Name));
                        }

                        var iLogFormatterExtensionInterfaceType       = typeof(ILogFormatter);
                        var iReportEventObserseExtensionInterfaceType = typeof(IReportEventsObserver);
                        var iCommandsListenerInterfaceType            = typeof(ICommandsListener);

                        foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name.Contains("ReportPortal")))
                        {
                            if (!_exploredAssemblies.Contains(assembly.Location))
                            {
                                _exploredAssemblies.Add(assembly.Location);
                                TraceLogger.Verbose($"Exploring '{assembly.FullName}' assembly for extensions.");
                                try
                                {
                                    foreach (var type in assembly.GetTypes().Where(t => t.IsClass))
                                    {
                                        if (!type.IsAbstract && type.GetConstructors().Any(ctor => ctor.GetParameters().Length == 0))
                                        {
                                            if (iLogFormatterExtensionInterfaceType.IsAssignableFrom(type))
                                            {
                                                var extension = Activator.CreateInstance(type);
                                                logFormatters.Add((ILogFormatter)extension);
                                                TraceLogger.Info($"Registered '{type.FullName}' type as {nameof(ILogFormatter)} extension.");
                                            }

                                            if (iReportEventObserseExtensionInterfaceType.IsAssignableFrom(type))
                                            {
                                                var extension = Activator.CreateInstance(type);
                                                reportEventObservers.Add((IReportEventsObserver)extension);
                                                TraceLogger.Info($"Registered '{type.FullName}' type as {nameof(IReportEventsObserver)} extension.");
                                            }

                                            if (iCommandsListenerInterfaceType.IsAssignableFrom(type))
                                            {
                                                var extension = Activator.CreateInstance(type);
                                                commandsListeners.Add((ICommandsListener)extension);
                                                TraceLogger.Info($"Registered '{type.FullName}' type as {nameof(ICommandsListener)} extension.");
                                            }
                                        }
                                    }
                                }
                                catch (ReflectionTypeLoadException exp)
                                {
                                    TraceLogger.Warn($"Couldn't load '{assembly.GetName().Name}' assembly into domain. \n {exp}");
                                    foreach (var loaderException in exp.LoaderExceptions)
                                    {
                                        TraceLogger.Error(loaderException.ToString());
                                    }
                                }
                            }
                        }

                        logFormatters.OrderBy(ext => ext.Order).ToList().ForEach(lf => LogFormatters.Add(lf));
                        reportEventObservers.ToList().ForEach(reo => ReportEventObservers.Add(reo));
                        commandsListeners.ForEach(cl => CommandsListeners.Add(cl));

                        _exploredPaths.Add(path);
                    }
                }
            }
        }
예제 #19
0
        private void RunLoggerPerfTest(string testName, int n, int logCode, TimeSpan target, TraceLogger logger)
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int i = 0; i < n; i++)
            {
                logger.Warn(logCode, "msg " + i);
            }
            var elapsed = stopwatch.Elapsed;
            string msg = testName + " : Elapsed time = " + elapsed;

            // Wait until the BulkMessageInterval time interval expires before wring the final log message - should cause bulk message flush
            while (stopwatch.Elapsed <= TraceLogger.BulkMessageInterval)
            {
                Thread.Sleep(10);
            }

            Console.WriteLine(msg);
            logger.Info(logCode, msg);
            Assert.IsTrue(elapsed < target.Multiply(timingFactor), "{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);
        }
        /// <summary>
        /// Copy files to container.
        /// </summary>
        /// <param name="directoryAndcontainerPath">Directory and container path as tuple.</param>
        /// <param name="cancellationToken"><see cref="CancellationToken"/></param>
        /// <param name="retryDelay">Bool for weather to delay 1 minute before retrying.</param>
        /// <returns></returns>
        public virtual async Task CopyToContainerAsync(Tuple <string, string> directoryAndcontainerPath, CancellationToken cancellationToken, bool retryDelay = true)
        {
            int    maxConcurrentUploads = Math.Max(Environment.ProcessorCount / 2, 1);
            string sourceParentDirectory;
            var    uploadDirectory = directoryAndcontainerPath.Item1;
            var    containerPath   = directoryAndcontainerPath.Item2;

            List <string> files;

            files = Directory.EnumerateFiles(uploadDirectory, "*", SearchOption.AllDirectories).ToList();
            sourceParentDirectory = uploadDirectory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

            TraceLogger.Info(string.Format(Resources.TotalUploadFiles, files.Count()));

            using (var uploadCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
            {
                // hook up reporting event from file container client.
                _fileContainerHelper.UploadFileReportTrace    += UploadFileTraceReportReceived;
                _fileContainerHelper.UploadFileReportProgress += UploadFileProgressReportReceived;

                try
                {
                    // try upload all files for the first time.
                    List <string> failedFiles = await ParallelUploadAsync(files, sourceParentDirectory, containerPath, maxConcurrentUploads, uploadCancellationTokenSource.Token);

                    if (failedFiles.Count == 0)
                    {
                        // all files have been upload succeed.
                        TraceLogger.Info(Resources.FileUploadSucceed);
                        return;
                    }
                    else
                    {
                        TraceLogger.Info(string.Format(Resources.FileUploadFailedRetryLater, failedFiles.Count));
                    }

                    if (retryDelay)
                    {
                        // Delay 1 min then retry failed files.
                        for (int timer = 60; timer > 0; timer -= 5)
                        {
                            TraceLogger.Info(string.Format(Resources.FileUploadRetryInSecond, timer));
                            await Task.Delay(TimeSpan.FromSeconds(5), uploadCancellationTokenSource.Token);
                        }
                    }

                    // Retry upload all failed files.
                    TraceLogger.Info(string.Format(Resources.FileUploadRetry, failedFiles.Count));
                    failedFiles = await ParallelUploadAsync(failedFiles, sourceParentDirectory, containerPath, maxConcurrentUploads, uploadCancellationTokenSource.Token);

                    if (failedFiles.Count == 0)
                    {
                        // all files have been upload succeed after retry.
                        TraceLogger.Info(Resources.FileUploadRetrySucceed);
                        return;
                    }
                    else
                    {
                        throw new Exception(Resources.FileUploadFailedAfterRetry);
                    }
                }
                finally
                {
                    _fileContainerHelper.UploadFileReportTrace    -= UploadFileTraceReportReceived;
                    _fileContainerHelper.UploadFileReportProgress -= UploadFileProgressReportReceived;
                }
            }
        }
        internal PersistentStreamPullingManager(
            GrainId id, 
            string strProviderName, 
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            PersistentStreamProviderConfig config)
            : base(id, runtime.ExecutingSiloAddress)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "IStreamProviderRuntime runtime reference should not be null");
            }
            if (streamPubSub == null)
            {
                throw new ArgumentNullException("streamPubSub", "StreamPubSub reference should not be null");
            }
            if (streamQueueBalancer == null)
            {
                throw new ArgumentNullException("streamQueueBalancer", "IStreamQueueBalancer streamQueueBalancer reference should not be null");
            }

            queuesToAgentsMap = new Dictionary<QueueId, PersistentStreamPullingAgent>();
            streamProviderName = strProviderName;
            providerRuntime = runtime;
            pubSub = streamPubSub;
            this.config = config;
            nonReentrancyGuarantor = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            latestCommandNumber = 0;
            queueBalancer = streamQueueBalancer;
            this.adapterFactory = adapterFactory;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger = TraceLogger.GetLogger(GetType().Name + "-" + streamProviderName, TraceLogger.LoggerType.Provider);
            logger.Info((int)ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);

            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
            queuePrintTimer = providerRuntime.RegisterTimer(AsyncTimerCallback, null, QUEUES_PRINT_PERIOD, QUEUES_PRINT_PERIOD);
        }
예제 #22
0
 public Async_TimingTests()
 {
     TraceLogger.Initialize(ClientConfiguration.StandardLoad());
     logger = TraceLogger.GetLogger("AC_TimingTests", TraceLogger.LoggerType.Application);
     logger.Info("----------------------------- STARTING AC_TimingTests -------------------------------------");
 }
예제 #23
0
        /// <summary>
        /// Start this silo.
        /// </summary>
        /// <returns></returns>
        public bool StartOrleansSilo()
        {
            try
            {
                if (string.IsNullOrEmpty(Thread.CurrentThread.Name))
                {
                    Thread.CurrentThread.Name = this.GetType().Name;
                }

                if (orleans != null)
                {
                    var shutdownEventName = Config.Defaults.SiloShutdownEventName ?? Name + "-Shutdown";
                    logger.Info(ErrorCode.SiloShutdownEventName, "Silo shutdown event name: {0}", shutdownEventName);

                    bool createdNew;
                    shutdownEvent = new EventWaitHandle(false, EventResetMode.ManualReset, shutdownEventName, out createdNew);
                    if (!createdNew)
                    {
                        logger.Info(ErrorCode.SiloShutdownEventOpened, "Opened existing shutdown event. Setting the event {0}", shutdownEventName);
                    }
                    else
                    {
                        logger.Info(ErrorCode.SiloShutdownEventCreated, "Created and set shutdown event {0}", shutdownEventName);
                    }

                    // Start silo
                    orleans.Start();

                    // Wait for the shutdown event, and trigger a graceful shutdown if we receive it.

                    var shutdownThread = new Thread(o =>
                    {
                        shutdownEvent.WaitOne();
                        logger.Info(ErrorCode.SiloShutdownEventReceived, "Received a shutdown event. Starting graceful shutdown.");
                        orleans.Shutdown();
                    });
                    shutdownThread.IsBackground = true;
                    shutdownThread.Start();

                    var startupEventName = Name;
                    logger.Info(ErrorCode.SiloStartupEventName, "Silo startup event name: {0}", startupEventName);

                    startupEvent = new EventWaitHandle(true, EventResetMode.ManualReset, startupEventName, out createdNew);
                    if (!createdNew)
                    {
                        logger.Info(ErrorCode.SiloStartupEventOpened, "Opened existing startup event. Setting the event {0}", startupEventName);
                        startupEvent.Set();
                    }
                    else
                    {
                        logger.Info(ErrorCode.SiloStartupEventCreated, "Created and set startup event {0}", startupEventName);
                    }

                    logger.Info(ErrorCode.SiloStarted, "Silo {0} started successfully", Name);
                    IsStarted = true;
                }
                else
                {
                    throw new InvalidOperationException("Cannot start silo " + this.Name + " due to prior initialization error");
                }
            }
            catch (Exception exc)
            {
                ReportStartupError(exc);
                orleans   = null;
                IsStarted = false;
                return(false);
            }

            return(true);
        }
예제 #24
0
 private void Heading(string testName)
 {
     logger.Info("\n\n************************ {0} {1}_{2} ********************************* \n\n", testNumber, streamProviderName, testName);
 }
예제 #25
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            ParseArgs(args, ToolName);

            InitializeLogger();

            PrintWelcome(ToolName, RevisionResource);

            if (CreateContextMenuEntry)
            {
                // create context menu entry
                try
                {
                    TraceLogger.Info("Creating context menu entry for ppt2x ...");
                    RegisterForContextMenu(GetContextMenuKey(ContextMenuInputExtension, ContextMenuText));
                    TraceLogger.Info("Succeeded.");
                }
                catch (Exception)
                {
                    TraceLogger.Info("Failed. Sorry :(");
                }
            }
            else
            {
                try
                {
                    if (InputFile.Contains("*.ppt"))
                    {
                        string[] files = Directory.GetFiles(InputFile.Replace("*.ppt", ""), "*.ppt");

                        foreach (String file in files)
                        {
                            if (new FileInfo(file).Extension.ToLower().EndsWith("ppt"))
                            {
                                ChoosenOutputFile = null;
                                processFile(file);
                            }
                        }
                    }
                    else
                    {
                        processFile(InputFile);
                    }
                }
                catch (ZipCreationException ex)
                {
                    TraceLogger.Error("Could not create output file {0}.", ChoosenOutputFile);
                    //TraceLogger.Error("Perhaps the specified outputfile was a directory or contained invalid characters.");
                    TraceLogger.Debug(ex.ToString());
                }
                catch (FileNotFoundException ex)
                {
                    TraceLogger.Error("Could not read input file {0}.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (MagicNumberException)
                {
                    TraceLogger.Error("Input file {0} is not a valid PowerPoint 97-2007 file.", InputFile);
                }
                catch (InvalidStreamException e)
                {
                    TraceLogger.Error("Input file {0} is not a valid PowerPoint 97-2007 file.", InputFile);
                }
                catch (InvalidRecordException)
                {
                    TraceLogger.Error("Input file {0} is not a valid PowerPoint 97-2007 file.", InputFile);
                }
                catch (StreamNotFoundException e)
                {
                    TraceLogger.Error("Input file {0} is not a valid PowerPoint 97-2007 file.", InputFile);
                }
                catch (Exception ex)
                {
                    TraceLogger.Error("Conversion of file {0} failed.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
            }

            TraceLogger.Info("End of program");
        }
        protected async Task MembershipTable_ReadAll_EmptyTable()
        {
            var data = await membershipTable.ReadAll();

            Assert.IsNotNull(data, "Membership Data not null");

            logger.Info("Membership.ReadAll returned VableVersion={0} Data={1}", data.Version, data);

            Assert.AreEqual(0, data.Members.Count, "Number of records returned - no table version row");
            Assert.IsNotNull(data.Version.VersionEtag, "ETag should not be null");
            Assert.AreEqual(0, data.Version.Version, "Initial tabel version should be zero");
        }
예제 #27
0
        public async Task Test_Reminders_Basic_StopByRef()
        {
            Console.WriteLine(TestContext.TestName + " started");
            log.Info(TestContext.TestName);
            IReminderTestGrain2 grain = GrainClient.GrainFactory.GetGrain <IReminderTestGrain2>(Guid.NewGuid());

            IGrainReminder r1 = await grain.StartReminder(DR);

            IGrainReminder r2 = await grain.StartReminder(DR);

            Console.WriteLine(TestContext.TestName + " reminders started");
            try
            {
                // First handle should now be out of date once the seconf handle to the same reminder was obtained
                await grain.StopReminder(r1);

                Assert.Fail("Removed reminder1, which shouldn't be possible.");
            }
            catch (Exception exc)
            {
                log.Info("Couldn't remove {0}, as expected. Exception received = {1}", r1, exc);
            }

            await grain.StopReminder(r2);

            log.Info("Removed reminder2 successfully");

            // trying to see if readreminder works
            IGrainReminder o1 = await grain.StartReminder(DR);

            IGrainReminder o2 = await grain.StartReminder(DR);

            IGrainReminder o3 = await grain.StartReminder(DR);

            IGrainReminder o4 = await grain.StartReminder(DR);

            IGrainReminder r = await grain.GetReminderObject(DR);

            await grain.StopReminder(r);

            log.Info("Removed got reminder successfully");
        }
예제 #28
0
        static void Main(string[] args)
        {
            ParseArgs(args, ToolName);

            InitializeLogger();

            PrintWelcome(ToolName, RevisionResource);

            if (CreateContextMenuEntry)
            {
                // create context menu entry
                try
                {
                    TraceLogger.Info("Creating context menu entry for xls2x ...");
                    RegisterForContextMenu(GetContextMenuKey(ContextMenuInputExtension, ContextMenuText));
                    TraceLogger.Info("Succeeded.");
                }
                catch (Exception)
                {
                    TraceLogger.Info("Failed. Sorry :(");
                }
            }
            else
            {
                try
                {
                    //copy processing file
                    ProcessingFile procFile = new ProcessingFile(InputFile);

                    //make output file name
                    if (ChoosenOutputFile == null)
                    {
                        if (InputFile.Contains("."))
                        {
                            ChoosenOutputFile = InputFile.Remove(InputFile.LastIndexOf(".")) + ".xlsx";
                        }
                        else
                        {
                            ChoosenOutputFile = InputFile + ".xlsx";
                        }
                    }

                    //parse the document
                    using (StructuredStorageReader reader = new StructuredStorageReader(procFile.File.FullName))
                    {
                        XlsDocument xlsDoc = new XlsDocument(reader);

                        OpenXmlPackage.DocumentType outType = Converter.DetectOutputType(xlsDoc);
                        string conformOutputFile            = Converter.GetConformFilename(ChoosenOutputFile, outType);
                        using (SpreadsheetDocument spreadx = SpreadsheetDocument.Create(conformOutputFile, outType))
                        {
                            //start time
                            DateTime start = DateTime.Now;
                            TraceLogger.Info("Converting file {0} into {1}", InputFile, conformOutputFile);

                            Converter.Convert(xlsDoc, spreadx);

                            DateTime end  = DateTime.Now;
                            TimeSpan diff = end.Subtract(start);
                            TraceLogger.Info("Conversion of file {0} finished in {1} seconds", InputFile, diff.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                        }
                    }
                }
                catch (ParseException ex)
                {
                    TraceLogger.Error("Could not convert {0} because it was created by an unsupported application (Excel 95 or older).", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (DirectoryNotFoundException ex)
                {
                    TraceLogger.Error(ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (FileNotFoundException ex)
                {
                    TraceLogger.Error(ex.Message);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (ZipCreationException ex)
                {
                    TraceLogger.Error("Could not create output file {0}.", ChoosenOutputFile);
                    TraceLogger.Debug(ex.ToString());
                }
                catch (Exception ex)
                {
                    TraceLogger.Error("Conversion of file {0} failed.", InputFile);
                    TraceLogger.Debug(ex.ToString());
                }
            }
        }
예제 #29
0
        /// <summary>
        /// Extracts the data from the stream
        /// </summary>
        public override void extractData()
        {
            BiffHeader bh;

            //try
            //{
            while (this.StreamReader.BaseStream.Position < this.StreamReader.BaseStream.Length)
            {
                bh.id     = (RecordType)this.StreamReader.ReadUInt16();
                bh.length = this.StreamReader.ReadUInt16();
                // Debugging output
                TraceLogger.DebugInternal("BIFF {0}\t{1}\t", bh.id, bh.length);

                switch (bh.id)
                {
                case RecordType.BoundSheet8:
                {
                    // Extracts the Boundsheet data
                    BoundSheet8 bs = new BoundSheet8(this.StreamReader, bh.id, bh.length);
                    TraceLogger.DebugInternal(bs.ToString());

                    SheetData sheetData = null;

                    switch (bs.dt)
                    {
                    case BoundSheet8.SheetType.Worksheet:
                        sheetData      = new WorkSheetData();
                        this.oldOffset = this.StreamReader.BaseStream.Position;
                        this.StreamReader.BaseStream.Seek(bs.lbPlyPos, SeekOrigin.Begin);
                        WorksheetExtractor se = new WorksheetExtractor(this.StreamReader, sheetData as WorkSheetData);
                        this.StreamReader.BaseStream.Seek(oldOffset, SeekOrigin.Begin);
                        break;

                    case BoundSheet8.SheetType.Chartsheet:
                        ChartSheetData chartSheetData = new ChartSheetData();

                        this.oldOffset = this.StreamReader.BaseStream.Position;
                        this.StreamReader.BaseStream.Seek(bs.lbPlyPos, SeekOrigin.Begin);
                        chartSheetData.ChartSheetSequence = new ChartSheetSequence(this.StreamReader);
                        this.StreamReader.BaseStream.Seek(oldOffset, SeekOrigin.Begin);

                        sheetData = chartSheetData;
                        break;

                    default:
                        TraceLogger.Info("Unsupported sheet type: {0}", bs.dt);
                        break;
                    }

                    if (sheetData != null)
                    {
                        // add general sheet info
                        sheetData.boundsheetRecord = bs;
                    }
                    this.workBookData.addBoundSheetData(sheetData);
                }
                break;

                case RecordType.Template:
                {
                    this.workBookData.Template = true;
                }
                break;

                case RecordType.SST:
                {
                    /* reads the shared string table biff record and following continue records
                     * creates an array of bytes and then puts that into a memory stream
                     * this all is used to create a longer biffrecord then 8224 bytes. If theres a string
                     * beginning in the SST that is then longer then the 8224 bytes, it continues in the
                     * CONTINUE BiffRecord, so the parser has to read over the SST border.
                     * The problem here is, that the parser has to overread the continue biff record header
                     */
                    SST    sst;
                    UInt16 length = bh.length;

                    // save the old offset from this record begin
                    this.oldOffset = this.StreamReader.BaseStream.Position;
                    // create a list of bytearrays to store the following continue records
                    // List<byte[]> byteArrayList = new List<byte[]>();
                    byte[] buffer = new byte[length];
                    LinkedList <VirtualStreamReader> vsrList = new LinkedList <VirtualStreamReader>();
                    buffer = this.StreamReader.ReadBytes((int)length);
                    // byteArrayList.Add(buffer);

                    // create a new memory stream and a new virtualstreamreader
                    MemoryStream        bufferstream = new MemoryStream(buffer);
                    VirtualStreamReader binreader    = new VirtualStreamReader(bufferstream);
                    BiffHeader          bh2;
                    bh2.id = (RecordType)this.StreamReader.ReadUInt16();

                    while (bh2.id == RecordType.Continue)
                    {
                        bh2.length = (UInt16)(this.StreamReader.ReadUInt16());

                        buffer = new byte[bh2.length];

                        // create a buffer with the bytes from the records and put that array into the
                        // list
                        buffer = this.StreamReader.ReadBytes((int)bh2.length);
                        // byteArrayList.Add(buffer);

                        // create for each continue record a new streamreader !!
                        MemoryStream        contbufferstream = new MemoryStream(buffer);
                        VirtualStreamReader contreader       = new VirtualStreamReader(contbufferstream);
                        vsrList.AddLast(contreader);


                        // take next Biffrecord ID
                        bh2.id = (RecordType)this.StreamReader.ReadUInt16();
                    }
                    // set the old position of the stream
                    this.StreamReader.BaseStream.Position = this.oldOffset;

                    sst = new SST(binreader, bh.id, length, vsrList);
                    this.StreamReader.BaseStream.Position = this.oldOffset + bh.length;
                    this.workBookData.SstData             = new SSTData(sst);
                }
                break;

                case RecordType.EOF:
                {
                    // Reads the end of the internal file !!!
                    this.StreamReader.BaseStream.Seek(0, SeekOrigin.End);
                }
                break;

                case RecordType.ExternSheet:
                {
                    ExternSheet extsheet = new ExternSheet(this.StreamReader, bh.id, bh.length);
                    this.externSheets.Add(extsheet);
                    this.workBookData.addExternSheetData(extsheet);
                }
                break;

                case RecordType.SupBook:
                {
                    SupBook supbook = new SupBook(this.StreamReader, bh.id, bh.length);
                    this.supBooks.Add(supbook);
                    this.workBookData.addSupBookData(supbook);
                }
                break;

                case RecordType.XCT:
                {
                    XCT xct = new XCT(this.StreamReader, bh.id, bh.length);
                    this.XCTList.Add(xct);
                    this.workBookData.addXCT(xct);
                }
                break;

                case RecordType.CRN:
                {
                    CRN crn = new CRN(this.StreamReader, bh.id, bh.length);
                    this.CRNList.Add(crn);
                    this.workBookData.addCRN(crn);
                }
                break;

                case RecordType.ExternName:
                {
                    ExternName externname = new ExternName(this.StreamReader, bh.id, bh.length);
                    this.workBookData.addEXTERNNAME(externname);
                }
                break;

                case RecordType.Format:
                {
                    Format format = new Format(this.StreamReader, bh.id, bh.length);
                    this.workBookData.styleData.addFormatValue(format);
                }
                break;

                case RecordType.XF:
                {
                    XF xf = new XF(this.StreamReader, bh.id, bh.length);
                    this.workBookData.styleData.addXFDataValue(xf);
                }
                break;

                case RecordType.Style:
                {
                    Style style = new Style(this.StreamReader, bh.id, bh.length);
                    this.workBookData.styleData.addStyleValue(style);
                }
                break;

                case RecordType.Font:
                {
                    Font font = new Font(this.StreamReader, bh.id, bh.length);
                    this.workBookData.styleData.addFontData(font);
                }
                break;

                case RecordType.NAME:
                case RecordType.Lbl:
                {
                    Lbl name = new Lbl(this.StreamReader, bh.id, bh.length);
                    this.workBookData.addDefinedName(name);
                }
                break;

                case RecordType.BOF:
                {
                    this.workBookData.BOF = new BOF(this.StreamReader, bh.id, bh.length);
                }
                break;

                case RecordType.CodeName:
                {
                    this.workBookData.CodeName = new CodeName(this.StreamReader, bh.id, bh.length);
                }
                break;

                case RecordType.FilePass:
                {
                    throw new ExtractorException(ExtractorException.FILEENCRYPTED);
                }
                break;

                case RecordType.Palette:
                {
                    Palette palette = new Palette(this.StreamReader, bh.id, bh.length);
                    workBookData.styleData.setColorList(palette.rgbColorList);
                }
                break;

                default:
                {
                    // this else statement is used to read BiffRecords which aren't implemented
                    byte[] buffer = new byte[bh.length];
                    buffer = this.StreamReader.ReadBytes(bh.length);
                    TraceLogger.Debug("Unknown record found. ID {0}", bh.id);
                }
                break;
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    TraceLogger.Error(ex.Message);
            //    TraceLogger.Debug(ex.ToString());
            //}
        }
예제 #30
0
 private static void LogStatus(TraceLogger log, string msg, params object[] args)
 {
     if (SystemStatus.Current.Equals(SystemStatus.Creating))
     {
         // Reduce log noise during silo startup
         if (log.IsVerbose) log.Verbose(msg, args);
     }
     else
     {
         // Changes in agent threads during all operations aside for initial creation are usually important diag events.
         log.Info(msg, args);
     }
 }
예제 #31
0
 public override Task OnDeactivateAsync()
 {
     logger.Info("GrainBasedReminderTable {0} OnDeactivateAsync. Full identity: {1}", Identity, Data.Address.ToFullString());
     return(TaskDone.Done);
 }
예제 #32
0
        public OutsideRuntimeClient(ClientConfiguration cfg, GrainFactory grainFactory, bool secondary = false)
        {
            this.grainFactory = grainFactory;
            this.clientId = GrainId.NewClientId();

            if (cfg == null)
            {
                Console.WriteLine("An attempt to create an OutsideRuntimeClient with null ClientConfiguration object.");
                throw new ArgumentException("OutsideRuntimeClient was attempted to be created with null ClientConfiguration object.", "cfg");
            }

            this.config = cfg;

            if (!TraceLogger.IsInitialized) TraceLogger.Initialize(config);
            StatisticsCollector.Initialize(config);
            SerializationManager.Initialize(config.UseStandardSerializer, cfg.SerializationProviders, config.UseJsonFallbackSerializer);
            logger = TraceLogger.GetLogger("OutsideRuntimeClient", TraceLogger.LoggerType.Runtime);
            appLogger = TraceLogger.GetLogger("Application", TraceLogger.LoggerType.Application);

            try
            {
                LoadAdditionalAssemblies();
                
                PlacementStrategy.Initialize();

                callbacks = new ConcurrentDictionary<CorrelationId, CallbackData>();
                localObjects = new ConcurrentDictionary<GuidId, LocalObjectData>();

                if (!secondary)
                {
                    UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnhandledException);
                }
                // Ensure SerializationManager static constructor is called before AssemblyLoad event is invoked
                SerializationManager.GetDeserializer(typeof(String));

                clientProviderRuntime = new ClientProviderRuntime(grainFactory, new DefaultServiceProvider());
                statisticsProviderManager = new StatisticsProviderManager("Statistics", clientProviderRuntime);
                var statsProviderName = statisticsProviderManager.LoadProvider(config.ProviderConfigurations)
                    .WaitForResultWithThrow(initTimeout);
                if (statsProviderName != null)
                {
                    config.StatisticsProviderName = statsProviderName;
                }

                responseTimeout = Debugger.IsAttached ? Constants.DEFAULT_RESPONSE_TIMEOUT : config.ResponseTimeout;
                BufferPool.InitGlobalBufferPool(config);
                var localAddress = ClusterConfiguration.GetLocalIPAddress(config.PreferredFamily, config.NetInterface);

                // Client init / sign-on message
                logger.Info(ErrorCode.ClientInitializing, string.Format(
                    "{0} Initializing OutsideRuntimeClient on {1} at {2} Client Id = {3} {0}",
                    BARS, config.DNSHostName, localAddress, clientId));
                string startMsg = string.Format("{0} Starting OutsideRuntimeClient with runtime Version='{1}'", BARS, RuntimeVersion.Current);
                startMsg = string.Format("{0} Config= "  + Environment.NewLine + " {1}", startMsg, config);
                logger.Info(ErrorCode.ClientStarting, startMsg);

                if (TestOnlyThrowExceptionDuringInit)
                {
                    throw new Exception("TestOnlyThrowExceptionDuringInit");
                }

                config.CheckGatewayProviderSettings();

                var generation = -SiloAddress.AllocateNewGeneration(); // Client generations are negative
                var gatewayListProvider = GatewayProviderFactory.CreateGatewayListProvider(config)
                    .WithTimeout(initTimeout).Result;
                transport = new ProxiedMessageCenter(config, localAddress, generation, clientId, gatewayListProvider);
                
                if (StatisticsCollector.CollectThreadTimeTrackingStats)
                {
                    incomingMessagesThreadTimeTracking = new ThreadTrackingStatistic("ClientReceiver");
                }
            }
            catch (Exception exc)
            {
                if (logger != null) logger.Error(ErrorCode.Runtime_Error_100319, "OutsideRuntimeClient constructor failed.", exc);
                ConstructorReset();
                throw;
            }
        }
        private async Task <List <string> > UploadAsync(string sourceParentDirectory, string containerPath, CancellationToken cancellationToken)
        {
            List <string> failedFiles = new List <string>();
            string        fileToUpload;
            Stopwatch     uploadTimer = new Stopwatch();
            var           containerId = _context.ContainerId;
            var           projectId   = _context.ProjectId;

            while (_fileUploadQueue.TryDequeue(out fileToUpload))
            {
                cancellationToken.ThrowIfCancellationRequested();
                try
                {
                    using (FileStream fs = File.Open(fileToUpload, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        string itemPath = (containerPath.TrimEnd('/') + "/" + fileToUpload.Remove(0, sourceParentDirectory.Length + 1)).Replace('\\', '/');
                        uploadTimer.Restart();
                        bool coughtExceptionDuringUpload = false;
                        HttpResponseMessage response     = null;
                        try
                        {
                            response = await _fileContainerHelper.UploadFileAsync(containerId, itemPath, fs, projectId, cancellationToken, chunkSize : 4 * 1024 * 1024);
                        }
                        catch (OperationCanceledException) when(cancellationToken.IsCancellationRequested)
                        {
                            TraceLogger.Error(string.Format(Resources.FileUploadCancelled, fileToUpload));
                            if (response != null)
                            {
                                response.Dispose();
                                response = null;
                            }

                            throw;
                        }
                        catch (Exception ex)
                        {
                            coughtExceptionDuringUpload = true;
                            TraceLogger.Error(string.Format(Resources.FileUploadFailed, fileToUpload, ex));
                        }

                        uploadTimer.Stop();
                        if (coughtExceptionDuringUpload || (response != null && response.StatusCode != HttpStatusCode.Created))
                        {
                            if (response != null)
                            {
                                TraceLogger.Info(string.Format(Resources.FileContainerUploadFailed, response.StatusCode, response.ReasonPhrase, fileToUpload, itemPath));
                            }

                            // output detail upload trace for the file.
                            ConcurrentQueue <string> logQueue;
                            if (_fileUploadTraceLog.TryGetValue(itemPath, out logQueue))
                            {
                                TraceLogger.Info(string.Format(Resources.FileUploadDetailTrace, itemPath));
                                string message;
                                while (logQueue.TryDequeue(out message))
                                {
                                    TraceLogger.Info(message);
                                }
                            }

                            // tracking file that failed to upload.
                            failedFiles.Add(fileToUpload);
                        }
                        else
                        {
                            TraceLogger.Debug(string.Format(Resources.FileUploadFinish, fileToUpload, uploadTimer.ElapsedMilliseconds));

                            // debug detail upload trace for the file.
                            ConcurrentQueue <string> logQueue;
                            if (_fileUploadTraceLog.TryGetValue(itemPath, out logQueue))
                            {
                                TraceLogger.Debug($"Detail upload trace for file: {itemPath}");
                                string message;
                                while (logQueue.TryDequeue(out message))
                                {
                                    TraceLogger.Debug(message);
                                }
                            }
                        }

                        if (response != null)
                        {
                            response.Dispose();
                            response = null;
                        }
                    }

                    Interlocked.Increment(ref filesProcessed);
                }
                catch (Exception ex)
                {
                    TraceLogger.Error(string.Format(Resources.FileUploadFileOpenFailed, ex.Message, fileToUpload));
                    throw ex;
                }
            }

            return(failedFiles);
        }