Ejemplo n.º 1
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.");
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public Formula(IStreamReader reader, RecordType id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);
            this.val          = new byte[8];
            this.rw           = reader.ReadUInt16();
            this.col          = reader.ReadUInt16();
            this.ixfe         = reader.ReadUInt16();
            this.boolValueSet = false;

            long oldStreamPosition = this.Reader.BaseStream.Position;

            this.val = reader.ReadBytes(8); // read 8 bytes for the value of the formula
            ProcessFormulaValue();


            this.grbit    = reader.ReadUInt16();
            this.chn      = reader.ReadUInt32(); // this is used for performance reasons only
            this.cce      = reader.ReadUInt16();
            this.ptgStack = new Stack <AbstractPtg>();
            // reader.ReadBytes(this.cce);

            // check always calc mode
            this.fAlwaysCalc = Utils.BitmaskToBool((int)this.grbit, 0x01);

            // check if shared formula
            this.fShrFmla = Utils.BitmaskToBool((int)this.grbit, 0x08);

            // check if this should ignore error checking
            this.fClearErrors = Utils.BitmaskToBool(this.grbit, 0x20);


            oldStreamPosition = this.Reader.BaseStream.Position;
            if (!this.fShrFmla)
            {
                try
                {
                    this.ptgStack = ExcelHelperClass.getFormulaStack(this.Reader, this.cce);
                }
                catch (Exception ex)
                {
                    this.Reader.BaseStream.Seek(oldStreamPosition, System.IO.SeekOrigin.Begin);
                    this.Reader.BaseStream.Seek(this.cce, System.IO.SeekOrigin.Current);
                    TraceLogger.Error("Formula parse error in Row {0} Column {1}", this.rw, this.col);
                    TraceLogger.Debug(ex.StackTrace);
                    TraceLogger.Debug("Inner exception: {0}", ex.InnerException.StackTrace);
                }
            }
            else
            {
                //If the next expression isn't 5 bytes long, it's not a PtgExp shared formula reference...just ignore for now
                if (this.cce != 5)
                {
                    reader.ReadBytes(this.cce);
                }

                //First 8 bits are reserved, must be 1 but we'll ignore them for now
                byte ptg = reader.ReadByte();
                //Next two bytes are the row containing the shared formula
                sharedRow = reader.ReadUInt16();
                //then the col containing the shared formula
                sharedCol = reader.ReadUInt16();
            }


            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Ejemplo n.º 4
0
        // Execute one or more turns for this activation.
        // This method is always called in a single-threaded environment -- that is, no more than one
        // thread will be in this method at once -- but other asynch threads may still be queueing tasks, etc.
        public void Execute()
        {
            lock (lockable)
            {
                if (state == WorkGroupStatus.Shutdown)
                {
                    if (!IsActive)
                    {
                        return;             // Don't mind if no work has been queued to this work group yet.
                    }
                    ReportWorkGroupProblemWithBacktrace(
                        "Cannot execute work items in a work item group that is in a shutdown state.",
                        ErrorCode.SchedulerNotExecuteWhenShutdown); // Throws InvalidOperationException
                    return;
                }
                state = WorkGroupStatus.Running;
            }

            var thread = WorkerPoolThread.CurrentWorkerThread;

            try
            {
                // Process multiple items -- drain the applicationMessageQueue (up to max items) for this physical activation
                int count     = 0;
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                do
                {
                    lock (lockable)
                    {
                        if (state == WorkGroupStatus.Shutdown)
                        {
                            if (WorkItemCount > 0)
                            {
                                log.Warn(ErrorCode.SchedulerSkipWorkStopping, "Thread {0} is exiting work loop due to Shutdown state {1} while still having {2} work items in the queue.",
                                         thread.ToString(), this.ToString(), WorkItemCount);
                            }
                            else
                            if (log.IsVerbose)
                            {
                                log.Verbose("Thread {0} is exiting work loop due to Shutdown state {1}. Has {2} work items in the queue.",
                                            thread.ToString(), this.ToString(), WorkItemCount);
                            }

                            break;
                        }

                        // Check the cancellation token (means that the silo is stopping)
                        if (thread.CancelToken.IsCancellationRequested)
                        {
                            log.Warn(ErrorCode.SchedulerSkipWorkCancelled, "Thread {0} is exiting work loop due to cancellation token. WorkItemGroup: {1}, Have {2} work items in the queue.",
                                     thread.ToString(), this.ToString(), WorkItemCount);
                            break;
                        }
                    }

                    // Get the first Work Item on the list
                    Task task;
                    lock (lockable)
                    {
                        if (workItems.Count > 0)
                        {
                            task = workItems.Dequeue();
                        }
                        else // If the list is empty, then we're done
                        {
                            break;
                        }
                    }

#if TRACK_DETAILED_STATS
                    if (StatisticsCollector.CollectGlobalShedulerStats)
                    {
                        SchedulerStatisticsGroup.OnWorkItemDequeue();
                    }
#endif

#if DEBUG
                    if (log.IsVerbose2)
                    {
                        log.Verbose2("About to execute task {0} in SchedulingContext={1}", task, SchedulingContext);
                    }
#endif
                    var taskStart = stopwatch.Elapsed;

                    try
                    {
                        thread.CurrentTask = task;
#if TRACK_DETAILED_STATS
                        if (StatisticsCollector.CollectTurnsStats)
                        {
                            SchedulerStatisticsGroup.OnTurnExecutionStartsByWorkGroup(workItemGroupStatisticsNumber, thread.WorkerThreadStatisticsNumber, SchedulingContext);
                        }
#endif
                        TaskRunner.RunTask(task);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ErrorCode.SchedulerExceptionFromExecute, String.Format("Worker thread caught an exception thrown from Execute by task {0}", task), ex);
                        throw;
                    }
                    finally
                    {
#if TRACK_DETAILED_STATS
                        if (StatisticsCollector.CollectTurnsStats)
                        {
                            SchedulerStatisticsGroup.OnTurnExecutionEnd(Utils.Since(thread.CurrentStateStarted));
                        }

                        if (StatisticsCollector.CollectThreadTimeTrackingStats)
                        {
                            thread.threadTracking.IncrementNumberOfProcessed();
                        }
#endif
                        totalItemsProcessed++;
                        var taskLength = stopwatch.Elapsed - taskStart;
                        if (taskLength > OrleansTaskScheduler.TurnWarningLengthThreshold)
                        {
                            SchedulerStatisticsGroup.NumLongRunningTurns.Increment();
                            log.Warn(ErrorCode.SchedulerTurnTooLong3, "Task {0} in WorkGroup {1} took elapsed time {2:g} for execution, which is longer than {3}. Running on thread {4}",
                                     OrleansTaskExtentions.ToString(task), SchedulingContext.ToString(), taskLength, OrleansTaskScheduler.TurnWarningLengthThreshold, thread.ToString());
                        }
                        thread.CurrentTask = null;
                    }
                    count++;
                }while (((MaxWorkItemsPerTurn <= 0) || (count <= MaxWorkItemsPerTurn)) &&
                        ((ActivationSchedulingQuantum <= TimeSpan.Zero) || (stopwatch.Elapsed < ActivationSchedulingQuantum)));
                stopwatch.Stop();
            }
            catch (Exception ex)
            {
                log.Error(ErrorCode.Runtime_Error_100032, String.Format("Worker thread {0} caught an exception thrown from IWorkItem.Execute", thread), ex);
            }
            finally
            {
                // Now we're not Running anymore.
                // If we left work items on our run list, we're Runnable, and need to go back on the silo run queue;
                // If our run list is empty, then we're waiting.
                lock (lockable)
                {
                    if (state != WorkGroupStatus.Shutdown)
                    {
                        if (WorkItemCount > 0)
                        {
                            state = WorkGroupStatus.Runnable;
                            masterScheduler.RunQueue.Add(this);
                        }
                        else
                        {
                            state = WorkGroupStatus.Waiting;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
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;
            }

            if (Message.WriteMessagingTraces)
            {
                msg.AddTimestamp(Message.LifecycleTag.EnqueueOutgoing);
            }

            // 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.TestHookup.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;
                }
                }
            }
        }
        /// <summary>
        /// Parses the arguments of the tool
        /// </summary>
        /// <param name="args">The args array</param>
        public static void ParseArgs(string[] args, string toolName)
        {
            try
            {
                if (args[0] == "-?")
                {
                    PrintUsage(toolName);
                    Environment.Exit(0);
                }
                else if (args[0].ToLower() == "-c")
                {
                    CreateContextMenuEntry = true;
                }
                else
                {
                    InputFile = args[0];
                }

                for (int i = 1; i < args.Length; i++)
                {
                    if (args[i].ToLower() == "-v")
                    {
                        //parse verbose level
                        string verbose = args[i + 1].ToLower();
                        int    vLvl;
                        if (Int32.TryParse(verbose, out vLvl))
                        {
                            TraceLogger.LogLevel = (TraceLogger.LoggingLevel)vLvl;
                        }
                        else if (verbose == "error")
                        {
                            TraceLogger.LogLevel = TraceLogger.LoggingLevel.Error;
                        }
                        else if (verbose == "warning")
                        {
                            TraceLogger.LogLevel = TraceLogger.LoggingLevel.Warning;
                        }
                        else if (verbose == "info")
                        {
                            TraceLogger.LogLevel = TraceLogger.LoggingLevel.Info;
                        }
                        else if (verbose == "debug")
                        {
                            TraceLogger.LogLevel = TraceLogger.LoggingLevel.Debug;
                        }
                        else if (verbose == "none")
                        {
                            TraceLogger.LogLevel = TraceLogger.LoggingLevel.None;
                        }
                    }
                    else if (args[i].ToLower() == "-o")
                    {
                        //parse output file name
                        ChoosenOutputFile = args[i + 1];
                    }
                }
            }
            catch (Exception)
            {
                TraceLogger.Error("At least one of the required arguments was not correctly set.\n");
                PrintUsage(toolName);
                Environment.Exit(1);
            }
        }
Ejemplo n.º 7
0
        public Formula(IStreamReader reader, RecordType id, UInt16 length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);
            this.val          = new byte[8];
            this.rw           = reader.ReadUInt16();
            this.col          = reader.ReadUInt16();
            this.ixfe         = reader.ReadUInt16();
            this.boolValueSet = false;

            long oldStreamPosition = this.Reader.BaseStream.Position;

            this.val = reader.ReadBytes(8); // read 8 bytes for the value of the formular
            if (this.val[6] == 0xFF && this.val[7] == 0xFF)
            {
                // this value is a string, an error or a boolean value
                byte firstOffset = this.val[0];
                if (firstOffset == 1)
                {
                    // this is a boolean value
                    this.boolValue    = val[2];
                    this.boolValueSet = true;
                }
                if (firstOffset == 2)
                {
                    // this is a error value
                    this.errorValue = (int)val[2];
                }
            }
            else
            {
                this.Reader.BaseStream.Seek(oldStreamPosition, System.IO.SeekOrigin.Begin);
                this.calculatedValue = reader.ReadDouble();
            }


            this.grbit    = reader.ReadUInt16();
            this.chn      = reader.ReadUInt32(); // this is used for performance reasons only
            this.cce      = reader.ReadUInt16();
            this.ptgStack = new Stack <AbstractPtg>();
            // reader.ReadBytes(this.cce);

            // check always calc mode
            this.fAlwaysCalc = Utils.BitmaskToBool((int)grbit, 0x01);

            // check if shared formula
            this.fShrFmla = Utils.BitmaskToBool((int)grbit, 0x08);



            oldStreamPosition = this.Reader.BaseStream.Position;
            if (!fShrFmla)
            {
                try
                {
                    this.ptgStack = ExcelHelperClass.getFormulaStack(this.Reader, this.cce);
                }
                catch (Exception ex)
                {
                    this.Reader.BaseStream.Seek(oldStreamPosition, System.IO.SeekOrigin.Begin);
                    this.Reader.BaseStream.Seek(this.cce, System.IO.SeekOrigin.Current);
                    TraceLogger.Error("Formula parse error in Row {0} Column {1}", this.rw, this.col);
                    TraceLogger.Debug(ex.StackTrace);
                    TraceLogger.Debug("Inner exception: {0}", ex.InnerException.StackTrace);
                }
            }
            else
            {
                reader.ReadBytes(this.cce);
            }


            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Ejemplo n.º 8
0
        internal static bool AnalyzeReadException(Exception exc, int iteration, string tableName, TraceLogger logger)
        {
            bool isLastErrorRetriable;
            var we = exc as WebException;
            if (we != null)
            {
                isLastErrorRetriable = true;
                var statusCode = we.Status;
                logger.Warn(ErrorCode.AzureTable_10, String.Format("Intermediate issue reading Azure storage table {0}: HTTP status code={1} Exception Type={2} Message='{3}'",
                    tableName,
                    statusCode,
                    exc.GetType().FullName,
                    exc.Message),
                    exc);
            }
            else
            {
                HttpStatusCode httpStatusCode;
                string restStatus;
                if (EvaluateException(exc, out httpStatusCode, out restStatus, true))
                {
                    if (StorageErrorCodeStrings.ResourceNotFound.Equals(restStatus))
                    {
                        if (logger.IsVerbose) logger.Verbose(ErrorCode.AzureTable_DataNotFound,
                            "DataNotFound reading Azure storage table {0}:{1} HTTP status code={2} REST status code={3} Exception={4}",
                            tableName,
                            iteration == 0 ? "" : (" Repeat=" + iteration),
                            httpStatusCode,
                            restStatus,
                            exc);

                        isLastErrorRetriable = false;
                    }
                    else
                    {
                        isLastErrorRetriable = IsRetriableHttpError(httpStatusCode, restStatus);

                        logger.Warn(ErrorCode.AzureTable_11, String.Format("Intermediate issue reading Azure storage table {0}:{1} IsRetriable={2} HTTP status code={3} REST status code={4} Exception Type={5} Message='{6}'",
                                tableName,
                                iteration == 0 ? "" : (" Repeat=" + iteration),
                                isLastErrorRetriable,
                                httpStatusCode,
                                restStatus,
                                exc.GetType().FullName,
                                exc.Message),
                                exc);
                    }
                }
                else
                {
                    logger.Error(ErrorCode.AzureTable_12, string.Format("Unexpected issue reading Azure storage table {0}: Exception Type={1} Message='{2}'",
                                     tableName,
                                     exc.GetType().FullName,
                                     exc.Message),
                                 exc);
                    isLastErrorRetriable = false;
                }
            }
            return isLastErrorRetriable;
        }
Ejemplo n.º 9
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());
                }
            }
        }
Ejemplo n.º 10
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");
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Extracting the data from the stream
        /// </summary>
        public override void extractData()
        {
            BiffHeader bh, latestbiff;
            BOF        firstBOF = null;

            //try
            //{
            while (this.StreamReader.BaseStream.Position < this.StreamReader.BaseStream.Length)
            {
                bh.id     = (RecordType)this.StreamReader.ReadUInt16();
                bh.length = this.StreamReader.ReadUInt16();

                TraceLogger.DebugInternal("BIFF {0}\t{1}\t", bh.id, bh.length);

                switch (bh.id)
                {
                case RecordType.EOF:
                {
                    this.StreamReader.BaseStream.Seek(0, SeekOrigin.End);
                }
                break;

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

                    switch (bof.docType)
                    {
                    case BOF.DocumentType.WorkbookGlobals:
                    case BOF.DocumentType.Worksheet:
                        firstBOF = bof;
                        break;

                    case BOF.DocumentType.Chart:
                        // parse chart

                        break;

                    default:
                        this.readUnkownFile();
                        break;
                    }
                }
                break;

                case RecordType.LabelSst:
                {
                    LabelSst labelsst = new LabelSst(this.StreamReader, bh.id, bh.length);
                    this.bsd.addLabelSST(labelsst);
                }
                break;

                case RecordType.MulRk:
                {
                    MulRk mulrk = new MulRk(this.StreamReader, bh.id, bh.length);
                    this.bsd.addMULRK(mulrk);
                }
                break;

                case RecordType.Number:
                {
                    Number number = new Number(this.StreamReader, bh.id, bh.length);
                    this.bsd.addNUMBER(number);
                }
                break;

                case RecordType.RK:
                {
                    RK rk = new RK(this.StreamReader, bh.id, bh.length);
                    this.bsd.addRK(rk);
                }
                break;

                case RecordType.MergeCells:
                {
                    MergeCells mergecells = new MergeCells(this.StreamReader, bh.id, bh.length);
                    this.bsd.MERGECELLSData = mergecells;
                }
                break;

                case RecordType.Blank:
                {
                    Blank blankcell = new Blank(this.StreamReader, bh.id, bh.length);
                    this.bsd.addBLANK(blankcell);
                } break;

                case RecordType.MulBlank:
                {
                    MulBlank mulblank = new MulBlank(this.StreamReader, bh.id, bh.length);
                    this.bsd.addMULBLANK(mulblank);
                }
                break;

                case RecordType.Formula:
                {
                    Formula formula = new Formula(this.StreamReader, bh.id, bh.length);
                    this.bsd.addFORMULA(formula);
                    TraceLogger.DebugInternal(formula.ToString());
                }
                break;

                case RecordType.Array:
                {
                    ARRAY array = new ARRAY(this.StreamReader, bh.id, bh.length);
                    this.bsd.addARRAY(array);
                }
                break;

                case RecordType.ShrFmla:
                {
                    ShrFmla shrfmla = new ShrFmla(this.StreamReader, bh.id, bh.length);
                    this.bsd.addSharedFormula(shrfmla);
                }
                break;

                case RecordType.String:
                {
                    STRING formulaString = new STRING(this.StreamReader, bh.id, bh.length);
                    this.bsd.addFormulaString(formulaString.value);
                }
                break;

                case RecordType.Row:
                {
                    Row row = new Row(this.StreamReader, bh.id, bh.length);
                    this.bsd.addRowData(row);
                }
                break;

                case RecordType.ColInfo:
                {
                    ColInfo colinfo = new ColInfo(this.StreamReader, bh.id, bh.length);
                    this.bsd.addColData(colinfo);
                }
                break;

                case RecordType.DefColWidth:
                {
                    DefColWidth defcolwidth = new DefColWidth(this.StreamReader, bh.id, bh.length);
                    this.bsd.addDefaultColWidth(defcolwidth.cchdefColWidth);
                }
                break;

                case RecordType.DefaultRowHeight:
                {
                    DefaultRowHeight defrowheigth = new DefaultRowHeight(this.StreamReader, bh.id, bh.length);
                    this.bsd.addDefaultRowData(defrowheigth);
                }
                break;

                case RecordType.LeftMargin:
                {
                    LeftMargin leftm = new LeftMargin(this.StreamReader, bh.id, bh.length);
                    this.bsd.leftMargin = leftm.value;
                }
                break;

                case RecordType.RightMargin:
                {
                    RightMargin rightm = new RightMargin(this.StreamReader, bh.id, bh.length);
                    this.bsd.rightMargin = rightm.value;
                }
                break;

                case RecordType.TopMargin:
                {
                    TopMargin topm = new TopMargin(this.StreamReader, bh.id, bh.length);
                    this.bsd.topMargin = topm.value;
                }
                break;

                case RecordType.BottomMargin:
                {
                    BottomMargin bottomm = new BottomMargin(this.StreamReader, bh.id, bh.length);
                    this.bsd.bottomMargin = bottomm.value;
                }
                break;

                case RecordType.Setup:
                {
                    Setup setup = new Setup(this.StreamReader, bh.id, bh.length);
                    this.bsd.addSetupData(setup);
                }
                break;

                case RecordType.HLink:
                {
                    long oldStreamPos = this.StreamReader.BaseStream.Position;
                    try
                    {
                        HLink hlink = new HLink(this.StreamReader, bh.id, bh.length);
                        bsd.addHyperLinkData(hlink);
                    }
                    catch (Exception ex)
                    {
                        this.StreamReader.BaseStream.Seek(oldStreamPos, System.IO.SeekOrigin.Begin);
                        this.StreamReader.BaseStream.Seek(bh.length, System.IO.SeekOrigin.Current);
                        TraceLogger.Debug("Link parse error");
                        TraceLogger.Error(ex.StackTrace);
                    }
                }
                break;

                case RecordType.MsoDrawing:
                {
                    // Record header has already been read. Reset position to record beginning.
                    this.StreamReader.BaseStream.Position -= 2 * sizeof(UInt16);
                    this.bsd.ObjectsSequence = new ObjectsSequence(this.StreamReader);
                }
                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);
                }
                break;
                }
                latestbiff = bh;
            }
            //}
            //catch (Exception ex)
            //{
            //    TraceLogger.Error(ex.Message);
            //    TraceLogger.Error(ex.StackTrace);
            //    TraceLogger.Debug(ex.ToString());
            //}
        }
Ejemplo n.º 12
0
        internal static bool AnalyzeReadException(Exception exc, int iteration, string tableName, TraceLogger logger)
        {
            bool isLastErrorRetriable;
            var  we = exc as WebException;

            if (we != null)
            {
                isLastErrorRetriable = true;
                var statusCode = we.Status;
                logger.Warn(ErrorCode.AzureTable_10, String.Format("Intermediate issue reading Azure storage table {0}: HTTP status code={1} Exception Type={2} Message='{3}'",
                                                                   tableName,
                                                                   statusCode,
                                                                   exc.GetType().FullName,
                                                                   exc.Message),
                            exc);
            }
            else
            {
                HttpStatusCode httpStatusCode;
                string         restStatus;
                if (EvaluateException(exc, out httpStatusCode, out restStatus, true))
                {
                    if (StorageErrorCodeStrings.ResourceNotFound.Equals(restStatus))
                    {
                        if (logger.IsVerbose)
                        {
                            logger.Verbose(ErrorCode.AzureTable_DataNotFound,
                                           "DataNotFound reading Azure storage table {0}:{1} HTTP status code={2} REST status code={3} Exception={4}",
                                           tableName,
                                           iteration == 0 ? "" : (" Repeat=" + iteration),
                                           httpStatusCode,
                                           restStatus,
                                           exc);
                        }

                        isLastErrorRetriable = false;
                    }
                    else
                    {
                        isLastErrorRetriable = IsRetriableHttpError(httpStatusCode, restStatus);

                        logger.Warn(ErrorCode.AzureTable_11, String.Format("Intermediate issue reading Azure storage table {0}:{1} IsRetriable={2} HTTP status code={3} REST status code={4} Exception Type={5} Message='{6}'",
                                                                           tableName,
                                                                           iteration == 0 ? "" : (" Repeat=" + iteration),
                                                                           isLastErrorRetriable,
                                                                           httpStatusCode,
                                                                           restStatus,
                                                                           exc.GetType().FullName,
                                                                           exc.Message),
                                    exc);
                    }
                }
                else
                {
                    logger.Error(ErrorCode.AzureTable_12, string.Format("Unexpected issue reading Azure storage table {0}: Exception Type={1} Message='{2}'",
                                                                        tableName,
                                                                        exc.GetType().FullName,
                                                                        exc.Message),
                                 exc);
                    isLastErrorRetriable = false;
                }
            }
            return(isLastErrorRetriable);
        }
        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);
        }
Ejemplo n.º 14
0
        internal void ValidateConfiguration(TraceLogger logger)
        {
            if (AreDefaults) return;

            Type type = null;               
            try
            {
                type = TypeUtils.ResolveType(FullTypeName);
            }
            catch (Exception exception)
            {
                string errStr = String.Format("Unable to find grain class type {0} specified in configuration; Failing silo startup.", FullTypeName);
                logger.Error(ErrorCode.Loader_TypeLoadError, errStr, exception);
                throw new OrleansException(errStr, exception);
            }

            if (type == null)
            {
                string errStr = String.Format("Unable to find grain class type {0} specified in configuration; Failing silo startup.", FullTypeName);
                logger.Error(ErrorCode.Loader_TypeLoadError_2, errStr);
                throw new OrleansException(errStr);
            }
            var typeInfo = type.GetTypeInfo();
            // postcondition: returned type must implement IGrain.
            if (!typeof(IGrain).GetTypeInfo().IsAssignableFrom(type))
            {
                string errStr = String.Format("Type {0} must implement IGrain to be used Application configuration context.",type.FullName);
                logger.Error(ErrorCode.Loader_TypeLoadError_3, errStr);
                throw new OrleansException(errStr);
            }
            // postcondition: returned type must either be an interface or a class.
            
            if (!typeInfo.IsInterface && !typeInfo.IsClass)
            {
                string errStr = String.Format("Type {0} must either be an interface or class used Application configuration context.",type.FullName);
                logger.Error(ErrorCode.Loader_TypeLoadError_4, errStr);
                throw new OrleansException(errStr);
            }
        }
Ejemplo n.º 15
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;
            }
        }
Ejemplo n.º 16
0
        public static bool CheckTimerDelay(DateTime previousTickTime, int totalNumTicks, 
                        TimeSpan dueTime, TimeSpan timerFrequency, TraceLogger logger, Func<string> getName, ErrorCode errorCode, bool freezeCheck)
        {
            TimeSpan timeSinceLastTick = DateTime.UtcNow - previousTickTime;
            TimeSpan exceptedTimeToNexTick = totalNumTicks == 0 ? dueTime : timerFrequency;
            TimeSpan exceptedTimeWithSlack;
            if (exceptedTimeToNexTick >= TimeSpan.FromSeconds(6))
            {
                exceptedTimeWithSlack = exceptedTimeToNexTick + TimeSpan.FromSeconds(3);
            }
            else
            {
                exceptedTimeWithSlack = exceptedTimeToNexTick.Multiply(1.5);
            }
            if (timeSinceLastTick <= exceptedTimeWithSlack) return true;

            // did not tick in the last period.
            var errMsg = String.Format("{0}{1} did not fire on time. Last fired at {2}, {3} since previous fire, should have fired after {4}.",
                freezeCheck ? "Watchdog Freeze Alert: " : "-", // 0
                getName == null ? "" : getName(),   // 1
                TraceLogger.PrintDate(previousTickTime), // 2
                timeSinceLastTick,                  // 3
                exceptedTimeToNexTick);             // 4

            if(freezeCheck)
            {
                logger.Error(errorCode, errMsg);
            }else
            {
                logger.Warn(errorCode, errMsg);
            }
            return false;
        }
Ejemplo n.º 17
0
 private void UnhandledException(ISchedulingContext context, Exception exception)
 {
     logger.Error(ErrorCode.Runtime_Error_100007, String.Format("OutsideRuntimeClient caught an UnobservedException."), exception);
     logger.Assert(ErrorCode.Runtime_Error_100008, context == null, "context should be not null only inside OrleansRuntime and not on the client.");
 }
Ejemplo n.º 18
0
 internal static CloudQueueClient GetCloudQueueClient(
     string storageConnectionString,
     IRetryPolicy retryPolicy,
     TimeSpan timeout,
     TraceLogger logger)
 {
     try
     {
         var storageAccount = GetCloudStorageAccount(storageConnectionString);
         CloudQueueClient operationsClient = storageAccount.CreateCloudQueueClient();
         operationsClient.DefaultRequestOptions.RetryPolicy = retryPolicy;
         operationsClient.DefaultRequestOptions.ServerTimeout = timeout;
         return operationsClient;
     }
     catch (Exception exc)
     {
         logger.Error(ErrorCode.AzureQueue_14, String.Format("Error creating GetCloudQueueOperationsClient."), exc);
         throw;
     }
 }
Ejemplo n.º 19
0
        /// <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.GetConfigurationForNode(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 (config.Globals.ReminderServiceType == GlobalConfiguration.ReminderServiceProviderType.NotSpecified ||
                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());
        }
Ejemplo n.º 20
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;
            }
        }
Ejemplo n.º 21
0
        public void FinishStep(StepExecutionEndingRequest request)
        {
            var key = GetStepKey(request.CurrentExecutionInfo, request.CurrentExecutionInfo.CurrentSpec, request.CurrentExecutionInfo.CurrentScenario, request.CurrentExecutionInfo.CurrentStep);

            TraceLogger.Verbose($"Finishing step with key: {key}");
            var stepReporter = _steps[key];

            var stepStatus = Status.Passed;

            // process gauge log messages
            var logMessages = request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.Message;

            if (logMessages != null)
            {
                foreach (var logMessage in logMessages)
                {
                    stepReporter.Log(new CreateLogItemRequest
                    {
                        Text  = logMessage,
                        Level = LogLevel.Debug,
                        Time  = DateTime.UtcNow
                    });
                }
            }

            // todo it's never skipped
            if (request.StepResult.ProtoItem.Step.StepExecutionResult.Skipped)
            {
                stepStatus = Status.Skipped;

                stepReporter.Log(new CreateLogItemRequest
                {
                    Time  = DateTime.UtcNow,
                    Level = LogLevel.Info,
                    Text  = $"Skip reason: {request.StepResult.ProtoItem.Step.StepExecutionResult.SkippedReason}"
                });
            }
            ;

            if (request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.Failed)
            {
                stepStatus = Status.Failed;

                stepReporter.Log(new CreateLogItemRequest
                {
                    Time  = DateTime.UtcNow,
                    Level = LogLevel.Error,
                    Text  = $"{request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.ErrorMessage}{Environment.NewLine}{Environment.NewLine}{request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.StackTrace}"
                });
            }

            try
            {
                var failureScreenshotFile = request.StepResult.ProtoItem.Step.StepExecutionResult.ExecutionResult.FailureScreenshotFile;
                if (!string.IsNullOrEmpty(failureScreenshotFile))
                {
                    stepReporter.Log(new CreateLogItemRequest
                    {
                        Time   = DateTime.UtcNow,
                        Level  = LogLevel.Error,
                        Text   = "Screenshot",
                        Attach = new Attach
                        {
                            Name     = "screenshot",
                            MimeType = Shared.MimeTypes.MimeTypeMap.GetMimeType(Path.GetExtension(failureScreenshotFile)),
                            Data     = File.ReadAllBytes(Path.Combine(_gaugeScreenshotsDir, failureScreenshotFile))
                        }
                    });
                }
            }
            catch (Exception exp)
            {
                TraceLogger.Error($"Couldn't parse failure step screenshot. {exp}");
            }

            // post hook messages
            if (request.StepResult.ProtoItem.Step.PostHookMessages.Count != 0)
            {
                foreach (var postHookMessage in request.StepResult.ProtoItem.Step.PostHookMessages)
                {
                    stepReporter.Log(new CreateLogItemRequest
                    {
                        Level = LogLevel.Debug,
                        Text  = postHookMessage,
                        Time  = DateTime.UtcNow
                    });
                }
            }

            stepReporter.Finish(new FinishTestItemRequest
            {
                EndTime = DateTime.UtcNow,
                Status  = stepStatus
            });

            _steps.TryRemove(key, out _);
        }